@ironm00n/pyret-embed
v0.0.1
Published
A modern library for embedding Pyret into webpages with Next.js 14+ support
Maintainers
Readme
@ironm00n/pyret-embed
A modern, TypeScript-first library for embedding Pyret into webpages with Next.js 14+ support.
Installation
npm install @ironm00n/pyret-embedBrowser Support
This library targets modern browsers and requires:
- ES2024 features support (including
Promise.withResolvers())
Usage
Next.js 14+ (App Router)
"use client";
import { useEffect, useRef } from "react";
import { makeEmbedConfig } from "@ironm00n/pyret-embed";
export default function PyretEmbed() {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!containerRef.current) return;
makeEmbedConfig({
container: containerRef.current,
state: {
editorContents: "use context starter2024\n\n'Hello from Next.js!'",
replContents: "",
definitionsAtLastRun: "",
interactionsSinceLastRun: [],
},
options: {
footerStyle: "hide",
warnOnExit: false,
},
});
}, []);
return <div ref={containerRef} className="w-full h-96" />;
}Traditional HTML/JavaScript
<!DOCTYPE html>
<html>
<head>
<script type="module">
import { makeEmbed } from "@ironm00n/pyret-embed/api";
async function initPyret() {
const container = document.getElementById("pyret-container");
const embed = await makeEmbed("pyret-1", container);
embed.sendReset({
editorContents: "use context starter2024\n\n'Hello World!'",
replContents: "",
definitionsAtLastRun: "",
interactionsSinceLastRun: [],
});
}
window.addEventListener("load", initPyret);
</script>
</head>
<body>
<div id="pyret-container" style="width: 100%; height: 400px;"></div>
</body>
</html>Vanilla JavaScript
import { makeEmbed } from "@ironm00n/pyret-embed/api";
const container = document.getElementById("pyret-container");
makeEmbed("pyret-1", container).then((embed) => {
embed.sendReset({
editorContents: "use context starter2024\n\n'Hello!'",
replContents: "",
definitionsAtLastRun: "",
interactionsSinceLastRun: [],
});
});API Reference
See src/pyret.ts for full API documentation.
Development
With Nix (Recommended)
nix develop
npm install
npm run buildWithout Nix
npm install
npm run buildAvailable Scripts
npm run build- Build the packagenpm run dev- Build in watch modenpm run clean- Clean build artifactsnpm run typecheck- Type check without building
Examples
See the examples/ directory for complete working examples:
basic.html- Basic HTML usagefs.html- File system integrationnextjs-example.tsx- Next.js componentsimple-test.html- Simple test page- Various JavaScript examples
