@@ -35,9 +35,11 @@ import { isSymbolLibraryReference } from './gridset/resolver';
3535import { generateCloneId } from '../utilities/analytics/utils/idGenerator' ;
3636import { translateWithSymbols , extractSymbolsFromButton } from './gridset/symbolAlignment' ;
3737import { ProcessorInput , readBinaryFromInput , decodeText } from '../utils/io' ;
38+ import type JSZip from 'jszip' ;
3839// Use dynamic import for JSZip to support both browser and Node environments
39- let JSZipModule : any ;
40- async function getJSZip ( ) {
40+ type JSZipStatic = typeof JSZip ;
41+ let JSZipModule : JSZipStatic | undefined ;
42+ async function getJSZip ( ) : Promise < JSZipStatic > {
4143 if ( ! JSZipModule ) {
4244 try {
4345 // Try ES module import first (browser/Vite)
@@ -54,6 +56,9 @@ async function getJSZip() {
5456 }
5557 }
5658 }
59+ if ( ! JSZipModule ) {
60+ throw new Error ( 'Zip handling requires JSZip in this environment.' ) ;
61+ }
5762 return JSZipModule ;
5863}
5964
@@ -443,7 +448,7 @@ class GridsetProcessor extends BaseProcessor {
443448 async loadIntoTree ( filePathOrBuffer : ProcessorInput ) : Promise < AACTree > {
444449 const tree = new AACTree ( ) ;
445450
446- let zip : any ;
451+ let zip : JSZip ;
447452 try {
448453 const JSZip = await getJSZip ( ) ;
449454 const zipInput = readBinaryFromInput ( filePathOrBuffer ) ;
@@ -452,11 +457,7 @@ class GridsetProcessor extends BaseProcessor {
452457 throw new Error ( `Invalid ZIP file format: ${ error . message } ` ) ;
453458 }
454459 const password = this . getGridsetPassword ( filePathOrBuffer ) ;
455- const entries = await getZipEntriesWithPassword (
456- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
457- zip ,
458- password
459- ) ;
460+ const entries = getZipEntriesWithPassword ( zip , password ) ;
460461 const parser = new XMLParser ( { ignoreAttributes : false } ) ;
461462 const isEncryptedArchive =
462463 typeof filePathOrBuffer === 'string' && filePathOrBuffer . toLowerCase ( ) . endsWith ( '.gridsetx' ) ;
@@ -617,9 +618,9 @@ class GridsetProcessor extends BaseProcessor {
617618 // Skip unreadable files
618619 continue ;
619620 }
620- let data : any ;
621+ let data : Record < string , unknown > ;
621622 try {
622- data = parser . parse ( xmlContent ) ;
623+ data = parser . parse ( xmlContent ) as Record < string , unknown > ;
623624 console . log ( `[Gridset] Parsed ${ entry . entryName } , root keys:` , Object . keys ( data ) ) ;
624625 } catch ( error : any ) {
625626 // Skip malformed XML but log the specific error
@@ -628,7 +629,7 @@ class GridsetProcessor extends BaseProcessor {
628629 }
629630
630631 // Grid3 XML: <Grid> root
631- const grid = data . Grid || data . grid ;
632+ const grid = ( data as { Grid ?: any ; grid ?: any } ) . Grid || ( data as { grid ?: any } ) . grid ;
632633 if ( ! grid ) {
633634 console . warn ( `[Gridset] No Grid/grid found in ${ entry . entryName } ` ) ;
634635 continue ;
@@ -1866,7 +1867,7 @@ class GridsetProcessor extends BaseProcessor {
18661867 suppressEmptyNode : true ,
18671868 } ) ;
18681869 const settingsXmlContent = settingsBuilder . build ( settingsData ) ;
1869- zip . file ( 'Settings0/settings.xml' , settingsXmlContent , 'utf8' ) ;
1870+ zip . file ( 'Settings0/settings.xml' , settingsXmlContent , { binary : false } ) ;
18701871
18711872 // Create Settings0/Styles/style.xml if there are styles
18721873 if ( uniqueStyles . size > 0 ) {
@@ -1904,7 +1905,7 @@ class GridsetProcessor extends BaseProcessor {
19041905 indentBy : ' ' ,
19051906 } ) ;
19061907 const styleXmlContent = styleBuilder . build ( styleData ) ;
1907- zip . file ( 'Settings0/Styles/styles.xml' , styleXmlContent , 'utf8' ) ;
1908+ zip . file ( 'Settings0/Styles/styles.xml' , styleXmlContent , { binary : false } ) ;
19081909 }
19091910
19101911 // Collect grid file paths for FileMap.xml
@@ -2073,7 +2074,7 @@ class GridsetProcessor extends BaseProcessor {
20732074 // Add to zip in Grids folder with proper Grid3 naming
20742075 const gridPath = `Grids/${ page . name || page . id } /grid.xml` ;
20752076 gridFilePaths . push ( gridPath ) ;
2076- zip . file ( gridPath , xmlContent , 'utf8' ) ;
2077+ zip . file ( gridPath , xmlContent , { binary : false } ) ;
20772078 } ) ;
20782079
20792080 // Write image files to ZIP
@@ -2125,7 +2126,7 @@ class GridsetProcessor extends BaseProcessor {
21252126 indentBy : ' ' ,
21262127 } ) ;
21272128 const fileMapXmlContent = fileMapBuilder . build ( fileMapData ) ;
2128- zip . file ( 'FileMap.xml' , fileMapXmlContent , 'utf8' ) ;
2129+ zip . file ( 'FileMap.xml' , fileMapXmlContent , { binary : false } ) ;
21292130
21302131 // Write the zip file
21312132 const zipBuffer = await zip . generateAsync ( { type : 'uint8array' } ) ;
0 commit comments