Interactive Apps
An app is a block in a document that runs as a small program: a calculator, a quiz, a chart, a 3D model. You write it as HTML in a fenced block marked app, or ask an agent to write one. The app is stored as text in its document, so it syncs, merges, exports and backs up with the document.
An app runs in a frame that EtherPK draws inside the document. The app cannot read your notes, your keys or anything else in EtherPK, and it cannot use the network. A published site shows the app in the same kind of frame.
Add an app to a document
- On an empty line, type three backticks and
app, and press Enter. - Write the app as HTML between the fences. You can use
<style>and<script>. - Move the cursor to another line.
app
<title>Bean counter</title>
<button id="sow">Sow a bean</button> <output id="count">0</output>
<script type="module">
let sown = 0
document.getElementById('sow').addEventListener('click', () => {
document.getElementById('count').textContent = String(++sown)
})
</script>
With the cursor outside the block, you see the app under a bar that reads App and the app's name. With the cursor inside the block, you see its code. To edit the code, click Edit code in the bar. When you move the cursor out again, the app starts from the beginning with the new code. Run again also starts it from the beginning.
An app keeps nothing between runs. Whatever you typed into it is gone when it starts again or the document closes.
What the block can hold
| In the block | What it does |
|---|---|
<title>Bean counter</title> |
Names the app. The bar shows the name, and a published site lists the app by it. An app with no title is called App. |
<meta name="etherpk:height" content="480"> |
Sets the height of the frame in pixels, from 80 to 2000. Without it, the frame is as tall as the app's content. |
<style> and <script> |
The app's styles and code, which the browser runs as written. |
<script type="importmap"> |
Names the libraries the app imports. See Use a library. |
An app can match the document's theme with these CSS variables.
| Variable | Colour |
|---|---|
--app-background |
The page behind the text |
--app-text |
Text |
--app-muted |
Text of less weight, such as a caption |
--app-border |
Borders and rules |
--app-accent |
Links and the main control |
Style an app
An app starts with a few styles from EtherPK: the background and text colours above, the system font at 16 pixels, and 12 pixels of space around its content. Nothing else from EtherPK, or from a published site's theme, reaches inside the frame. The app's own <style> comes after these styles, so it can change any of them, the variables included.
An app cannot load a stylesheet or a font from a web address. Put styles in a <style> element in the block, and a font in @font-face as a data: address.
In EtherPK, the variables hold the colours of your theme. When you switch between light and dark, the app starts again in the new colours. On a published site, they hold EtherPK's own light or dark colours, chosen by the reader's light or dark setting on their device, and not the colours of the site's theme.
Use a library
An app can import a library, such as a charting or 3D library. The library is a file in the graph, and the app names it in an import map by its path under assets.
app
<title>Seed list</title>
<script type="importmap">
{ "imports": { "seeds": "../assets/seeds-1-2-3.0f0f0f0f.js" } }
</script>
<script type="module">
import { seeds } from 'seeds'
document.body.textContent = seeds.join(', ')
</script>
EtherPK never fetches a library when a document opens. To add a library from the web:
- In the import map, write the library's
httpsaddress in place of the file path, for example"seeds": "https://cdn.example.com/seeds@1.2.3/seeds.js". - Move the cursor out of the block. In place of the app, EtherPK says which library has no copy in the graph.
- Click Keep a copy.
EtherPK fetches the file once, saves it with the graph's other files, and changes the address in the import map to the saved file. The app then runs with the copy, with or without a connection. The website you fetch from sees one request for the file from your device.
A library must be a single file of at most 4 MB that imports no other file by path or address. Many libraries publish such a file, often with module or esm in its name. An app can import up to 16 libraries. A library that needs a build step, such as Svelte, cannot be used.
Most libraries have a licence that asks you to keep its notice with any copy. The notice is usually a comment at the top of the file, so leave it in place.
Apps in a shared graph
In a graph you share with other people, an app that someone else might have written does not start by itself. In its place, EtherPK shows Run. Click Run to start the app. EtherPK remembers on this device that you ran that app, and starts it by itself from then on. If anyone changes the app's code, EtherPK shows Run again.
Run lets you look at an app's code first, with Edit code. It is not what keeps an app away from your notes. The frame keeps every app away from your notes.
When an app does not run
| What you see | Why |
|---|---|
| The block's code, in a protected document | An app does not run in a protected document. |
| Run, and a line that says the app was starting when EtherPK last stopped | The app might have stopped the page the last time it ran. Click Edit code to read the code before you run the app. |
| A line that names a library with no copy in the graph | The import map holds a web address. Click Keep a copy. |
| A line that says the import map cannot be used | The importmap block is not valid JSON, or one of its addresses is neither a file under assets nor an https address. Click Edit code and correct it. |
| A line that says a library could not be read | The file the import map names is not in the graph, or the graph's files cannot be reached now. |
| A line that says the frame did not load, with Try again | EtherPK could not load the page the app runs in. Check the connection and click Try again. |
| A line in the bar that says the app keeps changing its height | The app changed the height of its frame many times in a few seconds, so the frame stays as it is. Give the app a height with etherpk:height. |
| Error: and a message in the bar | A script in the app failed. The message is the browser's. |
A backlink that quotes a block with an app shows the app's name, not the app. A print or PDF of the document does the same.
Apps on a published site
A published page shows an app in a frame, as the document does, and the app runs when a reader opens the page. Its libraries are written into the page, so the site needs nothing more from EtherPK or the web. A page with a large library is larger by the size of that library.
The site's search and its feed list an app by its name. They never include its code.
On a published site, an app can send its own frame to another web address, which tells that address that someone opened the page. The app still cannot read the page around its frame, and the app leaves with nothing but its own code. Inside EtherPK, an app cannot do this.
What an app cannot do
- Read or change your documents, your graph, your keys or your account.
- Read or change the page around its frame, in EtherPK or on a published site.
- Use the network. It cannot fetch, send or load anything from an address. The one exception is on a published site, as described in Apps on a published site.
- Store anything on your device, open a window or download a file.
An app can draw anything inside its own frame, so read the bar above it to know what is an app and what is EtherPK. EtherPK never asks for a password or a Recovery Code inside a document.
An app that never stops working can make the page slow or stop it. The next time the document opens, EtherPK does not start that app by itself, as described in When an app does not run.
Ask an agent for an app
An agent that writes into a graph can write an app into a document: a quiz on a chapter, a chart of a measurement, a diagram with moving parts. See Using AI Agents With Your Notes for more information on connecting an agent. The agent writes the block as text. A library goes into the graph as a file, added with the agent's upload_asset tool or saved in the assets folder of a folder graph.