| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  | import * as fs from "fs" | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-21 02:44:35 +01:00
										 |  |  |  | function genImages(dryrun = false) { | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |     console.log("Generating images") | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |     // These images are not referenced via 'Svg.ts' anymore and can be ignored
 | 
					
						
							|  |  |  |  |     const blacklist: string[] = [ | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "add", | 
					
						
							|  |  |  |  |         "addSmall", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "back", | 
					
						
							| 
									
										
										
										
											2024-01-25 03:33:28 +01:00
										 |  |  |  |         "circle", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "blocked", | 
					
						
							|  |  |  |  |         "brick_wall", | 
					
						
							|  |  |  |  |         "brick_wall_raw", | 
					
						
							|  |  |  |  |         "brick_wall_round", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "brick_wall_square", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "bug", | 
					
						
							|  |  |  |  |         "center", | 
					
						
							|  |  |  |  |         "checkmark", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "clock", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "close", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "community", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "compass", | 
					
						
							|  |  |  |  |         "compass_arrow", | 
					
						
							|  |  |  |  |         "confirm", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "copyright", | 
					
						
							|  |  |  |  |         "cross", | 
					
						
							|  |  |  |  |         "cross_bottom_right", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "crosshair", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "crosshair_locked", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "crosshair-locked", | 
					
						
							| 
									
										
										
										
											2023-11-19 16:20:47 +01:00
										 |  |  |  |         "delete_not_allowed", | 
					
						
							|  |  |  |  |         "direction_gradient", | 
					
						
							|  |  |  |  |         "direction_stroke", | 
					
						
							|  |  |  |  |         "duplicate", | 
					
						
							|  |  |  |  |         "elevator", | 
					
						
							|  |  |  |  |         "elevator_wheelchair", | 
					
						
							| 
									
										
										
										
											2024-01-25 03:33:28 +01:00
										 |  |  |  |         "envelope", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "eye", | 
					
						
							|  |  |  |  |         "filter", | 
					
						
							|  |  |  |  |         "filter_disable", | 
					
						
							|  |  |  |  |         "floppy", | 
					
						
							|  |  |  |  |         "gear", | 
					
						
							|  |  |  |  |         "gender_bi", | 
					
						
							|  |  |  |  |         "gender_inter", | 
					
						
							|  |  |  |  |         "gender_female", | 
					
						
							|  |  |  |  |         "gender_male", | 
					
						
							|  |  |  |  |         "gender_trans", | 
					
						
							|  |  |  |  |         "gender_queer", | 
					
						
							|  |  |  |  |         "generic_map", | 
					
						
							|  |  |  |  |         "gps_arrow", | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |         "hand", | 
					
						
							|  |  |  |  |         "help", | 
					
						
							|  |  |  |  |         "home", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "length_crosshair", | 
					
						
							|  |  |  |  |         "length-crosshair", | 
					
						
							|  |  |  |  |         "liberapay", | 
					
						
							|  |  |  |  |         "location", | 
					
						
							|  |  |  |  |         "location_empty", | 
					
						
							|  |  |  |  |         "location_locked", | 
					
						
							|  |  |  |  |         "location_refused", | 
					
						
							|  |  |  |  |         "location-refused", | 
					
						
							|  |  |  |  |         "location_unlocked", | 
					
						
							|  |  |  |  |         "logo", | 
					
						
							|  |  |  |  |         "logout", | 
					
						
							|  |  |  |  |         "mapcomplete_logo", | 
					
						
							|  |  |  |  |         "mapillary", | 
					
						
							|  |  |  |  |         "mapillary_black", | 
					
						
							|  |  |  |  |         "mastodon", | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |         "min", | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |  |         "move", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "move-arrows", | 
					
						
							|  |  |  |  |         "move_confirm", | 
					
						
							|  |  |  |  |         "move_not_allowed", | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |         "not_found", | 
					
						
							|  |  |  |  |         "osm_logo_us", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "osm-logo-us", | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |         "party", | 
					
						
							| 
									
										
										
										
											2024-01-25 03:33:28 +01:00
										 |  |  |  |         "pencil", | 
					
						
							| 
									
										
										
										
											2023-12-09 16:51:42 +01:00
										 |  |  |  |         "person", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "pin", | 
					
						
							|  |  |  |  |         "plantnet_logo", | 
					
						
							|  |  |  |  |         "plus", | 
					
						
							|  |  |  |  |         "reload", | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |  |         "resolved", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "ring", | 
					
						
							|  |  |  |  |         "robot", | 
					
						
							| 
									
										
										
										
											2024-01-25 03:33:28 +01:00
										 |  |  |  |         "scissors", | 
					
						
							|  |  |  |  |         "search", | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |  |         "search_disable", | 
					
						
							|  |  |  |  |         "share", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "SocialImageForeground", | 
					
						
							| 
									
										
										
										
											2024-01-16 23:03:33 +01:00
										 |  |  |  |         "speech_bubble", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "speech_bubble_black_outline", | 
					
						
							|  |  |  |  |         "square", | 
					
						
							| 
									
										
										
										
											2024-01-17 18:08:14 +01:00
										 |  |  |  |         "square_rounded", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "star", | 
					
						
							|  |  |  |  |         "star_half", | 
					
						
							|  |  |  |  |         "star_outline", | 
					
						
							|  |  |  |  |         "teardrop", | 
					
						
							|  |  |  |  |         "teardrop_with_hole_green", | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |  |         "statistics", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "translate", | 
					
						
							|  |  |  |  |         "triangle", | 
					
						
							| 
									
										
										
										
											2024-01-22 04:08:19 +01:00
										 |  |  |  |         "up", | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         "Upload", | 
					
						
							|  |  |  |  |         "wikidata", | 
					
						
							|  |  |  |  |         "wikimedia-commons-white", | 
					
						
							|  |  |  |  |         "wikimedia_commons_white", | 
					
						
							|  |  |  |  |         "wikipedia", | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |     ].map((s) => s.toLowerCase()) | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |     const dir = fs.readdirSync("./assets/svg") | 
					
						
							| 
									
										
										
										
											2020-11-05 12:28:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |     let module = | 
					
						
							| 
									
										
										
										
											2024-01-10 23:46:57 +01:00
										 |  |  |  |         'import Img from "./UI/Base/Img";\n\n/* @deprecated */\nexport default class Svg {\n\n\n' | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |     for (const path of dir) { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  |         if (path.endsWith("license_info.json")) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-04-10 15:01:28 +02:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-07-27 14:15:30 +02:00
										 |  |  |  |         if (path.endsWith(".license")) { | 
					
						
							|  |  |  |  |             continue | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |         if (!path.endsWith(".svg")) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |             throw "Non-svg file detected in the svg files: " + path | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |         let svg: string = fs | 
					
						
							|  |  |  |  |             .readFileSync("./assets/svg/" + path, "utf-8") | 
					
						
							| 
									
										
										
										
											2020-11-14 02:54:33 +01:00
										 |  |  |  |             .replace(/<\?xml.*?>/, "") | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  |             .replace(/<!DOCTYPE [^>]*>/, "") | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  |             .replace(/fill: ?none;/g, "fill: none !important;") // This is such a brittle hack...
 | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |             .replace(/\n/g, " ") | 
					
						
							|  |  |  |  |             .replace(/\r/g, "") | 
					
						
							|  |  |  |  |             .replace(/\\/g, "\\") | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |             .replace(/"/g, '\\"') | 
					
						
							| 
									
										
										
										
											2023-10-26 14:13:04 +02:00
										 |  |  |  |             .replaceAll(" ", " ") | 
					
						
							| 
									
										
										
										
											2022-07-26 11:38:10 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-26 14:13:04 +02:00
										 |  |  |  |         let hasNonAsciiChars = Array.from(svg) | 
					
						
							|  |  |  |  |             .filter((char) => char.charCodeAt(0) > 127) | 
					
						
							|  |  |  |  |             .map((char) => char.charCodeAt(0)) | 
					
						
							|  |  |  |  |             .join(", ") | 
					
						
							|  |  |  |  |         if (hasNonAsciiChars.length > 0) { | 
					
						
							|  |  |  |  |             throw "The svg '" + path + "' has non-ascii characters: " + hasNonAsciiChars | 
					
						
							| 
									
										
										
										
											2022-07-26 11:38:10 +02:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-19 12:34:05 +02:00
										 |  |  |  |         const name = path.substring(0, path.length - 4).replace(/[ -]/g, "_") | 
					
						
							| 
									
										
										
										
											2021-11-21 02:44:35 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-06 23:56:50 +02:00
										 |  |  |  |         const nameUC = name.toUpperCase().at(0) + name.substring(1) | 
					
						
							|  |  |  |  |         const svelteCode = | 
					
						
							|  |  |  |  |             '<script>\nexport let color = "#000000"\n</script>\n' + | 
					
						
							| 
									
										
										
										
											2023-11-16 03:30:29 +01:00
										 |  |  |  |             svg | 
					
						
							|  |  |  |  |                 .replace( | 
					
						
							|  |  |  |  |                     "<svg ", | 
					
						
							|  |  |  |  |                     "<svg {...$$$$restProps} on:click on:mouseover on:mouseenter on:mouseleave on:keydown " | 
					
						
							|  |  |  |  |                 ) | 
					
						
							|  |  |  |  |                 .replace(/\\"/g, '"') | 
					
						
							|  |  |  |  |                 .replace(/(rgb\(0%,0%,0%\)|#000000|#000)/g, "{color}") | 
					
						
							| 
									
										
										
										
											2023-10-06 23:56:50 +02:00
										 |  |  |  |         fs.writeFileSync("./src/assets/svg/" + nameUC + ".svelte", svelteCode, "utf8") | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (blacklist.some((item) => path.toLowerCase().endsWith(item + ".svg"))) { | 
					
						
							|  |  |  |  |             continue | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (dryrun) { | 
					
						
							|  |  |  |  |             svg = "<omitting svg - dryrun>" | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         let rawName = name | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         module += `    public static ${name} = "${svg}"\n` | 
					
						
							|  |  |  |  |         if (!dryrun) { | 
					
						
							|  |  |  |  |             module += `    public static ${name}_svg() { return new Img(Svg.${rawName}, true);}\n` | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |             module += `    public static ${name}_svg() { return new Img("", true);}\n` | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  |     module += "}\n" | 
					
						
							| 
									
										
										
										
											2023-07-15 18:24:39 +02:00
										 |  |  |  |     fs.writeFileSync("src/Svg.ts", module) | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |  |     console.log("Done") | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 22:38:47 +02:00
										 |  |  |  | genImages() |