Skip to content

Latest commit

 

History

History
543 lines (420 loc) · 31.8 KB

getting-started.md

File metadata and controls

543 lines (420 loc) · 31.8 KB

Getting started

Vitrine is a small library of standard web components that display and edit source code, Markdown, JSON, CSV, tags, diffs, terminal sessions, file trees, HTTP exchanges, application logs, charts, OpenAPI descriptions, configuration files, hex dumps, timelines, jobs, Git histories, regular expressions, YAML, XML, TOML, JSON Web Tokens, cron schedules, X.509 certificates, data tables, status pages, calendars, pricing plans and the other blocks of a site, form fields, SQL results, test reports, distributed traces, Jupyter notebooks, math, diagrams, pivot tables, heat maps, flame graphs, treemaps, dataset profiles, dataset comparisons, install commands, download pages, contributors, support schedules, security advisories, dependency licenses, icon pickers, workflow runs, access logs, password fields, API key fields, version fields, cookie consent banners, changelogs, repository cards, indicators of compromise, CVSS scores, security headers, e-mail messages, DNS records, Nmap scans, URLs, hashes, network waterfalls, YARA rules, Sigma rules, packet captures, version ranges, color contrast, software bills of materials, Dockerfiles, Lighthouse reports, accessibility results, cookies, redirect chains, world maps, investigation timelines and loading indicators (spinners, progress bars and rings, skeletons, overlays, page bars, task steps, typing indicators, loading buttons and messages) on any web page. It needs no framework and no build step: add one script, then use the <vt-code>, <vt-markdown>, <vt-json>, <vt-csv>, <vt-tags>, <vt-diff>, <vt-terminal>, <vt-tree>, <vt-http>, <vt-log>, <vt-chart>, <vt-openapi>, <vt-env>, <vt-hex>, <vt-timeline>, <vt-job>, <vt-git>, <vt-regex>, <vt-yaml>, <vt-xml>, <vt-toml>, <vt-jwt>, <vt-cron>, <vt-cert>, <vt-table>, <vt-status>, <vt-calendar>, <vt-pricing>, <vt-faq>, <vt-gallery>, <vt-stats>, <vt-board>, <vt-field>, <vt-search>, <vt-date-picker>, <vt-menu>, <vt-upload>, <vt-testimonials>, <vt-countdown>, <vt-sql>, <vt-test-report>, <vt-trace>, <vt-notebook>, <vt-math>, <vt-diagram>, <vt-pivot>, <vt-heatmap>, <vt-flame>, <vt-treemap>, <vt-describe>, <vt-compare>, <vt-install>, <vt-download>, <vt-contributors>, <vt-lifecycle>, <vt-advisories>, <vt-licenses>, <vt-icon-picker>, <vt-workflow>, <vt-access-log>, <vt-ioc>, <vt-cvss>, <vt-headers>, <vt-email>, <vt-dns>, <vt-nmap>, <vt-url>, <vt-hash>, <vt-waterfall>, <vt-yara>, <vt-sigma>, <vt-pcap>, <vt-semver>, <vt-contrast>, <vt-sbom>, <vt-dockerfile>, <vt-lighthouse>, <vt-a11y>, <vt-cookies>, <vt-redirects>, <vt-map>, <vt-flowtime>, <vt-loading-button>, <vt-loading-message>, <vt-loading-overlay>, <vt-loading-steps>, <vt-page-progress>, <vt-progress>, <vt-progress-ring>, <vt-skeleton>, <vt-spinner> and <vt-typing> elements in your HTML.

This page covers installation, a first example for each component, and the ways to give content to an element.

Installation

The dist/ folder contains:

