@@ -254,6 +254,14 @@ interface Export3mfResult {
254254 error ?: string ;
255255}
256256
257+ interface GenerationProgressMessage {
258+ type : 'generation-progress' ;
259+ id : number ;
260+ current : number ;
261+ total : number ;
262+ currentItem : string ;
263+ }
264+
257265// Cache the last generated JSCAD geometries for STL export
258266let cachedSelectedTray : Geom3 | null = null ;
259267let cachedBox : Geom3 | null = null ;
@@ -697,9 +705,25 @@ function handleGenerate(msg: GenerateMessage): void {
697705 // Get all boxes from all layers
698706 const allBoxes = getAllBoxes ( project . layers ) ;
699707
708+ // Count all loose trays for progress tracking
709+ const allLooseTrays = project . layers . flatMap ( ( layer ) => layer . looseTrays ) ;
710+ const totalOperations = allBoxes . length + allLooseTrays . length ;
711+ let currentOperation = 0 ;
712+
700713 // Generate geometries for ALL boxes (for all-no-lid view) and cache JSCAD for STL export
701714 cachedAllBoxes = [ ] ;
702- const allBoxGeometries : BoxGeometryResult [ ] = allBoxes . map ( ( projectBox ) => {
715+ const allBoxGeometries : BoxGeometryResult [ ] = [ ] ;
716+
717+ for ( const projectBox of allBoxes ) {
718+ // Send progress update
719+ currentOperation ++ ;
720+ self . postMessage ( {
721+ type : 'generation-progress' ,
722+ id,
723+ current : currentOperation ,
724+ total : totalOperations ,
725+ currentItem : projectBox . name
726+ } as GenerationProgressMessage ) ;
703727 const boxValidation = validateCustomDimensions ( projectBox , cardSizes , counterShapes ) ;
704728 if ( ! boxValidation . valid ) {
705729 console . warn ( `Box "${ projectBox . name } " validation failed:` , boxValidation . errors ) ;
@@ -778,16 +802,16 @@ function handleGenerate(msg: GenerateMessage): void {
778802 trays : cachedTraysForBox
779803 } ) ;
780804
781- // Return box dimensions using the layer height (so all boxes in layer report same height)
782- return {
805+ // Add box dimensions using the layer height (so all boxes in layer report same height)
806+ allBoxGeometries . push ( {
783807 boxId : projectBox . id ,
784808 boxName : projectBox . name ,
785809 boxGeometry : boxBufferGeom ,
786810 lidGeometry : lidBufferGeom ,
787811 trayGeometries : trayGeoms ,
788812 boxDimensions : { width : projectBox . customWidth ?? 0 , depth : projectBox . customDepth ?? 0 , height : layerHeight }
789- } ;
790- } ) ;
813+ } ) ;
814+ }
791815
792816 // Generate geometries for all loose trays across all layers
793817 cachedAllLooseTrays = [ ] ;
@@ -798,6 +822,16 @@ function handleGenerate(msg: GenerateMessage): void {
798822 const layerHeight = layerHeights . get ( layer . id ) ?? 0 ;
799823
800824 for ( const looseTray of layer . looseTrays ) {
825+ // Send progress update
826+ currentOperation ++ ;
827+ self . postMessage ( {
828+ type : 'generation-progress' ,
829+ id,
830+ current : currentOperation ,
831+ total : totalOperations ,
832+ currentItem : looseTray . name
833+ } as GenerationProgressMessage ) ;
834+
801835 // Calculate tray dimensions for width/depth
802836 const trayDims = getTrayDimensionsForTray ( looseTray , cardSizes , counterShapes ) ;
803837 // Use layer height for the tray height so loose trays match box exterior height
0 commit comments