Live examples
Each example below is running on this page, under the same content security policy the docs are served with, and its code is the file that ran. Copy it, or start from a template in StackBlitz.
A design as SVG
renderSvg turns a document into an SVG string with no DOM, in a browser or in Node 22.3+. This one lays text out from the font files, so lines break where the app breaks them.
import { renderSvg } from '@getv.design/embed/static';
const text = `version 4
kind design
title "Pricing card"
frame card w=640 h=360 background=#ffffff
rect card.bg x=0 y=0 w=100% h=100% fill=#f4f4f6
text card.name x=48 y=96 w=544 h=44 size=36 weight=700 fill=#101014
"Pro"
text card.price x=48 y=160 w=544 h=86 size=72 weight=800 fill=#d64545
"$49 a month"
text card.note x=48 y=270 w=544 h=30 size=24 fill=#101014 opacity=0.6
"Billed yearly. Cancel any time."`;
// A string in, an SVG string out. No DOM is needed to make it; here it is inlined.
const svg = await renderSvg(text, { fonts: 'exact', fontBase: '/docs/vd/fonts/' });
document.querySelector('#demo-static').innerHTML = svg; View and present
A view the reader can page through, zoom (⌘ or Ctrl with the wheel) and present. Your own buttons drive the handle.
import { view } from '@getv.design/embed/view';
const text = `version 4
kind slides
title "Launch"
frame intro w=1280 h=720 background=#101014
text intro.title x=96 y=250 w=1000 h=86 size=72 weight=800 fill=#ffffff
"Ship the design"
text intro.sub x=96 y=370 w=1000 h=34 size=28 fill=#ffffff opacity=0.7
"A document the page can show, page and present."
frame second w=1280 h=720 background=#d64545
text second.title x=96 y=250 w=1000 h=86 size=72 weight=800 fill=#ffffff
"Then change it"
text second.sub x=96 y=370 w=1000 h=34 size=28 fill=#ffffff
"load() redraws in place; goTo() moves between pages."`;
const el = document.querySelector('#demo-view');
const handle = await view(el, text, { fit: 'page', fontBase: '/docs/vd/fonts/' });
// Your own controls drive the handle.
document.querySelector('#view-first').addEventListener('click', () => handle.goTo(0));
document.querySelector('#view-next').addEventListener('click', () => handle.goTo(1));
document.querySelector('#view-play').addEventListener('click', () => handle.play());
const status = document.querySelector('#view-page');
status.textContent = handle.pages()[0].id; // the page event fires on a change, not at the start
handle.on('page', (page) => {
status.textContent = page.id;
}); The editor
The same element, now an editor: only the canvas. Select, move and type on it, and use your own buttons for the rest. Nothing leaves the page.
import { edit } from '@getv.design/embed/edit';
const text = `version 4
kind design
title "Badge"
frame badge w=640 h=360 background=#eef1f8
text badge.label x=64 y=130 w=512 h=100 size=88 weight=800 fill=#101014
"Edit me"`;
const el = document.querySelector('#demo-edit');
// The editor is the canvas: select, move, resize and type on it directly.
// Everything else, like these buttons, is your page driving the handle.
const editor = await edit(el, text, {
fit: 'page',
fontBase: '/docs/vd/fonts/',
theme: { scheme: 'auto' }, // the canvas follows the reader's light or dark
});
document.querySelector('#edit-undo').addEventListener('click', () => editor.undo());
document.querySelector('#edit-redo').addEventListener('click', () => editor.redo());
document.querySelector('#edit-red').addEventListener('click', () => {
editor.apply('set badge.label fill=#d64545'); // one undo step
});
// change fires once per undo step; text() is the whole .vd file.
const out = document.querySelector('#edit-out');
editor.on('change', (event) => {
out.textContent = `${event.text().length} characters of .vd after your last edit`;
}); Build your own panels
There is no toolbar, thumbnail strip, layer list or properties panel to switch on. pages(), nodes() and read() give you what to draw; goTo(), select() and apply() are what your controls do. The three lists under the canvas are this page’s own HTML.
Pages
Layers
Properties
import { edit } from '@getv.design/embed/edit';
const text = `version 4
kind slides
title "Roadmap"
frame now name="Now" x=0 y=0 w=640 h=360 background=#ffffff
text now.title x=48 y=120 w=544 h=80 size=64 weight=800 fill=#101014
"Now"
rect now.bar x=48 y=230 w=240 h=16 fill=#3b5bdb
frame next name="Next" x=0 y=440 w=640 h=360 background=#eef1f8
text next.title x=48 y=120 w=544 h=80 size=64 weight=800 fill=#101014
"Next"
rect next.bar x=48 y=230 w=400 h=16 fill=#2f9e44
frame later name="Later" x=0 y=880 w=640 h=360 background=#101014
text later.title x=48 y=120 w=544 h=80 size=64 weight=800 fill=#ffffff
"Later"`;
// The embed draws no thumbnails, layer list or properties panel. These three are this
// page's own HTML, kept in step with the editor through the handle.
const editor = await edit(document.querySelector('#demo-panels'), text, {
fit: 'page',
fontBase: '/docs/vd/fonts/',
theme: { accent: '#3b5bdb', surface: '#eef1f8', scheme: 'light' },
});
const pagesEl = document.querySelector('#panels-pages');
const layersEl = document.querySelector('#panels-layers');
const propsEl = document.querySelector('#panels-props');
function button(label, onClick, current) {
const item = document.createElement('li');
const b = document.createElement('button');
b.type = 'button';
b.textContent = label;
if (current) b.setAttribute('aria-current', 'true');
b.addEventListener('click', onClick);
item.append(b);
return item;
}
function drawPages() {
const current = editor.currentPage();
pagesEl.replaceChildren(
...editor
.pages()
.map((page) => button(page.name ?? page.id, () => editor.goTo(page.id), page.id === current)),
);
}
function drawLayers() {
const selected = editor.selection();
layersEl.replaceChildren(
...editor
.nodes()
.filter((node) => node.depth > 0)
.map((node) => button(node.id, () => editor.select([node.id]), selected.includes(node.id))),
);
}
function drawProperties() {
const [id] = editor.selection();
const node = id && editor.read(id);
if (!node) return propsEl.replaceChildren('Select something.');
propsEl.replaceChildren(
...['x', 'y', 'w', 'h', 'fill', 'size']
.filter((key) => key in node.props)
.map((key) => {
const label = document.createElement('label');
const input = document.createElement('input');
input.value = node.props[key];
// A value goes straight back into apply(): one undo step.
input.addEventListener('change', () => editor.apply(`set ${id} ${key}=${input.value}`));
label.append(key, input);
return label;
}),
);
}
const draw = () => {
drawPages();
drawLayers();
drawProperties();
};
editor.on('select', draw);
editor.on('slide', draw);
editor.on('change', draw);
draw(); Your own agent
agent.send is your code, so the model is yours: ask() sends a prompt, and its answer, statements or a whole drafted document, lands as one undo step. ⌘K (Ctrl+K) on the canvas calls the same send. Here send answers from a table; the embed itself calls no model.
import { edit } from '@getv.design/embed/edit';
const text = `version 4
kind design
title "Headline"
frame card w=640 h=360 background=#ffffff
text card.head x=48 y=130 w=544 h=100 size=88 weight=800 fill=#101014
"Hello"`;
// send() is your code. Here it answers from a table; in your product it calls your
// model with the prompt and the document, and returns what the model wrote. A reply is
// edit statements (set, insert, delete, ...) or a whole .vd document, applied as one
// undo step.
const replies = {
'Make it red': 'set card.head fill=#d64545',
'Make it bigger': 'set card.head size=120',
'Draft a poster': `version 4
kind design
title "Poster"
frame card w=640 h=360 background=#101014
rect card.band x=0 y=0 w=100% h=24 fill=#d64545
text card.head x=48 y=110 w=544 h=100 size=88 weight=800 fill=#ffffff
"Open day"
text card.sub x=48 y=240 w=544 h=32 size=26 fill=#ffffff opacity=0.7
"Saturday, 10 am. Bring a friend."`,
};
const editor = await edit(document.querySelector('#demo-agent'), text, {
fit: 'page',
fontBase: '/docs/vd/fonts/',
theme: { scheme: 'auto' },
agent: {
name: 'Demo assistant',
async send(prompt) {
return replies[prompt] ?? 'set card.head fill=#101014';
},
},
});
// Your own composer: a form and some buttons. ask() runs the same agent as ⌘K does.
const log = document.querySelector('#agent-log');
async function ask(prompt) {
log.textContent = 'Working…';
try {
const { applied } = await editor.ask(prompt);
log.textContent = `Done: ${applied} change${applied === 1 ? '' : 's'}, one undo step.`;
} catch (error) {
log.textContent = error.message;
}
}
for (const id of ['agent-red', 'agent-big', 'agent-draft']) {
const button = document.querySelector(`#${id}`);
button.addEventListener('click', () => ask(button.textContent));
}
document.querySelector('#agent-form').addEventListener('submit', (event) => {
event.preventDefault();
const input = document.querySelector('#agent-prompt');
if (input.value.trim()) ask(input.value.trim());
input.value = '';
});
document.querySelector('#agent-undo').addEventListener('click', () => editor.undo()); Start from a template
Each opens in StackBlitz, installed and running.
- Plain HTML, from a CDN : No build step: one page and a module that imports the embed from jsDelivr.
- Vite : A bundler project that installs the package from npm and loads the editor on demand.