bundle
def bundle(
kind:str='js'
)->str:The runtime as one script (js) or one style sheet (css).
show for notebooks, md for Markdown, and Demo for FastHTML.
One runtime draws a spec everywhere. A host element carries the spec as inert JSON, and the runtime mounts it:
The runtime boots on load and after each htmx swap. Nothing is templated into the script.
bundle joins the core, the fns, the blocks and the boot script in a fixed order. There is no bundler and no build step.
The runtime as one script (js) or one style sheet (css).
The script starts with the core and ends with the boot. Each block is in it.
Each block style uses only the --rk-* vars for colour, so a demo takes the look of the page that holds it.
host writes the element that carries a spec. JSON in a <script> must not hold </script>, so every < becomes \u003c. JSON.parse reads it back as <.
The spec as JSON that is safe inside a <script> element.
page writes one self-contained HTML file: the runtime, the style, the specs, and abhyasa’s palette. The fonts argument picks how the page gets its fonts:
fonts |
what it does |
|---|---|
'link' |
links Literata and Libre Baskerville from ./fonts (save copies them) |
'embed' |
puts the fonts in the page as data URIs, about 160 KB more |
'none' |
uses the system serif; for a sandboxed srcdoc frame, which cannot load files |
The @font-face rules: linked from base, embedded as data URIs, or none.
page takes one spec or a list of specs. A list makes a gallery page with a rule between the demos.
One self-contained HTML document that draws specs, with no network.
A page loads nothing from the network: no src, href or url() points at http. (The SVG namespace string is not a request.) With fonts='none' it has no @font-face rule.
spec = dict(rupaka=1, id='t', title='T', state=dict(a=1), blocks=[dict(type='readout', text='{a}')])
p = page(spec)
assert not re.search(r'''(src|href)=["']?https?:|url\(\s*["']?https?:''', p)
assert '@font-face' in p and '@font-face' not in page(spec, fonts='none')
assert 'data:font/woff2;base64,' in page(spec, fonts='embed')save writes a page to a file. With linked fonts, it copies the font files beside it, so the file works from file://.
Write page(specs) to path; with fonts='link', copy the fonts to fonts/ beside it.
show(spec) returns an object that a notebook draws. It gives two mime types:
application/vnd.rupaka+json: the spec, for a frontend that knows rupaka (a later leela change).text/html: the whole page with fonts='none'. leela, Jupyter and VS Code draw it in a sandboxed frame. This works in leela today.md(spec) writes a ```rupaka fence with readable JSON. A renderer that knows rupaka mounts it; others show the JSON as code. md(spec, frame=True) writes a ```{=html} fence that holds a sandboxed frame. leela draws this in a Markdown cell today, with no change to leela.
A Markdown fence for spec: readable JSON, or a sandboxed frame.
Demo(spec) is the host element as an FT component. Assets(prefix) gives the Link and the Script for a server that serves the bundle at prefix.
The style and the script of the runtime, served at prefix; v busts the cache.
version() is a short hash of the bundle, for a cache-busting v.