File Format Behavior
dist/vitrine-loader.js Classic script Loads only the elements a page uses, from dist/esm/. See Loader.
dist/vitrine.min.js Classic script Every component in one file. Defines the eighty-four elements automatically and exposes a global Vitrine object.
dist/vitrine.esm.js ES module Every component in one file. Defines nothing by itself: import defineAll() and call it.
dist/esm/vt-<name>.js ES modules One module per component, which defines its element when imported. Code shared between components is in dist/esm/chunks/. See Per-component modules.
dist/esm/vitrine.js ES module Every component, built from the same shared chunks as the per-component modules. Call defineAll().
dist/esm/api.js ES module configure, registerLocale, registerTheme… without any element, sharing the configuration of the modules.
dist/integrations/*.js ES modules Plugins for markdown-it and remark: fenced code blocks become elements.
dist/languages/*.js ES modules Syntax highlighting languages loaded on demand (see Languages).
dist/syntax-themes/*.css CSS Syntax themes loaded on demand, and index.json listing them (see Syntax themes).
dist/vendor/*.js ES modules Libraries loaded on demand: echarts.js (Apache ECharts) by <vt-chart>, yaml.js (js-yaml) by <vt-openapi>, <vt-sigma> and <vt-yaml>, temml.js (Temml) by <vt-math>, and mermaid.js (Mermaid, with one file per type of diagram in mermaid/) by <vt-diagram>.

Loader: only the elements a page uses

One small script (about 1.2 KB gzipped) finds the vt-* elements of the page, now and whenever some are added later, and imports only their modules from dist/esm/. Code shared by several elements is downloaded once:

<script src="https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/vitrine-loader.js"
        data-config='{"theme": "auto", "lang": "fr"}'></script>

<vt-sql dialect="postgresql">SELECT * FROM users;</vt-sql>

A page with <vt-code> and <vt-markdown> downloads about 90 KB instead of the 509 KB of vitrine.min.js. The Integrations page of the website gives the size for any set of elements. When a site uses most elements, vitrine.min.js is smaller in all.

Attribute Description
data-config Options of configure() as JSON, applied before any element is drawn
data-lazy An element is loaded when it comes near the screen (400 px before)
data-base URL of the dist/ folder, when the loader is not served from it

Only the names of Vitrine's elements are ever turned into URLs: <vt-anything> is ignored. It works under a strict Content Security Policy with Trusted Types. From JavaScript, window.VitrineLoader has load(tag) (resolves with the class once the element is defined), configure(options) and ready() (resolves once every element requested so far is defined):

await VitrineLoader.load('vt-diagram');
VitrineLoader.configure({ theme: 'dim' });

Do not load the loader and vitrine.min.js on the same page.

CDN (classic script)

<script src="https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/vitrine.min.js"></script>

The script defines the sixty-six elements as soon as it runs, and exposes the API as window.Vitrine (for example Vitrine.configure() or Vitrine.render()).

Each GitHub release lists SRI hashes for the release files. If you add an integrity attribute, pin an exact version (@0.14.0) instead of @0, because the hash changes with every release. Until 1.0, a new minor version may change the API: pin a version in production too.

For example:

<script
  src="https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0.14.0/dist/vitrine.min.js"
  integrity="sha384-HASH-FROM-THE-RELEASE-NOTES"
  crossorigin="anonymous"
></script>

CDN (ES module)

<script type="module">
  import { defineAll } from 'https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/vitrine.esm.js';

  defineAll();
</script>

The ES module does not create a global. Import what you need from it: defineAll, configure, getConfig, render, registerTheme, registerLocale, listThemes, getTheme, BUILT_IN_THEMES, listSyntaxThemes, EVENTS, registry, version, and the class of every element (VtCode, VtMarkdown, VtJson… VtSql, VtTestReport, VtTrace, VtNotebook, VtMath, VtDiagram). See Configuration and API.

defineAll() is safe to call several times, and it skips elements that are already defined (for example by another copy of Vitrine on the same page).

Per-component modules

To load only the elements a page uses, import their modules. Each one defines its element as soon as it is imported (unless an element with that name is already defined):

<script type="module" src="https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/esm/vt-code.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/esm/vt-tags.js"></script>

The modules import shared chunks from dist/esm/chunks/, so code used by several components (the base element, the highlighter, the editor) is downloaded once. Each module also exports its element class and the shared API: configure, getConfig, EVENTS, registerLocale, registerTheme, getTheme, listThemes, BUILT_IN_THEMES and listSyntaxThemes. Configuration, themes and locales are shared by every element loaded this way.

import { configure } from 'https://cdn.jsdelivr.net/gh/ecrou-exact/vitrine@0/dist/esm/vt-markdown.js';

configure({ syntaxTheme: 'github', syntaxThemeDark: 'github-dark' });

render, defineAll, registry and version are only exported by the full modules. For every component as ES modules with the same shared chunks, import dist/esm/vitrine.js and call defineAll(). Do not mix the per-component modules with dist/vitrine.esm.js or dist/vitrine.min.js on the same page: they are separate builds that do not share code or configuration.

Download size (minified and gzipped), each module counted with every chunk it loads:

File Size (gzip)
dist/vitrine.min.js 646.1 KB
dist/vitrine.esm.js 645.9 KB
dist/vitrine-loader.js 1.3 KB
dist/esm/vt-code.js 60.0 KB
dist/esm/vt-markdown.js 79.4 KB
dist/esm/vt-json.js 64.1 KB
dist/esm/vt-csv.js 61.0 KB
dist/esm/vt-tags.js 30.7 KB
dist/esm/vt-diff.js 66.6 KB
dist/esm/vt-terminal.js 63.2 KB
dist/esm/vt-tree.js 62.3 KB
dist/esm/vt-http.js 71.2 KB
dist/esm/vt-log.js 64.7 KB
dist/esm/vt-env.js 61.2 KB
dist/esm/vt-chart.js 61.7 KB
dist/esm/vt-openapi.js 64.4 KB
dist/esm/vt-timeline.js 60.5 KB
dist/esm/vt-git.js 64.1 KB
dist/esm/vt-job.js 63.7 KB
dist/esm/vt-hex.js 28.6 KB
dist/esm/vt-regex.js 64.2 KB
dist/esm/vt-toml.js 67.9 KB
dist/esm/vt-cron.js 66.0 KB
dist/esm/vt-jwt.js 65.2 KB
dist/esm/vt-xml.js 65.9 KB
dist/esm/vt-cert.js 67.0 KB
dist/esm/vt-yaml.js 65.7 KB
dist/esm/vt-table.js 57.1 KB
dist/esm/vt-status.js 62.5 KB
dist/esm/vt-calendar.js 66.9 KB
dist/esm/vt-pricing.js 61.3 KB
dist/esm/vt-faq.js 58.8 KB
dist/esm/vt-gallery.js 59.3 KB
dist/esm/vt-stats.js 59.7 KB
dist/esm/vt-testimonials.js 59.5 KB
dist/esm/vt-countdown.js 59.4 KB
dist/esm/vt-field.js 64.0 KB
dist/esm/vt-board.js 68.1 KB
dist/esm/vt-search.js 61.9 KB
dist/esm/vt-upload.js 63.4 KB
dist/esm/vt-menu.js 61.2 KB
dist/esm/vt-date-picker.js 65.2 KB
dist/esm/vt-install.js 28.8 KB
dist/esm/vt-download.js 63.2 KB
dist/esm/vt-contributors.js 62.6 KB
dist/esm/vt-lifecycle.js 62.3 KB
dist/esm/vt-advisories.js 63.1 KB
dist/esm/vt-licenses.js 63.4 KB
dist/esm/vt-icon-picker.js 30.9 KB
dist/esm/vt-workflow.js 67.1 KB
dist/esm/vt-access-log.js 65.7 KB
dist/esm/vt-password.js 39.0 KB
dist/esm/vt-secret.js 35.4 KB
dist/esm/vt-version.js 35.1 KB
dist/esm/vt-consent.js 30.5 KB
dist/esm/vt-changelog.js 65.1 KB
dist/esm/vt-repo.js 62.2 KB
dist/esm/vt-ioc.js 60.7 KB
dist/esm/vt-cvss.js 62.4 KB
dist/esm/vt-headers.js 62.1 KB
dist/esm/vt-email.js 64.2 KB
dist/esm/vt-dns.js 63.5 KB
dist/esm/vt-nmap.js 62.4 KB
dist/esm/vt-url.js 66.8 KB
dist/esm/vt-hash.js 61.0 KB
dist/esm/vt-waterfall.js 65.7 KB
dist/esm/vt-yara.js 65.3 KB
dist/esm/vt-sigma.js 65.0 KB
dist/esm/vt-pcap.js 40.6 KB
dist/esm/vt-semver.js 61.7 KB
dist/esm/vt-contrast.js 62.2 KB
dist/esm/vt-sbom.js 64.6 KB
dist/esm/vt-dockerfile.js 64.1 KB
dist/esm/vt-lighthouse.js 62.3 KB
dist/esm/vt-a11y.js 60.7 KB
dist/esm/vt-nmap.js 62.9 KB
dist/esm/vt-cookies.js 62.5 KB
dist/esm/vt-redirects.js 61.4 KB
dist/esm/vt-loading-button.js 19.9 KB
dist/esm/vt-loading-message.js 16.5 KB
dist/esm/vt-loading-overlay.js 17.0 KB
dist/esm/vt-loading-steps.js 21.9 KB
dist/esm/vt-page-progress.js 15.7 KB
dist/esm/vt-progress.js 16.6 KB
dist/esm/vt-progress-ring.js 16.2 KB
dist/esm/vt-skeleton.js 16.2 KB
dist/esm/vt-spinner.js 15.7 KB
dist/esm/vt-typing.js 15.1 KB
dist/esm/vt-compare.js 30.5 KB
dist/esm/vt-describe.js 62.3 KB
dist/esm/vt-treemap.js 62.3 KB
dist/esm/vt-flame.js 60.6 KB
dist/esm/vt-heatmap.js 60.4 KB
dist/esm/vt-pivot.js 61.4 KB
dist/esm/vt-sql.js 68.0 KB
dist/esm/vt-test-report.js 67.7 KB
dist/esm/vt-trace.js 63.4 KB
dist/esm/vt-notebook.js 83.7 KB
dist/esm/vt-math.js 61.0 KB
dist/esm/vt-diagram.js 59.6 KB

These are the sizes of the current build, measured by npm run size, which fails when a file goes over its budget (660 KB for the full bundles; 2 KB for the loader; 62, 81, 66, 63, 34, 68, 64, 64, 69, 66, 62, 64, 66, 64, 66, 66, 58, 66, 69, 67, 66, 67, 68, 67, 74, 64, 69, 63, 61, 62, 62, 62, 62, 66, 71, 64, 66, 64, 68, 31, 66, 65, 65, 66, 66, 33, 70, 68, 42, 38, 38, 36, 66, 64, 33, 65, 65, 63, 63, 64, 70, 70, 66, 86, 63 and 62 KB for the modules above). Language files, syntax themes and the files of dist/vendor/ are loaded on demand and are not included: dist/vendor/echarts.js (about 225 KB gzipped) is loaded only by <vt-chart>, the first time a page shows a chart, and dist/vendor/yaml.js (about 15 KB gzipped) only by <vt-openapi> and <vt-sigma>, the first time a page shows YAML. Loading two modules downloads their shared chunks only once, so the total is less than the sum.

Git submodule

The main branch does not contain build output. The dist/ folder exists only in the release commits that the vX.Y.Z tags point to, so check out a release tag after adding the submodule:

git submodule add https://github.com/ecrou-exact/vitrine.git vendor/vitrine
git -C vendor/vitrine checkout vX.Y.Z

Then load the script from your own server:

<script src="/vendor/vitrine/dist/vitrine.min.js"></script>

Self-hosting

Copy the dist/ folder of a release (from the release tag) to your server. Keep its structure: the languages/, syntax-themes/ and vendor/ folders next to the scripts, and esm/ with its chunks/ folder:

your-site/
  assets/vitrine/
    vitrine.min.js
    vitrine.esm.js
    esm/
      vt-code.js
      vt-tags.js
      ...
      chunks/
    languages/
      rust.js
      go.js
      ...
    syntax-themes/
      github.css
      index.json
      ...
    vendor/
      echarts.js
      yaml.js
      temml.js
      mermaid.js
      mermaid/

The .map files are optional source maps.

Syntax highlighting languages

Ten languages are bundled in the main script and work immediately: bash, diff, javascript, json, markdown, plaintext, python, shell, xml (also used for HTML) and yaml.

Every other highlight.js language (183 more) is a separate file in dist/languages/, loaded the first time an element needs it. Vitrine finds that folder automatically:

  • the classic script looks for languages/ next to its own URL (document.currentScript.src);
  • the ES module looks for languages/ next to its own URL (import.meta.url);
  • the modules in dist/esm/ look for languages/ in the parent dist/ folder.

Syntax themes are found the same way, in syntax-themes/ (setting: syntaxThemesUrl), and so are the files of dist/vendor/, in vendor/ (setting: vendorUrl).

If the language files live somewhere else (for example when you bundle Vitrine with your own build tool), set the base URL explicitly:

Vitrine.configure({ languagesUrl: 'https://static.example.com/vitrine/languages/' });

If a language file cannot be loaded, the code is shown without highlighting and a warning is logged in the console. Only names that exist in the built-in language index are ever turned into a URL; an unknown language value never causes a request.

First examples

Code

<vt-code language="python" line-numbers>
  def hello(name):
      return f"Hello {name}"
</vt-code>

Markdown

<vt-markdown>
  <script type="text/markdown">
    # Release notes

    - Faster search
    - **New** dim theme
  </script>
</vt-markdown>

JSON

<vt-json variant="full" label="user.json">
  <script type="application/json">
    { "name": "Ada", "languages": ["en", "fr"], "admin": true }
  </script>
</vt-json>

CSV

<vt-csv variant="full" label="scores.csv">
  <template>
    name,score
    Ada,98
    Alan,95
  </template>
</vt-csv>

Tags

<form>
  <vt-tags name="topics" mode="edit" prefix="#">
    <template>{ "value": ["design"], "options": ["design", "research", "a11y"] }</template>
  </vt-tags>
</form>

Diff

<vt-diff variant="full" language="js">
  <template data-original>const a = 1;</template>
  <template data-modified>const a = 2;</template>
</vt-diff>

Terminal

<vt-terminal variant="full" label="Install">
  <template>
    $ npm install vitrine
    added 1 package in 2s
  </template>
</vt-terminal>

Tree

<vt-tree variant="full" label="my-app">
  <template>
    src/
      app.ts
    package.json  # scripts and dependencies
  </template>
</vt-tree>

HTTP

<vt-http variant="full" label="Get a task">
  <template>
    GET https://api.example.com/v1/tasks/981
    Accept: application/json
  </template>
</vt-http>

Log

<vt-log variant="full" label="api.log">
  <template>
    2026-10-07 18:00:01 [INFO] server started on :8080
    2026-10-07 18:00:04 [WARN] slow query (1.2 s)
    2026-10-07 18:00:09 [ERROR] database unreachable
  </template>
</vt-log>

Chart

<vt-chart type="bar" variant="full" label="Visitors">
  <template>
    month,desktop,mobile
    Jan,186,80
    Feb,305,200
    Mar,237,120
  </template>
</vt-chart>

OpenAPI

<vt-openapi variant="full" src="/openapi.yaml"></vt-openapi>

Editing

Any component can become an editor:

<vt-markdown mode="edit" variant="full">
  <script type="text/markdown"># Draft</script>
</vt-markdown>

See Editing.

Simple and full variants

Every element has two presets, selected with the variant attribute:

  • simple (default): only the content, with no header bar.
  • full: a header with a title, a badge and action buttons (copy, search, download, full screen…), plus component-specific extras such as tabs or a table of contents.

A variant is only a shortcut for a set of features. Any individual feature attribute overrides the preset, in either variant:

<!-- Full variant, without the search button -->
<vt-code variant="full" search="false" language="js">console.log('hi');</vt-code>

<!-- Simple variant, plus a copy button -->
<vt-code copy language="js">console.log('hi');</vt-code>

The features of each preset are listed in Presets are shortcuts and in each component reference.

Content sources

An element reads its content from the first available source, in this order:

  1. The content property (or the data property of <vt-json> and <vt-tree>, or the exchange property of <vt-http>), set from JavaScript. <vt-diff> also has original and modified, <vt-tags> has value and options, and <vt-log> adds text at the end with write(). The data property of <vt-chart> and the spec property of <vt-openapi> are read-only: set content instead.
  2. The src attribute: a URL fetched by Vitrine.
  3. A child <template>, or a child <script> with a non-executable data type: text/plain, text/markdown, text/x-markdown, application/json or text/json (whichever comes first among the children).
  4. The text of the element itself.

Setting the content property overrides src and inline content. Setting it back to null (or undefined) returns to src or inline content.

Warning: inline content is not safe for untrusted data. Everything written inside the element (sources 3 and 4) is parsed by the browser as part of your page HTML before Vitrine runs. Vitrine cannot sanitize what the browser has already parsed. Never write user-provided or third-party data inside the element. Pass untrusted data through the content property (or data for <vt-json> and <vt-tree>, exchange for <vt-http>), or load it with src.

For the same reason, a </script> sequence inside a <script type="text/plain"> block closes the block early, and whatever follows is parsed as page HTML.

The content property (recommended for dynamic data)

<vt-code id="snippet" language="js"></vt-code>
const element = document.getElementById('snippet');
element.content = userProvidedCode; // displayed as text, never parsed as HTML

For <vt-json>, you can also pass a JavaScript value:

document.querySelector('vt-json').data = { id: 1, tags: ['a', 'b'] };

Reading content returns the text currently displayed (an empty string while loading or after an error).

The src attribute

<vt-markdown src="/docs/intro.md"></vt-markdown>
<vt-code src="/examples/server.py" language="python"></vt-code>

By default, only same-origin http: and https: URLs are allowed. Add allow-remote to load from another origin (the server must allow it with CORS). Requests are limited in size and time. See Common attributes and Security.

Changing src starts a new request and cancels the previous one; only the latest response is displayed.

A child <script> block

Use a data <script> for code that contains <, & or HTML tags. The browser does not parse markup inside it, and Vitrine reads its text as is:

<vt-code language="html">
  <script type="text/plain">
    <ul>
      <li>a < b && c</li>
    </ul>
  </script>
</vt-code>

The type must be one of the data types listed above. A <script> without a type (or with an executable type) is run by the browser like any other script before Vitrine sees it.

A child <template>

A template is read in one of two ways:

  • If it contains markup (at least one element), its HTML source is used: <template><b>x</b></template> displays <b>x</b>. The browser has already parsed this markup, so the text you get is the browser's serialization of it (attribute quoting and entities may be normalized).
  • If it contains only text, the text is used: <template>if (a &lt; b)</template> displays if (a < b).
<vt-code language="html">
  <template>
    <button class="primary" type="button">Save</button>
  </template>
</vt-code>

Element text

Plain text written directly inside the element is used last. HTML entities are decoded, and any child elements contribute only their text:

<vt-json>{"compact": [1, 2, 3], "ok": true}</vt-json>

Indentation and line endings

Inline content (template, data script, element text) is dedented: the common leading indentation is removed, and blank lines at the start and end are trimmed. This lets you indent content naturally in your HTML.

Content from every source has its line endings normalized (\r\n and \r become \n).

When no content property and no src are set, Vitrine watches the element's children: editing the inline content re-renders the element.

States

While content loads from src, the element shows a loading placeholder. If content cannot be loaded or displayed, it shows an inline error message and dispatches a vt-error event. Empty content shows "Nothing to display" (<vt-tags> shows "No tags" in view mode). Content longer than the configured maxSize (2 MiB of characters by default) is refused with an error.

Next steps