Skip to content

Embedding the editor in a web page

Audience: web developers who want a struktJS editor inside their own page · ~6 min read · Prerequisites: The editor basics

What it is

The embeddable editor is the projectional editor on its own, without the IDE around it: no menus, no panes, no project tree, no source control. You give it a piece of source text and an element; it draws the editable structure there, checks it as you type, offers completion and intentions, and tells your page what changed.

Everything that makes the editor an editor works inside it: structural editing, completion, intentions (Alt+Enter), placement constraints, type and rule checks shown on the nodes, and a language's own notations — maths, diagrams and so on.

Build it

npm run build:embed

This writes dist/embed/: struktjs-embed.js, struktjs-embed.css, a chunks/ folder (loaded on demand), a wasm/ folder (the parsers) and a demo.html you can open from any static web server. Serve the folder as it is; nothing in it needs a back end.

The build keeps only the languages listed in customers/embed-minimal/customer.json — Core, the formula (maths) language and the diagram language by default. A smaller set means a smaller download. To embed other languages, copy that file, change its languages.include list, and run node scripts/build-embed.mjs --profile <your-folder-name>. A second ready-made profile, embed-nocore, leaves out the Core language entirely, for pages that embed their own languages. Add "embed": { "defaultLanguage": "<name>" } to a profile to choose the language used when the page does not name one.

Try the demo

Quickest (development server). Run npm run dev, then open /tests/fixtures/embed-demo.html on the address Vite prints. Type "a" + 1 to see a type error, press Ctrl+Space for completion and Alt+Enter for intentions. /embed-host-demo.html shows the same editor on a page with its own styles, to check that the page and the editor do not affect each other.

The built library. Run npm run build:embed, then serve dist/embed/ with any static web server and open demo.html. Use a web server, not a file:// address: the parsers and the on-demand chunks are loaded over HTTP.

A page for customers. npm run build:showcase writes dist/showcase/: a finished, themeable page with five examples: a loan formula, a discount table and an approval flow, each opening with one deliberate mistake for the visitor to fix, an equipment-selection example (a pile, the ground and an equipment catalogue, ranked by rules) whose report is generated from the model and refreshes as the visitor edits, and a robot maze whose program is also generated as a small interactive page (Play, Step, Reset) that restarts when the visitor edits the program. Serve the folder from any static web server (every link is relative, so a sub-folder works). The page, its colours (one block of --sc-* variables at the top of showcase.css) and its examples live in embed/showcase/.

Without Core. node scripts/build-embed.mjs --profile embed-nocore builds the Core-free profile (default language sexpr; asking for core reports an unknown language). It writes to dist/embed/ too, so it replaces the previous build; add --out <dir> to keep both.

Several models. Pass models: [{ name, source }] (and modelName for the edited one) to mountEditor, and call setModels(list) to change them later. See the options below.

Put it in a page

<link rel="stylesheet" href="./struktjs-embed.css">
<div id="editor"></div>
<script type="module">
  import { mountEditor } from "./struktjs-embed.js";

  const ed = await mountEditor(document.getElementById("editor"), {
    source: 'x = 1\ny = "a" + 1\n',
    onChange: (text) => console.log(text),
    onIssues: (issues) => console.log(issues.map((i) => i.message)),
  });
</script>

The stylesheet only styles the editor. Your page's own colours, fonts and layout stay as they are, and the editor does not inherit your page's text styling.

Options

