package file→ .shtukbase/packages/lenses/kit/README.md
kit/README.md
182 lines, 13.9 KB.
- # Shtukbase HTML lenses
- A lens is an HTML page that shows the records of a Shtukbase base in its own perspective:
- architecture with links, an ontology of types, nesting, a board. The source of truth is markdown records;
- lenses are built from them by a script and rebuilt on every change of the base.
- **Where it lies.** Since 28.11.2026 the kit is part of the standard's `lenses` package: `apps/standard/packages/lenses/kit/` in the repository,
- `.shtukbase/packages/lenses/kit/` in a project after install. In a project it is run by the package's actions:
- `shtuk run lenses build | check | serve`. There are no npm dependencies: js-yaml lies as one file in `vendor/`
- (the build `dist/js-yaml.min.js`, the MIT license in `vendor/js-yaml.LICENSE`); `bun install` is not needed.
- **Ready patterns (patterns/).** Building a map lens — one canvas with pictures on cards, frames, a tree and
- a view switch — step by step: [`patterns/map.md`](patterns/map.md), a working example in `examples/base/`.
- Card pictures in the set's style and the helper `bin/shtukbase-icons.js`: [`patterns/pictures.md`](patterns/pictures.md).
- ```
- <base>/
- lib/ ← the one helper folder of the base (in the base root, visible, no dot)
- kit.js, kit.css ← the component set and templates (in git); kit.css = the skins and style of the kit-style package + its own part kit/kit.css
- index.html ← the gallery of all lenses (in git)
- data.js ← the base's records in one file (built, not in git)
- bodies.js ← the records' texts, loaded when a record is first opened (built, not in git)
- <layer>/*.data.js ← the layer's lens data from the standard's generators (in git)
- <any folder>/x.html ← an HTML lens: the header `type: Lens` in the first comment
- ```
- A lens lies anywhere and links `lib/` by a relative path (`../lib/kit.js`,
- `../../lib/kit.js` …). This way it opens both in Shtukbase and straight from disk (`file://`, a double
- click), no server needed. A browser does not let a page from disk read `.md` files (`fetch` to `file://`
- is forbidden), but `<script src>` is allowed — so the data is built into `data.js`. After a clone:
- `shtukbase-lenses build` in the base root.
- ## Commands
- ```sh
- bun bin/shtukbase-lenses.js build --root <base> # build the lenses
- bun bin/shtukbase-lenses.js check --root <base> # check that lenses are up to date (code 1 — out of date)
- bun bin/shtukbase-lenses.js hook --root <base> # print a git hook that rebuilds the lenses
- ```
- It also works under Node. There are no npm dependencies.
- ## A new lens
- Create `<base>/lenses/<id>.lens.md`:
- ```yaml
- ---
- type: Lens
- title: Title
- icon: "🧭"
- description: "One line: what is visible on this lens"
- template: canvas # canvas | lanes | types | nest | board | custom
- ...template parameters
- ---
- The text "About the lens": how to read the picture. Links to records are as in the base: [agents](/product/agents.md).
- ```
- Run `shtukbase-lenses build` — `<id>.html` and a card in `index.html` appear.
- ### How to select records
- The same in all templates: `from` — a folder (`/product/agents`), `type` — a record type,
- `where` / `not` — a filter on fields (`{kind: channel}`, a value or a list), `sort` — the sort field.
- ### Templates
- | Template | What it shows | Main parameters |
- |---|---|---|
- | `canvas` — canvas | areas with cards and arrows along link fields | `layout {columns, stacks \| areas}`, `regions [{id, title, from, where, group, card, linked}]`, `edges [{field, from, to, label, color, dash, reverse}]` |
- | `lanes` — lanes | rows by a field's value (for example, a business function), inside — columns: entry → main path → branches, a shared column on the right; arrows along link fields, filters in the side panel | `lane {field, sort, other}`, `columns [{id, title, role: entry\|main\|child\|side, from, where, attach, parent, sortBy, card}]`, `edges [… off]`, `filters` |
- | `types` — ontology | record types by layer and the links between types | `layers`, `skipTypes`, `skipFields`, `layout {columns, stacks \| areas}` |
- | `nest` — nesting | boxes inside boxes by a parent field | `from`, `parent`, `group`, `groupOrder`, `chips`, `refs` |
- | `board` — board | columns by a field, link counters on the cards | `by`, `columns {from, sort}`, `card`, `meters [{label, field} \| {label, back}]` |
- | `custom` — own layout | anything | `script`, `style` — files next to the lens |
- Details are in the header of each file `kit/templates/*.js`.
- A link in `edges` can have `off: true` — that kind of link is hidden at first and is turned on by clicking the legend.
- A link kind can combine several fields: `fields: [field, …]` instead of `field`; `edgeLabel: true` labels
- the arrow with the field's name. Record fields whose name starts with `_` are service fields: the record card does not show them.
- A canvas also has `counters [[label, number], …]` — a row of counters above the canvas, `list {title, hint, groups, card}` —
- record cards under the canvas, `fit: "width"` — shrink a wide canvas to the window width on opening.
- This is how, for example, the lens of concept links of a layer in shtukbase-standard is built (`render_layer_ontology.py`).
- It is meant for frequent links that without a filter turn a canvas into a cobweb (an example is `leads on to` in the scenario map).
- In YAML records boolean values are only `true`/`false`; `on`, `off`, `yes`, `no` are read as strings.
- ### Compact layout
- A lens does not stretch to the whole screen: the content is centered and takes as much room as it needs.
- - No long rows: up to three cards or areas stand in a row, beyond that the group folds into a grid close to a square
- (9 is 3×3, 6 is 3×2), a row is no longer than four. The columns are computed by `Lens.gridCols(count, cap)`; on a canvas `columns: auto` on an area does the same (`units: auto` if the
- cards have a `size`). In your own layout call `Lens.gridCols` yourself. The class `lx-lines-3` holds exactly three lines for text —
- cards in a row come out the same height.
- - Canvas: an area with `tree: <field>` is drawn as a tree left to right — a card, and to the right those that enter it by this field.
- - Canvas: `layout.groups` — named stacks of areas inside the `areas` layout (areas one under another with no gaps, a nested list — in a row).
- - Canvas: `areaMax` — the cap on an area's and a card's width (720px in the set); an area with `hug: true` — an area as wide as its content, in the middle of its cell. In detail — `patterns/map.md`.
- - Canvas and ontology: `layout.stacks` — a list of columns, in each the areas go one under another with no gaps;
- `layout.columns` — the column widths (better fixed ones, for example `"250px 250px 520px 270px"`).
- `layout.areas` (CSS grid areas) is kept for complex grids, but rows there stretch to the tallest area.
- - Nesting: boxes are laid out as "bricks" in columns of 330px, big boxes move to the neighboring column.
- - Board: columns of 270px, the board is centered; if there are many columns — sideways scroll.
- ### Own layout
- `template: custom`, next to it `script: my-view.js` (and if wanted `style: my-view.css`).
- The script registers `Lens.templates.custom = function (cfg) { ... }` and builds the page from shared elements:
- - `Lens.page(cfg)` → `{main, sidebar, panel, section, settings, left, showBar, layout}`. The frame follows the
- [Lens layout convention](../../design-components/pages/design/conventions/layout.md). Lens authors append content to
- `main`, add settings with `section` or `settings`, and can add the optional left panel with `left`. `layout` exposes
- the mounted frame controller. The build reads `layout:` from `/design/design.md` and bundles its assets.
- - `Lens.stats([[label, n], ...])`, `Lens.segmented(options, value, onchange)`, `Lens.edgesPanel(...)` —
- blocks for the side panel;
- - `Lens.zoom(scroller, target)` — scale for a canvas: the buttons −/+/fit, Ctrl/⌘ + wheel, the keys `+ − 0 f`;
- - `Lens.query({from, type, where, sort})`, `Lens.prop(r, key)`, `Lens.targets(id, field)`, `Lens.back(id, field)` — data and links;
- - `Lens.card(id, {sub, chips, compact, full, art, ratio, size})` (`full` — the text under the title in full, no truncation; `art` — a record field with a path to a picture from the base root, a large icon to the left of the title and text instead of the glyph; `ratio` — the card's aspect ratio, for example `"3/2"`; `size` — the size `xs`, `s`, `m`, `l` or `auto` by text length, on a canvas such cards lie in a dense grid; `modes` on a canvas — card views with a switch in the side panel; on a canvas `surface: paper` makes the areas white and the cards lightly tinted with a shadow), `Lens.region({...})`, `Lens.chip(text, color)`, `Lens.optionChip(r, key)` — elements;
- - `Lens.icon(r)`, `Lens.iconOf(r)`, `Lens.glyph(value, fromId)` — a record's icon with the fallback (own `icon` → the collection's `icons.item` → the collection page's icon → 📄; tier `none` gives none), an emoji as text, an `.svg` path as `<img>` (the package "Page icons");
- - `Lens.edges(container, edges, opts)`, `Lens.legend(...)` — arrows between cards (`data-node`);
- - `Lens.open(id)` — a record page, as in the Shtukbase app: properties, markdown, links there and back.
- Colors are the Notion palette from Shtukbase: `Lens.color(name)`, `Lens.tone(name)` (background, dot, text).
- An example is `examples/access-matrix.*` (the matrix "agents × accesses").
- ## How a record opens and what is remembered
- A click on a card opens its record. The record is drawn compactly:
- - the glyph and the title — in one line and once; there is no separate header with the title;
- - the buttons (back, expand to the whole window and back, pin, how to open, close) appear at the top right when you hover the record
- or enter it with the keyboard; on a screen without a mouse they are always visible;
- - under the title the main fields stand in one row: the record type and up to four select fields (the field's label is in the tooltip);
- - in the same row two icons, visible on hover over the record: a chevron opens the other fields ("Details"), a chain link
- with a number — back links ("Linked here"); they open under the row, the choice is remembered;
- - below goes the record text; there are no divider lines;
- - in the "Card" mode the window is no taller than its record: height by content, but no more than the remembered one, a long record
- scrolls inside.
- How to open a record is chosen in the menu on it ("How to open records"):
- - **Side** — over the lens on the right; the width is dragged by the left edge, a double click — the usual width.
- - **Center** — a window over a dimmed backdrop.
- - **Side panel** — next to the lens, does not cover it; the width is dragged the same way as for "Side".
- - **Card** — a small window with no dimming, scrolls inside. The first time it stands next to what was
- clicked; after that all records (in this and other lenses) open in it, in the same place and of the same size.
- It is moved by the header, the size is dragged by the bottom right corner; it closes with the cross, Esc and a click outside.
- The icon in the header switches pinning: **to the window** (by default: stays in place, the canvas moves under it, it does not leave
- the window's edge) or **to the board** (pinned to the canvas: it moves and scales together with it; in templates without
- scaling — board, gallery, nest — it scrolls with the page). On switching it stays where it is visible.
- A canvas (`canvas`) moves in any direction: by wheel and trackpad on two axes or by dragging an empty spot; around the diagram
- there is a margin. Arrows go over the areas and where possible around the cards, labels — over everything, on a plate.
- Counters (`counters`) are in the "Overview" section of the side panel, as in the other templates, not on the canvas.
- An area or a card is no wider than `--block-max` (720px), even if the layout stretched it to the full width; an area's
- explanation is up to three lines, a click opens it in full.
- **Rule: what is remembered and where.** All of a user's view settings the kit stores only through `Lens.prefs`
- (`get`/`set`, keys with the prefix `lx-`, the format version in `lx-prefs-version`) in `localStorage`; they survive
- a reload and a move to another lens. Shared by all lenses: the theme `lx-theme`, the style (skin) `lx-skin`, the background `lx-bg`, the record mode
- `lx-open-mode`, the width `lx-reader-w-side` / `lx-reader-w-panel`, for "Card" the place `lx-card-x`/`-y`, the size
- `lx-reader-w-card`/`lx-reader-h-card`, the pinning `lx-card-pin`, the panel's collapsed sections `lx-fold:<section>`,
- whether the panel is open `lx-side`. Each lens has its own (the key by file path, `Lens.prefs.lens(name)`): the scale and place of the canvas
- `lx-lens:<path>:view`. An address can set settings for one showing without remembering them: `?skin=keer&theme=dark` (shared `theme`, `skin`, `bg`, `side`, `open-mode`), the other parameters are the lens's own settings (`?view=deps` → `Lens.prefs.lens("view")`). `localStorage` is shared by lenses of one origin — a site or files from disk in Chrome and Electron.
- Where it is closed or separate for each file (a sandbox without `allow-same-origin`, private mode, `file://` in Firefox),
- the settings are duplicated in `window.name`: they pass to the next lens in the same tab or window, but not to a new tab.
- ## Auto-update
- The hook from `shtukbase-lenses hook` rebuilds the lenses after checkout and merge.
- `shtukbase-lenses check` suits CI: it fails if someone committed records without a rebuild.
- ## Examples
- `examples/base/` — a teaching base (a vegetable garden) with a map lens `map.html`: `patterns/map.md` walks through it, and `npm run check` builds
- and checks it (build, freshness, picture style).
- `examples/*.lens.md` — lenses of the an earlier product base in the old `lens.md` format: the architecture of agents (canvas),
- the ontology (types), surfaces (nesting), capabilities by direction (board), the access matrix (own layout).
- The base itself is not in the repository; these are samples of settings, not working lenses.