diff options
Diffstat (limited to 'ext/js/templates/sandbox/anki-template-renderer.js')
-rw-r--r-- | ext/js/templates/sandbox/anki-template-renderer.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index ef2c1610..52087336 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -22,7 +22,7 @@ import {DictionaryDataUtil} from '../../dictionary/dictionary-data-util.js'; import {PronunciationGenerator} from '../../display/sandbox/pronunciation-generator.js'; import {StructuredContentGenerator} from '../../display/sandbox/structured-content-generator.js'; import {CssStyleApplier} from '../../dom/sandbox/css-style-applier.js'; -import {JapaneseUtil} from '../../language/sandbox/japanese-util.js'; +import {convertHiraganaToKatakana, convertKatakanaToHiragana, distributeFurigana, getKanaMorae, getPitchCategory, isMoraPitchHigh} from '../../language/japanese.js'; import {AnkiTemplateRendererContentManager} from './anki-template-renderer-content-manager.js'; import {TemplateRendererMediaProvider} from './template-renderer-media-provider.js'; import {TemplateRenderer} from './template-renderer.js'; @@ -42,16 +42,14 @@ export class AnkiTemplateRenderer { this._pronunciationStyleApplier = new CssStyleApplier('/data/pronunciation-style.json'); /** @type {RegExp} */ this._structuredContentDatasetKeyIgnorePattern = /^sc([^a-z]|$)/; - /** @type {JapaneseUtil} */ - this._japaneseUtil = new JapaneseUtil(null); /** @type {TemplateRenderer} */ this._templateRenderer = new TemplateRenderer(); /** @type {AnkiNoteDataCreator} */ - this._ankiNoteDataCreator = new AnkiNoteDataCreator(this._japaneseUtil); + this._ankiNoteDataCreator = new AnkiNoteDataCreator(); /** @type {TemplateRendererMediaProvider} */ this._mediaProvider = new TemplateRendererMediaProvider(); /** @type {PronunciationGenerator} */ - this._pronunciationGenerator = new PronunciationGenerator(this._japaneseUtil); + this._pronunciationGenerator = new PronunciationGenerator(); /** @type {?(Map<string, unknown>[])} */ this._stateStack = null; /** @type {?import('anki-note-builder').Requirement[]} */ @@ -171,7 +169,7 @@ export class AnkiTemplateRenderer { /** @type {import('template-renderer').HelperFunction<string>} */ _furigana(args, context, options) { const {expression, reading} = this._getFuriganaExpressionAndReading(args, context, options); - const segments = this._japaneseUtil.distributeFurigana(expression, reading); + const segments = distributeFurigana(expression, reading); let result = ''; for (const {text, reading: reading2} of segments) { @@ -190,7 +188,7 @@ export class AnkiTemplateRenderer { /** @type {import('template-renderer').HelperFunction<string>} */ _furiganaPlain(args, context, options) { const {expression, reading} = this._getFuriganaExpressionAndReading(args, context, options); - const segments = this._japaneseUtil.distributeFurigana(expression, reading); + const segments = distributeFurigana(expression, reading); let result = ''; for (const {text, reading: reading2} of segments) { @@ -512,13 +510,13 @@ export class AnkiTemplateRenderer { /** @type {import('template-renderer').HelperFunction<boolean>} */ _isMoraPitchHigh(args) { const [index, position] = /** @type {[index: number, position: number]} */ (args); - return this._japaneseUtil.isMoraPitchHigh(index, position); + return isMoraPitchHigh(index, position); } /** @type {import('template-renderer').HelperFunction<string[]>} */ _getKanaMorae(args) { const [text] = /** @type {[text: string]} */ (args); - return this._japaneseUtil.getKanaMorae(`${text}`); + return getKanaMorae(`${text}`); } /** @type {import('template-renderer').HelperFunction<import('core').TypeofResult>} */ @@ -555,7 +553,7 @@ export class AnkiTemplateRenderer { const isVerbOrAdjective = DictionaryDataUtil.isNonNounVerbOrAdjective(wordClasses); const pitches = DictionaryDataUtil.getPronunciationsOfType(pronunciations, 'pitch-accent'); for (const {position} of pitches) { - const category = this._japaneseUtil.getPitchCategory(reading, position, isVerbOrAdjective); + const category = getPitchCategory(reading, position, isVerbOrAdjective); if (category !== null) { categories.add(category); } @@ -666,7 +664,7 @@ export class AnkiTemplateRenderer { */ _createStructuredContentGenerator(data) { const contentManager = new AnkiTemplateRendererContentManager(this._mediaProvider, data); - const instance = new StructuredContentGenerator(contentManager, this._japaneseUtil, document); + const instance = new StructuredContentGenerator(contentManager, document); this._cleanupCallbacks.push(() => contentManager.unloadAll()); return instance; } @@ -735,7 +733,7 @@ export class AnkiTemplateRenderer { if (typeof downstepPosition !== 'number') { return ''; } if (!Array.isArray(nasalPositions)) { nasalPositions = []; } if (!Array.isArray(devoicePositions)) { devoicePositions = []; } - const morae = this._japaneseUtil.getKanaMorae(reading); + const morae = getKanaMorae(reading); switch (format) { case 'text': @@ -756,7 +754,7 @@ export class AnkiTemplateRenderer { const ii = args.length; const {keepProlongedSoundMarks} = options.hash; const value = (ii > 0 ? args[0] : this._computeValue(options, context)); - return typeof value === 'string' ? this._japaneseUtil.convertKatakanaToHiragana(value, keepProlongedSoundMarks === true) : ''; + return typeof value === 'string' ? convertKatakanaToHiragana(value, keepProlongedSoundMarks === true) : ''; } /** @@ -765,7 +763,7 @@ export class AnkiTemplateRenderer { _katakana(args, context, options) { const ii = args.length; const value = (ii > 0 ? args[0] : this._computeValue(options, context)); - return typeof value === 'string' ? this._japaneseUtil.convertHiraganaToKatakana(value) : ''; + return typeof value === 'string' ? convertHiraganaToKatakana(value) : ''; } /** |