Skip to content

Commit

Permalink
Added example
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Klotz committed Oct 16, 2023
1 parent 2239522 commit 933e3ca
Show file tree
Hide file tree
Showing 17 changed files with 2,038 additions and 303 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: build-pages

on:
workflow_dispatch:
inputs:
busytexreleasetag:
description: 'wasm_release_tag'
required: true

jobs:
build-pages:
runs-on: ubuntu-22.04
steps:

- uses: actions/checkout@v2

- run: npm install && npm build

- run: |
mkdir pages
cd $GITHUB_WORKSPACE/pages
mkdir -p example
cp ../example/* example/
mkdir -p build/wasm/
cp ../build/wasm/busytex.wasm ../build/wasm/busytex.js build/wasm/
mkdir -p build-js/
cp ../build-js/BusytexAsync.browser.js build-js/
mkdir -p typescript/test/assets
cp ../typescript/test/assets/* typescript/test/assets/
- uses: actions/upload-pages-artifact@v2
with:
path: $GITHUB_WORKSPACE/pages
1 change: 0 additions & 1 deletion example/README.md

This file was deleted.

Binary file removed example/assets/test.png
Binary file not shown.
2 changes: 0 additions & 2 deletions example/assets/test.svg

This file was deleted.

1 change: 0 additions & 1 deletion example/assets/test.txt

This file was deleted.

5 changes: 0 additions & 5 deletions example/example.bib

This file was deleted.

185 changes: 0 additions & 185 deletions example/example.html

This file was deleted.

30 changes: 0 additions & 30 deletions example/example.py

This file was deleted.

43 changes: 0 additions & 43 deletions example/example.sh

This file was deleted.

14 changes: 0 additions & 14 deletions example/example.tex

This file was deleted.

16 changes: 16 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>

<head>
<title>Busytex Async</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/react/jsxLoader.min.js"></script>
<script data-type="module" type="text/babel" src="index.jsx"></script>
</head>

<body>
</body>

</html>
55 changes: 55 additions & 0 deletions example/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const initialEditorText = await fetch("../typescript/test/assets/test.tex").then((result) => result.text());

const worker = new Worker("worker.js");
worker.postMessage({ type: "initialize" });

let numMessages = 0;

function DemoEditor() {
const [editorText, setEditorText] = React.useState(initialEditorText);
const [isCompiling, setIsCompiling] = React.useState(false);
const [isInitialized, setIsInitialized] = React.useState(false);
const [logContent, setLogContent] = React.useState([]);
const [pdfDataUrl, setPdfDataUrl] = React.useState("");
const logEndRef = React.createRef();

React.useEffect(() => {
logEndRef.current.scrollIntoView({ behavior: 'smooth' });
});

worker.onmessage = (event) => {
console.log("Main thread recieved", event)
if (event.data.type === "initialized") {
setIsInitialized(true);
} else if (event.data.type === "print") {
setLogContent([...logContent, <p className="m-0 p-0 text-monospace" key={numMessages++}>{event.data.message}</p>]);
} else if (event.data.type === "printErr") {
setLogContent([...logContent, <p className="m-0 p-0 text-monospace text-danger" key={numMessages++}>{event.data.message}</p>]);
} else if (event.data.type === "compiled") {
setIsCompiling(false);
setPdfDataUrl(event.data.pdf);
setLogContent([...logContent, <p className="m-0 p-0 text-monospace text-success" key={numMessages++}>Compile done!</p>]);
}
}

return <div className="container">
<div className="row mt-3">
<div className="col">
<button onClick={() => { worker.postMessage({type: "compile", tex: editorText}); setIsCompiling(true); }} disabled={isCompiling || !isInitialized}>Compile</button>
{ !(isInitialized) && <span>Initializing WASM, please wait...</span> }
{ pdfDataUrl!="" && <a download="main.pdf" href={pdfDataUrl}>Download PDF</a> }
</div>
</div>
<div className="row mt-3 mh-75 h-75">
<textarea className="col mh-100" style={{fontFamily:"monospace"}} onChange={(e) => setEditorText(e.target.value)} value={editorText}></textarea>
<div className="col mh-100 overflow-auto">{logContent}<div ref={logEndRef} /></div>
</div>
</div>;
}


const root = ReactDOM.render(
<DemoEditor />,
document.body
);

Loading

0 comments on commit 933e3ca

Please sign in to comment.