@texuli/blocks
v0.18.0
Published
Content blocks: closed vocabulary, untrusted guard, formula AST and catalog metadata for pages, documents and slides.
Maintainers
Readme
@texuli/blocks
Content blocks for pages, documents and slides: a closed vocabulary of typed JSON blocks (headings, rich text, columns, tabs, images, tables, KPIs, charts, maps, polls, code and more), an untrusted-input guard that validates them, framework-free engines and Svelte 5 renderers. It is built for content that comes from people or AI agents: anything that fails validation becomes an inert notice instead of reaching the page. It is part of Texuli, "Small pieces. Infinite possibilities.": an MIT Svelte 5 component library by Dailybot, Inc.
In the stack: layer L5, on the @texuli/core texels, the @texuli/tokens token engine, the texuli components and the @texuli/charts, @texuli/data and @texuli/media domain packages. The agent catalog, the player, @texuli/pages, @texuli/slides, @texuli/astro and @texuli/tools build on it.
Status: 0.x release.
@texuli/blocksis published on npm as0.18.0, a pre-1.0 release (1.0.0 will be the first stable release). Under 0.x, a new minor (0.14.0) may contain breaking changes, so pin the exact version or use^0.18.0, which accepts only 0.18.x.
Install
npm install @texuli/blocks @texuli/tokens sveltesvelte(^5.57.2) is a peer dependency.- The renderers style themselves with the Texuli
--tx-*design tokens. Import the token stylesheet once in your app (installing@texuli/tokensdirectly lets your bundler resolve it); each renderer imports its own CSS.
@import '@texuli/tokens/base.css';Quick start
Validate untrusted JSON, then render the text family with its lazily loaded renderer:
<script lang="ts">
import { isTextFamilyBlock, loadTextFamily, parseUntrustedBlocks } from '@texuli/blocks';
// For example, JSON produced by an agent.
let { input }: { input: string } = $props();
const result = $derived(parseUntrustedBlocks(input));
</script>
{#if result.success}
{#await loadTextFamily() then { default: TextBlockView }}
{#each result.blocks.filter(isTextFamilyBlock) as block, index (index)}
<TextBlockView {block} />
{/each}
{/await}
{:else}
<p>This content could not be displayed.</p>
{/if}With input set to
[{"type":"heading","level":2,"text":"Release notes"},{"type":"text","markdown":"A **safe** paragraph."}],
this renders an h2 and a paragraph. parseUntrustedBlocks accepts JSON text
or objects, enforces size, depth and count limits, strips invisible and
bidirectional control characters, and returns either the typed blocks or a
list of issues. It never throws.
The package root exports a load*Family() renderer loader and a
*_BLOCK_TYPES list for every family, plus check*Block guards and
is*FamilyBlock narrowers for most of them.
What's inside
| Family | Block types | Imports |
| --- | --- | --- |
| Core | Schemas, limits, safety checks, the untrusted guard, text helpers and catalog metadata | @texuli/blocks, @texuli/blocks/core |
| Formula | A closed calculator language: parser, AST, evaluator and formatter | @texuli/blocks/formula |
| Text | heading, text, list, quote, callout | @texuli/blocks/text, @texuli/blocks/text/engine, @texuli/blocks/text/markdown, @texuli/blocks/text/renderers |
| Structure | columns, grid, tabs, accordion, cards, divider, cta | @texuli/blocks/structure, @texuli/blocks/structure/engine, @texuli/blocks/structure/renderers |
| Media | image, figure, video, gallery | @texuli/blocks/media, @texuli/blocks/media/engine, @texuli/blocks/media/renderers |
| Embed | embed-app, link-preview | @texuli/blocks/embed, @texuli/blocks/embed/engine, @texuli/blocks/embed/renderers |
| Interactive | poll, quiz, calculator, checklist | @texuli/blocks/interactive, @texuli/blocks/interactive/engine, @texuli/blocks/interactive/renderers |
| Data | table, stat, kpi, chart (line, area, bar, stacked bar, combo, heatmap, scatter) | @texuli/blocks/data, @texuli/blocks/data/engine, @texuli/blocks/data/renderers |
| Map | map: places and an optional route on an offline basemap | @texuli/blocks/map, @texuli/blocks/map/engine, @texuli/blocks/map/renderers |
| Diagram | flow, tree, board and terminal diagrams | @texuli/blocks/diagram, @texuli/blocks/diagram/engine, @texuli/blocks/diagram/renderers |
| Code | code, with syntax colors from an owned tokenizer | @texuli/blocks/code, @texuli/blocks/code/engine, @texuli/blocks/code/tokenizer, @texuli/blocks/code/renderers |
| Code field | CodeField: an editable, syntax-highlighted textarea for forms (<CodeField bind:value language="ts" />; new in 0.13.1) | @texuli/blocks/code-field |
| Labels | BLOCKS_MESSAGES_EN (every block label id and its English default) and the BlocksMessageId union, for one dictionary set near the root with setTexuliLabels or <LabelsProvider> from texuli (ADR-026) | @texuli/blocks/i18n |
| Spanish labels | BLOCKS_LABELS_ES: every block label id in Spanish, opt-in, for <LabelsProvider> from texuli/i18n (from 0.14.3; no native-speaker review yet; see the texuli i18n guide) | @texuli/blocks/i18n/es |
In each family, the plain subpath is the light API (guards, labels, the lazy
loader), /engine is framework-free logic, and /renderers gives you the
Svelte views eagerly. @texuli/blocks/text/markdown is the owned Markdown
subset parser.
The core vocabulary includes safeParseBlocks and safeParseBlock,
parseUntrustedBlocks, BLOCK_LIMITS, BLOCK_CATALOG with
validateBlocksForAuthoring (metadata for builders and agents), and the
text helpers walkBlocks, blockText and headingOutline.
New in 0.13.1
CodeField(@texuli/blocks/code-field): an editable, syntax-highlighted code field,<CodeField bind:value language="ts" />. A real textarea (caret, selection, undo, form value) sits over the owned tokenizer's output, printed as elements. Tab indents; Escape, then Tab, leaves the field. It renders highlighted on the server, and turns highlighting off past 20,000 characters (code).
New in 0.9.0
treediagrams takevariant, notstyle(variant: 'file-tree' | 'org'). The untrusted draft scan refuses everystylekey, so atreeblock could never pass blueprint validation for an agent. The parser acceptsstyleas an alias through 0.9.x and returnsvariant; sending both with different values is refused. From0.10.0styleis refused with "style was removed in 0.10.0; send variant". Thelistblock's optionalstylehas the same limit (agents can send lists without it) and is not renamed yet.- Design-system tokens: the block stylesheets read the token contract v2
system tokens (
--tx-space-*,--tx-shape-radius-*,--tx-type-*) with the visual-baseline pixels unchanged;codeandstructurekeep their literals because they also render inside deck themes (seescripts/check-token-usage.ts).
New in 0.6.0
Ships in 0.6.0; the 0.5.0 release predates it: the packed declarations of
the diagram and interactive block components type-check for consumers (no
self-named imports, TS2440), and the structure renderers carry the styled
components' API contract and motion. No API change.
New in 0.5.0
Ships in 0.5.0; the 0.4.0 release predates it:
- Text family: heading
align; textalignandsize; liststyle(bullet,number,checkwith per-itemdone,iconwith per-itemicon); quoteroleandavatar; callouticon(text). - Structure family: card
icon; dividerlabelandvariant: "space". The text and structure family views take the host resolversresolveIcon?(name)andresolveAvatar?(id)(quote avatars passsafeImageSrc), and the structure view passes them to nested blocks (structure). - Data family: stat
titleandsource, and a per-itemtrendsparkline onstatandkpi(data). - Code:
headerandtoolbarsnippets on the code block bar (code). - Linear-time Markdown.
@texuli/blocks/text/markdownreads heading, fence and rule lines and inline markers without backtracking, so hostile agent text parses in linear time; U+2028 and U+2029 end a line.
Key guarantees
- Untrusted by design. Every block passes an owned runtime validator before anything renders; a rejected block becomes an inert, translatable notice.
- No HTML sinks. Markdown, code and every other block render as Svelte
text and elements, never through
{@html}. Raw tags in Markdown stay literal text. - URL policy on every link. Links, calls to action and link previews pass
safeHrefat theuntrustedtier. Block media accepts only avatar ids, small inlinedata:images and videos, and relative paths; remote URLs are refused at parse time. - No code execution. Formulas are closed JSON ASTs that are parsed, evaluated and formatted, never run as code. Embed apps start only after the user activates them, inside a host-provided mount, and link previews never fetch.
- No network from maps. The map block draws on an offline, fictional basemap; it never loads tiles or geocodes.
- Trojan Source safe. Bidirectional overrides and invisible control characters are stripped or refused.
Documentation
- Site: texuli.com and the blocks gallery
- Families: text, structure, media, embed, interactive, data, map, code, formula
- Source: github.com/DailybotHQ/texuli · Issues: github.com/DailybotHQ/texuli/issues
Contributing
Contributions are welcome; start at the GitHub repository.
License
MIT © Dailybot, Inc. Powered by Dailybot.
