Storytelling›Storyboard

storytelling

Storyboard

Comic and storyboard layouts from images and captions

Install

  1. Add the package: npm install @refrakt-md/storytelling
  2. Add it to the plugins array in refrakt.config.json: "plugins": ["@refrakt-md/storytelling"]

About the plugin and its runes

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()],
		});
	},
});

View plugins/storytelling/src/tags/storyboard.ts on GitHub

A comic or storyboard layout: a grid of panels, each an image with a caption.

Basic usage

{% storyboard columns=3 %}
![Knights of the Silver Order in formation](https://assets.refrakt.md/faction-the-silver-order.png)

The Silver Order rides out of Thornwall at first light.

![Terraced halls above a river gorge](https://assets.refrakt.md/realm-rivendell.png)

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

![Flooded tunnels lit by a single lantern](https://assets.refrakt.md/realm-the-undercroft.png)

Beneath the city, the Undercroft is already waiting.
{% /storyboard %}
<div data-rune="storyboard" data-rune-fields="{&quot;variant&quot;:&quot;clean&quot;,&quot;columns&quot;:&quot;3&quot;}">
  <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>

Knights of the Silver Order in formation

The Silver Order rides out of Thornwall at first light.

Terraced halls above a river gorge

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

Flooded tunnels lit by a single lantern

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 writeIt becomes
An imageStarts a new panel
A paragraph after itThe panel's caption

Panel styles

variant changes how the panels are framed; columns sets how many sit in a row.

variantPanels look like
cleanMinimal frames (the default)
comicThick borders and slightly tilted panels, like a comic book
polaroidWhite-framed photos with drop shadows, as if pinned to a board

Attributes

AttributeTypeRequiredDescription
columnsnumber—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.

AttributeTypeRequiredDescription
bgstring—Background preset applied to this block
bg-fromstring—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-tostring—Gradient end colour — a semantic token name
bg-viastring—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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
reveal"none" | "fade" | "slide" | "scale" | "blur"—Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography
staggerboolean—Cascade this block's items in as it reveals (no-op on single-child runes)
spacing

Block-level rhythm override.

AttributeTypeRequiredDescription
spacing"flush" | "tight" | "default" | "loose" | "breathe"—Vertical spacing above and below this block
substrate

Generated pattern fills behind the content, drawn by the theme.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
tintstring—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.

AttributeTypeRequiredDescription
width"compact" | "narrow" | "content" | "wide" | "full"—Maximum width constraint for this block
Not availableWhy
dropcap, readingthis rune declares no prose body
framethis rune declares neither a `frameTarget` nor a media section
prominencethis 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.

AttributeTypeRequiredDescription
bgstring—Background preset applied to this block
bg-fromstring—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-tostring—Gradient end colour — a semantic token name
bg-viastring—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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
reveal"none" | "fade" | "slide" | "scale" | "blur"—Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography
staggerboolean—Cascade this block's items in as it reveals (no-op on single-child runes)
spacing

Block-level rhythm override.

AttributeTypeRequiredDescription
spacing"flush" | "tight" | "default" | "loose" | "breathe"—Vertical spacing above and below this block
substrate

Generated pattern fills behind the content, drawn by the theme.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
tintstring—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.

AttributeTypeRequiredDescription
width"compact" | "narrow" | "content" | "wide" | "full"—Maximum width constraint for this block
Not availableWhy
dropcap, readingthis rune declares no prose body
framethis rune declares neither a `frameTarget` nor a media section
prominencethis rune has no page-section header or featured quotation