wip
This commit is contained in:
		
							parent
							
								
									fff4fdea81
								
							
						
					
					
						commit
						89e36d7eb0
					
				
					 8 changed files with 0 additions and 6074 deletions
				
			
		
							
								
								
									
										93
									
								
								tests/web.rs
									
										
									
									
									
								
							
							
						
						
									
										93
									
								
								tests/web.rs
									
										
									
									
									
								
							|  | @ -1,93 +0,0 @@ | |||
| //! Test suite for the Web and headless browsers.
 | ||||
| 
 | ||||
| #![cfg(target_arch = "wasm32")] | ||||
| 
 | ||||
| extern crate wasm_bindgen_test; | ||||
| use wasm_bindgen_test::*; | ||||
| 
 | ||||
| wasm_bindgen_test_configure!(run_in_browser); | ||||
| 
 | ||||
| #[wasm_bindgen_test] | ||||
| fn basic_merge() { | ||||
|     // arrange
 | ||||
|     let array: js_sys::Array = js_sys::Array::new(); | ||||
|     let file1 = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version='1.0' encoding='utf-8'?>
 | ||||
|          <gpx version='1.0' encoding='UTF-8'> | ||||
|            <trk> | ||||
|              <name>file1 tracks</name> | ||||
|              <type>1</type> | ||||
|              <trkseg> | ||||
|                <trkpt lat='35.466388' lon='-111.640076'> | ||||
|                  <ele>2152.8</ele> | ||||
|                  <time>2020-09-27T15:39:27+00:00</time> | ||||
|                </trkpt> | ||||
|              </trkseg> | ||||
|            </trk> | ||||
|          </gpx>",
 | ||||
|     ); | ||||
|     let file2 = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version='1.0' encoding='utf-8'?>
 | ||||
|          <gpx version='1.0' encoding='UTF-8'> | ||||
|            <trk> | ||||
|              <name>file2 tracks</name> | ||||
|              <type>1</type> | ||||
|              <trkseg> | ||||
|                <trkpt lat='35.339854' lon='-111.737165'> | ||||
|                  <ele>2556.8</ele> | ||||
|                  <time>2020-09-26T19:07:14+00:00</time> | ||||
|                </trkpt> | ||||
|              </trkseg> | ||||
|            </trk> | ||||
|          </gpx>",
 | ||||
|     ); | ||||
|     array.push(&file1); | ||||
|     array.push(&file2); | ||||
| 
 | ||||
|     let exp = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version=\"1.0\" encoding=\"utf-8\"?>
 | ||||
| <gpx version=\"1.1\" creator=\"https://github.com/georust/gpx\">
 | ||||
|   <metadata> | ||||
|     <name>merged</name> | ||||
|     <author> | ||||
|       <link href=\"https://gpx.thermokar.st\" />
 | ||||
|     </author> | ||||
|   </metadata> | ||||
|   <trk> | ||||
|     <name>file1 tracks</name> | ||||
|     <type>1</type> | ||||
|     <trkseg> | ||||
|       <trkpt lat=\"35.466388\" lon=\"-111.640076\">
 | ||||
|         <ele>2152.8</ele> | ||||
|         <time>2020-09-27T15:39:27+00:00</time> | ||||
|       </trkpt> | ||||
|     </trkseg> | ||||
|   </trk> | ||||
|   <trk> | ||||
|     <name>file2 tracks</name> | ||||
|     <type>1</type> | ||||
|     <trkseg> | ||||
|       <trkpt lat=\"35.339854\" lon=\"-111.737165\">
 | ||||
|         <ele>2556.8</ele> | ||||
|         <time>2020-09-26T19:07:14+00:00</time> | ||||
|       </trkpt> | ||||
|     </trkseg> | ||||
|   </trk> | ||||
|   <rte /> | ||||
| </gpx>",
 | ||||
|     ); | ||||
| 
 | ||||
|     // act
 | ||||
|     let obs = gpx_web_utils::merge(array); | ||||
| 
 | ||||
|     // assert
 | ||||
|     assert_eq!(obs, exp); | ||||
| } | ||||
| 
 | ||||
| // TODO: https://github.com/rustwasm/wasm-bindgen/issues/2286
 | ||||
| // #[wasm_bindgen_test]
 | ||||
| // #[should_panic]
 | ||||
| // fn invalid_inputs() {
 | ||||
| //     let array: js_sys::Array = js_sys::Array::new_with_length(10);
 | ||||
| //     let obs = gpx_web_utils::merge(array);
 | ||||
| // }
 | ||||
							
								
								
									
										2
									
								
								www/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								www/.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,2 +0,0 @@ | |||
| node_modules | ||||
| dist | ||||
							
								
								
									
										5
									
								
								www/bootstrap.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								www/bootstrap.js
									
										
									
									
										vendored
									
									
								
							|  | @ -1,5 +0,0 @@ | |||
| // A dependency graph that contains any wasm must all be imported
 | ||||
| // asynchronously. This `bootstrap.js` file does the single async import, so
 | ||||
| // that no one else needs to worry about it again.
 | ||||
