diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-01-31 08:38:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 13:38:30 +0000 |
commit | 87ed7c8affd3ade9d3cd2d9ed1a61dd5f224e473 (patch) | |
tree | be727294e31ef21e8a3f634734610e69e4a155ac /ext/js/templates/sandbox | |
parent | 3e419aa562aab03ca20421aaf7e4d1a39194a5b4 (diff) |
Module refactoring (#588)
* Convert PronunciationGenerator into static functions
* Convert DictionaryDataUtil into static functions
* Convert AnkiNoteDataCreator into static functions
* Convert MediaUtil into static functions
* Convert RegexUtil into static functions
* Convert StringUtil into static functions
* Convert ArrayBufferUtil into static functions
* Convert AnkiUtil into static functions
* Convert PermissionsUtil into static functions
* Convert ProfileConditionsUtil into static functions
Diffstat (limited to 'ext/js/templates/sandbox')
-rw-r--r-- | ext/js/templates/sandbox/anki-template-renderer-content-manager.js | 1 | ||||
-rw-r--r-- | ext/js/templates/sandbox/anki-template-renderer.js | 22 |
2 files changed, 9 insertions, 14 deletions
diff --git a/ext/js/templates/sandbox/anki-template-renderer-content-manager.js b/ext/js/templates/sandbox/anki-template-renderer-content-manager.js index 932b6ab7..664746bf 100644 --- a/ext/js/templates/sandbox/anki-template-renderer-content-manager.js +++ b/ext/js/templates/sandbox/anki-template-renderer-content-manager.js @@ -24,7 +24,6 @@ export class AnkiTemplateRendererContentManager { * Creates a new instance of the class. * @param {import('./template-renderer-media-provider.js').TemplateRendererMediaProvider} mediaProvider The media provider for the object. * @param {import('anki-templates').NoteData} data The data object passed to the Handlebars template renderer. - * See AnkiNoteDataCreator.create's return value for structure information. */ constructor(mediaProvider, data) { /** @type {import('./template-renderer-media-provider.js').TemplateRendererMediaProvider} */ diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index 52087336..26d3f336 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -17,9 +17,9 @@ */ import {Handlebars} from '../../../lib/handlebars.js'; -import {AnkiNoteDataCreator} from '../../data/sandbox/anki-note-data-creator.js'; -import {DictionaryDataUtil} from '../../dictionary/dictionary-data-util.js'; -import {PronunciationGenerator} from '../../display/sandbox/pronunciation-generator.js'; +import {createAnkiNoteData} from '../../data/sandbox/anki-note-data-creator.js'; +import {getPronunciationsOfType, isNonNounVerbOrAdjective} from '../../dictionary/dictionary-data-util.js'; +import {createPronunciationDownstepPosition, createPronunciationGraph, createPronunciationText} 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 {convertHiraganaToKatakana, convertKatakanaToHiragana, distributeFurigana, getKanaMorae, getPitchCategory, isMoraPitchHigh} from '../../language/japanese.js'; @@ -44,12 +44,8 @@ export class AnkiTemplateRenderer { this._structuredContentDatasetKeyIgnorePattern = /^sc([^a-z]|$)/; /** @type {TemplateRenderer} */ this._templateRenderer = new TemplateRenderer(); - /** @type {AnkiNoteDataCreator} */ - this._ankiNoteDataCreator = new AnkiNoteDataCreator(); /** @type {TemplateRendererMediaProvider} */ this._mediaProvider = new TemplateRendererMediaProvider(); - /** @type {PronunciationGenerator} */ - this._pronunciationGenerator = new PronunciationGenerator(); /** @type {?(Map<string, unknown>[])} */ this._stateStack = null; /** @type {?import('anki-note-builder').Requirement[]} */ @@ -104,7 +100,7 @@ export class AnkiTemplateRenderer { ]); /* eslint-enable no-multi-spaces */ this._templateRenderer.registerDataType('ankiNote', { - modifier: ({marker, commonData}) => this._ankiNoteDataCreator.create(marker, commonData), + modifier: ({marker, commonData}) => createAnkiNoteData(marker, commonData), composeData: ({marker}, commonData) => ({marker, commonData}) }); this._templateRenderer.setRenderCallbacks( @@ -550,8 +546,8 @@ export class AnkiTemplateRenderer { const categories = new Set(); for (const {headwordIndex, pronunciations} of termPronunciations) { const {reading, wordClasses} = headwords[headwordIndex]; - const isVerbOrAdjective = DictionaryDataUtil.isNonNounVerbOrAdjective(wordClasses); - const pitches = DictionaryDataUtil.getPronunciationsOfType(pronunciations, 'pitch-accent'); + const isVerbOrAdjective = isNonNounVerbOrAdjective(wordClasses); + const pitches = getPronunciationsOfType(pronunciations, 'pitch-accent'); for (const {position} of pitches) { const category = getPitchCategory(reading, position, isVerbOrAdjective); if (category !== null) { @@ -737,11 +733,11 @@ export class AnkiTemplateRenderer { switch (format) { case 'text': - return this._getPronunciationHtml(this._pronunciationGenerator.createPronunciationText(morae, downstepPosition, nasalPositions, devoicePositions)); + return this._getPronunciationHtml(createPronunciationText(morae, downstepPosition, nasalPositions, devoicePositions)); case 'graph': - return this._getPronunciationHtml(this._pronunciationGenerator.createPronunciationGraph(morae, downstepPosition)); + return this._getPronunciationHtml(createPronunciationGraph(morae, downstepPosition)); case 'position': - return this._getPronunciationHtml(this._pronunciationGenerator.createPronunciationDownstepPosition(downstepPosition)); + return this._getPronunciationHtml(createPronunciationDownstepPosition(downstepPosition)); default: return ''; } |