forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wasmerio#351 from wasmerio/bare-wasix-example
Add some examples for running WASI programs
- Loading branch information
Showing
26 changed files
with
1,969 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Markdown Editor (Improved) | ||
|
||
An improved version of [the original Markdown Editor][original] which uses a | ||
Wasmer package instead of running a `*.wasm` file directly. | ||
|
||
[original]: ../markdown-editor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Wasmer Markdown Editor</title> | ||
<script type="module" defer src="./index.ts"></script> | ||
<link rel="stylesheet" href="./style.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="editor-container"> | ||
<textarea id="markdown-input" placeholder="Type your Markdown here..."></textarea> | ||
<iframe id="html-output"></iframe> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { init, Wasmer, Command } from "@wasmer/sdk"; | ||
|
||
async function initialize() { | ||
await init(); | ||
return await Wasmer.fromRegistry("wasmer-examples/markdown-renderer"); | ||
} | ||
|
||
function debounce(func: (...args: any[]) => void, delay: number): (...args: any[]) => void { | ||
let debounceTimer: ReturnType<typeof setTimeout>; | ||
|
||
return function(...args: any[]) { | ||
clearTimeout(debounceTimer); | ||
debounceTimer = setTimeout(() => func(...args), delay); | ||
}; | ||
} | ||
|
||
async function renderMarkdown(cmd: Command, markdown: string) { | ||
const instance = await cmd.run(); | ||
const stdin = instance.stdin.getWriter(); | ||
const encoder = new TextEncoder(); | ||
await stdin.write(encoder.encode(markdown)); | ||
await stdin.close(); | ||
|
||
const result = await instance.wait(); | ||
return result.ok ? result.stdoutUtf8 : null; | ||
} | ||
|
||
async function main() { | ||
const pkg = await initialize(); | ||
const output = document.getElementById("html-output") as HTMLIFrameElement; | ||
const markdownInput = document.getElementById("markdown-input") as HTMLTextAreaElement; | ||
|
||
const debouncedRender = debounce(async () => { | ||
const renderedHtml = await renderMarkdown(pkg.entrypoint!, markdownInput.value); | ||
if (renderedHtml) { | ||
output.srcdoc = renderedHtml; | ||
} | ||
}, 500); // 500 milliseconds debounce period | ||
|
||
markdownInput.addEventListener("input", debouncedRender); | ||
} | ||
|
||
main(); |
Oops, something went wrong.