2023-11-02 04:35:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  Conversion ,  DesugaringStep  }  from  "./Conversion" 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  ThemeConfigJson  }  from  "../Json/ThemeConfigJson" 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  Utils  }  from  "../../../Utils" 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-15 18:04:30 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  metapaths  from  "../../../assets/schemas/layoutconfigmeta.json" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  tagrenderingmetapaths  from  "../../../assets/schemas/questionabletagrenderingconfigmeta.json" 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  Translations  from  "../../../UI/i18n/Translations" 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-02 02:59:20 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  parse  as  parse_html  }  from  "node-html-parser" 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-02 04:35:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  ConversionContext  }  from  "./ConversionContext" 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								export  class  ExtractImages  extends  Conversion < 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ThemeConfigJson , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    {  path : string ;  context : string  } [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 02:36:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    private  static  readonly  layoutMetaPaths  =  metapaths . filter ( ( mp )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  typeHint  =  mp . hints . typehint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  ( 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ExtractImages . mightBeTagRendering ( < any > mp )  || 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 02:36:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ( typeHint  !==  undefined  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ( typeHint  ===  "image"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    typeHint  ===  "icon"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    typeHint  ===  "image[]"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    typeHint  ===  "icon[]" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    private  static  readonly  tagRenderingMetaPaths  =  tagrenderingmetapaths 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    private  _isOfficial : boolean 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  _sharedTagRenderings : Set < string > 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 02:45:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    constructor ( isOfficial : boolean ,  sharedTagRenderings : Set < string > )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-05-16 15:48:55 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        super ( "ExctractImages" ,  "Extract all images from a layoutConfig using the meta paths." ,  [ ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        this . _isOfficial  =  isOfficial 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        this . _sharedTagRenderings  =  sharedTagRenderings 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    public  static  mightBeTagRendering ( metapath :  {  type ? :  string  |  string [ ]  } ) :  boolean  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! metapath . type )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        let  type :  any [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! Array . isArray ( metapath . type ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            type  =  [ metapath . type ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            type  =  metapath . type 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  type . some ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ( t )  = > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                t  !==  null  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ( t [ "$ref" ]  ==  "#/definitions/TagRenderingConfigJson"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    t [ "$ref" ]  ==  "#/definitions/MinimalTagRenderingConfigJson"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    t [ "$ref" ]  ==  "#/definitions/QuestionableTagRenderingConfigJson"  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    ( t [ "properties" ] ? . render  !==  undefined  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        t [ "properties" ] ? . mappings  !==  undefined ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    static  isImageType ( metapath : any ) :  boolean  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( metapath . hints . typehint  ===  "icon"  ||  metapath . hints . typehint  ===  "image" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  types  =  metapath . hints . types ? . split ( ";" ) . map ( ( x )  = >  x . trim ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( types ? . some ( ( t )  = >  t  ===  "icon"  ||  t  ===  "image" ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    / * * 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *   const  images  =  new  ExtractImages ( true ,  new  Set < string > ( ) ) . convert ( < any > { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *      "layers" :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *          { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *              tagRenderings :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                      "mappings" :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "if" :  "bicycle_parking=stands" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "then" :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  "en" :  "Staple racks" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "icon" :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  path :  "./assets/layers/bike_parking/staple.svg" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  class :  "small" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "if" :  "bicycle_parking=stands" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "then" :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  "en" :  "Bollard" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "icon" :  "./assets/layers/bike_parking/bollard.svg" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                      ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *              ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *          } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *      ] 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  } ,  ConversionContext . test ( ) ) . map ( i  = >  i . path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  images . length  // => 2
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-10 14:28:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  images . findIndex ( img  = >  img  ==  "./assets/layers/bike_parking/staple.svg" )  >=  0  // => true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  images . findIndex ( img  = >  img  ==  "./assets/layers/bike_parking/bollard.svg" )  >=  0  // => true
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  // should not pickup rotation, should drop color
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  const  images  =  new  ExtractImages ( true ,  new  Set < string > ( ) ) . convert ( < any > { "layers" :  [ { "pointRendering" :  [ { "location" :  [ "point" ,  "centroid" ] , marker :  [ { "icon" :  "pin:black" } ] , rotation : 180 , iconSize :  "40,40,center" } ] } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  } ,  ConversionContext . test ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 03:11:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  images . length  // => 1
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-10 14:28:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  images [ 0 ] . path  // => "pin"
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     * / 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    convert ( 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        json : ThemeConfigJson , 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        context : ConversionContext 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ) :  {  path : string ;  context : string  } [ ]  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  allFoundImages :  {  path : string ;  context : string  } [ ]  =  [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 02:45:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        for  ( const  metapath  of  ExtractImages . layoutMetaPaths )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            const  mightBeTr  =  ExtractImages . mightBeTagRendering ( < any > metapath ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            const  allRenderedValuesAreImages  =  ExtractImages . isImageType ( metapath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            const  found  =  Utils . CollectPath ( metapath . path ,  json ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( found . length  ===  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( mightBeTr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // We might have tagRenderingConfigs containing icons here
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 02:45:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                for  ( const  el  of  found )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    const  path  =  el . path 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    const  foundImage  =  el . leaf 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    if  ( typeof  foundImage  ===  "string" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( ! allRenderedValuesAreImages )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( foundImage  ==  "" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            context . warn ( context  +  "."  +  path . join ( "." )  +  " Found an empty image" ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-18 23:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( this . _sharedTagRenderings ? . has ( foundImage ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-18 23:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            // This is not an image, but a shared tag rendering
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            // At key positions for checking, they'll be expanded already, so we can safely ignore them here
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-18 23:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        allFoundImages . push ( {  path : foundImage ,  context : context  +  "."  +  path  } ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        // This is a tagRendering.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        // Either every rendered value might be an icon
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        // or -in the case of a normal tagrendering- only the 'icons' in the mappings have an icon (or exceptionally an '<img>' tag in the translation
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 02:45:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        for  ( const  trpath  of  ExtractImages . tagRenderingMetaPaths )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            // Inspect all the rendered values
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-11 19:56:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            const  fromPath  =  Utils . CollectPath ( trpath . path ,  foundImage ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 02:36:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            const  isRendered  =  trpath . hints . typehint  ===  "rendered" 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            const  isImage  =  ExtractImages . isImageType ( trpath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-11 19:56:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            for  ( const  img  of  fromPath )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                if  ( allRenderedValuesAreImages  &&  isRendered )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                    // What we found is an image
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    if  ( img . leaf  ===  ""  ||  img . leaf [ "path" ]  ==  "" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        context 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            . enter ( path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            . enter ( img . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            . warn ( "Found an emtpy image" ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    }  else  if  ( typeof  img . leaf  !==  "string" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        const  c  =  context . enter ( img . path ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 22:08:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        const  msg  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            "found an image path that is not a string: "  + 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-13 19:11:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                            JSON . stringify ( img . leaf ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 22:08:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        if  ( this . _isOfficial )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-13 19:11:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                            c . err ( msg ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 22:08:00 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-13 19:11:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                            c . warn ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        allFoundImages . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            path : img.leaf , 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                            context : context  +  "."  +  path , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        } ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                if  ( ! allRenderedValuesAreImages  &&  isImage )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 17:17:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    // Extract images from the translations
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    allFoundImages . push ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                        . . . Translations . T ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            img . leaf , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            "extract_images from "  +  img . path . join ( "." ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            . ExtractImages ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                            . map ( ( path )  = >  ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                                path , 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                                context : context  +  "."  +  path , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                            } ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                    ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-18 23:10:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 17:39:16 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                for  ( const  foundElement  of  found )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    if  ( foundElement . leaf  ===  "" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        context . enter ( foundElement . path ) . warn ( "Found an empty image" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 17:39:16 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-09 00:10:59 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    if  ( typeof  foundElement . leaf  !==  "string" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    allFoundImages . push ( { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-22 14:43:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        context : context.path.join ( "." )  +  "."  +  foundElement . path . join ( "." ) , 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-21 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        path : foundElement.leaf , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-09 00:10:59 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    } ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-19 17:39:16 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  cleanedImages :  {  path : string ;  context : string  } [ ]  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        for  ( const  foundImage  of  allFoundImages )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-02 02:59:20 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( foundImage . path . startsWith ( "<" )  &&  foundImage . path . endsWith ( ">" ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-22 14:43:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                // This is probably html
 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-02 02:59:20 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                const  doc  =  parse_html ( foundImage . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                const  images  =  Array . from ( doc . getElementsByTagName ( "img" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                const  paths  =  images . map ( ( i )  = >  i . getAttribute ( "src" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                cleanedImages . push ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    . . . paths . map ( ( path )  = >  ( {  path ,  context : foundImage.context  +  " (in html)"  } ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            // Split "circle:white;./assets/layers/.../something.svg" into ["circle", "./assets/layers/.../something.svg"]
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            const  allPaths  =  Utils . NoNull ( 
							 
						 
					
						
							
								
									
										
										
										
											2025-06-04 00:21:28 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                Utils . NoEmpty ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    foundImage . path ? . split ( ";" ) ? . map ( ( part )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( part . startsWith ( "http" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            return  part 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        return  part . split ( ":" ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 03:57:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            for  ( const  path  of  allPaths )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                cleanedImages . push ( {  path ,  context : foundImage.context  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  cleanedImages 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								export  class  FixImages  extends  DesugaringStep < ThemeConfigJson >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    private  readonly  _knownImages : Set < string > 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    constructor ( knownImages : Set < string > )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        super ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            "Walks over the entire theme and replaces images to the relative URL. Only works if the ID of the theme is an URL" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            "fixImages" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        this . _knownImages  =  knownImages 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  If  the  id  is  an  URL  to  a  json  file ,  replaces  "./"  in  images  with  the  path  to  the  json  file 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  const  theme  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *           "id" :  "https://raw.githubusercontent.com/seppesantens/MapComplete-Themes/main/VerkeerdeBordenDatabank/verkeerdeborden.json" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *          "layers" :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *              { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *                  "pointRendering" :  [ 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *                      { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *                          marker :  [ { "icon" :  "./TS_bolt.svg" } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *                          iconBadges :  [ { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              if :  "id=yes" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              then :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  mappings :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                          if :  "id=yes" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                          then :  "./Something.svg" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                                  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          "location" :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "point" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                              "centroid" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                          ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *                  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *              } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *          ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *      } 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-12 16:55:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     *  const  fixed  =  new  FixImages ( new  Set < string > ( ) ) . convert ( < any >  theme ,  ConversionContext . test ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  fixed . layers [ 0 ] [ "pointRendering" ] [ 0 ] . marker [ 0 ] . icon  // => "https://raw.githubusercontent.com/seppesantens/MapComplete-Themes/main/VerkeerdeBordenDatabank/TS_bolt.svg"
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  fixed . layers [ 0 ] [ "pointRendering" ] [ 0 ] . iconBadges [ 0 ] . then . mappings [ 0 ] . then  // => "https://raw.githubusercontent.com/seppesantens/MapComplete-Themes/main/VerkeerdeBordenDatabank/Something.svg"
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-23 19:48:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     * / 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    convert ( json : ThemeConfigJson ,  context : ConversionContext ) :  ThemeConfigJson  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        let  url : URL 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            url  =  new  URL ( json . id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            // Not a URL, we don't rewrite
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  json 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        const  absolute  =  url . protocol  +  "//"  +  url . host 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        let  relative  =  url . protocol  +  "//"  +  url . host  +  url . pathname 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        relative  =  relative . substring ( 0 ,  relative . lastIndexOf ( "/" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( relative . endsWith ( "assets/generated/themes" ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            context . warn ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                "Detected 'assets/generated/themes' as relative URL. I'm assuming that you are loading your file for the MC-repository, so I'm rewriting all image links as if they were absolute instead of relative" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-21 16:47:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            relative  =  absolute 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        const  knownImages  =  this . _knownImages 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        function  replaceString ( leaf : string )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( knownImages . has ( leaf ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  leaf 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( typeof  leaf  !==  "string" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                context . warn ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    "Found a non-string object while replacing images: "  +  JSON . stringify ( leaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  leaf 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-28 20:49:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( leaf . startsWith ( "./" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  relative  +  leaf . substring ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( leaf . startsWith ( "/" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  absolute  +  leaf 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  leaf 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        json  =  Utils . Clone ( json ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        for  ( const  metapath  of  metapaths )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 16:57:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( ! ExtractImages . isImageType ( metapath ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            const  mightBeTr  =  ExtractImages . mightBeTagRendering ( < any > metapath ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            Utils . WalkPath ( metapath . path ,  json ,  ( leaf )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( typeof  leaf  ===  "string" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    return  replaceString ( leaf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                if  ( mightBeTr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    // We might have reached a tagRenderingConfig containing icons
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    // lets walk every rendered value and fix the images in there
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-08 01:14:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    for  ( const  trpath  of  tagrenderingmetapaths )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 02:36:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        if  ( trpath . hints . typehint  !==  "rendered" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        Utils . WalkPath ( trpath . path ,  leaf ,  ( rendered )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            return  replaceString ( rendered ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        } ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  leaf 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-11 04:16:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  json 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-09 22:37:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-08 21:40:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}