| import("./index.js") | ||||
|   .catch(e => console.error("Error importing `index.js`:", e)); | ||||
|  | @ -1,46 +0,0 @@ | |||
| <!DOCTYPE html> | ||||
| <html> | ||||
|   <head> | ||||
|     <meta charset="utf-8"> | ||||
|     <title>gpx.thermokar.st</title> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|     <style> | ||||
|       body { | ||||
|         max-width: 35em; | ||||
|         margin: 0 auto; | ||||
|         line-height: 1.5; | ||||
|         font-family: sans-serif; | ||||
|         font-size: large; | ||||
|       } | ||||
|     </style> | ||||
|   </head> | ||||
|   <body> | ||||
|     <h1> | ||||
|       <a href="https://gpx.thermokar.st">gpx.thermokar.st</a> | ||||
|     </h1> | ||||
|     <noscript> | ||||
|       <mark> | ||||
|         This page contains webassembly and javascript content, please enable | ||||
|         javascript in your browser. | ||||
|       </mark> | ||||
|     </noscript> | ||||
|     <p> | ||||
|       This client-side tool is for merging | ||||
|       <a href="https://www.topografix.com/gpx.asp">GPX files</a>. | ||||
|       Please note, this has only been tested on GPX files produced by | ||||
|       <a href="https://www.garmin.com">Garmin</a> and | ||||
|       <a href="https://www.strava.com">Strava</a> - your mileage may vary. | ||||
|     </p> | ||||
|     <form> | ||||
|       <input id="gpxInput" type="file" multiple accept="text/gpx,.gpx"> | ||||
|     </form> | ||||
|     <hr> | ||||
|     <p> | ||||
|       <small> | ||||
|          <a href="https://github.com/thermokarst/gpx-web-utils"> | ||||
|           https://github.com/thermokarst/gpx-web-utils</a> | ||||
|       </small> | ||||
|     </p> | ||||
|     <script src="./bootstrap.js"></script> | ||||
|   </body> | ||||
| </html> | ||||
							
								
								
									
										37
									
								
								www/index.js
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								www/index.js
									
										
									
									
									
								
							|  | @ -1,37 +0,0 @@ | |||
| import * as gpx from "gpx-web-utils"; | ||||
| 
 | ||||
| const inputElement = document.getElementById("gpxInput"); | ||||
| const loadingElement = document.createElement("span"); | ||||
| 
 | ||||
| loadingElement.innerHTML = "<strong>processing...</strong>"; | ||||
| inputElement.value = ""; | ||||
| inputElement.addEventListener("change", readFiles, false); | ||||
| 
 | ||||
| function readFiles() { | ||||
|   if (inputElement.files.length < 2) { alert("open two or more files"); return; } | ||||
| 
 | ||||
|   inputElement.replaceWith(loadingElement); | ||||
|   const files = Array.from(inputElement.files); | ||||
|   const promises = files.map(f => f.text()); | ||||
| 
 | ||||
|   Promise.all(promises).then(gpxes => { | ||||
|     try { | ||||
|       const merged = gpx.merge(gpxes); | ||||
|       writeOutput(merged); | ||||
|     } catch { | ||||
|       alert("there was a problem, please check the console."); | ||||
|     } finally { | ||||
|       inputElement.value = ""; | ||||
|       loadingElement.replaceWith(inputElement); | ||||
|     } | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| function writeOutput(file) { | ||||
|     const blob = new Blob([file], {type: "text/gpx"}); | ||||
|     const anchorElement = document.createElement("a"); | ||||
|     anchorElement.href = URL.createObjectURL(blob); | ||||
|     anchorElement.download = "merged.gpx"; | ||||
|     anchorElement.click(); | ||||
|     URL.revokeObjectURL(anchorElement.href); | ||||
| } | ||||
							
								
								
									
										5842
									
								
								www/package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										5842
									
								
								www/package-lock.json
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -1,35 +0,0 @@ | |||
| { | ||||
|   "name": "gpx-web-utils", | ||||
|   "version": "0.0.1", | ||||
|   "description": "just some gpx-related tools that i want to use.", | ||||
|   "main": "index.js", | ||||
|   "scripts": { | ||||
|     "build": "webpack --config webpack.config.js", | ||||
|     "start": "webpack-dev-server" | ||||
|   }, | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "git+https://github.com/thermokarst/gpx-web-utils.git" | ||||
|   }, | ||||
|   "keywords": [ | ||||
|     "webassembly", | ||||
|     "wasm", | ||||
|     "rust", | ||||
|     "webpack" | ||||
|   ], | ||||
|   "author": "Matthew Ryan Dillon <matthewrdillon@gmail.com>", | ||||
|   "license": "MIT", | ||||
|   "bugs": { | ||||
|     "url": "https://github.com/thermokarst/gpx-web-utils/issues" | ||||
|   }, | ||||
|   "homepage": "https://github.com/thermokarst/gpx-web-util#readme", | ||||
|   "dependencies": { | ||||
|     "gpx-web-utils": "file:../pkg" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "webpack": "^4.29.3", | ||||
|     "webpack-cli": "^3.1.0", | ||||
|     "webpack-dev-server": "^3.1.5", | ||||
|     "copy-webpack-plugin": "^5.0.0" | ||||
|   } | ||||
| } | ||||
|  | @ -1,14 +0,0 @@ | |||
| const CopyWebpackPlugin = require("copy-webpack-plugin"); | ||||
| const path = require('path'); | ||||
| 
 | ||||
| module.exports = { | ||||
|   entry: "./bootstrap.js", | ||||
|   output: { | ||||
|     path: path.resolve(__dirname, "dist"), | ||||
|     filename: "bootstrap.js", | ||||
|   }, | ||||
|   mode: "development", | ||||
|   plugins: [ | ||||
|     new CopyWebpackPlugin(['index.html']) | ||||
|   ], | ||||
| }; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue