From caba1c041aeaef88d16e9fd06f3d36ee8abffd40 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 24 Nov 2020 06:03:46 -0500 Subject: [PATCH] refactor: individual downloads --- src/main.ts | 41 ++--------------------------------------- src/mscore.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0f385bc..23ffc95 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import { waitForDocumentLoaded, saveAs, console } from './utils' import { downloadPDF } from './pdf' import { downloadMscz } from './mscz' import { getFileUrl } from './file' -import { WebMscore, loadSoundFont } from './mscore' +import { INDV_DOWNLOADS } from './mscore' import { BtnList, BtnAction, BtnListMode } from './btn' import { ScoreInfoInPage, SheetInfoInPage } from './scoreinfo' import i18n from './i18n' @@ -65,44 +65,7 @@ const main = (): void => { const fieldset = w.document.createElement('fieldset') w.document.body.append(fieldset) - interface IndividualDownload { - name: string; - fileExt: string; - action (score: WebMscore): Promise; - } - - const downloads: IndividualDownload[] = [ - { - name: i18n('DOWNLOAD')('PDF'), - fileExt: 'pdf', - action: (score) => score.savePdf(), - }, - { - name: i18n('DOWNLOAD')('MSCZ'), - fileExt: 'mscz', - action: (score) => score.saveMsc('mscz'), - }, - { - name: i18n('DOWNLOAD')('MusicXML'), - fileExt: 'mxl', - action: (score) => score.saveMxl(), - }, - { - name: i18n('DOWNLOAD')('MIDI'), - fileExt: 'mid', - action: (score) => score.saveMidi(true, true), - }, - { - name: i18n('DOWNLOAD_AUDIO')('FLAC'), - fileExt: 'flac', - action: (score) => loadSoundFont(score).then(() => score.saveAudio('flac')), - }, - { - name: i18n('DOWNLOAD_AUDIO')('OGG'), - fileExt: 'ogg', - action: (score) => loadSoundFont(score).then(() => score.saveAudio('ogg')), - }, - ] + const downloads = INDV_DOWNLOADS // part selection const DEFAULT_PART = -1 // initially select "full score" diff --git a/src/mscore.ts b/src/mscore.ts index e20f02e..bd88969 100644 --- a/src/mscore.ts +++ b/src/mscore.ts @@ -1,9 +1,11 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { fetchMscz } from './mscz' import { fetchData } from './utils' import { ScoreInfo } from './scoreinfo' import isNodeJs from 'detect-node' +import i18n from './i18n' const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.10/webmscore.js' @@ -88,3 +90,42 @@ export const loadMscore = async (scoreinfo: ScoreInfo, w?: Window): Promise; +} + +export const INDV_DOWNLOADS: IndividualDownload[] = [ + { + name: i18n('DOWNLOAD')('PDF'), + fileExt: 'pdf', + action: (score) => score.savePdf(), + }, + { + name: i18n('DOWNLOAD')('MSCZ'), + fileExt: 'mscz', + action: (score) => score.saveMsc('mscz'), + }, + { + name: i18n('DOWNLOAD')('MusicXML'), + fileExt: 'mxl', + action: (score) => score.saveMxl(), + }, + { + name: i18n('DOWNLOAD')('MIDI'), + fileExt: 'mid', + action: (score) => score.saveMidi(true, true), + }, + { + name: i18n('DOWNLOAD_AUDIO')('FLAC'), + fileExt: 'flac', + action: (score) => loadSoundFont(score).then(() => score.saveAudio('flac')), + }, + { + name: i18n('DOWNLOAD_AUDIO')('OGG'), + fileExt: 'ogg', + action: (score) => loadSoundFont(score).then(() => score.saveAudio('ogg')), + }, +]