|
17 | 17 | */ |
18 | 18 |
|
19 | 19 | import {ExtensionError} from '../core/extension-error.js'; |
20 | | -import {getDisambiguations, getGroupedPronunciations, getTermFrequency, groupKanjiFrequencies, groupTermFrequencies, groupTermTags, isNonNounVerbOrAdjective} from '../dictionary/dictionary-data-util.js'; |
| 20 | +import {getDisambiguations, getGroupedPronunciations, getTermFrequency, groupKanjiFrequencies, groupTermFrequencies, groupTermTags, isNonNounVerbOrAdjective, groupByPronunciation} from '../dictionary/dictionary-data-util.js'; |
21 | 21 | import {HtmlTemplateCollection} from '../dom/html-template-collection.js'; |
22 | 22 | import {distributeFurigana, getKanaMorae, getPitchCategory, isCodePointKanji} from '../language/ja/japanese.js'; |
23 | 23 | import {getLanguageFromText} from '../language/text-utilities.js'; |
@@ -119,7 +119,8 @@ export class DisplayGenerator { |
119 | 119 |
|
120 | 120 | this._appendMultiple(inflectionRuleChainsContainer, this._createInflectionRuleChain.bind(this), inflectionRuleChainCandidates); |
121 | 121 | this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false); |
122 | | - this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations); |
| 122 | + const dictionariesGroupedByPronunciation = groupByPronunciation(groupedPronunciations); |
| 123 | + this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciationByPronunciation.bind(this), dictionariesGroupedByPronunciation); |
123 | 124 | this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length); |
124 | 125 |
|
125 | 126 | for (const term of uniqueTerms) { |
@@ -659,37 +660,32 @@ export class DisplayGenerator { |
659 | 660 | } |
660 | 661 |
|
661 | 662 | /** |
662 | | - * @param {import('dictionary-data-util').DictionaryGroupedPronunciations} details |
| 663 | + * @param {import('dictionary-data-util').PronunciationsInSeveralDictionaries} details |
663 | 664 | * @returns {HTMLElement} |
664 | 665 | */ |
665 | | - _createGroupedPronunciation(details) { |
666 | | - const {dictionary, dictionaryAlias, pronunciations} = details; |
| 666 | + _createGroupedPronunciationByPronunciation({pronunciation, dictionaries}) { |
| 667 | + const container = document.createElement('div'); |
| 668 | + container.classList.add('grouped-pronunciation-container'); |
667 | 669 |
|
668 | 670 | const node = this._instantiate('pronunciation-group'); |
669 | | - node.dataset.dictionary = dictionary; |
670 | | - node.dataset.pronunciationsMulti = 'true'; |
671 | | - node.dataset.pronunciationsCount = `${pronunciations.length}`; |
672 | | - |
673 | | - const n1 = this._querySelector(node, '.pronunciation-group-tag-list'); |
674 | | - const tag = this._createTag(this._createTagData(dictionaryAlias, 'pronunciation-dictionary')); |
675 | | - tag.dataset.details = dictionary; |
676 | | - n1.appendChild(tag); |
677 | 671 |
|
678 | | - let hasTags = false; |
679 | | - for (const {pronunciation: {tags}} of pronunciations) { |
680 | | - if (tags.length > 0) { |
681 | | - hasTags = true; |
682 | | - break; |
683 | | - } |
| 672 | + const tagListNode = this._querySelector(node, '.pronunciation-group-tag-list'); |
| 673 | + for (const dictionary of dictionaries) { |
| 674 | + const tag = this._createTag(this._createTagData(dictionary, 'pronunciation-dictionary')); |
| 675 | + tag.dataset.details = dictionary; |
| 676 | + tagListNode.appendChild(tag); |
684 | 677 | } |
685 | 678 |
|
686 | | - const n = this._querySelector(node, '.pronunciation-list'); |
687 | | - n.dataset.hasTags = `${hasTags}`; |
688 | | - this._appendMultiple(n, this._createPronunciation.bind(this), pronunciations); |
| 679 | + const pronunciationListNode = this._querySelector(node, '.pronunciation-list'); |
689 | 680 |
|
690 | | - return node; |
| 681 | + this._appendMultiple(pronunciationListNode, this._createPronunciation.bind(this), [pronunciation]); |
| 682 | + |
| 683 | + container.appendChild(node); |
| 684 | + |
| 685 | + return container; |
691 | 686 | } |
692 | 687 |
|
| 688 | + |
693 | 689 | /** |
694 | 690 | * @param {import('dictionary-data-util').GroupedPronunciation} details |
695 | 691 | * @returns {HTMLElement} |
@@ -1067,14 +1063,20 @@ export class DisplayGenerator { |
1067 | 1063 | * @returns {?string} |
1068 | 1064 | */ |
1069 | 1065 | _getPronunciationCategories(reading, termPronunciations, wordClasses, headwordIndex) { |
1070 | | - if (termPronunciations.length === 0) { return null; } |
| 1066 | + if (termPronunciations.length === 0) { |
| 1067 | + return null; |
| 1068 | + } |
1071 | 1069 | const isVerbOrAdjective = isNonNounVerbOrAdjective(wordClasses); |
1072 | 1070 | /** @type {Set<import('japanese-util').PitchCategory>} */ |
1073 | 1071 | const categories = new Set(); |
1074 | 1072 | for (const termPronunciation of termPronunciations) { |
1075 | | - if (termPronunciation.headwordIndex !== headwordIndex) { continue; } |
| 1073 | + if (termPronunciation.headwordIndex !== headwordIndex) { |
| 1074 | + continue; |
| 1075 | + } |
1076 | 1076 | for (const pronunciation of termPronunciation.pronunciations) { |
1077 | | - if (pronunciation.type !== 'pitch-accent') { continue; } |
| 1077 | + if (pronunciation.type !== 'pitch-accent') { |
| 1078 | + continue; |
| 1079 | + } |
1078 | 1080 | const category = getPitchCategory(reading, pronunciation.position, isVerbOrAdjective); |
1079 | 1081 | if (category !== null) { |
1080 | 1082 | categories.add(category); |
|
0 commit comments