-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
33 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
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 |
---|---|---|
|
@@ -163,3 +163,7 @@ label { | |
align-items: center; | ||
flex-wrap: wrap; | ||
} | ||
|
||
iframe#strudel { | ||
display: none; | ||
} |
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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<body style="background-color: #111"> | ||
<script type="module"> | ||
// this is expected to run in an iframe | ||
// this way, strudel runs in an iframe | ||
// so it wont mess with the global scope | ||
// + we can sandbox the evaluation | ||
// the js here is only for plumbing postMessages | ||
// + creating the strudel session | ||
import { StrudelSession } from "./src/strudel"; | ||
function send(type, msg) { | ||
window.parent.postMessage({ type, msg }); | ||
} | ||
window.parent.highlights = {}; | ||
|
||
const strudel = new StrudelSession({ | ||
onError: (...args) => send("onError", args), | ||
onHighlight: (...args) => { | ||
const [docId, phase, haps] = args; | ||
window.parent.highlights[docId] = haps; // set haps on window to skip serialization | ||
send("onHighlight", [docId, phase]); | ||
}, | ||
onUpdateMiniLocations: (...args) => send("onUpdateMiniLocations", args), | ||
}); | ||
|
||
window.addEventListener("message", (event) => { | ||
if (event.origin !== window.location.origin) { | ||
return; | ||
} | ||
// console.log("received", event.data); | ||
if (event.data.type === "eval") { | ||
strudel.eval(event.data.msg); | ||
} | ||
}); | ||
|
||
console.log("strudel iframe loaded", strudel); | ||
</script> | ||
</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,12 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
build: { | ||
rollupOptions: { | ||
input: { | ||
main: "index.html", | ||
strudel: "strudel.html", // iframe | ||
}, | ||
}, | ||
}, | ||
}); |