Option What it does
source The text to edit, in the language's own file syntax (Python-style for Core, JavaScript for a JavaScript language, and so on).
core A core made with createCore({ packs }) (see the headless core). The editor then edits with that core's languages and does not load the build's own set; language and imports name languages of that core, and the default is core.defaultLanguage. Several editors can share one core. The core and the editor must come from the same build (the package gives you that).
language The name of a built-in language, such as "formula" or "diagram". Default: Core, or the build profile's default language.
imports Other built-in languages to compose into language, by name, as a model's imports do in the IDE. language: "core", imports: ["coreDecisionTable"] gives Core with decision tables drawn as tables. They must be in the build's language set.
runtime How run() executes a program of a language that runs on Python (Core): { engine?, pyodideUrl?, autoDownload?, confirmDownload? }. By default the program runs on Pyodide (CPython compiled to WebAssembly) in a worker. Nothing is downloaded unless the page agrees: autoDownload: true, or confirmDownload(origin) resolving true; otherwise run() resolves { ok: false, error } saying why. pyodideUrl is the directory of a Pyodide distribution you serve yourself (offline pages); the default is the jsDelivr copy of the pinned version. engine: "evaluator" runs it on struktJS's own evaluator in the page instead: nothing is downloaded and a strict Content-Security-Policy is fine (the customer showcase does this), and the other options then do nothing. Other languages run on their evaluator and ignore it.
models, modelName Other models of the same project, as { name, source }, and the name of the one being edited (default "main"). The editor then offers and checks references into them, and run() can follow imports of them, as far as the language supports that. setModels(list) replaces them later.
theme "light", "dark", "ember" (the look of the struktJS website: a light palette of cream, white, near-black ink and an orange accent, the same as the Ember colour theme of the IDE) or "auto" (light or dark, following the page's colour scheme). Default "auto".
onChange(text) Called after every edit with the new source text.
onIssues(issues) Called after every check run with the problems found. Each has severity, message and the nodeId it belongs to. A type problem in arithmetic (+, -, *, /) also has explain: { reason, hint? }, the same problem in plain words with a suggestion.
onSelect(nodeId) Called when the selected node changes: its id, or null when nothing is selected. Selecting a value reports the node that holds it. It is not called again for the same node.
onOpenInfoPanel(nodeId) Called when the visitor presses More info in a node's tooltip (double-click a node). The button is only offered when this is set or an Inspector is mounted with ed.mountInspector(el); with an Inspector it also brings that Inspector into view.
rememberCompletions true stores which completions you pick in the page's local storage so frequent ones rank first next time. Default false: the editor writes nothing to your page's storage.
notations A list of notation names to show from the start, e.g. ["math", "grid"] for KernelF: a node whose concept offers one opens in it (a / b as a stacked fraction, a decision table as a grid) instead of in its text form. The source text does not change and the visitor can switch a node back. It applies to what is there when the editor opens (and after setSource), not to nodes typed later.
rootHeader false leaves out the header line a language's root writes above the program (kernelf, formula, robot file :, device :), so the program starts on the first line instead of indented under a name. Default true. A language whose root has no header, such as Core, is unaffected.
wasmBase Where the parser files are, if you moved the wasm/ folder.

What you can do with it

mountEditor returns an object with:

  • getSource() and setSource(text) — read or replace the whole program.
  • await getChunk() and await setChunk(chunk) — the same, as a LionWeb serialization chunk (JSON). Every node keeps a stable id across edits, so the chunk can be stored or sent to a LionWeb repository and read back with mountEditor(el, { chunk }). setChunk resolves with a report of anything the language could not carry over (empty means nothing was lost) and rejects something that is not a chunk of exactly one root. getChunk({ version, newId }) can say which serialization format to write (a repository only accepts its own) and where the ids of new nodes come from. getChunkSync() is the same without waiting: it returns the chunk once the LionWeb code has been loaded (by an earlier getChunk/setChunk or a chunk option) and null before that, for a handler such as pagehide that has to write synchronously.
  • getIssues() and focusNode(nodeId) — list the issues and jump to the node one belongs to.
  • workbench.types.describe(nodeId) — what a reader wants to know about one node: its text (text), its type in plain words (plain: "a number", "text", "true or false"), and the type problems on it, each with its plain-words explain where there is one. Use it with onSelect to show the selected node's type next to the editor. text is the node's source when it is short and on one line, otherwise the name of its concept ("decision table"), and named is true then. A statement that carries a value (a return) is described by that value's type and names it as of. A statement without a value, or a node nothing is known about, gives null; a node with no type of its own gives the nearest enclosing node's type and says which (via). A node inside an expression that has a type problem gets that expression and its problems as within, so you can say what the node is and what is wrong around it.
  • mountProblems(element) — a ready-made problems list: one row per issue with its severity colour and message. Clicking a row jumps to the node. It updates after every check. (The same list without an editor: see Problems and results without an editor below.)
  • mountInspector(element) — the Inspector: details for the node you have selected (its type, description and relations). It follows the selection in the editor.
  • run() — run the program and get back its output lines, any error and its final value. For Core this is real Python on Pyodide (see the runtime option); input() inside functions works in Chromium-based browsers. Pass { input: (prompt) => "…" } to answer the program's input() calls, and { timeoutMs: 5000 } or { signal } to stop a program that runs too long; the result then says cancelled: true and keeps what was printed so far.
  • generate() — run the language's generator and get the text it produces.
  • dispose() — remove the editor, its pop-ups and everything it added to the page.

You can mount several editors on one page, in different languages. Each keeps its own text, checks and undo history.

Good to know

  • Ghost text is on by default, as in the IDE: typing into an empty cell greys in the one clear continuation instead of opening the completion menu, and Ctrl+Space opens the menu. The embedded editor reads the same ghostText preference from the host page's struktjs.preferences entry in localStorage if there is one; a host that wants the menu to open while typing sets ghostText to false there.

  • Browsers. Chromium-based browsers, Firefox and Safari are tested.

  • Page styles. The editor protects your page from its own styles, and its own look is protected from your page's plain element rules (for example button { … } or a CSS framework's base styles). Rules marked !important, rules that target classes or ids the editor happens to use, and rules for SVG or MathML elements can still reach it.
  • What is not included. Project files and folders (other models are passed in as text) and source control. The debugger and live collaboration are not part of the embedded editor.

