Skip to content

Commit

Permalink
samples: update wasmJs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeHaine committed Mar 23, 2024
1 parent 31035e4 commit 114cc31
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 18 deletions.
1 change: 0 additions & 1 deletion samples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ plugins {

repositories {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}

Expand Down
83 changes: 68 additions & 15 deletions samples/src/wasmJsMain/resources/index.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- http://localhost:80 -->
<meta http-equiv="origin-trial" content="AjytAe1FWUIWH/RzqsOWlXYw7kGwt11ejbvR/ArmAU4QbXIPg69wzpniDhPByiOZ9pdNqsdMsXsoxggVtfGhwwMAAABOeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwIiwiZmVhdHVyZSI6IldlYkFzc2VtYmx5R0MiLCJleHBpcnkiOjE2OTg5Njk1OTl9">
<!-- http://localhost:8080 -->
<meta http-equiv="origin-trial" content="AtSRFRWKTCcQHDFUUQL1VaVz9mjmsK1xm5k0S8etkmvMLa5TsiNeQsle/eDgdZVkm1PM1WmrSMx52kI8yAP2UgEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8081 -->
<meta http-equiv="origin-trial" content="AspyK9xe4tO2aIvJWnr5HTRT9GqpGJID2qZjj+0OvhKHp9JrUP+92PF+Rt11Tyi7cKSEB7OFFGdeVs7Ns5TMhAUAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODEiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8082 -->
<meta http-equiv="origin-trial" content="AoPGqwBGEQW3twSDYvXt1JHz5zg7Z4o+Orwr8NxdVoXJ68zjwOi2C8/0w4xFYW6UUH8w97eIjykGOa/+jIBfTQMAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODIiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8083 -->
<meta http-equiv="origin-trial" content="AvV2HYiHMw7lpIVcmGMSVmm6xC0Gzu4W5xBnZExmfHtE5zyNKFszcyNGm5IfCFQ6swnMotbn16lS1ozkJ0QzEAEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODMiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<meta charset="UTF-8">
<!-- http://localhost:80 -->
<meta http-equiv="origin-trial"
content="AjytAe1FWUIWH/RzqsOWlXYw7kGwt11ejbvR/ArmAU4QbXIPg69wzpniDhPByiOZ9pdNqsdMsXsoxggVtfGhwwMAAABOeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwIiwiZmVhdHVyZSI6IldlYkFzc2VtYmx5R0MiLCJleHBpcnkiOjE2OTg5Njk1OTl9">
<!-- http://localhost:8080 -->
<meta http-equiv="origin-trial"
content="AtSRFRWKTCcQHDFUUQL1VaVz9mjmsK1xm5k0S8etkmvMLa5TsiNeQsle/eDgdZVkm1PM1WmrSMx52kI8yAP2UgEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8081 -->
<meta http-equiv="origin-trial"
content="AspyK9xe4tO2aIvJWnr5HTRT9GqpGJID2qZjj+0OvhKHp9JrUP+92PF+Rt11Tyi7cKSEB7OFFGdeVs7Ns5TMhAUAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODEiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8082 -->
<meta http-equiv="origin-trial"
content="AoPGqwBGEQW3twSDYvXt1JHz5zg7Z4o+Orwr8NxdVoXJ68zjwOi2C8/0w4xFYW6UUH8w97eIjykGOa/+jIBfTQMAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODIiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">
<!-- http://localhost:8083 -->
<meta http-equiv="origin-trial"
content="AvV2HYiHMw7lpIVcmGMSVmm6xC0Gzu4W5xBnZExmfHtE5zyNKFszcyNGm5IfCFQ6swnMotbn16lS1ozkJ0QzEAEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODMiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0=">

<title>LittleKt - WASM</title>
<title>LittleKt - WASM</title>
<style>
#warning {
display: none;
}

#warning li {
padding-bottom: 15px;
}

#warning span.code {
font-family: monospace;
}
</style>
</head>
<body>
<div id="canvas-container" style="text-align:center;">
<div id="warning">
⚠️ Please make sure that your runtime environment supports the latest version of Wasm GC and Exception-Handling
proposals.
For more information, see <a href="https://kotl.in/wasm-help">https://kotl.in/wasm-help</a>.
<br/>
<br/>
<ul>
<li>For <b>Chrome</b> and <b>Chromium-based</b> browsers (Edge, Brave etc.), it <b>should just work</b> since
version 119.
</li>
<li>For <b>Firefox</b> 120 it <b>should just work</b>.</li>
<li>For <b>Firefox</b> 119:
<ol>
<li>Open <span class="code">about:config</span> in the browser.</li>
<li>Enable <strong>javascript.options.wasm_gc</strong>.</li>
<li>Refresh this page.</li>
</ol>
</li>
</ul>
</div>
<div id="canvas-container" style="text-align:center;">
<canvas id="canvas" width="960" height="540" style="border:1px solid #000000;"></canvas>
</div>
</body><script type="text/javascript" src="samples.js"></script>
</div>
</body>
<script type="text/javascript" src="samples.js"></script>

<script type="application/javascript">
const unhandledError = (event, error) => {
if (error instanceof WebAssembly.CompileError) {
document.getElementById("warning").style.display="initial";

// Hide a Scary Webpack Overlay which is less informative in this case.
const webpackOverlay = document.getElementById("webpack-dev-server-client-overlay");
if (webpackOverlay != null) webpackOverlay.style.display="none";
}
}
addEventListener("error", (event) => unhandledError(event, event.error));
addEventListener("unhandledrejection", (event) => unhandledError(event, event.reason));
</script>
</html>
10 changes: 8 additions & 2 deletions samples/src/wasmJsMain/webpack.config.d/cleanupSourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

const outDir = __dirname + "/kotlin/"
const projecName = path.basename(__dirname);
const mapFile = outDir + projecName + ".map"
const mapFileLegacy = outDir + projecName + ".map"
const mapFile = outDir + projecName + ".wasm.map"

const sourcemap = JSON.parse(fs.readFileSync(mapFile))
let sourcemap
try {
sourcemap = JSON.parse(fs.readFileSync(mapFileLegacy))
} catch (e) {
sourcemap = JSON.parse(fs.readFileSync(mapFile))
}
const sources = sourcemap["sources"]
srcLoop: for (let i in sources) {
const srcFilePath = sources[i];
Expand Down

0 comments on commit 114cc31

Please sign in to comment.