diff options
| author | brian cully <bjc@spork.org> | 2025-12-27 14:33:52 -0500 |
|---|---|---|
| committer | brian cully <bjc@spork.org> | 2025-12-27 14:33:52 -0500 |
| commit | c182d8179ddd382543b7e56f46e78bf6a6724b2a (patch) | |
| tree | 0bc2f2e45ec99711110b4d6b463e472312c6224c | |
| parent | b35fd970e93a5bb4290134f842ac4f7e00a177b2 (diff) | |
| download | polyring-c182d8179ddd382543b7e56f46e78bf6a6724b2a.tar.gz polyring-c182d8179ddd382543b7e56f46e78bf6a6724b2a.zip | |
dispatch wasm/pure based on query part of url
| -rw-r--r-- | site/index.html | 6 | ||||
| -rw-r--r-- | site/main.mjs | 29 | ||||
| -rw-r--r-- | site/pure.mjs | 4 | ||||
| -rw-r--r-- | site/wasm.mjs | 7 |
4 files changed, 34 insertions, 12 deletions
diff --git a/site/index.html b/site/index.html index bdb2f5d..2d4c0e1 100644 --- a/site/index.html +++ b/site/index.html @@ -8,7 +8,8 @@ </head> <body> - <h1>polyring</h1> + <h1>polyring<sub class='subst-type'></sub></h1> + <p class='subst-alts'></p> <p>benchmarking maximal convex polygon finding</p> <button>go</button> @@ -16,8 +17,7 @@ <br> <canvas width='500' height='500'></canvas> - <!-- <script src='./pure.mjs' type='module'></script> --> - <script src='./wasm.mjs' type='module'></script> + <script src='./main.mjs' type='module'></script> <footer> <address><a href='https://git.spork.org/polyring.git'>src</a></address> diff --git a/site/main.mjs b/site/main.mjs new file mode 100644 index 0000000..1457958 --- /dev/null +++ b/site/main.mjs @@ -0,0 +1,29 @@ +let type = 'pure'; +let alts = ['wasm']; +switch (self.location.search) { +case '?wasm': + type = 'wasm'; + alts = ['pure']; + break; +} +const mod = `./${type}.mjs`; + +document.querySelectorAll('.subst-type').forEach(elt => { + elt.textContent = type; +}); +document.querySelectorAll('.subst-alts').forEach(elt => { + const links = alts.map(t => { + const link = document.createElement('a'); + link.setAttribute('href', `?${t}`); + link.textContent = t; + return link; + }); + links.forEach(l => elt.appendChild(l)); +}); + +async function loaded() { + const x = await import(mod); + await x.default(); +} + +document.addEventListener('DOMContentLoaded', loaded); diff --git a/site/pure.mjs b/site/pure.mjs index 336b876..6a4447c 100644 --- a/site/pure.mjs +++ b/site/pure.mjs @@ -201,7 +201,7 @@ function bouncePoints(points) { return didBounce; } -async function loaded() { +export default async function () { const canvas = document.querySelector('canvas'); const ctx = canvas.getContext('2d'); console.debug('canvas:', canvas, 'ctx', ctx); @@ -258,5 +258,3 @@ async function loaded() { //goButton.onclick({ target: goButton }); render(document.timeline.currentTime); } - -document.addEventListener('DOMContentLoaded', loaded); diff --git a/site/wasm.mjs b/site/wasm.mjs index 29a2741..e11f642 100644 --- a/site/wasm.mjs +++ b/site/wasm.mjs @@ -1,7 +1,2 @@ import init from './wasm/polyring.js'; - -async function loaded() { - await init(); -} - -document.addEventListener('DOMContentLoaded', loaded); +export default init; |
