11import { stopChapterAudio } from './api.js' ;
2+ import { getVerseTextFromStorage } from './highlights.js' ;
23import { applyColorTheme , applyTheme , getFormattedDateForFilename , getFormattedDateForDisplay , handleError , showLoading } from '../main.js' ;
34import { populateChapterDropdown , updateChapterDropdownVisibility } from './navigation.js' ;
45import { loadPassage } from './passage.js' ;
56import { APP_VERSION , saveToCookies , saveToStorage , state , updateBibleGatewayVersion , updateURL } from './state.js' ;
6- import { restorePanelStates , restoreSidebarState , switchNotesView , updateMarkdownPreview , updateReferencePanel } from './ui.js' ;
7+ import { restorePanelStates , restoreSidebarState , switchNotesView , updateMarkdownPreview , updateReferencePanel , updateScriptureFontSize } from './ui.js' ;
78export function exportData ( ) {
89 try {
910 const fileDate = getFormattedDateForFilename ( ) ;
1011 const exportDate = getFormattedDateForDisplay ( ) ;
12+ const highlightsWithText = Object . entries ( state . highlights ) . reduce (
13+ ( acc , [ reference , color ] ) => {
14+ const verseText = getVerseTextFromStorage ( reference ) || '' ;
15+ acc [ reference ] = { color : color , text : verseText } ;
16+ return acc ;
17+ } ,
18+ { }
19+ ) ;
1120 const payload = {
1221 version : '2.0' ,
1322 exportDate : exportDate ,
14- highlights : { ... state . highlights } ,
23+ highlights : highlightsWithText ,
1524 notes : state . notes ,
1625 settings : { ...state . settings }
1726 } ;
@@ -21,7 +30,7 @@ export function exportData() {
2130 const url = URL . createObjectURL ( blob ) ;
2231 const link = document . createElement ( 'a' ) ;
2332 link . href = url ;
24- link . download = `provinent-bible -study-backup-${ fileDate } .json` ;
33+ link . download = `provinent-scripture -study-backup-${ fileDate } .json` ;
2534 link . style . display = 'none' ;
2635 document . body . appendChild ( link ) ;
2736 link . click ( ) ;
@@ -73,7 +82,26 @@ function confirmImport() {
7382}
7483function applyImportedData ( incoming ) {
7584 Object . assign ( state . settings , incoming . settings ) ;
76- state . highlights = incoming . highlights || { } ;
85+ const incomingHighlights = incoming . highlights || { } ;
86+ const colorMap = { } ;
87+ const verseTextMap = { } ;
88+ Object . entries ( incomingHighlights ) . forEach ( ( [ reference , data ] ) => {
89+ if ( typeof data === 'string' ) {
90+ colorMap [ reference ] = data ;
91+ } else if ( data && typeof data === 'object' ) {
92+ colorMap [ reference ] = data . color ;
93+ verseTextMap [ reference ] = data . text ;
94+ }
95+ } ) ;
96+ state . highlights = colorMap ;
97+ try {
98+ const cachedRaw = localStorage . getItem ( 'cachedVerses' ) ;
99+ const cached = cachedRaw ? JSON . parse ( cachedRaw ) : { } ;
100+ const merged = { ...cached , ...verseTextMap } ;
101+ localStorage . setItem ( 'cachedVerses' , JSON . stringify ( merged ) ) ;
102+ } catch ( e ) {
103+ console . error ( 'Failed to merge cached verses on import:' , e ) ;
104+ }
77105 state . notes = incoming . notes || '' ;
78106}
79107function saveImportedData ( ) {
@@ -124,9 +152,21 @@ function populateSettingsForm() {
124152 const translationSelect = document . getElementById ( 'bibleTranslationSetting' ) ;
125153 const audioToggle = document . getElementById ( 'audioControlsToggle' ) ;
126154 const versionElement = document . getElementById ( 'appVersion' ) ;
155+ const fontSizeSlider = document . getElementById ( 'fontSizeSlider' ) ;
156+ const fontSizeValue = document . getElementById ( 'fontSizeValue' ) ;
127157 if ( translationSelect ) translationSelect . value = state . settings . bibleTranslation ;
128158 if ( audioToggle ) audioToggle . checked = state . settings . audioControlsVisible ;
129159 if ( versionElement ) versionElement . textContent = APP_VERSION ;
160+ if ( fontSizeSlider ) {
161+ fontSizeSlider . value = state . settings . fontSize || 16 ;
162+ fontSizeSlider . addEventListener ( 'input' , ( ) => {
163+ const val = fontSizeSlider . value ;
164+ if ( fontSizeValue ) fontSizeValue . textContent = `${ val } px` ;
165+ } ) ;
166+ }
167+ if ( fontSizeValue ) {
168+ fontSizeValue . textContent = `${ state . settings . fontSize || 16 } px` ;
169+ }
130170 updateColorThemeSelection ( ) ;
131171}
132172function updateColorThemeSelection ( ) {
@@ -168,10 +208,14 @@ function getSettingsFromForm() {
168208 const translationSelect = document . getElementById ( 'bibleTranslationSetting' ) ;
169209 const audioToggle = document . getElementById ( 'audioControlsToggle' ) ;
170210 const selectedTheme = document . querySelector ( '.color-theme-option.selected' ) ;
211+ const narratorSelect = document . getElementById ( 'narratorSelect' ) ;
212+ const fontSizeSlider = document . getElementById ( 'fontSizeSlider' ) ;
171213 return {
172214 translation : translationSelect ?. value || state . settings . bibleTranslation ,
173215 audioControlsVisible : audioToggle ?. checked ?? state . settings . audioControlsVisible ,
174- colorTheme : selectedTheme ?. dataset . theme || state . settings . colorTheme
216+ colorTheme : selectedTheme ?. dataset . theme || state . settings . colorTheme ,
217+ narrator : narratorSelect ?. value || state . settings . audioNarrator ,
218+ fontSize : fontSizeSlider ? parseInt ( fontSizeSlider . value , 10 ) : state . settings . fontSize
175219 } ;
176220}
177221function validateSettings ( settings ) {
@@ -186,6 +230,8 @@ async function applyNewSettings(newSettings) {
186230 state . settings . bibleTranslation = newSettings . translation ;
187231 state . settings . audioControlsVisible = newSettings . audioControlsVisible ;
188232 state . settings . colorTheme = newSettings . colorTheme ;
233+ state . settings . audioNarrator = newSettings . narrator || state . settings . audioNarrator ;
234+ state . settings . fontSize = newSettings . fontSize ?? state . settings . fontSize ;
189235 updateURL ( newSettings . translation , state . settings . manualBook , state . settings . manualChapter , 'push' ) ;
190236 updateAudioControlsVisibility ( ) ;
191237 updateBibleGatewayVersion ( ) ;
@@ -200,6 +246,9 @@ function updateUIAfterSettingsChange() {
200246 if ( referenceTranslationSelect ) {
201247 referenceTranslationSelect . value = state . settings . referenceVersion ;
202248 }
249+ if ( typeof updateScriptureFontSize === 'function' ) {
250+ updateScriptureFontSize ( state . settings . fontSize ) ;
251+ }
203252}
204253async function reloadPassageWithNewSettings ( ) {
205254 await loadPassage ( ) ;
@@ -288,4 +337,10 @@ export function initializeAudioControls() {
288337 saveToStorage ( ) ;
289338 }
290339 updateAudioControlsVisibility ( ) ;
340+ }
341+ export function initialiseNarratorSelect ( ) {
342+ const sel = document . getElementById ( 'narratorSelect' ) ;
343+ if ( sel ) {
344+ sel . value = state . settings . audioNarrator || 'gilbert' ;
345+ }
291346}
0 commit comments