11import {
22 BaseProcessor ,
3+ ExtractedString ,
34 ExtractStringsResult ,
4- ProcessorOptions ,
55 SourceString ,
66 TranslatedString ,
7+ VocabLocation ,
78} from '../core/baseProcessor' ;
8- import { AACTree , AACButton , AACPage , AACSemanticAction , AACSemanticCategory , AACSemanticIntent } from '../core/treeStructure' ;
9+ import {
10+ AACTree ,
11+ AACButton ,
12+ AACPage ,
13+ AACSemanticCategory ,
14+ AACSemanticIntent ,
15+ } from '../core/treeStructure' ;
916import { detectCasing } from '../core/stringCasing' ;
1017import { encodeText , ProcessorInput } from '../utils/io' ;
1118import {
@@ -16,11 +23,6 @@ import {
1623 NuVoiceHeaderRecord ,
1724 NuVoiceLayoutRecord ,
1825 NuVoiceMemoryRecord ,
19- NuVoicePageRecord ,
20- NuVoiceActionRecord ,
21- NuVoiceNavigationRecord ,
22- NuVoiceGridRecord ,
23- NuVoiceCellRecord ,
2426 parseNuVoiceDocument ,
2527 parseTextSegment ,
2628 serializeNuVoiceDocument ,
@@ -47,8 +49,11 @@ class NuVoiceProcessor extends BaseProcessor {
4749
4850 tree . metadata = {
4951 format : 'nuvoice' ,
50- version : ( document . records . find ( ( record ) => record . type === 'v' ) as NuVoiceHeaderRecord ) ?. version ,
51- name : ( document . records . find ( ( record ) => record . type === 'v' ) as NuVoiceHeaderRecord ) ?. product || 'NuVoice MTI' ,
52+ version : ( document . records . find ( ( record ) => record . type === 'v' ) as NuVoiceHeaderRecord )
53+ ?. version ,
54+ name :
55+ ( document . records . find ( ( record ) => record . type === 'v' ) as NuVoiceHeaderRecord ) ?. product ||
56+ 'NuVoice MTI' ,
5257 recordCounts,
5358 invalidChecksumCount : document . records . filter (
5459 ( record ) => record . type !== 'v' && 'checksumValid' in record && ! record . checksumValid
@@ -67,10 +72,12 @@ class NuVoiceProcessor extends BaseProcessor {
6772 ( record ) : record is NuVoiceDictionaryRecord => record . type === 'd'
6873 ) ;
6974 const memoryRecords = document . records . filter (
70- ( record ) : record is NuVoiceMemoryRecord => record . type === 'm' && 'textSegment' in record && record . textSegment !== null
75+ ( record ) : record is NuVoiceMemoryRecord =>
76+ record . type === 'm' && 'textSegment' in record && record . textSegment !== null
7177 ) ;
7278 const layoutRecords = document . records . filter (
73- ( record ) : record is NuVoiceLayoutRecord => record . type === 'x' && 'textSegment' in record && record . textSegment !== null
79+ ( record ) : record is NuVoiceLayoutRecord =>
80+ record . type === 'x' && 'textSegment' in record && record . textSegment !== null
7481 ) ;
7582
7683 // Dictionary page
@@ -207,9 +214,6 @@ class NuVoiceProcessor extends BaseProcessor {
207214 const navigationRecords = document . records . filter (
208215 ( record ) => record . type === 'n' && 'bodyBytes' in record
209216 ) ;
210- const gridRecords = document . records . filter (
211- ( record ) => record . type === 'G' && 'bodyBytes' in record
212- ) ;
213217 const cellRecords = document . records . filter (
214218 ( record ) => record . type === 'C' && 'bodyBytes' in record
215219 ) ;
@@ -241,10 +245,8 @@ class NuVoiceProcessor extends BaseProcessor {
241245 ) ;
242246
243247 // Try to find associated cells for this page
244- const pageCells = cellRecords . filter ( cell => {
245- // Simple heuristic: include all cells for now
246- return true ;
247- } ) ;
248+ // Simple heuristic: include all cells for now.
249+ const pageCells = cellRecords ;
248250
249251 pageCells . forEach ( ( cell , cellIndex ) => {
250252 const cellBinary = cell as NuVoiceBinaryRecordBase ;
@@ -276,7 +278,7 @@ class NuVoiceProcessor extends BaseProcessor {
276278 type : 'NAVIGATE' ,
277279 semanticAction : {
278280 category : AACSemanticCategory . NAVIGATION ,
279- intent : AACSemanticIntent . NAVIGATE_TO ,
281+ intent : AACSemanticIntent . NAVIGATE_TO ,
280282 parameters : { pageId : `page-${ index } ` } ,
281283 } ,
282284 } )
@@ -372,7 +374,9 @@ class NuVoiceProcessor extends BaseProcessor {
372374
373375 // Handle remaining unknown record types
374376 const otherRecords = document . records . filter (
375- ( record ) => ! [ 'v' , 'd' , 'm' , 'x' , 'X' , 'P' , 'A' , 'n' , 'C' ] . includes ( record . type ) && 'bodyBytes' in record
377+ ( record ) =>
378+ ! [ 'v' , 'd' , 'm' , 'x' , 'X' , 'P' , 'A' , 'n' , 'C' ] . includes ( record . type ) &&
379+ 'bodyBytes' in record
376380 ) ;
377381
378382 if ( otherRecords . length > 0 ) {
@@ -384,7 +388,7 @@ class NuVoiceProcessor extends BaseProcessor {
384388
385389 // Group by record type for better organization
386390 const recordsByType : Record < string , typeof otherRecords > = { } ;
387- otherRecords . forEach ( record => {
391+ otherRecords . forEach ( ( record ) => {
388392 if ( ! recordsByType [ record . type ] ) {
389393 recordsByType [ record . type ] = [ ] ;
390394 }
@@ -454,16 +458,17 @@ class NuVoiceProcessor extends BaseProcessor {
454458 if ( record . type === 'd' ) {
455459 const dictRecord = record as NuVoiceDictionaryRecord ;
456460 dictRecord . word = translations . get ( dictRecord . word ) ?? dictRecord . word ;
457- dictRecord . pronunciation = translations . get ( dictRecord . pronunciation ) ?? dictRecord . pronunciation ;
461+ dictRecord . pronunciation =
462+ translations . get ( dictRecord . pronunciation ) ?? dictRecord . pronunciation ;
458463 } else if ( record . type === 'm' && 'textSegment' in record && record . textSegment ) {
459464 const nextText = translations . get ( record . textSegment . text ) ;
460465 if ( nextText !== undefined ) {
461- setNuVoiceMemoryText ( record as NuVoiceMemoryRecord , nextText ) ;
466+ setNuVoiceMemoryText ( record , nextText ) ;
462467 }
463468 } else if ( record . type === 'x' && 'textSegment' in record && record . textSegment ) {
464469 const nextText = translations . get ( record . textSegment . text ) ;
465470 if ( nextText !== undefined ) {
466- setNuVoiceLayoutText ( record as NuVoiceLayoutRecord , nextText ) ;
471+ setNuVoiceLayoutText ( record , nextText ) ;
467472 }
468473 } else if ( 'bodyBytes' in record ) {
469474 // Try to update text in other binary records (P, A, n, C, etc.)
@@ -477,7 +482,11 @@ class NuVoiceProcessor extends BaseProcessor {
477482 const newTextBytes = latin1ToBytes ( nextText ) ;
478483 if ( newTextBytes . length <= record . bodyBytes . length ) {
479484 // Replace the text segment in place
480- const textStart = binaryRecord . bodyBytes . length - textSegment . suffixBytes . length - ( textSegment . hasNullTerminator ? 1 : 0 ) - textSegment . text . length ;
485+ const textStart =
486+ binaryRecord . bodyBytes . length -
487+ textSegment . suffixBytes . length -
488+ ( textSegment . hasNullTerminator ? 1 : 0 ) -
489+ textSegment . text . length ;
481490 binaryRecord . bodyBytes . set ( newTextBytes , textStart ) ;
482491 }
483492 }
@@ -490,9 +499,11 @@ class NuVoiceProcessor extends BaseProcessor {
490499 return encodeText ( serialized ) ;
491500 }
492501
493- async saveFromTree ( _tree : AACTree , _outputPath : string ) : Promise < void > {
494- throw new Error (
495- 'NuVoice MTI saveFromTree is not supported yet; use processTexts on an existing .mti file.'
502+ saveFromTree ( _tree : AACTree , _outputPath : string ) : Promise < void > {
503+ return Promise . reject (
504+ new Error (
505+ 'NuVoice MTI saveFromTree is not supported yet; use processTexts on an existing .mti file.'
506+ )
496507 ) ;
497508 }
498509
@@ -543,15 +554,7 @@ class NuVoiceProcessor extends BaseProcessor {
543554 return this . generateTranslatedDownloadGeneric ( filePath , translatedStrings , sourceStrings ) ;
544555 }
545556
546- private buildExtractedEntry (
547- source : string ,
548- vocabLocation : {
549- table : string ;
550- id : string ;
551- column : string ;
552- casing : ReturnType < typeof detectCasing > ;
553- }
554- ) {
557+ private buildExtractedEntry ( source : string , vocabLocation : VocabLocation ) : ExtractedString {
555558 return {
556559 string : source ,
557560 vocabPlacementMeta : {
0 commit comments