2019-12-25 02:45:57 +00:00
|
|
|
/*
|
2021-01-01 19:50:41 +00:00
|
|
|
* Copyright (C) 2019-2021 Yomichan Authors
|
2019-12-25 02:45:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-02-26 01:21:05 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-12-25 02:45:57 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-11 02:30:36 +00:00
|
|
|
/* global
|
2020-07-31 00:45:52 +00:00
|
|
|
* DictionaryDataUtil
|
2020-10-08 00:47:44 +00:00
|
|
|
* HtmlTemplateCollection
|
2021-07-17 14:26:20 +00:00
|
|
|
* PronunciationGenerator
|
2021-06-26 18:40:37 +00:00
|
|
|
* StructuredContentGenerator
|
2020-03-11 02:30:36 +00:00
|
|
|
*/
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
class DisplayGenerator {
|
2021-01-20 01:48:10 +00:00
|
|
|
constructor({japaneseUtil, mediaLoader, hotkeyHelpController=null}) {
|
2020-11-29 18:09:02 +00:00
|
|
|
this._japaneseUtil = japaneseUtil;
|
2020-04-11 18:23:49 +00:00
|
|
|
this._mediaLoader = mediaLoader;
|
2021-01-18 20:23:49 +00:00
|
|
|
this._hotkeyHelpController = hotkeyHelpController;
|
2020-10-08 00:47:44 +00:00
|
|
|
this._templates = null;
|
2021-06-26 19:49:23 +00:00
|
|
|
this._structuredContentGenerator = new StructuredContentGenerator(this._mediaLoader, document);
|
2021-07-17 14:26:20 +00:00
|
|
|
this._pronunciationGenerator = new PronunciationGenerator(japaneseUtil);
|
2019-12-27 23:58:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:43:01 +00:00
|
|
|
async prepare() {
|
2021-02-14 20:53:35 +00:00
|
|
|
const html = await yomichan.api.getDisplayTemplatesHtml();
|
2020-10-08 00:47:44 +00:00
|
|
|
this._templates = new HtmlTemplateCollection(html);
|
2021-01-18 20:23:49 +00:00
|
|
|
this.updateHotkeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHotkeys() {
|
|
|
|
const hotkeyHelpController = this._hotkeyHelpController;
|
2021-01-20 01:48:10 +00:00
|
|
|
if (hotkeyHelpController === null) { return; }
|
2021-01-18 20:23:49 +00:00
|
|
|
for (const template of this._templates.getAllTemplates()) {
|
|
|
|
hotkeyHelpController.setupNode(template.content);
|
|
|
|
}
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
createTermEntry(dictionaryEntry) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('term-entry');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
const headwordsContainer = node.querySelector('.headword-list');
|
2021-04-04 20:22:35 +00:00
|
|
|
const inflectionsContainer = node.querySelector('.inflection-list');
|
2021-07-26 23:45:30 +00:00
|
|
|
const groupedPronunciationsContainer = node.querySelector('.pronunciation-group-list');
|
2021-01-09 15:41:17 +00:00
|
|
|
const frequencyGroupListContainer = node.querySelector('.frequency-group-list');
|
2021-02-27 21:32:44 +00:00
|
|
|
const definitionsContainer = node.querySelector('.definition-list');
|
2021-04-08 23:59:55 +00:00
|
|
|
const headwordTagsContainer = node.querySelector('.headword-list-tag-list');
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
const {headwords, type, inflections, definitions, frequencies, pronunciations} = dictionaryEntry;
|
2021-07-26 23:45:30 +00:00
|
|
|
const groupedPronunciations = DictionaryDataUtil.getGroupedPronunciations(dictionaryEntry);
|
|
|
|
const pronunciationCount = groupedPronunciations.reduce((i, v) => i + v.pronunciations.length, 0);
|
2021-04-04 20:22:35 +00:00
|
|
|
const groupedFrequencies = DictionaryDataUtil.groupTermFrequencies(dictionaryEntry);
|
|
|
|
const termTags = DictionaryDataUtil.groupTermTags(dictionaryEntry);
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
const uniqueTerms = new Set();
|
2020-11-24 16:56:40 +00:00
|
|
|
const uniqueReadings = new Set();
|
2021-04-04 20:22:35 +00:00
|
|
|
for (const {term, reading} of headwords) {
|
|
|
|
uniqueTerms.add(term);
|
2020-11-24 16:56:40 +00:00
|
|
|
uniqueReadings.add(reading);
|
|
|
|
}
|
|
|
|
|
2020-11-14 00:48:22 +00:00
|
|
|
node.dataset.format = type;
|
2021-04-08 23:59:55 +00:00
|
|
|
node.dataset.headwordCount = `${headwords.length}`;
|
2020-11-14 00:48:22 +00:00
|
|
|
node.dataset.definitionCount = `${definitions.length}`;
|
2021-07-26 23:45:30 +00:00
|
|
|
node.dataset.pronunciationDictionaryCount = `${groupedPronunciations.length}`;
|
|
|
|
node.dataset.pronunciationCount = `${pronunciationCount}`;
|
2021-04-08 23:59:55 +00:00
|
|
|
node.dataset.uniqueTermCount = `${uniqueTerms.size}`;
|
2020-11-24 16:56:40 +00:00
|
|
|
node.dataset.uniqueReadingCount = `${uniqueReadings.size}`;
|
2021-01-09 15:41:17 +00:00
|
|
|
node.dataset.frequencyCount = `${frequencies.length}`;
|
|
|
|
node.dataset.groupedFrequencyCount = `${groupedFrequencies.length}`;
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
for (let i = 0, ii = headwords.length; i < ii; ++i) {
|
|
|
|
const node2 = this._createTermHeadword(headwords[i], i, pronunciations);
|
2021-03-25 23:55:31 +00:00
|
|
|
node2.dataset.index = `${i}`;
|
2021-04-04 20:22:35 +00:00
|
|
|
headwordsContainer.appendChild(node2);
|
2021-03-25 23:55:31 +00:00
|
|
|
}
|
2021-04-04 20:22:35 +00:00
|
|
|
headwordsContainer.dataset.count = `${headwords.length}`;
|
2021-03-25 23:55:31 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
this._appendMultiple(inflectionsContainer, this._createTermInflection.bind(this), inflections);
|
2021-01-09 15:41:17 +00:00
|
|
|
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false);
|
2021-07-26 23:45:30 +00:00
|
|
|
this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations);
|
2021-04-08 23:59:55 +00:00
|
|
|
this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length);
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
for (const term of uniqueTerms) {
|
2021-04-08 23:59:55 +00:00
|
|
|
headwordTagsContainer.appendChild(this._createSearchTag(term));
|
2021-02-17 02:19:52 +00:00
|
|
|
}
|
|
|
|
for (const reading of uniqueReadings) {
|
2021-04-04 20:22:35 +00:00
|
|
|
if (uniqueTerms.has(reading)) { continue; }
|
2021-04-08 23:59:55 +00:00
|
|
|
headwordTagsContainer.appendChild(this._createSearchTag(reading));
|
2021-02-17 02:19:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 02:33:30 +00:00
|
|
|
// Add definitions
|
|
|
|
const dictionaryTag = this._createDictionaryTag(null);
|
|
|
|
for (let i = 0, ii = definitions.length; i < ii; ++i) {
|
|
|
|
const definition = definitions[i];
|
|
|
|
const {dictionary} = definition;
|
|
|
|
|
|
|
|
if (dictionaryTag.dictionary === dictionary) {
|
|
|
|
dictionaryTag.redundant = true;
|
|
|
|
} else {
|
|
|
|
dictionaryTag.redundant = false;
|
|
|
|
dictionaryTag.dictionary = dictionary;
|
|
|
|
dictionaryTag.name = dictionary;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
const node2 = this._createTermDefinition(definition, dictionaryTag, headwords, uniqueTerms, uniqueReadings);
|
2021-01-29 02:33:30 +00:00
|
|
|
node2.dataset.index = `${i}`;
|
|
|
|
definitionsContainer.appendChild(node2);
|
|
|
|
}
|
|
|
|
definitionsContainer.dataset.count = `${definitions.length}`;
|
|
|
|
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
createKanjiEntry(dictionaryEntry) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('kanji-entry');
|
2020-04-10 02:03:16 +00:00
|
|
|
|
|
|
|
const glyphContainer = node.querySelector('.kanji-glyph');
|
2021-01-09 15:41:17 +00:00
|
|
|
const frequencyGroupListContainer = node.querySelector('.frequency-group-list');
|
2021-02-27 21:32:44 +00:00
|
|
|
const tagContainer = node.querySelector('.kanji-tag-list');
|
2021-04-08 23:59:55 +00:00
|
|
|
const definitionsContainer = node.querySelector('.kanji-gloss-list');
|
2020-04-10 02:03:16 +00:00
|
|
|
const chineseReadingsContainer = node.querySelector('.kanji-readings-chinese');
|
|
|
|
const japaneseReadingsContainer = node.querySelector('.kanji-readings-japanese');
|
|
|
|
const statisticsContainer = node.querySelector('.kanji-statistics');
|
|
|
|
const classificationsContainer = node.querySelector('.kanji-classifications');
|
|
|
|
const codepointsContainer = node.querySelector('.kanji-codepoints');
|
|
|
|
const dictionaryIndicesContainer = node.querySelector('.kanji-dictionary-indices');
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
this._setTextContent(glyphContainer, dictionaryEntry.character, 'ja');
|
|
|
|
const groupedFrequencies = DictionaryDataUtil.groupKanjiFrequencies(dictionaryEntry.frequencies);
|
2020-01-29 00:06:50 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
const dictionaryTag = this._createDictionaryTag(dictionaryEntry.dictionary);
|
2021-01-29 02:33:30 +00:00
|
|
|
|
2021-01-09 15:41:17 +00:00
|
|
|
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true);
|
2021-04-04 20:22:35 +00:00
|
|
|
this._appendMultiple(tagContainer, this._createTag.bind(this), [...dictionaryEntry.tags, dictionaryTag]);
|
|
|
|
this._appendMultiple(definitionsContainer, this._createKanjiDefinition.bind(this), dictionaryEntry.definitions);
|
|
|
|
this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.onyomi);
|
|
|
|
this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), dictionaryEntry.kunyomi);
|
2020-04-10 02:03:16 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
statisticsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.misc));
|
|
|
|
classificationsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.class));
|
|
|
|
codepointsContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.code));
|
|
|
|
dictionaryIndicesContainer.appendChild(this._createKanjiInfoTable(dictionaryEntry.stats.index));
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:43:54 +00:00
|
|
|
createEmptyFooterNotification() {
|
|
|
|
return this._templates.instantiate('footer-notification');
|
|
|
|
}
|
|
|
|
|
2021-03-26 00:54:39 +00:00
|
|
|
createTagFooterNotificationDetails(tagNode, dictionaryEntry) {
|
2021-01-09 21:02:03 +00:00
|
|
|
const node = this._templates.instantiateFragment('footer-notification-tag-details');
|
|
|
|
|
2021-02-28 19:44:44 +00:00
|
|
|
let details = tagNode.dataset.details;
|
|
|
|
if (typeof details !== 'string') {
|
|
|
|
const label = tagNode.querySelector('.tag-label-content');
|
|
|
|
details = label !== null ? label.textContent : '';
|
|
|
|
}
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node.querySelector('.tag-details'), details);
|
2021-01-09 21:02:03 +00:00
|
|
|
|
2021-03-26 00:54:39 +00:00
|
|
|
if (dictionaryEntry !== null) {
|
|
|
|
const {headwords} = dictionaryEntry;
|
|
|
|
const disambiguationHeadwords = [];
|
|
|
|
const {headwords: headwordIndices} = tagNode.dataset;
|
|
|
|
if (typeof headwordIndices === 'string' && headwordIndices.length > 0) {
|
|
|
|
for (let headwordIndex of headwordIndices.split(' ')) {
|
|
|
|
headwordIndex = Number.parseInt(headwordIndex, 10);
|
|
|
|
if (!Number.isNaN(headwordIndex) && headwordIndex >= 0 && headwordIndex < headwords.length) {
|
|
|
|
disambiguationHeadwords.push(headwords[headwordIndex]);
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 21:02:03 +00:00
|
|
|
}
|
|
|
|
|
2021-03-26 00:54:39 +00:00
|
|
|
if (disambiguationHeadwords.length > 0 && disambiguationHeadwords.length < headwords.length) {
|
|
|
|
const disambiguationContainer = node.querySelector('.tag-details-disambiguation-list');
|
2021-04-08 23:59:55 +00:00
|
|
|
const copyAttributes = ['totalHeadwordCount', 'matchedHeadwordCount', 'unmatchedHeadwordCount'];
|
2021-03-26 00:54:39 +00:00
|
|
|
for (const attribute of copyAttributes) {
|
|
|
|
const value = tagNode.dataset[attribute];
|
|
|
|
if (typeof value === 'undefined') { continue; }
|
|
|
|
disambiguationContainer.dataset[attribute] = value;
|
|
|
|
}
|
|
|
|
for (const {term, reading} of disambiguationHeadwords) {
|
|
|
|
const disambiguationItem = document.createElement('span');
|
|
|
|
disambiguationItem.className = 'tag-details-disambiguation';
|
|
|
|
this._appendFurigana(disambiguationItem, term, reading, (container, text) => {
|
|
|
|
container.appendChild(document.createTextNode(text));
|
|
|
|
});
|
|
|
|
disambiguationContainer.appendChild(disambiguationItem);
|
|
|
|
}
|
2021-01-09 21:02:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-01-30 17:33:29 +00:00
|
|
|
createAnkiNoteErrorsNotificationContent(errors) {
|
|
|
|
const content = this._templates.instantiate('footer-notification-anki-errors-content');
|
|
|
|
|
|
|
|
const header = content.querySelector('.anki-note-error-header');
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(header, (errors.length === 1 ? 'An error occurred:' : `${errors.length} errors occurred:`), 'en');
|
2021-01-30 17:33:29 +00:00
|
|
|
|
|
|
|
const list = content.querySelector('.anki-note-error-list');
|
|
|
|
for (const error of errors) {
|
|
|
|
const div = document.createElement('li');
|
|
|
|
div.className = 'anki-note-error-message';
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(div, isObject(error) && typeof error.message === 'string' ? error.message : `${error}`);
|
2021-01-30 17:33:29 +00:00
|
|
|
list.appendChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2020-12-30 04:38:44 +00:00
|
|
|
createProfileListItem() {
|
|
|
|
return this._templates.instantiate('profile-list-item');
|
|
|
|
}
|
|
|
|
|
2021-02-15 19:31:16 +00:00
|
|
|
instantiateTemplate(name) {
|
|
|
|
return this._templates.instantiate(name);
|
2021-01-24 02:13:01 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 02:03:16 +00:00
|
|
|
// Private
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermHeadword(headword, headwordIndex, pronunciations) {
|
|
|
|
const {term, reading, tags} = headword;
|
2020-11-14 18:42:50 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
const node = this._templates.instantiate('headword');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
const termContainer = node.querySelector('.headword-term');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
node.dataset.readingIsSame = `${reading === term}`;
|
|
|
|
node.dataset.frequency = DictionaryDataUtil.getTermFrequency(tags);
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-03-26 23:50:54 +00:00
|
|
|
const {wordClasses} = headword;
|
2021-07-25 22:16:07 +00:00
|
|
|
const pronunciationCategories = this._getPronunciationCategories(reading, pronunciations, wordClasses, headwordIndex);
|
|
|
|
if (pronunciationCategories !== null) {
|
|
|
|
node.dataset.pronunciationCategories = pronunciationCategories;
|
2021-02-28 18:26:34 +00:00
|
|
|
}
|
2021-03-26 23:50:54 +00:00
|
|
|
if (wordClasses.length > 0) {
|
|
|
|
node.dataset.wordClasses = wordClasses.join(' ');
|
|
|
|
}
|
2021-02-28 18:26:34 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
this._setTextContent(node.querySelector('.headword-reading'), reading);
|
2021-02-08 22:52:35 +00:00
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
this._appendFurigana(termContainer, term, reading, this._appendKanjiLinks.bind(this));
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermInflection(inflection) {
|
2021-02-27 21:32:44 +00:00
|
|
|
const fragment = this._templates.instantiateFragment('inflection');
|
|
|
|
const node = fragment.querySelector('.inflection');
|
2021-04-04 20:22:35 +00:00
|
|
|
this._setTextContent(node, inflection);
|
|
|
|
node.dataset.reason = inflection;
|
2020-01-30 01:47:24 +00:00
|
|
|
return fragment;
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermDefinition(definition, dictionaryTag, headwords, uniqueTerms, uniqueReadings) {
|
|
|
|
const {dictionary, tags, headwordIndices, entries} = definition;
|
2021-03-25 23:55:31 +00:00
|
|
|
const disambiguations = DictionaryDataUtil.getDisambiguations(headwords, headwordIndices, uniqueTerms, uniqueReadings);
|
|
|
|
|
2021-02-27 21:32:44 +00:00
|
|
|
const node = this._templates.instantiate('definition-item');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-02-27 21:32:44 +00:00
|
|
|
const tagListContainer = node.querySelector('.definition-tag-list');
|
|
|
|
const onlyListContainer = node.querySelector('.definition-disambiguation-list');
|
2021-04-08 23:59:55 +00:00
|
|
|
const entriesContainer = node.querySelector('.gloss-list');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2020-04-11 18:23:49 +00:00
|
|
|
node.dataset.dictionary = dictionary;
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
this._appendMultiple(tagListContainer, this._createTag.bind(this), [...tags, dictionaryTag]);
|
|
|
|
this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), disambiguations);
|
2021-04-04 20:22:35 +00:00
|
|
|
this._appendMultiple(entriesContainer, this._createTermDefinitionEntry.bind(this), entries, dictionary);
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermDefinitionEntry(entry, dictionary) {
|
|
|
|
if (typeof entry === 'string') {
|
|
|
|
return this._createTermDefinitionEntryText(entry);
|
|
|
|
} else if (typeof entry === 'object' && entry !== null) {
|
|
|
|
switch (entry.type) {
|
2020-04-11 18:23:49 +00:00
|
|
|
case 'image':
|
2021-04-04 20:22:35 +00:00
|
|
|
return this._createTermDefinitionEntryImage(entry, dictionary);
|
2021-05-19 22:24:50 +00:00
|
|
|
case 'structured-content':
|
|
|
|
return this._createTermDefinitionEntryStructuredContent(entry.content, dictionary);
|
2020-04-11 18:23:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermDefinitionEntryText(text) {
|
2021-04-08 23:59:55 +00:00
|
|
|
const node = this._templates.instantiate('gloss-item');
|
|
|
|
const container = node.querySelector('.gloss-content');
|
2021-04-04 20:22:35 +00:00
|
|
|
this._setMultilineTextContent(container, text);
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermDefinitionEntryImage(data, dictionary) {
|
2021-05-18 21:41:27 +00:00
|
|
|
const {description} = data;
|
|
|
|
|
|
|
|
const node = this._templates.instantiate('gloss-item');
|
|
|
|
|
|
|
|
const contentContainer = node.querySelector('.gloss-content');
|
2021-06-26 18:40:37 +00:00
|
|
|
const image = this._structuredContentGenerator.createDefinitionImage(data, dictionary);
|
2021-05-18 21:41:27 +00:00
|
|
|
contentContainer.appendChild(image);
|
|
|
|
|
|
|
|
if (typeof description === 'string') {
|
|
|
|
const fragment = this._templates.instantiateFragment('gloss-item-image-description');
|
|
|
|
const container = fragment.querySelector('.gloss-image-description');
|
|
|
|
this._setMultilineTextContent(container, description);
|
|
|
|
contentContainer.appendChild(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-05-19 22:24:50 +00:00
|
|
|
_createTermDefinitionEntryStructuredContent(content, dictionary) {
|
|
|
|
const node = this._templates.instantiate('gloss-item');
|
2021-06-26 18:40:37 +00:00
|
|
|
const child = this._structuredContentGenerator.createStructuredContent(content, dictionary);
|
2021-05-19 22:24:50 +00:00
|
|
|
if (child !== null) {
|
|
|
|
const contentContainer = node.querySelector('.gloss-content');
|
|
|
|
contentContainer.appendChild(child);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:19:58 +00:00
|
|
|
_createTermDisambiguation(disambiguation) {
|
2021-02-27 21:32:44 +00:00
|
|
|
const node = this._templates.instantiate('definition-disambiguation');
|
2020-04-10 02:19:58 +00:00
|
|
|
node.dataset.term = disambiguation;
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node, disambiguation, 'ja');
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
_createKanjiLink(character) {
|
2019-12-25 02:45:57 +00:00
|
|
|
const node = document.createElement('a');
|
2021-04-08 23:59:55 +00:00
|
|
|
node.className = 'headword-kanji-link';
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node, character, 'ja');
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createKanjiDefinition(text) {
|
2021-04-08 23:59:55 +00:00
|
|
|
const node = this._templates.instantiate('kanji-gloss-item');
|
|
|
|
const container = node.querySelector('.kanji-gloss-content');
|
2021-04-04 20:22:35 +00:00
|
|
|
this._setMultilineTextContent(container, text);
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
_createKanjiReading(reading) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('kanji-reading');
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node, reading, 'ja');
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
_createKanjiInfoTable(details) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('kanji-info-table');
|
2019-12-25 02:45:57 +00:00
|
|
|
const container = node.querySelector('.kanji-info-table-body');
|
|
|
|
|
2020-11-14 18:42:50 +00:00
|
|
|
const count = this._appendMultiple(container, this._createKanjiInfoTableItem.bind(this), details);
|
|
|
|
if (count === 0) {
|
|
|
|
const n = this._createKanjiInfoTableItemEmpty();
|
|
|
|
container.appendChild(n);
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
_createKanjiInfoTableItem(details) {
|
2021-03-25 23:55:31 +00:00
|
|
|
const {content, name, value} = details;
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('kanji-info-table-item');
|
2019-12-25 02:45:57 +00:00
|
|
|
const nameNode = node.querySelector('.kanji-info-table-item-header');
|
|
|
|
const valueNode = node.querySelector('.kanji-info-table-item-value');
|
2021-03-25 23:55:31 +00:00
|
|
|
this._setTextContent(nameNode, content.length > 0 ? content : name);
|
|
|
|
this._setTextContent(valueNode, value);
|
2019-12-25 02:45:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
_createKanjiInfoTableItemEmpty() {
|
2020-10-08 00:47:44 +00:00
|
|
|
return this._templates.instantiate('kanji-info-table-empty');
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTag(tag) {
|
|
|
|
const {content, name, category, redundant} = tag;
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate('tag');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-02-21 18:57:28 +00:00
|
|
|
const inner = node.querySelector('.tag-label-content');
|
2020-01-30 00:52:24 +00:00
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
const contentString = content.join('\n');
|
|
|
|
|
|
|
|
node.title = contentString;
|
2021-02-21 18:57:28 +00:00
|
|
|
this._setTextContent(inner, name);
|
2021-03-25 23:55:31 +00:00
|
|
|
node.dataset.details = contentString.length > 0 ? contentString : name;
|
2021-02-21 18:57:28 +00:00
|
|
|
node.dataset.category = category;
|
|
|
|
if (redundant) { node.dataset.redundant = 'true'; }
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_createTermTag(tagInfo, totalHeadwordCount) {
|
|
|
|
const {tag, headwordIndices} = tagInfo;
|
2021-01-09 21:02:03 +00:00
|
|
|
const node = this._createTag(tag);
|
2021-03-25 23:55:31 +00:00
|
|
|
node.dataset.headwords = headwordIndices.join(' ');
|
2021-04-08 23:59:55 +00:00
|
|
|
node.dataset.totalHeadwordCount = `${totalHeadwordCount}`;
|
|
|
|
node.dataset.matchedHeadwordCount = `${headwordIndices.length}`;
|
|
|
|
node.dataset.unmatchedHeadwordCount = `${Math.max(0, totalHeadwordCount - headwordIndices.length)}`;
|
2021-01-09 21:02:03 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
_createTagData(name, category) {
|
|
|
|
return {
|
|
|
|
name,
|
|
|
|
category,
|
|
|
|
order: 0,
|
|
|
|
score: 0,
|
|
|
|
content: [],
|
|
|
|
dictionaries: [],
|
2020-11-25 00:06:29 +00:00
|
|
|
redundant: false
|
2021-03-25 23:55:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_createSearchTag(text) {
|
|
|
|
return this._createTag(this._createTagData(text, 'search'));
|
2020-01-26 19:00:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 23:45:30 +00:00
|
|
|
_createGroupedPronunciation(details) {
|
|
|
|
const {dictionary, pronunciations} = details;
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
const node = this._templates.instantiate('pronunciation-group');
|
2020-03-01 19:15:28 +00:00
|
|
|
node.dataset.dictionary = dictionary;
|
2021-07-26 23:45:30 +00:00
|
|
|
node.dataset.pronunciationsMulti = 'true';
|
|
|
|
node.dataset.pronunciationsCount = `${pronunciations.length}`;
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
const tag = this._createTag(this._createTagData(dictionary, 'pronunciation-dictionary'));
|
|
|
|
node.querySelector('.pronunciation-group-tag-list').appendChild(tag);
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2020-11-27 20:22:06 +00:00
|
|
|
let hasTags = false;
|
2021-07-26 23:45:30 +00:00
|
|
|
for (const {tags} of pronunciations) {
|
2020-11-27 20:22:06 +00:00
|
|
|
if (tags.length > 0) {
|
|
|
|
hasTags = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
const n = node.querySelector('.pronunciation-list');
|
2020-11-27 20:22:06 +00:00
|
|
|
n.dataset.hasTags = `${hasTags}`;
|
2021-07-26 23:45:30 +00:00
|
|
|
this._appendMultiple(n, this._createPronunciation.bind(this), pronunciations);
|
2020-03-01 19:15:28 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-07-26 23:45:30 +00:00
|
|
|
_createPronunciation(details) {
|
2020-11-29 18:09:02 +00:00
|
|
|
const jp = this._japaneseUtil;
|
2021-07-16 02:39:33 +00:00
|
|
|
const {reading, position, nasalPositions, devoicePositions, tags, exclusiveTerms, exclusiveReadings} = details;
|
2020-03-28 14:47:02 +00:00
|
|
|
const morae = jp.getKanaMorae(reading);
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
const node = this._templates.instantiate('pronunciation');
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
node.dataset.pitchAccentDownstepPosition = `${position}`;
|
2021-07-16 02:39:33 +00:00
|
|
|
if (nasalPositions.length > 0) { node.dataset.nasalMoraPosition = nasalPositions.join(' '); }
|
|
|
|
if (devoicePositions.length > 0) { node.dataset.devoiceMoraPosition = devoicePositions.join(' '); }
|
2020-03-01 19:15:28 +00:00
|
|
|
node.dataset.tagCount = `${tags.length}`;
|
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
let n = node.querySelector('.pronunciation-tag-list');
|
2020-04-10 02:02:17 +00:00
|
|
|
this._appendMultiple(n, this._createTag.bind(this), tags);
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
n = node.querySelector('.pronunciation-disambiguation-list');
|
2021-07-26 23:45:30 +00:00
|
|
|
this._createPronunciationDisambiguations(n, exclusiveTerms, exclusiveReadings);
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-17 18:44:36 +00:00
|
|
|
n = node.querySelector('.pronunciation-downstep-notation-container');
|
2021-07-18 17:43:11 +00:00
|
|
|
n.appendChild(this._pronunciationGenerator.createPronunciationDownstepPosition(position));
|
2021-07-17 18:44:36 +00:00
|
|
|
|
|
|
|
n = node.querySelector('.pronunciation-text-container');
|
2021-07-17 14:26:20 +00:00
|
|
|
n.lang = 'ja';
|
2021-07-17 18:44:36 +00:00
|
|
|
n.appendChild(this._pronunciationGenerator.createPronunciationText(morae, position, nasalPositions, devoicePositions));
|
2020-03-01 19:15:28 +00:00
|
|
|
|
2021-07-17 18:44:36 +00:00
|
|
|
node.querySelector('.pronunciation-graph-container').appendChild(this._pronunciationGenerator.createPronunciationGraph(morae, position));
|
2020-03-01 19:20:11 +00:00
|
|
|
|
2020-03-01 19:15:28 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-07-26 23:45:30 +00:00
|
|
|
_createPronunciationDisambiguations(container, exclusiveTerms, exclusiveReadings) {
|
2021-07-25 22:16:07 +00:00
|
|
|
const templateName = 'pronunciation-disambiguation';
|
2021-04-04 20:22:35 +00:00
|
|
|
for (const term of exclusiveTerms) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate(templateName);
|
2021-04-08 23:59:55 +00:00
|
|
|
node.dataset.type = 'term';
|
2021-04-04 20:22:35 +00:00
|
|
|
this._setTextContent(node, term, 'ja');
|
2020-03-29 15:27:13 +00:00
|
|
|
container.appendChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const exclusiveReading of exclusiveReadings) {
|
2020-10-08 00:47:44 +00:00
|
|
|
const node = this._templates.instantiate(templateName);
|
2020-03-29 15:27:13 +00:00
|
|
|
node.dataset.type = 'reading';
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node, exclusiveReading, 'ja');
|
2020-03-29 15:27:13 +00:00
|
|
|
container.appendChild(node);
|
|
|
|
}
|
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
container.dataset.count = `${exclusiveTerms.length + exclusiveReadings.length}`;
|
2021-04-08 23:59:55 +00:00
|
|
|
container.dataset.termCount = `${exclusiveTerms.length}`;
|
2020-03-29 15:27:13 +00:00
|
|
|
container.dataset.readingCount = `${exclusiveReadings.length}`;
|
2020-03-01 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 15:41:17 +00:00
|
|
|
_createFrequencyGroup(details, kanji) {
|
2021-03-25 23:55:31 +00:00
|
|
|
const {dictionary, frequencies} = details;
|
2021-02-25 22:48:39 +00:00
|
|
|
|
2021-01-09 15:41:17 +00:00
|
|
|
const node = this._templates.instantiate('frequency-group-item');
|
2021-02-25 22:48:39 +00:00
|
|
|
const body = node.querySelector('.tag-body-content');
|
2021-01-09 15:41:17 +00:00
|
|
|
|
2021-02-25 22:48:39 +00:00
|
|
|
this._setTextContent(node.querySelector('.tag-label-content'), dictionary);
|
|
|
|
node.dataset.details = dictionary;
|
2021-01-09 15:41:17 +00:00
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
const ii = frequencies.length;
|
|
|
|
for (let i = 0; i < ii; ++i) {
|
|
|
|
const item = frequencies[i];
|
2021-02-25 22:48:39 +00:00
|
|
|
const itemNode = (kanji ? this._createKanjiFrequency(item, dictionary) : this._createTermFrequency(item, dictionary));
|
|
|
|
itemNode.dataset.index = `${i}`;
|
|
|
|
body.appendChild(itemNode);
|
|
|
|
}
|
2021-01-09 15:41:17 +00:00
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
body.dataset.count = `${ii}`;
|
|
|
|
node.dataset.count = `${ii}`;
|
2021-02-28 19:44:44 +00:00
|
|
|
node.dataset.details = dictionary;
|
2021-01-09 15:41:17 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
_createTermFrequency(details, dictionary) {
|
2021-03-25 23:55:31 +00:00
|
|
|
const {term, reading, values} = details;
|
2021-01-09 15:41:17 +00:00
|
|
|
const node = this._templates.instantiate('term-frequency-item');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-02-25 22:48:39 +00:00
|
|
|
this._setTextContent(node.querySelector('.tag-label-content'), dictionary);
|
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
const frequency = values.join(', ');
|
2021-01-09 15:41:17 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
this._setTextContent(node.querySelector('.frequency-disambiguation-term'), term, 'ja');
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node.querySelector('.frequency-disambiguation-reading'), (reading !== null ? reading : ''), 'ja');
|
|
|
|
this._setTextContent(node.querySelector('.frequency-value'), frequency, 'ja');
|
2019-12-25 02:45:57 +00:00
|
|
|
|
2021-04-08 23:59:55 +00:00
|
|
|
node.dataset.term = term;
|
2020-11-24 16:56:40 +00:00
|
|
|
node.dataset.reading = reading;
|
2021-01-09 15:41:17 +00:00
|
|
|
node.dataset.hasReading = `${reading !== null}`;
|
2021-03-25 23:55:31 +00:00
|
|
|
node.dataset.readingIsSame = `${reading === term}`;
|
2020-11-24 16:56:40 +00:00
|
|
|
node.dataset.dictionary = dictionary;
|
2021-01-09 15:41:17 +00:00
|
|
|
node.dataset.frequency = `${frequency}`;
|
2021-02-28 19:44:44 +00:00
|
|
|
node.dataset.details = dictionary;
|
2019-12-25 02:45:57 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-01-09 15:41:17 +00:00
|
|
|
_createKanjiFrequency(details, dictionary) {
|
2021-03-25 23:55:31 +00:00
|
|
|
const {character, values} = details;
|
2021-01-09 15:41:17 +00:00
|
|
|
const node = this._templates.instantiate('kanji-frequency-item');
|
|
|
|
|
2021-03-25 23:55:31 +00:00
|
|
|
const frequency = values.join(', ');
|
2020-12-05 22:45:45 +00:00
|
|
|
|
2021-02-25 22:48:39 +00:00
|
|
|
this._setTextContent(node.querySelector('.tag-label-content'), dictionary);
|
2021-02-08 22:52:35 +00:00
|
|
|
this._setTextContent(node.querySelector('.frequency-value'), frequency, 'ja');
|
2020-12-05 22:45:45 +00:00
|
|
|
|
|
|
|
node.dataset.character = character;
|
|
|
|
node.dataset.dictionary = dictionary;
|
2021-01-09 15:41:17 +00:00
|
|
|
node.dataset.frequency = `${frequency}`;
|
2021-02-28 19:44:44 +00:00
|
|
|
node.dataset.details = dictionary;
|
2020-12-05 22:45:45 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2019-12-25 02:45:57 +00:00
|
|
|
_appendKanjiLinks(container, text) {
|
2020-11-29 18:09:02 +00:00
|
|
|
const jp = this._japaneseUtil;
|
2019-12-25 02:45:57 +00:00
|
|
|
let part = '';
|
|
|
|
for (const c of text) {
|
2020-03-21 17:22:14 +00:00
|
|
|
if (jp.isCodePointKanji(c.codePointAt(0))) {
|
2019-12-25 02:45:57 +00:00
|
|
|
if (part.length > 0) {
|
|
|
|
container.appendChild(document.createTextNode(part));
|
|
|
|
part = '';
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:02:17 +00:00
|
|
|
const link = this._createKanjiLink(c);
|
2019-12-25 02:45:57 +00:00
|
|
|
container.appendChild(link);
|
|
|
|
} else {
|
|
|
|
part += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (part.length > 0) {
|
|
|
|
container.appendChild(document.createTextNode(part));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 18:42:50 +00:00
|
|
|
_appendMultiple(container, createItem, detailsArray, ...args) {
|
2020-01-25 05:14:27 +00:00
|
|
|
let count = 0;
|
2020-11-22 02:17:39 +00:00
|
|
|
const {ELEMENT_NODE} = Node;
|
2020-11-14 18:42:50 +00:00
|
|
|
if (Array.isArray(detailsArray)) {
|
|
|
|
for (const details of detailsArray) {
|
2020-04-10 02:35:26 +00:00
|
|
|
const item = createItem(details, ...args);
|
2020-04-10 02:16:55 +00:00
|
|
|
if (item === null) { continue; }
|
|
|
|
container.appendChild(item);
|
2020-11-22 02:17:39 +00:00
|
|
|
if (item.nodeType === ELEMENT_NODE) {
|
|
|
|
item.dataset.index = `${count}`;
|
|
|
|
}
|
2020-04-10 02:16:55 +00:00
|
|
|
++count;
|
|
|
|
}
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 05:14:27 +00:00
|
|
|
container.dataset.count = `${count}`;
|
|
|
|
|
|
|
|
return count;
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 20:22:35 +00:00
|
|
|
_appendFurigana(container, term, reading, addText) {
|
2021-03-07 22:55:51 +00:00
|
|
|
container.lang = 'ja';
|
2021-04-04 20:22:35 +00:00
|
|
|
const segments = this._japaneseUtil.distributeFurigana(term, reading);
|
2021-04-14 00:32:24 +00:00
|
|
|
for (const {text, reading: reading2} of segments) {
|
|
|
|
if (reading2) {
|
2019-12-25 02:45:57 +00:00
|
|
|
const ruby = document.createElement('ruby');
|
|
|
|
const rt = document.createElement('rt');
|
|
|
|
addText(ruby, text);
|
|
|
|
ruby.appendChild(rt);
|
2021-04-14 00:32:24 +00:00
|
|
|
rt.appendChild(document.createTextNode(reading2));
|
2019-12-25 02:45:57 +00:00
|
|
|
container.appendChild(ruby);
|
|
|
|
} else {
|
|
|
|
addText(container, text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 02:33:30 +00:00
|
|
|
_createDictionaryTag(dictionary) {
|
2021-03-25 23:55:31 +00:00
|
|
|
return this._createTagData(dictionary, 'dictionary');
|
2021-01-29 02:33:30 +00:00
|
|
|
}
|
2021-02-08 22:52:35 +00:00
|
|
|
|
|
|
|
_setTextContent(node, value, language) {
|
2021-03-06 18:41:38 +00:00
|
|
|
if (typeof language === 'string') {
|
|
|
|
node.lang = language;
|
|
|
|
} else if (this._japaneseUtil.isStringPartiallyJapanese(value)) {
|
|
|
|
node.lang = 'ja';
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:52:35 +00:00
|
|
|
node.textContent = value;
|
2021-03-06 18:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_setMultilineTextContent(node, value, language) {
|
|
|
|
// This can't just call _setTextContent because the lack of <br> elements will
|
|
|
|
// cause the text to not copy correctly.
|
2021-02-08 22:52:35 +00:00
|
|
|
if (typeof language === 'string') {
|
|
|
|
node.lang = language;
|
|
|
|
} else if (this._japaneseUtil.isStringPartiallyJapanese(value)) {
|
|
|
|
node.lang = 'ja';
|
|
|
|
}
|
2021-03-06 18:41:38 +00:00
|
|
|
|
|
|
|
let start = 0;
|
|
|
|
while (true) {
|
|
|
|
const end = value.indexOf('\n', start);
|
|
|
|
if (end < 0) { break; }
|
|
|
|
node.appendChild(document.createTextNode(value.substring(start, end)));
|
|
|
|
node.appendChild(document.createElement('br'));
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start < value.length) {
|
|
|
|
node.appendChild(document.createTextNode(start === 0 ? value : value.substring(start)));
|
|
|
|
}
|
2021-02-08 22:52:35 +00:00
|
|
|
}
|
2021-02-28 18:26:34 +00:00
|
|
|
|
2021-07-25 22:16:07 +00:00
|
|
|
_getPronunciationCategories(reading, pronunciations, wordClasses, headwordIndex) {
|
2021-03-25 23:55:31 +00:00
|
|
|
if (pronunciations.length === 0) { return null; }
|
2021-04-29 01:57:49 +00:00
|
|
|
const isVerbOrAdjective = DictionaryDataUtil.isNonNounVerbOrAdjective(wordClasses);
|
2021-02-28 18:33:33 +00:00
|
|
|
const categories = new Set();
|
2021-03-25 23:55:31 +00:00
|
|
|
for (const pronunciation of pronunciations) {
|
|
|
|
if (pronunciation.headwordIndex !== headwordIndex) { continue; }
|
|
|
|
for (const {position} of pronunciation.pitches) {
|
2021-03-26 23:50:54 +00:00
|
|
|
const category = this._japaneseUtil.getPitchCategory(reading, position, isVerbOrAdjective);
|
2021-02-28 18:26:34 +00:00
|
|
|
if (category !== null) {
|
2021-02-28 18:33:33 +00:00
|
|
|
categories.add(category);
|
2021-02-28 18:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 18:33:33 +00:00
|
|
|
return categories.size > 0 ? [...categories].join(' ') : null;
|
2021-02-28 18:26:34 +00:00
|
|
|
}
|
2019-12-25 02:45:57 +00:00
|
|
|
}
|