2022-01-14 03:14:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  { LayoutConfigJson }  from  "../Json/LayoutConfigJson" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { Utils }  from  "../../../Utils" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  LineRenderingConfigJson  from  "../Json/LineRenderingConfigJson" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { LayerConfigJson }  from  "../Json/LayerConfigJson" ;  
						 
					
						
							
								
									
										
										
										
											2022-02-04 15:48:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  { DesugaringStep ,  Fuse ,  OnEvery }  from  "./Conversion" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  *  as  metapaths  from  "../../../assets/layoutconfigmeta.json"  
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  class  UpdateLegacyLayer  extends  DesugaringStep < LayerConfigJson  |  string  |  {  builtin ,  override  } >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( "Updates various attributes from the old data format to the new to provide backwards compatibility with the formats" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            [ "overpassTags" ,  "source.osmtags" ,  "tagRenderings[*].id" ,  "mapRendering" ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-04 01:05:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    convert ( json : LayerConfigJson ,  context : string ) :  {  result : LayerConfigJson ;  errors : string [ ] ;  warnings : string [ ]  }  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  warnings  =  [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-27 01:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( typeof  json  ===  "string"  ||  json [ "builtin" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Reuse of an already existing layer; return as-is
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { result : json ,  errors :  [ ] ,  warnings :  [ ] } 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  config : any  =  { . . . json } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( config [ "overpassTags" ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            config . source  =  config . source  ? ?  { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            config . source . osmTags  =  config [ "overpassTags" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            delete  config [ "overpassTags" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( config . tagRenderings  !==  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-17 21:33:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            let  i  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            for  ( const  tagRendering  of  config . tagRenderings )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 19:56:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                i ++ ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-27 01:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( typeof  tagRendering  ===  "string"  ||  tagRendering [ "builtin" ]  !==  undefined  ||  tagRendering [ "rewrite" ]  !==  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 19:56:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                if  ( tagRendering [ "id" ]  ===  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-04 22:31:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ( tagRendering [ "#" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        tagRendering [ "id" ]  =  tagRendering [ "#" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        delete  tagRendering [ "#" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    }  else  if  ( tagRendering [ "freeform" ] ? . key  !==  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        tagRendering [ "id" ]  =  config . id  +  "-"  +  tagRendering [ "freeform" ] [ "key" ] 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-17 21:33:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        tagRendering [ "id" ]  =  "tr-"  +  i 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-21 03:48:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( config . mapRendering  ===  undefined )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-14 16:57:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            config . mapRendering  =  [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            // This is a legacy format, lets create a pointRendering
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            let  location :  ( "point"  |  "centroid" ) [ ]  =  [ "point" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            let  wayHandling : number  =  config [ "wayHandling" ]  ? ?  0 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-11 17:35:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( wayHandling  !==  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                location  =  [ "point" ,  "centroid" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( config [ "icon" ]  ? ?  config [ "label" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  pointConfig  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    icon : config [ "icon" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    iconBadges : config [ "iconOverlays" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    label : config [ "label" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    iconSize : config [ "iconSize" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    location , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    rotation : config [ "rotation" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config . mapRendering . push ( pointConfig ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( wayHandling  !==  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const  lineRenderConfig  =  < LineRenderingConfigJson > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    color : config [ "color" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    width : config [ "width" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    dashArray : config [ "dashArray" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( Object . keys ( lineRenderConfig ) . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    config . mapRendering . push ( lineRenderConfig ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( config . mapRendering . length  ===  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                throw  "Could not convert the legacy theme into a new theme: no renderings defined for layer "  +  config . id 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-14 16:57:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-07 21:20:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        delete  config [ "color" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "width" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "dashArray" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "icon" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "iconOverlays" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "label" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "iconSize" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "rotation" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        delete  config [ "wayHandling" ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 02:29:25 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        delete  config [ "hideUnderlayingFeaturesMinPercentage" ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        for  ( const  mapRenderingElement  of  config . mapRendering )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( mapRenderingElement [ "iconOverlays" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                mapRenderingElement [ "iconBadges" ]  =  mapRenderingElement [ "iconOverlays" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( const  overlay  of  mapRenderingElement [ "iconBadges" ]  ? ?  [ ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( overlay [ "badge" ]  !==  true )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    warnings . push ( "Warning: non-overlay element for " ,  config . id ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                delete  overlay [ "badge" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result : config , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            errors :  [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            warnings 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  UpdateLegacyTheme  extends  DesugaringStep < LayoutConfigJson >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( "Small fixes in the theme config" ,  [ "roamingRenderings" ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-04 01:05:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    convert ( json : LayoutConfigJson ,  context : string ) :  {  result : LayoutConfigJson ;  errors : string [ ] ;  warnings : string [ ]  }  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  oldThemeConfig  =  { . . . json } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( oldThemeConfig [ "roamingRenderings" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( oldThemeConfig [ "roamingRenderings" ] . length  ==  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                delete  oldThemeConfig [ "roamingRenderings" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    result : null , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    errors :  [ context  +  ": The theme contains roamingRenderings. These are not supported anymore" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    warnings :  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-24 16:43:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        oldThemeConfig . layers  =  Utils . NoNull ( oldThemeConfig . layers ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-27 01:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        delete  oldThemeConfig [ "language" ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            errors :  [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            warnings :  [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result : oldThemeConfig 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-10-29 01:41:37 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-21 18:35:31 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export  class  FixLegacyTheme  extends  Fuse < LayoutConfigJson >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            "Fixes a legacy theme to the modern JSON format geared to humans. Syntactic sugars are kept (i.e. no tagRenderings are expandend, no dependencies are automatically gathered)" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  UpdateLegacyTheme ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new  OnEvery ( "layers" ,  new  UpdateLegacyLayer ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-02-04 15:48:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  class  FixImages  extends  DesugaringStep < LayoutConfigJson >  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  readonly  _knownImages : Set < string > ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constructor ( knownImages : Set < string > )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( "Walks over the entire theme and replaces images to the relative URL. Only works if the ID of the theme is an URL" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . _knownImages  =  knownImages ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Walks  the  path  into  the  object  till  the  end . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  If  a  list  is  encountered ,  this  is  tranparently  walked  recursively  on  every  object . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  The  leaf  objects  are  replaced 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  static  WalkPath ( path : string [ ] ,  object :  any ,  replaceLeaf :  ( ( leaf : any )  = >  any ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  head  =  path [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( path . length  ===  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // We have reached the leaf
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  leaf  =  object [ head ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( leaf  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                object [ head ]  =  replaceLeaf ( leaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  sub  =  object [ head ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( sub  ===  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( typeof  sub  !==  "object" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( sub [ "forEach" ]  !==  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            sub . forEach ( el  = >  FixImages . WalkPath ( path . slice ( 1 ) ,  el ,  replaceLeaf ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        FixImages . WalkPath ( path . slice ( 1 ) ,  sub ,  replaceLeaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    convert ( json : LayoutConfigJson ,  context : string ) :  {  result : LayoutConfigJson ;  errors? : string [ ] ;  warnings? : string [ ]  }  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  url : URL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console . log ( "Fixing images!" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            url  =  new  URL ( json . id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Not a URL, we don't rewrite
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  { result : json } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  absolute  =   url . protocol  + "//" + url . host 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  relative  =  url . protocol  + "//" +  url . host  +  url . pathname  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        relative  =  relative . substring ( 0 ,  relative . lastIndexOf ( "/" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  self  =  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        function  replaceString ( leaf : string )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( self . _knownImages . has ( leaf ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  leaf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( leaf . startsWith ( "./" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  relative  +  leaf . substring ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( leaf . startsWith ( "/" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  absolute  +  leaf 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  leaf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        json  =  Utils . Clone ( json ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  paths  =  metapaths [ "default" ]  ? ?  metapaths 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  metapath  of  paths )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( metapath . typeHint  !==  "image"  &&  metapath . typeHint  !==  "icon" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            FixImages . WalkPath ( metapath . path ,  json ,  leaf  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                console . log ( "Detected leaf: " ,  leaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( typeof  leaf  ===  "string" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  replaceString ( leaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( metapath . type [ "some" ]  !==  undefined  &&  ( < any [ ] > metapath . type ) . some ( t  = >  t [ "$ref" ]  ==  "\"#/definitions/TagRenderingConfigJson\"" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    console . log ( "Possibly found a tagrendering" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  leaf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result : json 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}