For how it works inside, see Embedding in a web page in the Developer Guide.

The workbench API of an embed

The handle mountEditor returns has a workbench property: the workbench API bound to that one editor. Its model, editor, checks, generator, run, types, history and event namespaces work on the embedded document; project, files, Git, the debugger and the IDE's windows are not part of an embed and report UnavailableError (see workbench.capabilities).

Remember the visitor's edits

The editor itself writes nothing to your page's storage; keeping a visitor's work across a reload is up to your page, and it takes a few lines with onChange and setSource:

const KEY = "my-page.source.v1";
const SEED = 'x = 1\n';
const read = () => { try { return localStorage.getItem(KEY); } catch { return null; } };
const write = (s) => { try { s.trim() === SEED.trim() ? localStorage.removeItem(KEY) : localStorage.setItem(KEY, s); } catch {} };

const remembered = read();
const ed = await mountEditor(el, { source: remembered ?? SEED, onChange: write });
// a stored text the parser had to repair does not read back as it was saved: start over from the seed
if (remembered !== null && ed.getSource().trim() !== remembered.trim()) ed.setSource(SEED);

Things worth knowing: keep the storage calls in try/catch (a frame without storage access, or a browser that blocks site data, throws; the editor still starts, it just forgets), store nothing while the text equals the seed, put a version in the key so you can change the format later, and compare ignoring blank lines and a trailing newline (the editor prints without them). The demo page embed-demo.html (npm run dev) is a working copy of this (it keeps the model as a LionWeb chunk through getChunk()/chunk instead of text, and shows how big that is: a few KB for a short program), and the showcase does the same per tab (as a LionWeb chunk too, so nodes keep their ids): it keeps your edits in this browser, shows a note, and Reset starts over. Nothing leaves the browser.

Keep the model in your own LionWeb repository

If you run a LionWeb repository, a second small file, struktjs-embed-lionweb.js, lets a page push the editor's model to it and pull it back. It is not loaded by the editor and the public showcase does not ship it.

import { mountEditor } from "./struktjs-embed.js";
import { connectRepository } from "./struktjs-embed-lionweb.js";

let repo;
const ed = await mountEditor(el, { source, onChange: () => repo?.changed() });
repo = connectRepository(ed, { url: "https://lionweb.example.com", repository: "default", token, onStatus: (s) => show(s.state) });
await repo.pull(partitionId); // load a partition, or: await repo.push() to create one from this model
  • changed() (call it from onChange) pushes once, a second after the last edit. A failure is reported through onStatus and status; the edit is sent with the next push.
  • pull() without an id takes the partition this page is bound to, else the only one the repository has. push() creates the partition the first time and then updates it in place: every node keeps its id, so other tools reading the repository see edits, not replacements.
  • It is last writer wins: there is no live merging, so a page that has not pulled recently overwrites a newer model with its next push.
  • The token is kept in memory only. A token in a static page is visible to every visitor: use a read-only repository, or a proxy that adds the token. The repository has to allow your page's address (CORS).

Try it with the reference server: npm run lionweb:demo -- up (needs Docker), then open embed/dev/embed-lionweb-demo.html from npm run dev.

Use the engine without the editor (headless core)

npm run build:embed also writes the engine on its own, with no editor, no DOM and no stylesheet, and the languages as separate files you load only when you want them. The files above are for browsers; the same files built for Node 22 are in node/ (node/struktjs-core.js, node/packs/…, node/struktjs-grammar-python.js, node/wasm/), and a plain Node program imports those:

