Examples #
The high-level Burokku runner used below registers Burokku's own extensions,
which install the UI tree, scrolling, and the JavaScript ResizeObserver. An
application adds fonts, globals, and scripts through extensions of its own; see
burokku::extension. ResizeObserver observes the layouts the host computes,
so it needs the runner's host.
Resize observation #
const win = app.createElement("window");
const panel = app.createElement("div");
panel.style.setProperty("width", "50%");
win.appendChild(panel);
app.appendChild(win);
const observer = new ResizeObserver(entries => {
for (const entry of entries) {
console.log(entry.target.localName, entry.size.width, entry.size.height);
}
});
observer.observe(win);
observer.observe(panel);
// Later: observer.unobserve(panel) or observer.disconnect().
Entries contain immutable layout sizes in logical pixels. Delivery is asynchronous
and is not guaranteed before paint. Box-selection options are future work.
@burokku/runtime declares the global constructor and exports the
BurokkuResizeObserver, BurokkuResizeObserverEntry, and
BurokkuResizeObserverCallback types.
Event dispatch showcase #
example/events renders an interactive div and displays click, pointer, wheel,
keyboard, bubbling, and pointer-capture events as they are dispatched. A single
resize observer watches both the div and the native window, showing their current
layout sizes in the UI and logging changes. Resize the window to see both update.
cargo run -p burokku-example-events
For a bounded smoke run:
BUROKKU_SMOKE=1 cargo run -p burokku-example-events
LLRT counter #
example/counter is a Rust binary that embeds a JavaScript application and uses
LLRT's setInterval to update a live UI tree text node once per second. The
"Count every second" toggle pauses and resumes the timer.
cargo run -p burokku-example-counter
For a bounded smoke run, remove the Window after the first counter tick:
BUROKKU_SMOKE=1 cargo run -p burokku-example-counter
React counter #
example/react renders the LLRT counter's interface from React components
through @burokku/react: state hooks hold the count and each control's pointer
state, an effect runs the timer while the toggle is on, and the window title
follows the count. Vite bundles src/main.tsx into dist/app.js, which the
binary embeds, so build the bundle and the packages it uses first:
pnpm --filter '{./example/react}...' build
cargo run -p burokku-example-react
For a bounded smoke run:
BUROKKU_SMOKE=1 cargo run -p burokku-example-react
Layout showcase #
example/layouts embeds src/app.js, registers the bundled Noto Sans fixture,
and presents flex layout, inherited text runs, backgrounds, and wrapped
paragraphs through Taffy, Parley, and the platform compositor, with text drawn
on the CPU by Vello CPU. A resize observer shows each card's content width, so
the 1 : 2 : 1 split stays visible as the window resizes.
cargo run -p burokku-example-layouts
A bounded smoke run is also available:
BUROKKU_SMOKE=1 cargo run -p burokku-example-layouts
Positioned mixed-layout showcase #
example/positioning mixes a flex shell, relative grid, static block wrapper,
absolute overlay, and fixed footer. The source includes an XML-like view of the
authoritative UI tree so its parentage can be compared with the rendered layout.
cargo run -p burokku-example-positioning
For a bounded smoke run:
BUROKKU_SMOKE=1 cargo run -p burokku-example-positioning
Scrolling showcase #
example/scroll shows overflowing elements: a 60-row message list, a card strip
that scrolls sideways inside another scroller, and an overflow: hidden ticker
scrolled by a timer. Scroll with the wheel, drag or click a scrollbar thumb's
track, or click a scroller and use the arrow keys, Page Up/Down, Space, Home,
and End. The buttons call scrollTo, scrollBy, and scrollIntoView; Tab
moves between them, and Enter or Space activates the focused one. The list's
scroll events update its position readout.
cargo run -p burokku-example-scroll
For a bounded smoke run:
BUROKKU_SMOKE=1 cargo run -p burokku-example-scroll
SolidJS counter #
example/solid is the counter written with SolidJS. @burokku/solid renders
Solid components into the UI tree through solid-js/universal, and Vite
bundles src/app.tsx into dist/app.js, which the Rust binary embeds. A
<Show> adds a Reset button while the count is not zero, and a <For> lists
the three newest changes.
Cargo needs the bundle, so build it first:
pnpm install
pnpm --filter '@burokku/example-solid...' build
cargo run -p burokku-example-solid
just example solid does both. For a bounded smoke run:
BUROKKU_SMOKE=1 cargo run -p burokku-example-solid
An app sets up the Solid compiler and TypeScript as this example does:
vite.config.tspassesgenerate: "universal"andmoduleName: "@burokku/solid"tovite-plugin-solid, and builds an IIFE, since Burokku runs one classic script.tsconfig.jsonsets"jsxImportSource": "@burokku/solid", which types thediv,flex,grid,text, andwindowelements.render(() => <App />, app)mounts the app; its top element is awindow.
JSX properties map onto the UI tree:
styletakes an object of native properties in kebab case, as CSS writes them, such as{ "background-color": "#16171dff", "flex-grow": 1 }.onPointerDownlistens forpointerdown: handler names are lowercased.on:namelistens fornameas written.prop:namesets the element's property, such asprop:scrollTop.tabindex, and a window'stitle,width, andheight, set attributes.attr:namesets any other attribute;nullandundefinedremove one.
Text belongs in a text element; other elements hold only elements. Where
Solid keeps an empty spot among an element's children, such as a <Show>
that shows nothing, an empty div with position: absolute stands in, so it
takes no space.
SolidJS block editor #
example/editor is a block editor in the shape of Notion's, written with
SolidJS on the input element. A page is a title and a list of blocks,
each one <input> the user edits in place, whose children are styled
text runs; the engine edits the runs as the platform asks, and the app
reads them back through input events to keep its block model. Enter
splits a block at the caret, Backspace at a block's start merges it into
the one before or demotes a list item, the arrows at a block's edges move
on to the next, # , ## , - , [] , and > typed at a paragraph's
start make a heading, subheading, bullet, to-do, or quote, and / opens a
menu of kinds. Command+B, +I, and +E mark the selection bold, accent, or
code, and the marks follow the text through edits. The status bar shows
the caret, the IME's composition while it lasts, and the last edit's
inputType and data; while an IME composes, every key is left to it.
The text is set in Noto Sans, which has no ⌘ or ☐; the engine draws them
with the family the platform names for them, as a browser would.
pnpm --filter '@burokku/example-editor...' build
cargo run -p burokku-example-editor