A page is ordinary HTML that Leaf's widgets, themes and layouts extend, and
packages add reusable widgets, themes and behavior to Leaf. Their contracts
let each contribution work alongside other packages and the page's own
content.
This guide is for whoever builds on Leaf: what a page can hold, how it takes a
theme and how it is laid out, then who owns what, how packages share data, a
package tutorial, CSS contracts and the registry keys.
How it works introduces Leaf's core concepts and
how they fit together, and its
Package interface topic
explains what a package leans on Leaf for and why.
Using covers working on a page.
In this topic
A page is an HTML document an agent writes around the work. This tab covers
what a page can hold and how it takes a theme, and Layout covers which
layout fits the work.
Parts of a page
The agent writes an HTML document containing the page's title,
description, content, and layout. When the server delivers it, Leaf adds
the page identity, visual theme, browser JavaScript, and canonical URL.
The browser runtime supplies the commenting and collaboration interface.
Authors build the content with these tools, starting with ordinary HTML:
Ordinary HTML. Leaf's reading theme, which a page takes
by default, styles headings, an hgroup's label above its
heading, paragraphs, tables, code, and details without
requiring CSS classes. These elements provide most of a page's content.
Leaf's classes. Leaf supplies classes for common
presentation patterns on every page, whatever its theme, including
.lf-lede and .lf-callout.
Widgets. A widget is a complete page feature, authored
as a custom HTML element, such as <lf-options> for
choices and <lf-board> for cards in columns. Other
lf-* elements provide structure, such as
<lf-pane> for a pane. The
registry declares each element’s attributes and
behavior using JSON Schema. The browser, validator, and agent
instructions read those same declarations.
Page-specific presentation. A local
<style> and inline SVG can define arrangements and
drawings specific to the page. They use the theme's shared color and
type tokens to stay consistent with the rest of Leaf. The Layout tab's
drawings use this approach.
Leaf elements load their JavaScript modules when the page uses them.
Behavior specific to one page can use inline module scripts or local
modules under
page/. Reusable behavior belongs in a package, a directory
containing element declarations and their supporting files. The
page-behavior reference
defines module and dependency rules.
Widgets
These examples are interactive parts of this page. Their choices, card
moves, and comments share its event log and Undo; as samples, they ask
nothing, so On Me stays empty. Each activity feed shows the same page
history, including actions in other examples.
Example page: a release review
Choose a rollout audience, then one follow-up job. Open
Show activity to inspect both selections. Choose
Undo in the page’s leaf menu to withdraw the job
choice, then press Activity changed in the feed. The
rollout audience remains selected.
Start with canary clients; expand after the error rate settles.
Canary clients Start with a small group and compare
its error rate before expanding.All clients Enable the release for everyone once
the checks pass.Hold the release Gather more evidence before
enabling it for any clients.
Which job should start first?
Prepare the rollback flagAdd a concurrency testSet up the error-rate comparison
Recorded actions
Options with explanations render as cards; options containing only
labels render as rows. The content determines the presentation. A row
can link to a section that explains the choice. Clicking an option
immediately shows the selection and records it for the agent. A later
revision preserves that choice. The options also include an empty one
for an answer the author did not list.
Move “Flaky auth test” to “This week” by dragging its grip. With a
keyboard, focus the grip, press Enter to grab, Right to move, and Enter
to drop. On a narrow touch screen, use the card’s Move to buttons. Open
Show activity to inspect the recorded move. Choose
Undo in the page’s leaf menu to return the card to
Incoming; press Activity changed in the feed to see the
move marked undone.
Flaky auth test Fails one run in twenty on CI
only.Dark-mode contrast passRate-limit the exportTokenize the palette
Recorded actions
In a live Leaf, cards drag between columns by a grip, and each drop
reaches the agent as a structured action.
The widget catalog also includes diagrams, charts, diffs with collapsible
files, annotated code, editable drafts, playgrounds, and recorded browser
traces. The
examples gallery opens complete pages using them.
Asking the user
Any widget can ask, whether bundled, from a package or the page’s own, by
declaring awaits in its registry entry,
and says on each of the user's gestures whether it is answered. To ask
about content that asks nothing, such as a paragraph or a chart, or to
leave the user a step such as trying a build, the agent opens a thread on
that content or the page with a message sent with
--obligation, and the user’s reply answers it. Nothing goes
On Me that neither a widget nor a thread answers, so no item carries a
generic Done, and Leaf adds no answer to a widget beyond those the widget
declares.
Each ask joins the user's On Me list until the widget or thread that asks
it is answered (On Me and the agent’s list).
External data
External values, such as benchmarks or build status, use one JSON
publication per named source. leaf data set validates the
value against the page’s declaration, records the contract beside the
value in the source file, and replaces the publication atomically. Any
process can call it. Leaf validates the value against the recorded
contract on read and displays a source error for a mismatch.
A source replacement updates the open page without creating a revision;
each publication holds its latest value. A later page revision may bind
the source to another contract, which its next write takes. An
lf-num instead freezes a number into authored text. It
retains that number when the source changes, and
leaf page check reports when its source has changed.
Styles and overrides
The user chooses the visual direction. A theme supplies shared colors,
type and reusable styles; widget packages draw their own controls; the
author arranges the page and makes local adjustments.
flowchart TD
accTitle: A page selects its theme as a package
accDescr: The author selects the Editorial theme from the packages on the user's machine, which also hold Leaf's reading theme and the user's Dense theme. The release-review page records that selection, and the export carries the same theme.
Themes["Themes on this machine<br/>Reading · Editorial · Dense"] -->|select Editorial| Page["Release review<br/>Selects: Editorial"]
Page -->|export| Export["Exported review<br/>Same Editorial theme"]
A page’s theme is a package it selects.leaf package list shows Leaf’s reading theme beside the
user’s own. The page records its selection, and its export carries the
theme’s rules.
Choosing a theme and honoring browser preferences
leaf package list shows each theme the machine can select
with its author instructions: Leaf's reading theme,
reading, and any the user installed. A theme is a package,
which page init --package NAME selects ahead of the page's
other packages. A theme builds on the reading theme where the page
selects reading before it, and replaces it where the page
selects the theme alone. A page with a design wholly its own selects no
theme and starts from the browser's defaults, while Leaf's widgets,
classes, threads and panel keep their faces. Re-initializing keeps the
page's packages unless --package names a new list. The
author follows the user's request first, then the task and the theme's
instructions.
The reading theme supports light and dark schemes. Authors preserve
supported platform preferences when composing a page; an explicit visual
comparison may need a fixed appearance, declared with
color-scheme. CSS precedence determines which rule wins,
not who has authority over the work.
Make a local adjustment: colors, width or controls
To change
Write
Leaf's colors
:root { --lf-accent: teal; }
A Layout's width
:root { --lf-col: 46rem; }
A widget
lf-card { padding: 8px; }
Controls a widget builds
lf-card::part(grip) { color: teal; }
A Layout reads tokens such as --lf-col,
--lf-sidebar and --lf-page-pad-start, and any
other rule changes it too, such as
main { padding-top: 28px; }.
A bare button or input rule styles every one
in the document, the controls a widget builds there included, so name
the widget to aim a rule at its controls. A widget that draws in a
shadow root of its own, as a board's card does, names as parts the
controls a page may style, which a rule reaches through
::part(). Leaf’s panel and thread cards keep their own look
against a rule as light as one class, and inherit theme inputs such as
--lf-accent and --lf-sans from
:root.
For stylesheet roles, cascade precedence and nested widget boundaries, see
the CSS tab's contract.
In this topic
Layouts
Leaf supplies page layouts and a layout for blocks within a page. A
column, sidebar, or workspace sets the page’s shape; tiles arrange a
block’s children and can be used within any of them. The table and
drawings below show the same classes in the same order.
Class
Arrangement
layout-column
Page layout
Text in a centred 720px column; figures, boards and tables may
extend past it. Suits plans, reviews and explanations, including
this page.
layout-sidebar
Page layout
A body beside a narrower side column, with the header across both,
as wide as the window up to 1600px. A board and its status, a
release dashboard, or a review with its verdict beside the diff.
layout-workspace
Page layout
Task regions kept together: a queue beside its selected item, or
controls beside a preview. In a large window, the workspace fills
the height and its panes scroll separately.
layout-tiles
Block layout
Equal cells, as many to a row as fit. A row of metrics or status
tiles.
A column pagelayout-column on main. Text keeps the 720px
column, and a block with a declared width, such as a diagram, extends
past it.
A sidebar pagelayout-sidebar on main widens the page and
sets a body beside its side column. Every block starts at its region's
left edge, and text retains its reading width.
A workspacelayout-workspace keeps task regions together. In a large
window it fills the height, and its panes scroll separately.
A tile blocklayout-tiles arranges children in equal cells, wrapping
as the available width changes. The surrounding page keeps its own
layout.
Leaf's Layout classes are ordinary CSS, applied beneath the page's own
stylesheet in the cascade. A page can adjust them with CSS rules, for
example to change a column's share of the width or a gap. It can also use
its own grid when the supplied layouts do not fit.
The reading column
On a layout-column page, headings, paragraphs, lists, and
code occupy a centred column up to 720px wide. On a sidebar page too, the
theme limits paragraphs, list items, and headings to that reading width. A
workspace applies neither the reading width nor the limits below: every
block fills its pane.
A diagram, board, or wide table can extend into the margins beyond the
reading column. The text above and below it keeps its width and position.
These width settings control the block:
column is the text measure. In a wider region, such as a
sidebar page's body, a column block starts at the same left
edge as the text.
wide starts at the edge the text starts from (the left, in
a left-to-right page) and extends toward its end, up to about 910px,
enough for 100 columns of code. Wide blocks share this width so they
align with one another.
available uses the window's width after subtracting the
outer page margins and space for Leaf's margin controls.
The registry, which declares each element's behavior,
also gives it a default width. For example, lf-options uses
column, lf-diff uses wide, and
lf-board uses available. A
data-width attribute asks for wide or
available on any block, overriding the default. If the
margins have unequal space, an available block extends
farther into the wider margin. A table given one of these widths uses its
columns' natural width, up to that limit, rather than stretching across
the extra space.
data-width on a block The block extends
past the column, and the paragraphs around it keep their width.
A log, feed, or long listing with data-bound scrolls within a
limited height: start opens at its first line, and
end follows its newest entry. Its growing content therefore
does not make the whole page longer.
Margins
A sufficiently wide window places these controls and notes beside the
reading column:
The rail, on the right, where Leaf places a marker
beside each commented or decided passage. It needs a window about 960px
wide, or about 1010px on a touch screen. A sidebar page shows it from
about 1920px, or from 640px with data-rail="right" on
body. A workspace has no rail; a comment there shows as a
pin on its block.
A sidebar, an aside beside the body in
layout-sidebar. Its authored layout-track
holds contents, a legend or reference facts, and stays in view while the
body scrolls when both fit beside each other.
Sidenotes, which the page floats into the right margin
with its own CSS. The rail's markers don't avoid them, so a page of
sidenotes gives the margin to them with data-rail="none" on
body.
The browser places these compositions as soon as the HTML arrives. In a
narrow window, the sidebar stacks in source order.
Sidebar pages
layout-sidebar on main places the header across
the top, with a body and a narrower side column below it. The page fills
the window up to 1600px, with an outer margin that grows from 24px to
64px. Its blocks and title share a left edge, while paragraphs still wrap
at 720px.
The side column is an aside; placing it before or after the
body in the HTML puts it on the left or right. The regions stack in HTML
order below about 870px, or when the body's content needs the full width,
such as a board with many columns.
For a reading page, give the body layout-column: prose keeps
its reading measure while wide exhibits use the remaining room. A
section.lf-panel groups a region by its compact heading and
spacing, without a surrounding card.
<main class="layout-sidebar">
<header><h1>Release 4.2 rollout</h1></header>
<div>…</div> <!-- body: the work in progress -->
<aside><div class="layout-track">…</div></aside>
</main>
layout-workspace fits the page to the window above Leaf's
panel. A single-row header holds the title and status tags.
The body takes the remaining height and contains an lf-pane,
a widget that arranges its own panes, or a grid of panes defined by the
page's CSS. Each pane scrolls its content beneath its own
header. A pane's footer stays visible, keeping its actions
within reach.
An lf-tabs list="side" in the workspace body displays a list
of tabs as a queue, such as tickets or findings. The selected item's
content appears beside that list.
The workspace fills the window's height when the window is at least 720px
wide and 480px tall. In a smaller window, panes expand to fit their
content and the whole page scrolls.
A large window The workspace fills the window. Each
pane scrolls under its header, and a footer's actions stay in view.
A small window Below 720px wide or 480px tall, the
panes take their natural height and the page scrolls.
density-working reduces type size and spacing for a compact
working surface. It is independent of the Layout: a workspace can use
ordinary reading sizes, and a pane or table on another page can use
working density.
layout-tiles arranges an element's children in equal cells at
least 9rem wide, placing as many cells in each row as fit. Cells in the
same row have equal heights. A page can set its own columns when it needs
a particular grouping, such as four tiles in two rows of two. A row of
headline numbers can use a layout-tiles block of native
dl elements with labels in dt and values in
dd.
Tabs and parts
An lf-tabs at the top of a page creates tabs like the ones on
this page. Their tab strip stays at the window's top while the page
scrolls, and one tab's content is visible at a time. All tabs share the
page's width, Layout, threads, and version history.
When different parts of the work need different layouts,
lf-parts holds an lf-part for each. Each part
contains its own layout container; main itself carries no
Layout. For example, one part can hold an interactive workspace and
another a proposal read in a column. Parts share the page’s history,
threads, and On Me list. The
page-layout reference
gives the markup.
Narrow windows
In a narrow window, page regions stack vertically in HTML order. Margin
notes move into the reading column, a side column appears above or below
its body, and workspace panes expand to fit their content. Tiles can still
fit two per row on a 390px phone.
A side column on a phone The side column stacks under
the body, so region 3 follows region 2.
In this topic
Who is responsible for what
The user sets the goal and preferences. The author composes the page;
packages supply its visual language and widget behavior. Leaf core keeps
the shared record of what the user does.
flowchart TD
accTitle: Ownership boundaries in a Leaf page
accDescr: The user gives the author a goal and selects a theme. Within the authored page, the author owns content and layout, and the widget package owns controls and action meaning. Theme inputs style both. Widgets send actions to Leaf core, which owns the record, current state and Undo.
User([User])
Theme["Theme package<br/>Color, type and spacing"]
subgraph Page["Authored page"]
Content["Page author<br/>Content and layout"]
Widget["Widget package<br/>Controls<br/>Action meaning"]
Content -->|places and configures| Widget
end
Core["Leaf core<br/>Record, state and Undo"]
User -->|goal| Page
User -->|theme preference| Theme
Theme -.->|visual inputs| Page
Widget -->|actions| Core
Core -->|current state| Widget
Ownership architecture. The author places widgets inside the page; each
package owns its widget’s behavior. Theme inputs style the page and its
controls. Leaf core owns the record behind them.
Instructions to the agent, actions on the page, and themes
installed as packages. Theme colors can follow the browser's
color-scheme preference.
Page author
Content, initial values, package selection, and composition.
Semantic HTML, declared widget attributes, data bindings, page
CSS, and optional page modules.
Widget package
Domain meaning, controls, and rendering within the allotted box.
Registry declarations, browser modules, scoped styles, and author
instructions. Each leans on Leaf through the
package interface.
Theme package
Reusable visual choices and presentation idioms.
Theme inputs and explicit page-wide styles, independently of
whether the package declares widgets.
Leaf kernel
Shared state, event admission, Undo, and interaction services.
The registry contract and public module APIs. Core interprets
declarations; packages supply each widget's domain behavior.
These are contribution boundaries, not a sandbox: package and page scripts
run in the same document. Each package's selectors decide where its rules
match, and inheritance connects nested content's presentation. The
CSS contract describes selector reach and
cascade precedence. The package checks validate
declarations and rendered behavior.
Choose the extension boundary
One page. Semantic HTML, existing Leaf elements, a
page-local <style>, and inline SVG shape one
document. Keep presentation here when no other page needs it.
A package. A reusable element, theme, browser behavior,
or author instructions belong in a package. A project-local package, an
installed package, and a package bundled with Leaf all use the same
composition format.
Leaf's kernel. Runtime, chrome, and protocol behavior
shared by every page belongs in Leaf itself. A package consumes those
capabilities; it does not add a parallel runtime path.
Data between packages
A package meets Leaf through the package interface:
How it works draws it,
walks through a whole widget that records a choice, and gives the form
each kind of need takes with the reasons for that design.
Packages meet each other through declared inputs and outputs. A release
review can use one package to read a patch and another to navigate its
files, without either package knowing the other’s implementation.
flowchart TD
accTitle: A typed output connects independent widgets
accDescr: The author supplies a patch. The Diff widget publishes its changed files using the file-list contract. The page binds a File tree widget to that output, without either widget knowing the other's implementation.
Patch["Author supplies a patch"] --> Diff["Diff widget"]
Diff -->|files: file-list| Tree["File tree widget"]
The page connects these widgets with for="release-patch".
The producer and consumer agree on the file-list value’s
shape. The file tree can also read a stored source with that contract. A
published output is a browser-local derivation, not a decision in the
page’s log.
Independent capabilities, validation and package selection
Leaf's core, called the kernel, supplies the browser runtime, shared
controls, and collaboration protocol. Packages supply reusable elements,
JavaScript modules, styles, and authoring instructions. The default
package provides common widgets and structural elements; optional
packages add capabilities such as diagrams and diffs. Project packages
use the same format and can replace or extend the page's selected layer.
The
package catalog shows the bundled packages; the
tutorial builds a small custom package.
A package declares capabilities independently: what an action records,
whether it decides a proposed change, which typed data it consumes or
publishes, and where its styles apply. Ordinary data fields do not
acquire decision meaning from their names. Two occurrences of the same
widget can select different input contracts without replacing the
widget's declaration. Leaf validates lasting input where it enters the
event log; the render check validates the outputs a widget actually
publishes during the check. The
state and data contract
defines those interfaces.
page init records the page's package selection. The Leaf
serving, checking or exporting the page composes its layer from
that selection and supplies the browser runtime. Each revision captures
the authored content, page-owned declarations and modules, and the
package selection. Historical revisions run with the current Leaf's
runtime and composed layer while retaining their authored content and
recorded decisions. The
package contract
defines how packages are combined and replaced.
In this topic
Build a package with two files
Create a package in the project, then check the empty composition:
Leaf writes a working starter, a yes-or-no choice that records the user's
press: its element declaration, its browser module and its styles. It
checks the complete candidate before changing the package, and each part
is there to be changed into the widget you need. The module defines an
Effect UI component and passes it to defineWidget. The
component asks Leaf for what only Leaf can do by issuing a Command of
Leaf's services, as the starter records a press with
RecordAction. A widget that adds keys draws them with
Keys, each a row that names a control to press or a message
to send the component. The same live rows feed keyboard dispatch, help,
accessibility shortcuts, and, for a row marked
decision: true, the controls shown inline for an obligation.
How it works walks through a
widget of that form line by line. The tutorial below stays with the
smaller CSS-only form so each contract remains visible.
Style the element
A package's defaults.css joins Leaf's existing cascade as
written, so its rules name the elements they style, starting with
lf-callout itself:
--lf-block-frame: 1 tells the shared layout that this rule
draws the widget's inset. The
style contract
distinguishes a declaration to Leaf, as this one is, from theme tokens
such as --lf-accent, facts about a box, and vendor bridges.
The CSS contract explains how widget, theme
and control sheets compose.
Declare the element
The page will author the callout as ordinary readable markup:
<lf-callout id="migration-warning">
<strong>Migration window</strong>
Writes pause for about two minutes.
</lf-callout>
Its complete registry.json entry validates the attributes.
example is the sample an author queries with the entry:
{
"lf-callout": {
"description": "A short warning or constraint that belongs in the reading flow.",
"attributes": { "required": ["id"] },
"example": "<lf-callout id=\"migration-warning\"><strong>Migration window</strong> Writes pause for about two minutes.</lf-callout>"
}
}
attributes is a JSON Schema of the element's attributes, and
the entry needs no other Leaf declaration: the body is the author's markup
unless content says otherwise. Every element takes an
id, which Leaf adds with its grammar, so the entry says only
that this one requires it. Leaf also writes the schema's
type and additionalProperties, so
page check refuses an attribute the entry doesn't name, such
as a misspelt one. description and example make
the merged registry useful to an author.
The registry-key reference lists every other fact a
declaration can state, in sections by what it is about. A CSS-only widget
stops here.
A page keeps its own copy of a package it selects by path, so re-running
page init --package is the explicit update for an existing
page.
leaf package install packages/callout copies the checked
package into ~/.local/state/leaf/packages/, after which
--package callout reaches it by name from any project on this
machine.
A complete package containing the widgets used across Leaf pages.
In this topic
CSS contracts
Widget packages style their own elements; theme packages supply
presentation across the page. Stylesheet roles set where rules reach, and
the cascade sets which rule wins.
Styles and overrides, in the Pages tab,
covers selecting a theme and making local page adjustments.
Which rule wins
Leaf sorts CSS into tiers by who wrote it. The tiers are CSS cascade
layers (@layer), and a rule in a higher tier wins. Each
switch below puts the rule beside it into the tier its page or package
writes into, for the same card, so the card shows what the browser
decides.
Rules in tier order, highest first. The card takes its
padding from the highest rule that is on, which is outlined.
A lower tier's rule loses however specific its selector is, as the widget
package's lf-card.featured shows. Within a tier, the more
specific selector wins, and between equally specific selectors the later
rule wins. !important reverses the order of the tiers, so a
page's !important loses to Leaf's own; an ordinary rule is
all an override needs.
The tiers
A page's own CSS goes in one of four places, and each ranks against Leaf's
tiers as below. Unlayered rules, and rules in a layer of any name but
base or reset, outrank everything Leaf draws, so
a page restyles a widget there.
The page's document, highest first. Leaf's tiers are
tinted. Leaf's panel and thread cards are unlayered too, after the
page's rules, and keep their look against a selector as light as one
class. !important reverses the order.
A framework's base layer holds its reset beside the element rules its
author writes, as Tailwind 4's base holds preflight. The
author's rules must beat the theme, and the reset must leave Leaf's
widgets their margins and borders, so Leaf places
base between its theme and its own elements. A layer ranks as
a whole, so the reset also beats the theme's look on the page's own
markup: a list loses its bullets and a code block its frame. A page that
wants the theme's look under Tailwind imports preflight into
reset instead:
A page selects its theme and its other packages once, with
leaf page init --package NAME, which records them in the page
directory. Each time Leaf serves or exports the page, it composes one
stylesheet from its own sheets and each selected package's, every sheet in
its tier, and links it at the top of the page's <head>,
ahead of the page's own <style> and
<link> elements. That sheet's first rule names Leaf's
tiers, reset and base among them. A layer ranks
where its name first appears, so a framework's own statement, such as
Tailwind's @layer theme, base, components, utilities, leaves
base where Leaf put it and ranks its other layers above
Leaf's.
Where a page's styles come from. Leaf's tiers are
tinted. An export inlines the same sheet in a
<style> in its place.
A widget’s shadow tree
flowchart TD
accTitle: CSS precedence inside a widget's shadow tree
accDescr: For normal declarations, Leaf's marks have the highest precedence, then lf-state, lf-overrides, lf-shadow and lf-base. Page rules and Layouts do not enter the shadow tree.
Marks["Marks · Leaf"] --> State["lf-state · Leaf"]
State --> Theme["lf-overrides · theme packages"]
Theme --> Shadow["lf-shadow · Leaf and widgets"]
Shadow --> Base["lf-base · widget defaults"]
Normal declarations, highest precedence first.
Page rules stop at the shadow root; marks are the highlights Leaf draws.
Which styles contribute to each tier?
Tier
Contributions
lf-state
Leaf's rules that hide what a decision removed.
lf-overrides
Each package's overrides.css, in package order.
lf-layouts
Leaf’s Layout classes, such as layout-column.
lf-shadow
Leaf’s shared shadow rules and each package’s
widget-shadow.css.
lf-base
In the document: the reading look for text Leaf draws, such as a
thread's messages, then Leaf's faces for its own elements and
controls, then packages' widget-shadow.css and
defaults.css. In a shadow tree: defaults the widget
adopts inside @layer lf-base { … }.
lf-theme
Leaf's tokens and page shell, the reading look for the page's own
markup and controls, and each package's theme.css.
Page rules and Layouts stop at the shadow root. Inherited inputs such as
--lf-accent cross it. A widget can also expose a part for
styling with ::part.
A nested widget owns its interior
Put a choice inside a release review: the review package arranges the
choice's box, and the default package styles its Options widget inside.
Leaf adds no boundary between them, so the review package keeps its rules
off the choice's interior by naming its own structure: a child combinator
such as lf-release-review > p, or its own classes. Shared
theme inputs, such as color and type, flow through both.
flowchart TD
accTitle: A nested widget keeps its own styling when the outer package names its own structure
accDescr: Shared theme inputs inherit through the review widget and its nested Options widget. The review package styles its own heading and evidence with selectors that name them, and arranges the nested widget's host box. The default package styles the Options interior.
Theme["Shared theme inputs<br/>Color, type and spacing"]
subgraph Review["Review widget"]
Content["Review package<br/>Heading and evidence"]
subgraph Host["Nested widget host"]
Options["Default package<br/>Options interior"]
end
Content -->|arranges| Host
end
Theme -.->|inherit through both| Review
Each package names what it styles.
The review package's rules reach the nested host and stop short of its
interior because they name the review's own children and classes; a bare
descendant rule such as lf-release-review p would reach
inside. The theme's colors and type reach both widgets.
These are styling conventions, not a security sandbox. Page and theme
rules deliberately have wider reach; packages run in the same document. A
widget's presentation depends on its allotted box and supported theme
inputs, so it can move between page layouts.
Choose a stylesheet by where its rules should reach
A package can contribute widget, theme and control styles independently.
Declaring a widget does not change the reach of its other sheets.
Stylesheet
Reaches
defaults.css
The page document, below Leaf's Layouts.
widget-shadow.css
The page document and every declared shadow tree;
:host(lf-tag) keeps a rule to its widget's own tree.
overrides.css
The page document, above Leaf's Layouts.
Leaf adds no scope to a sheet, so each rule names the widget it styles:
lf-callout .title in the document, and
:host(lf-callout) .title in a widget's shadow tree. Shadow
trees form a browser boundary: document selectors do not enter them, but
inherited inputs and public ::part selectors can.
The
package reference
defines the stylesheet roles and supported inputs.
Choose a bundled package
The core product gallery shows
Leaf’s default widgets and controls in the reading theme. The other pages
below each demonstrate an optional package; the Code review package
provides authoring instructions.
These developer pages are for debugging Leaf itself. The core product
gallery keeps Leaf’s controls and its core interactions on one page;
optional widgets live with their working examples under
Choose a bundled package.
An element declaration holds the JSON Schema of its attributes. Its other
keys tell Leaf how the element reads, renders, changes, and joins the
collaboration loop, for the parts of Leaf that read it without running the
widget's module, listed in sections by what each is about. The index jumps
to a key's summary, and a longer contract opens in place.
This reference is generated from the registry's $keys, the
same entry an agent can query in a page's merged
registry.json. The
complete package contract
says how the keys combine.
Element
The element's attributes and its content, each of which a declaration may leave to its default.
attributes
The JSON Schema of the element's attributes, as Draft 2020-12 has it, which page check and message markup hold each occurrence to.
Full contract
It names each attribute in properties, and its other keywords, such as required and dependentRequired, constrain the attributes named there. Composing the vocabulary writes into properties the id every element takes, and each attribute an input binds by where the declaration doesn't name it there (inputs). It also writes "type": "object" and "additionalProperties": false into this schema and into a verb's detail schema ($verbs), so a declaration writes neither keyword in either, and each schema admits only what its properties names. An attribute schema may write "additionalProperties": true to admit attributes it doesn't name; a detail schema that writes any other value for either keyword is refused. A declaration with nothing to say about its element's attributes leaves attributes out, and the element then takes only the attributes composing the vocabulary writes for it, such as an optional id.
content
The element's content: markup (the author's markup), which is the default, members (only this element's declared member elements), data (one <pre> holding text in the notation the description names, with & < > escaped as & < >; an element leaves it out where its markup binds its value input, and may leave it out where it has a value input and its markup binds only other inputs), markdown (one <pre> escaped as for data, holding Markdown that Leaf renders as safe block Markdown read as a file, a soft line break reading as a space; a body record keeps the source, and passages read the rendered words), or empty. The server, page check, the passage reader and the first paint each read it.
State
What the server admits as actions and keeps on the On lists, which it can't learn by running the widget's module.
verbs
Declares each verb of a widget that has state: the unit of state it changes, who writes it, and either its record (how the state reads in markup, $verbs.record) or the schema of its detail.
Full contract
A verb is the user's, sent from the page as action events, unless it declares writer: "agent"; the agent writes it with leaf page report, as report events. A user verb may create a child element (creates). An agent verb with text: true requires each report to carry a non-empty detail.text, a short note the report feed shows as written. The page marks a reported widget data-lf-reported until a version answers the report ($report). For each [widget, unit, verb] key, the latest action not taken back wins, and different verbs on one unit coexist. Leaf combines those actions with the authored values and hands the widget its complete state, keyed by verb, as its state, which its component's view draws. A past action keeps its key after the widget leaves the page. When an action of a widget that asks says its obligation is answered (awaits), and either records the answer itself (its verb is awaits.value) or turns the obligation from open to answered, Leaf records meaning.answer on it: the thread named by the widget's resolves attribute in the document the action came from, which the answer closes, or null. A decision whose outcome is the one its verb withdraws also records null, and the page reads as if nothing had been proposed. A verb with decides: true selects which members leave the page (retired-when); its required outcome field names the choice. An outcome field on any other verb is ordinary domain data.
awaits
The widget asks the user for input while its authored attributes match when, which puts an obligation on their list, On Me.
Full contract
The obligation's id is widget:<source-id> and never changes. value names the verb (verbs) whose state is the typed answer. Whether the obligation is answered is the widget's own word: its class may define a static answered(state, element), which Leaf calls with the state it sets and the widget's authored element after each of the widget's actions and each undo of one, as where a partial value can stand while the obligation is open, or an empty value can be a complete answer. Without one, the obligation is answered while the user's acts in force hold a state at that verb: one that records a non-empty value, or any action of a verb with no record. Either way only the user's acts count, never a value the markup holds. Leaf sends the word on each act and undo of the widget, as answered, refuses one that leaves it out, and draws the obligation answered or open in the gesture's own task; the latest of the widget's gestures in force decides, and a version that restates an element the widget's decisions rest on asks again until the user's next gesture on it ($restated). An answer written only into the markup answers nothing, so a version that settles a question there retires it (retired). all names the outcome one control can give every obligation of this kind at once. Once created, an obligation stays answered or withdrawn after when stops matching; an element that never matched creates none, and neither does a widget inside an exhibit (exhibit). A restated event asks again. While the agent owes a reply in a thread about the obligation, anchored inside the widget, or inside the group the author declares round it but no other obligation, the agent is its next actor and the obligation stays unanswered. A widget in a thread message keeps its obligation after the thread closes. A question the user answers in words is an agent message's obligation, not a widget's (--obligation). Any widget may declare it, whether bundled, from a package or a page's own; the user answers through its own gestures, and Leaf adds no answer of its own, such as a generic Done, to a widget or anything else On Me.
retired-when
On a member: the outcome of its owner's decision that removes it from the page, as accept removes a suggestion's lf-old.
Full contract
Requires owners. The outcome is a value of the outcome field on the owner's one deciding verb. Leaf renders the decision itself, including its undo: it writes data-lf-state="<outcome>" on the owner and data-lf-retired on the removed members, which one theme rule hides. A widget reads the decision from its state, not these attributes. Once the log decides, page check lets a revision drop the member's ids, and page check --render reports a removed member that still shows words.
exhibit
true or {when: {attribute: [values]}}: the element shows content rather than asking, so widgets inside it never put an obligation on the user's On Me list, whichever form it takes.
Full contract
Where the element's attributes match when, by the presence and value rules of awaits.when, and always for true, the widgets inside are also quoted: they take no input, and delivery paints the element data-lf-exhibit. Elsewhere they take input but still ask nothing, as in an interactive sample. A module reads that mark before wiring input of its own.
history
true: the module renders the page's history, so a page that contains one is served the history reading with its state.
Full contract
The reading is the newest 50 logged events, newest first, each with who acted, what they did, the id of the thread it was in, whether a later undo took it back, and, for a widget gesture, the words its ids had when it was made. The module reads it with readHistory.
Structure
Where the element may stand and what it names, which page check and message markup hold markup to without running a module.
owners
The element declarations that may directly own this element. An owner's direct children of these kinds are its members, and a gesture on the owner's whole box stops at them.
refers
The attributes whose value names another element by its id, each mapped to an empty object, as an option's for is.
Full contract
An input's reference adds its attribute to them (inputs). In the browser a module names the attribute in NavigateToDatum to reach the named widget; it looks in the referrer's own document (its message, for a widget in a reply) before the page.
reading-role
The structural role the element plays, named by its required label.
Full contract
pane is a reading region whose body scrolls on its own while the workspace is full-height: it holds exactly one body element, optionally between a direct header and footer, and a visible heading goes in the header. group is a named group of what it holds, one part of the page that its label names wherever Leaf names it; a widget that asks inside it takes the innermost group as its question, the group's label as the question's words and the group as where going to the question starts. Leaf gives the element the ARIA role its reading role maps to (the kernel registry's $marks), with its label as its accessible name, and makes a pane's body its reading region, so an element in either role needs no module. Leaf reads this declaration, not tag names, so a package can contribute panes and groups under its own tags.
Words
How the element's words read to the passage reader, a version comparison and a browser that hasn't run its module.
verbatim
true: the upgraded element keeps its authored words where they stand, so the passage reader reads them as the page's prose and a version comparison compares them; each nested widget's own declarations cover the words it generates.
Full contract
Without this key the passage reader treats the widget as opaque, since its module may insert, replace or reorder words: a comment's quote stays inside one of its authored children, and a data body it holds isn't read as words.
shadow
true: the module renders the page's words into an open shadow root, and Leaf's passage reading, selection capture and id lookups reach into it.
Full contract
A shadow root attached without this key, as a page script's own custom element attaches one, is opaque: its own words can't be quoted, and the passage reading reads its host by its light children.
inline
true: the element sits inline among the surrounding words. The render check therefore requires neither a width of its own nor a place where a block may stand.
visual
How a rendered picture offers Comment targets.
Full contract
Declaring it also tells the theme the widget is a picture (painted data-lf-visual), so an lf-options lays out options that hold one as it does options holding images. whole makes the picture one target. With {prefixes: [PREFIX, …]}, the module marks each part's node with data-lf-part="ID", or states them as the element's lfParts, whose read() returns the current list of {id, element, label, surface?}; a comment on a part stores its id as anchor.visual. Leaf accepts as a part any longer id starting with one of the prefixes, such as commit:3f2a under commit:, and the rest of the picture stays one target. surface may name a descendant whose own paint, without decoration, gives the outline Leaf marks; element stays the target for hits and travel. A comment whose part is gone detaches on replay instead of widening to the whole picture. A visual that draws its parts over time also gives reveal: reveal(id) must synchronously show a state that holds that part, cancelling any pending change that would remove it, and Leaf calls it before going to the part from a thread or NavigateToDatum. While a declared part is missing from the current state, its threads sit on the whole picture. A visual with too many parts to list, such as a chart's points, also gives find and at: find(id) returns the record for one part of the current state, drawing an element for it if it must, or null, and Leaf asks it rather than searching read, which may then list none, since read is what the target picker and a screen reader's list offer; a part it doesn't find sits on the whole picture, since the visual may draw it once it can, as a chart draws no point before it has room; at(node) returns the part a node of the visual stands for where no element read names holds it, or null: Leaf asks it for a hit, as on a line through the data, and for the visual itself when focus on it names a target, as the point a chart's keys reached. A visual whose parts are no places to stand also gives focus and takes focus for them itself: Leaf calls focus(id) as it places focus on the visual for part id, travelling there or handing the user back from a comment on it, and at no other time, and the visual settles on the part, as a chart moves its reading to the point. Dispatch a bubbling, composed lf-layout event on the element after any change to rendering or geometry, including an attribute or style change in place. The render check validates each record.
Paint
How the element's box is laid out at first paint, before any module runs.
views
An object with members, a CSS selector matching direct authored children shown one at a time, and optional parts: true for a page's parts.
Full contract
Delivery carries the selector; the browser owns their membership and hidden attribute from first paint onward; authored hidden does not select a view. openingView returns the fragment's member, else the tab's saved member, else its supplied fallback (first member by default); reload prefers the saved member. keepView both shows a member and remembers it, or shows none when passed null without forgetting the last member. Its optional third argument keeps an outgoing member visible for an animation without selecting or saving it. A parts holder stands directly in a main with no Layout, each member holding its own Layout. module-state.md, "State only this tab keeps", owns view-state behavior, and what Leaf keeps of the open member: its name in the address and the user's place in it.
space
The width past the reading measure the element takes in a column or sidebar Layout: wide takes the shared, capped width for a block slightly wider than the column, from the prose's start edge; available takes all the width the page shell can give, into both margins.
Full contract
Without it the element fills its container, as every element does in other Layouts; an element read as lines of text keeps to the measure in its own stylesheet (max-inline-size: var(--lf-measure)). An authored element may override it with data-width=wide|available, which the theme applies without moving the prose.
height
The height in CSS pixels the page reserves for the element before its module draws: the declared number, or an authored data-height, which overrides it; true reserves only where data-height is given.
Full contract
The theme holds the box to it from first paint until the module marks the element drawn (lf-rendered). Declare it on a widget whose drawing can't be sized from its markup. A module that can draw at any height, such as a chart's, draws at this one, so nothing moves; for content with its own height, the reserved height is the author's estimate of it.
bound
The element has its own height and scrolls inside it, so a long log or feed never grows the page.
Full contract
start opens at the first line; end follows the newest entry while the user is at the end, and stays where the user scrolled back to otherwise. An authored element may set or override it with data-bound=start|end; delivery writes it as data-lf-bound.
flow
true: the element draws no box of its own around its authored blocks, so in a column or sidebar Layout they stand in the page's flow, as a section's do: words keep the prose's start edge, a block declaring more room takes it, and the element's box grows round that block.
Full contract
{when: {attribute: [values]}} makes it so only while those authored attributes match, by the same rules as awaits.when, as a tab set written flow="page" draws no frame and a boxed one does. Where it holds, the element has no width of its own, so a data-width written on it has no effect; it belongs on the block that needs the room.
Data
The typed values the server checks against $data.contracts and the browser delivers.
inputs
The widget's named typed data inputs.
Full contract
Each names a $data.contracts contract and at least one of the two attributes markup binds it by: source names the attribute holding a page source id, and reference the attribute holding a widget's id. Naming an attribute as source or reference declares it: composing the vocabulary writes it into the attribute schema's properties as a string, unless the declaration gives it a schema there, and writes a reference's attribute into refers. So a declaration names such an attribute once, here, and lists it in attributes only to require it or to say more of it than that it is a string. The input reads the one output of its contract that the named widget declares (outputs); page check refuses a widget with none or more than one. Markup binds the source or the relation, never both. Leaf leaves the property of an unbound input to the widget, except that a content: data element's input whose property is value reads the text of its <pre>. A document binds each source to one contract; later documents may rebind it and read the value against their own contract. Optional property names the element property Leaf sets to the delivered value, or null while there is none; a module reads the input only there, never through a package-owned source name, and dispatches drawn naming that property and the value it drew once its marked records stand. Optional measured names the widget's receipt attribute, which the declaration requires beside the source attribute (package check names a declaration that doesn't), tying the value written in the element's content to the source run that produced it: when the source holds a different run, page check warns that the measurement is stale, and page state reports it. Rewriting the source counts as a new run even with the same value; age alone never makes a measurement stale.
outputs
What the widget holds for other widgets to read: each output is a property of its element, under the output's name, typed by one $data.contracts contract.
Full contract
The module sets the property to the complete value, or null while it has none, and then dispatches change on the element, as a form control does for value. Another widget's input (inputs) reads it by naming the element (reference) and binds by contract. A tag that declares more than one output of a contract passes package check, and page check refuses each input of that contract that names an element of that tag. An output lives with its element in the browser: it reaches neither the server nor the agent, and has no source revision or run receipt.
Authoring
What an agent reads once it has chosen the element.
example
Authored markup exhibiting the element, valid against the merged registry: an agent reads it with the element declaration and writes from it, and page check, page init and package check name one a page could not hold.
instructions
Instructions for an author using this element, read after choosing it and before writing markup. One non-empty string, separate from the short description and the attribute schema.