File What it is
struktjs-core.js createCore({ packs, languages }): parse, check, type-check, run and generate. No languages inside.
packs/<plugin>.js One language pack per language plugin in the build (packs/lang-core.js, packs/lang-formula.js, packs/lang-diagram.js, …). Each is a small file; they share the engine with struktjs-core.js.
struktjs-grammar-python.js loadGrammarPython(): the Python/JavaScript/TypeScript grammars that Core and most languages are saved in. Its .wasm files are in wasm/.
import { createCore } from "./struktjs-core.js";
import { loadGrammarPython } from "./struktjs-grammar-python.js";
import core from "./packs/lang-core.js";
import formula from "./packs/lang-formula.js";

await loadGrammarPython();                              // before createCore; skip it for a language that needs no grammar
const c = await createCore({ packs: [core, formula] }); // every language a pack offers is registered, dependencies first
const model = c.parse('x = 1\nprint(x + 2)\n', { language: "core" });
model.check();      // { issues: [{ nodeId, severity, message }], errors, warnings }
model.types();      // the type pass only
await model.run();  // { output: [...lines], value }   the language's own evaluator; rejects if the program throws
model.generate();   // { text, errors, files }
model.print();      // canonical source text

Things to know:

  • A pack needs what its languages import. createCore({ packs: [diagram] }) fails with "diagram" imports "core", which no given pack or language provides: add packs/lang-core.js. Core also takes the standard-library languages (packs/lang-stdlib.js) when you provide them, as the IDE does; a build made for the embedded editor leaves that pack out.
  • The packs in a build are the languages that build was made with. npm run build:embed -- --profile <name> keeps only that profile's languages (see customization); the files in packs/ are exactly those.
  • You can also write your own language against the exports of struktjs-core.js (BaseConcept, ChildSlot, Prop, conceptsFromModule, …; the authoring surface is still provisional) and pass it as languages: [myLanguage].
  • Use node/ under Node, not the browser files. The browser files cannot run under Node (the tree-sitter runtime's Node support is left out of them). Both builds are tested: real Core and Formula source parses, checks and runs in a plain Node process from node/, and in Chromium from the browser files. The command-line tool is the other way to run the engine from Node, with the whole product.
  • run() is the language's evaluator, not a host runtime: Core does not execute real Python this way.
  • Size, measured on the full set: the engine with the Formula pack is 1.2 MB, with Core, standard library, Formula, Diagram and decision tables 2.2 MB (uncompressed). The Python standard-library type stubs are not in a pack.
  • Every core owns its languages (core.registry): two cores on one page, or in one Node process, can hold a same-named, different language, and a language only another core registered is not found through this one (an editor mounted over it says unknown language). A core can also carry persistence grammars of its own (createCore({ grammars: [...] }), or a grammars list on a pack): they are visible to that core's languages only. A grammar registered by loading its module is the page's and is shared by every core (registering a name twice there is an error), and so is the page's own registry, the one the build's built-in languages use when you give mountEditor no core.
  • The editor and the core come from the same build and share one copy of the engine; load both from one folder.

Install it as packages (@struktjs/*)

npm run build:package packs the same build as separate npm packages under the @struktjs scope, one tarball each in dist/ (struktjs-<name>-<version>.tgz). They are distributed as those tarballs (private: the licence is UNLICENSED, nothing is published to the public npm registry). Install the ones you need together, in one command: their peer dependencies are pinned to exactly the same version, which no registry serves, and npm resolves them from the tarballs you list.

npm install ./struktjs-core-0.1.0.tgz ./struktjs-grammar-python-0.1.0.tgz ./struktjs-lang-core-0.1.0.tgz
Package What Needs
@struktjs/core the headless engine (createCore), browser and Node 22 or newer nothing
@struktjs/grammar-python the tree-sitter grammars and their wasm: await loadGrammarPython() (@struktjs/grammar-python/wasm/* are the four .wasm files) core
@struktjs/lang-core, lang-formula, lang-diagram, lang-core-decision-table, lang-pattern one language pack each (the packs of the build profile); the default export goes to createCore({ packs }) core and lang-core; formula also needs lang-diagram and lang-core-decision-table
@struktjs/widgets the Problems and Results views, and the stylesheet (@struktjs/widgets/style.css) core
@struktjs/editor mountEditor (browser only); it carries no languages of its own, so it needs a core core, widgets, grammar-python
@struktjs/diagram optional: the ELK layout engine (about 2 MB, loaded only when a layout is asked for). import "@struktjs/diagram" once, anywhere on the page, and the diagram editor's Layout Diagram (ELK) actions use it; without it they say which package to add, and the built-in Layout Diagram still works core
@struktjs/git structural version control over model source texts: diffModels (a tree diff), mergeModelTexts (a three-way merge that reports conflicts and takes your resolutions) and computeGitAnnotate (per-node blame, given functions that fetch the file versions). No git binary, no filesystem, no UI: it works in a page, a Node script or a merge driver. Load the grammar the files are written in first core
@struktjs/collab headless collaboration, no editor and no UI: the AST-to-Yjs mirror (createMirrorContext, reconcileLocalToYjs, hydrateFromYjs, applyYjsToLocal) and the relay session (hostSession, joinSession, resumeSession). A bot, a server-side check or a test can be a peer in Node 22 or newer or a page. It exports Y, the yjs it was built with: create your documents with that one, never a second copy of yjs. Secure by default: a plain-http relay on a local network and the pure-JS crypto fallback are refused until you install a settings reader with setCollabSettingsReader. The presence, cursor and join-dialog manager is part of the IDE, not this package core
@struktjs/python-runtime real Python execution: createPythonRuntime() returns a runtime you give to the core, createCore({ packs, runtime }), and model.run() then runs the languages that run on Python (Core) on CPython instead of the language's own evaluator; every other language, and a core with no runtime, is unchanged. In a page it runs Pyodide in a worker from the package's own pyodide/ folder (about 13 MB, same origin, no download prompt; name another folder or a CDN in pyodideUrl); in Node it uses the machine's python3 when there is one, else Pyodide (python: "host" \| "pyodide" \| "auto"). It depends on the pyodide package. You own the runtime: call dispose() when done core
@struktjs/lionweb the LionWeb repository helper core
@struktjs/stubs-python opt-in, only in a build made with --with-stubs core, grammar-python

npm install of one package pulls in its peers when you list their tarballs too; a tree with a package but not what it needs fails to install, and a tree never holds two copies of @struktjs/core (they import each other's files, so they must share one). Take all the tarballs from one build: the version number alone does not tell two builds apart (the packages import each other's files by their build-specific names), so tarballs of different builds never mix, even at the same version, and a mix fails when the page or program loads, not when npm installs. Importing a built entry file by its path is refused; @struktjs/<name>/chunks/… exists only for the packages that import each other and is not API. In Node the node condition picks the Node build, in a bundler or browser the browser build. TypeScript declarations ship with each package (bundler, node16 and nodenext resolution all work), and zod is the one third-party dependency (its types are named in core's declarations).

import { createCore } from "@struktjs/core";
import { loadGrammarPython } from "@struktjs/grammar-python";
import core from "@struktjs/lang-core";

await loadGrammarPython();
const c = await createCore({ packs: [core] });
const model = c.parse("x = 1 + 2\nprint(x)\n", { language: "core" });
console.log(model.check().errors, (await model.run()).output);

A page with no bundler serves the installed packages as they are, and the packages import each other by name, so it needs an import map from each package name to its folder ({ "imports": { "@struktjs/core": "/pkg/core/struktjs-core.js", "@struktjs/core/": "/pkg/core/", … } }; each package's exports["."].default is its entry file). A bundler needs nothing.

In an application built with a bundler (Vite, webpack, …) the library cannot know where the bundler put the .wasm files, so name the folder yourself: copy node_modules/@struktjs/grammar-python/wasm to a folder your server publishes (for Vite: public/strukts-wasm) and pass it, loadGrammarPython({ wasmBase: "/strukts-wasm/" }) and mountEditor(el, { wasmBase: "/strukts-wasm/" }). A page that serves the package folders as they are needs nothing. mountEditor(el, { core }) edits with the languages of a core you made from packs: the packaged editor has no languages of its own, so a mount without a core is an error that says so, and a page carries only the language packs it installs. Tested: a Node ESM script, a TypeScript program (skipLibCheck: false), a plain HTML page and a built Vite application, each against the installed tarballs (a subset each: Node with only core, the grammar and Core; an editor with only what it needs; widgets with no editor; the whole set), in Chromium and WebKit (and Firefox in CI). Not covered: the Vite development server (its dependency pre-bundling moves the library's files, so the default wasm location is wrong there too; use wasmBase and, if needed, optimizeDeps.exclude: ["@struktjs/core", "@struktjs/editor", "@struktjs/grammar-python"]). The Python standard-library type stubs are not in the default package (they are about 5,000 files). Packages built with node scripts/build-package.mjs --with-stubs add @struktjs/stubs-python (about 4 MB packed): call loadStubsPython() before mountEditor and the editor offers and understands standard-library modules (import os). They feed the editor; the headless core does not load them.

Problems and results without an editor

@struktjs/widgets (struktjs-widgets.js in a build, about 3 KB, plus the shared stylesheet) holds two views that need no editor and no engine, for a page that checks and runs models headlessly with the core and only wants to show the outcome:

import { createCore } from "@struktjs/core";
import { mountProblems, mountResults } from "@struktjs/widgets";
import "@struktjs/widgets/style.css";           // their styles are part of the embed stylesheet, which the widgets package carries

const model = core.parse(text, { language: "core" });
const problems = mountProblems(el, { issues: model.check().issues, onSelect: (issue) => highlight(issue.nodeId) });
const results = mountResults(el2, { result: { lines: [{ kind: "output", text: "3" }], ok: true, durationMs: 1 } });
problems.update(model.check().issues);          // after the next check

mountProblems takes any list of { severity, message, nodeId? }: a core model's check().issues, or the editor's onIssues items. mountResults draws a run's lines (the editor's run() result fits as it is), marks a failure and shows the time. The Inspector needs the editor's selection, so it stays ed.mountInspector(element).

Publish the showcase on your site

npm run build:showcase writes dist/showcase/: about 9 MB in some 30 files, all static. Upload the folder as it is, to the site root or any sub-folder (every link is relative); there is no back end and nothing leaves the visitor's browser (the page keeps a visitor's edits and theme in the browser's local storage, per tab; where a frame has no storage access it simply forgets them). To update, rebuild and replace the whole folder (the chunk file names change with their content).

What the web server needs

  • .wasm as application/wasm. The parsers are WebAssembly; most servers know the type, some CMS hosts do not.
  • Compression (gzip or brotli). A first visit loads about 4.3 MB of script and parsers uncompressed, about 1.0 MB compressed; the diagram tab adds about 0.7 MB when it is first opened.
  • Caching. Files in embed/chunks/ have content-hashed names: Cache-Control: public, max-age=31536000, immutable. Everything else (index.html, showcase.js, showcase.css, embed/struktjs-embed.*, embed/wasm/) keeps its name between builds: let it revalidate.
  • Content-Security-Policy (if you set one). This is enough, tested from a sub-path: default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; worker-src 'self' blob:. 'unsafe-eval' is not needed (the editor tries it once, is refused, and carries on; the browser console shows one blocked attempt). style-src 'unsafe-inline' is needed for inline styles: the diagram sets style attributes, the editor adds each language's own CSS as a <style> element, and the equipment report is a small HTML document (shown in a sandboxed frame that runs no scripts) with its own <style>.

The robot-maze simulation runs a script, in a frame sandboxed with allow-scripts only (never allow-same-origin: it cannot reach the page, its storage or your origin). A frame built from inline text inherits the page's policy, so under the policy above its inline script is refused: the page then shows "The simulation could not start" and everything else keeps working. To enable it, add 'unsafe-inline' to script-src for that folder (this also relaxes the page's own script policy), or leave the maze example out of your build.

In an <iframe>. Do not send X-Frame-Options: DENY for that folder; use Content-Security-Policy: frame-ancestors https://your-site.example to allow only your pages. The page's height changes per tab and with the width, so it tells the parent page: it posts { type: "strukts-showcase-height", height } whenever it changes.

<iframe id="demo" src="/demo/" style="width:100%;border:0;height:1200px" title="Live model editor demo"></iframe>
<script>
  addEventListener("message", (e) => {
    if (e.origin === "https://demo.your-site.example" && e.data?.type === "strukts-showcase-height")
      document.getElementById("demo").style.height = e.data.height + "px";
  });
</script>

Browsers and devices. Checked in Chromium and WebKit (Safari's engine), at desktop and phone widths, in light and dark. Not checked here: Firefox (run npm run test:embed, which includes it), real phones with an on-screen keyboard (touch editing is verified with emulated touch only), Windows and Linux fonts for the maths, and screen readers. On a touch screen the page shows a short note on how to confirm an edit.

Accessibility. The page and the editor inside it pass the automated WCAG 2.2 AA audit (axe) on every tab in both themes, the page is operable by keyboard (arrow keys move between tabs) and respects reduced motion. An automated audit finds only part of the problems: it has not been checked with a screen reader.