storytelling
Storyboard
Comic and storyboard layouts from images and captions
Install
- Add the package:
npm install @refrakt-md/storytelling - Add it to the
pluginsarray inrefrakt.config.json:"plugins": ["@refrakt-md/storytelling"]
Source
import Markdoc from '@markdoc/markdoc';
import type { Node, RenderableTreeNode } from '@markdoc/markdoc';
const { Ast, Tag } = Markdoc;
import {
createComponentRenderable,
createContentModelSchema,
bodyOnly,
asNodes,
renderNodes,
isMediaNode,
} from '@refrakt-md/runes';
import { RenderableNodeCursor } from '@refrakt-md/runes';
const variantType = ['comic', 'clean', 'polaroid'] as const;
export const storyboardPanelMediaSlots = { image: 'cover' } as const;
export const storyboardPanel = createContentModelSchema({
mediaSlots: storyboardPanelMediaSlots,
contentModel: bodyOnly(),
transform(resolved, attrs, config) {
const children = renderNodes(resolved.body, config);
const image = (
children
.flatten()
.toArray()
.filter((n) => isMediaNode(n)) as InstanceType<typeof Tag>[]
).slice(0, 1);
const caption = children.tag('p').limit(1);
const body = children.wrap('div');
return createComponentRenderable({
rune: 'storyboard-panel',
tag: 'div',
refs: {
image,
caption,
body: body.tag('div'),
},
children: [body.next()],
});
},
});
function convertStoryboardChildren(nodes: unknown[]): unknown[] {
const converted: Node[] = [];
let currentPanelChildren: Node[] = [];
const flushPanel = () => {
if (currentPanelChildren.length > 0) {
converted.push(new Ast.Node('tag', {}, currentPanelChildren, 'storyboard-panel'));
currentPanelChildren = [];
}
};
for (const node of nodes as Node[]) {
if (
node.type === 'image' ||
(node.type === 'paragraph' && Array.from(node.walk()).some((n) => n.type === 'image'))
) {
flushPanel();
currentPanelChildren.push(node);
} else if (currentPanelChildren.length > 0) {
currentPanelChildren.push(node);
} else {
currentPanelChildren.push(node);
}
}
flushPanel();
return converted;
}
export const storyboard = createContentModelSchema({
attributes: {
columns: {
type: Number,
required: false,
description: 'Number of panel columns in the grid layout.',
},
variant: {
type: String,
required: false,
matches: variantType.slice(),
description:
'Visual style: comic (speech bubbles), clean (minimal), or polaroid (photo frame).',
},
},
contentModel: {
type: 'custom',
processChildren: convertStoryboardChildren,
description:
'Image-triggered panel accumulator. Each image starts a new panel; ' +
'subsequent non-image content becomes the panel caption.',
},
transform(resolved, attrs, config) {
const allChildren = asNodes(resolved.children);
const body = new RenderableNodeCursor(
Markdoc.transform(allChildren, config) as RenderableTreeNode[],
);
const variantMeta = new Tag('meta', { content: attrs.variant ?? 'clean' });
const columnsMeta = new Tag('meta', { content: String(attrs.columns ?? 3) });
const panels = body.tag('div').typeof('StoryboardPanel');
const panelsContainer = panels.wrap('div');
return createComponentRenderable({
rune: 'storyboard',
tag: 'div',
properties: {
panel: panels,
variant: variantMeta,
columns: columnsMeta,
},
refs: { panels: panelsContainer },
children: [panelsContainer.next()],
});
},
});
A comic or storyboard layout: a grid of panels, each an image with a caption.
Basic usage
{% storyboard columns=3 %}

The Silver Order rides out of Thornwall at first light.

In Hollowmere, Elena finds Lord Ashford's last letter.

Beneath the city, the Undercroft is already waiting.
{% /storyboard %}<div data-rune="storyboard" data-rune-fields="{"variant":"clean","columns":"3"}">
<div data-name="panels">
<div data-rune="storyboard-panel" data-field="panel">
<div data-name="body">
<p data-name="caption">
<img src="https://assets.refrakt.md/faction-the-silver-order.png" alt="Knights of the Silver Order in formation" data-name="image">
</p>
<p>The Silver Order rides out of Thornwall at first light.</p>
</div>
</div>
<div data-rune="storyboard-panel" data-field="panel">
<div data-name="body">
<p data-name="caption">
<img src="https://assets.refrakt.md/realm-rivendell.png" alt="Terraced halls above a river gorge" data-name="image">
</p>
<p>In Hollowmere, Elena finds Lord Ashford's last letter.</p>
</div>
</div>
<div data-rune="storyboard-panel" data-field="panel">
<div data-name="body">
<p data-name="caption">
<img src="https://assets.refrakt.md/realm-the-undercroft.png" alt="Flooded tunnels lit by a single lantern" data-name="image">
</p>
<p>Beneath the city, the Undercroft is already waiting.</p>
</div>
</div>
</div>
</div>
The Silver Order rides out of Thornwall at first light.

In Hollowmere, Elena finds Lord Ashford's last letter.

Beneath the city, the Undercroft is already waiting.
<div class="rf-storyboard rf-storyboard--clean rf-storyboard--3" data-variant="clean" data-columns="3" data-elevation="flush" data-rune="storyboard" data-density="full" style="--sb-columns: 3">
<div data-name="panels" class="rf-storyboard__panels">
<div class="rf-storyboard-panel" data-field="panel" data-rune="storyboard-panel" data-density="full">
<div data-name="body" class="rf-storyboard-panel__body">
<p data-name="caption" class="rf-storyboard-panel__caption">
<img src="https://assets.refrakt.md/faction-the-silver-order.png" alt="Knights of the Silver Order in formation" data-name="image" class="rf-storyboard-panel__image" data-media="cover" />
</p>
<p>The Silver Order rides out of Thornwall at first light.</p>
</div>
</div>
<div class="rf-storyboard-panel" data-field="panel" data-rune="storyboard-panel" data-density="full">
<div data-name="body" class="rf-storyboard-panel__body">
<p data-name="caption" class="rf-storyboard-panel__caption">
<img src="https://assets.refrakt.md/realm-rivendell.png" alt="Terraced halls above a river gorge" data-name="image" class="rf-storyboard-panel__image" data-media="cover" />
</p>
<p>In Hollowmere, Elena finds Lord Ashford's last letter.</p>
</div>
</div>
<div class="rf-storyboard-panel" data-field="panel" data-rune="storyboard-panel" data-density="full">
<div data-name="body" class="rf-storyboard-panel__body">
<p data-name="caption" class="rf-storyboard-panel__caption">
<img src="https://assets.refrakt.md/realm-the-undercroft.png" alt="Flooded tunnels lit by a single lantern" data-name="image" class="rf-storyboard-panel__image" data-media="cover" />
</p>
<p>Beneath the city, the Undercroft is already waiting.</p>
</div>
</div>
</div>
</div>How Markdown is read
| You write | It becomes |
|---|---|
| An image | Starts a new panel |
| A paragraph after it | The panel's caption |
Panel styles
variant changes how the panels are framed; columns sets how many sit in a row.
variant | Panels look like |
|---|---|
clean | Minimal frames (the default) |
comic | Thick borders and slightly tilted panels, like a comic book |
polaroid | White-framed photos with drop shadows, as if pinned to a board |
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
columns | number | — | Number of panel columns in the grid layout. |
variant | "comic" | "clean" | "polaroid" | — | Visual style: comic (speech bubbles), clean (minimal), or polaroid (photo frame). |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |
storyboard-panel
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |