@@ -19,9 +19,12 @@ import {
1919 ChartBlock ,
2020 DiagramBlock ,
2121 OSFCodeBlock ,
22+ type TextRun as OSFTextRun ,
2223} from 'omniscript-parser' ;
2324import { Converter , ConverterOptions , ConversionResult } from './types' ;
2425
26+ type DocxElement = Paragraph | Table ;
27+
2528export class DOCXConverter implements Converter {
2629 getSupportedFormats ( ) : string [ ] {
2730 return [ 'docx' ] ;
@@ -51,8 +54,11 @@ export class DOCXConverter implements Converter {
5154 } ;
5255 }
5356
54- private generateDocumentElements ( document : OSFDocument , options : ConverterOptions ) : any [ ] {
55- const elements : any [ ] = [ ] ;
57+ private generateDocumentElements (
58+ document : OSFDocument ,
59+ options : ConverterOptions
60+ ) : DocxElement [ ] {
61+ const elements : DocxElement [ ] = [ ] ;
5662
5763 for ( const block of document . blocks ) {
5864 switch ( block . type ) {
@@ -85,8 +91,8 @@ export class DOCXConverter implements Converter {
8591 return elements ;
8692 }
8793
88- private renderMetaBlock ( meta : MetaBlock ) : any [ ] {
89- const elements : any [ ] = [ ] ;
94+ private renderMetaBlock ( meta : MetaBlock ) : DocxElement [ ] {
95+ const elements : DocxElement [ ] = [ ] ;
9096
9197 if ( meta . props . title ) {
9298 elements . push (
@@ -129,9 +135,9 @@ export class DOCXConverter implements Converter {
129135 return elements ;
130136 }
131137
132- private renderDocBlock ( doc : DocBlock ) : any [ ] {
138+ private renderDocBlock ( doc : DocBlock ) : DocxElement [ ] {
133139 const content = doc . content || '' ;
134- const elements : any [ ] = [ ] ;
140+ const elements : DocxElement [ ] = [ ] ;
135141
136142 // Split content into lines and process markdown-like syntax
137143 const lines = content . split ( '\n' ) ;
@@ -212,8 +218,8 @@ export class DOCXConverter implements Converter {
212218 return elements ;
213219 }
214220
215- private renderSlideBlock ( slide : SlideBlock ) : any [ ] {
216- const elements : any [ ] = [ ] ;
221+ private renderSlideBlock ( slide : SlideBlock ) : DocxElement [ ] {
222+ const elements : DocxElement [ ] = [ ] ;
217223
218224 // Add slide title
219225 if ( slide . title ) {
@@ -256,8 +262,8 @@ export class DOCXConverter implements Converter {
256262 return elements ;
257263 }
258264
259- private renderSheetBlock ( sheet : SheetBlock ) : any [ ] {
260- const elements : any [ ] = [ ] ;
265+ private renderSheetBlock ( sheet : SheetBlock ) : DocxElement [ ] {
266+ const elements : DocxElement [ ] = [ ] ;
261267
262268 // Add sheet title
263269 if ( sheet . name ) {
@@ -361,7 +367,12 @@ export class DOCXConverter implements Converter {
361367 { regex : / ` ( .+ ?) ` / g, format : { font : 'Courier New' } } ,
362368 ] ;
363369
364- const matches : Array < { index : number ; length : number ; text : string ; format : any } > = [ ] ;
370+ const matches : Array < {
371+ index : number ;
372+ length : number ;
373+ text : string ;
374+ format : { bold ?: boolean ; italics ?: boolean ; font ?: string } ;
375+ } > = [ ] ;
365376
366377 // Find all formatting matches
367378 for ( const pattern of patterns ) {
@@ -410,16 +421,18 @@ export class DOCXConverter implements Converter {
410421 return runs ;
411422 }
412423
413- private extractText ( run : any ) : string {
424+ private extractText ( run : OSFTextRun ) : string {
414425 if ( typeof run === 'string' ) return run ;
415- if ( run . type === 'link' ) return run . text ;
416- if ( run . type === 'image' ) return run . alt || '' ;
417- if ( run . text ) return run . text ;
426+ if ( 'type' in run ) {
427+ if ( run . type === 'link' ) return run . text ;
428+ if ( run . type === 'image' ) return run . alt || '' ;
429+ }
430+ if ( 'text' in run ) return run . text ;
418431 return '' ;
419432 }
420433
421- private renderChartBlock ( chart : ChartBlock ) : any [ ] {
422- const elements : any [ ] = [ ] ;
434+ private renderChartBlock ( chart : ChartBlock ) : DocxElement [ ] {
435+ const elements : DocxElement [ ] = [ ] ;
423436
424437 if ( chart . title ) {
425438 elements . push (
@@ -463,8 +476,8 @@ export class DOCXConverter implements Converter {
463476 return elements ;
464477 }
465478
466- private renderDiagramBlock ( diagram : DiagramBlock ) : any [ ] {
467- const elements : any [ ] = [ ] ;
479+ private renderDiagramBlock ( diagram : DiagramBlock ) : DocxElement [ ] {
480+ const elements : DocxElement [ ] = [ ] ;
468481
469482 if ( diagram . title ) {
470483 elements . push (
@@ -510,8 +523,8 @@ export class DOCXConverter implements Converter {
510523 return elements ;
511524 }
512525
513- private renderCodeBlock ( code : OSFCodeBlock ) : any [ ] {
514- const elements : any [ ] = [ ] ;
526+ private renderCodeBlock ( code : OSFCodeBlock ) : DocxElement [ ] {
527+ const elements : DocxElement [ ] = [ ] ;
515528
516529 if ( code . caption ) {
517530 elements . push (
0 commit comments