Everyinit npm package
The everyinit npm package exposes framework-neutral helpers and a Vite
integration for consuming the data generated by Evin's
evin/docs@v1 action. It does not
include a ready-made page renderer or documentation theme. Your frontend maps
the page AST to its own components and controls routing presentation and
styling.
Install and choose an entry point
npm install everyinit
The package requires Node.js 20 or later. everyinit/vite has an optional Vite
peer dependency at version 6 or later. The Evin CLI must also be available to
run the documentation build command configured for the Vite plugin.
| Import | Purpose |
|---|---|
everyinit | Route helpers, runtime construction, binary search decoding, and search. |
everyinit/vite | Vite plugin that loads generated docs data and diagram SVGs. |
virtual:evin/docs | Generated manifest, routes, pages, assets, and diagrams. |
virtual:evin/search | Lazy search-index loading and search. |
everyinit/highlight | Flow, ESH, and JSON code tokenization. |
For a guided setup from source pages through a Vite site, see Build a documentation site.
Vite integration
Register the plugin in vite.config.js:
import { defineConfig } from "vite";
import evinDocs from "everyinit/vite";
export default defineConfig({
plugins: [
evinDocs({
command: ["evin", "run", "docs:build"],
cwd: "../..",
watch: ["../../docs"],
}),
],
});
The plugin runs the command when Vite starts and before a production build.
During development, edits under the watched directories rerun the command and
invalidate virtual:evin/docs.
| Option | Type | Default | Meaning |
|---|---|---|---|
command | string[] | ['evin', 'run', 'docs:build'] | Executable and arguments used to generate docs data. An empty array skips the command. |
cwd | string | Vite project root | Working directory for the command, manifest, and watched paths. |
manifest | string | dist/docs-data/manifest.json | Manifest path relative to cwd. |
watch | string[] | ['docs'] | Source paths relative to cwd that trigger regeneration. |
The command must produce the manifest, page files, and asset map before the plugin can load. It rejects an unsupported manifest schema, missing page data, or paths that escape the generated output directory.
Generated docs module
virtual:evin/docs exports named values and the same runtime as its default
export:
import docs, {
manifest,
routes,
pages,
assets,
diagrams,
resolveRoute,
counterpart,
routeForPage,
} from "virtual:evin/docs";
const route = resolveRoute(window.location.pathname);
if (route) {
const page = route.page;
const pageAssets = assets[page.id] ?? {};
const pageDiagrams = diagrams[page.id] ?? {};
// Render page.page.ast with your framework's components.
}
resolveRoute normalizes leading and trailing slashes and ignores query and
fragment text. It returns a route with its page data, or null when no route
matches. Use generated route records rather than rebuilding routes from source
filenames.
Each route contains path, page_id, page_file, version, locale,
content_locale, is_fallback, navigation_order, and counterparts. When a
localized page falls back to another locale, content_locale identifies the
language of the actual page content. counterparts maps a version/locale
pair to an equivalent page ID, or null when no equivalent exists.
The manifest is available as docs.manifest:
| Field | Meaning |
|---|---|
schema, format_version | Manifest contract identifier; the current schema is evin.docs.manifest/v1. |
latest_version, default_locale | Version and locale used for unqualified routes. |
versions, locales | Configured version and locale inventories. Each version has an id and latest flag. |
routes | Route records described above. |
assets | Relative path to the generated asset map file. |
search_indexes | Search artifact descriptors with version, locale, path, byte length, and SHA-256. |
diagnostics | Build findings with severity, code, message, version, locale, and route. |
pages is keyed by stable page ID. Each page includes metadata, format, source
path, route, table of contents, reference data, and a serialized document AST.
assets[pageId] maps source media paths to imported asset URLs.
diagrams[pageId][diagramId] contains imported SVG source strings. Embed a
diagram as inline SVG to retain its authored ID and let site CSS style it; an
img element does not expose the SVG's internal nodes to page styles.
Each EvinDocsPage has schema, id, version, locale, content_locale,
source_path, route, is_fallback, and navigation_order fields. Its
nested page record contains the source slug and format, metadata, the
formal reference when present, a toc array of heading level/text/anchor
records, and the serialized ast. The AST is the content contract; render its
nodes with your framework rather than treating page data as prebuilt HTML.
Use counterpart(route, version, locale) to find the equivalent page when it
exists, then routeForPage(page) to find its route. createRouteTable(docs, render) maps the runtime's route list to { path, element, handle } records
for router adapters.
Framework-neutral runtime
When you load the generated manifest and page JSON files yourself, construct
the runtime with createDocsRuntime:
import { createDocsRuntime, normalizeDocsPath, createRouteTable } from "everyinit";
const docs = createDocsRuntime(manifest, pages, assets);
const path = normalizeDocsPath("guide/?mode=print"); // "/guide"
const route = docs.resolveRoute(path);
const routeTable = createRouteTable(docs, (entry) => renderPage(entry.page));
createDocsRuntime verifies the manifest schema and that each route refers to
the matching page ID. It throws TypeError when these inputs are invalid.
normalizeDocsPath accepts a path string, strips query and fragment text,
normalizes slash direction, and ensures a leading slash.
Search
In a Vite app, load the selected version and locale's binary search artifact only when search is opened:
import { loadSearchIndex, searchDocs } from "virtual:evin/search";
const index = await loadSearchIndex(route.version, route.locale);
const results = searchDocs(index, "workspace configuration", {
limit: 8,
allowFuzzy: true,
});
loadSearchIndex(version, locale) caches the decoded result and checks its
size and SHA-256 digest when Web Crypto is available. searchDocs(index, query, options) requires all query terms to match. It supports term prefixes and,
when no prefix matches, optional one-edit fuzzy matching for longer terms.
The module's default export contains these same two functions.
limit defaults to 10 and is clamped to at least 1. Results include the page
ID, route with an optional heading anchor, title, section, snippet, reference
ID, result kind, and score.
Each result is an EvinDocsSearchRecord with pageId, route, pageTitle,
title, sectionTitle, anchor, referenceId, snippet, kind, and
score. A page result has an empty anchor; a section result can link to its
heading. EvinDocsSearchIndex.records contains the searchable records, while
terms and termList hold the decoded lookup tables.
Without Vite, import decodeSearchIndex and searchDocs from everyinit and
fetch or load the binary file with your own runtime. decodeSearchIndex accepts
an ArrayBuffer or Uint8Array and returns the index expected by searchDocs.
Code highlighting
everyinit/highlight tokenizes Flow, ESH, and JSON with the same TextMate
grammars as the VS Code extension:
import { createCodeHighlighter } from "everyinit/highlight";
const highlighter = await createCodeHighlighter();
const tokens = highlighter.tokenizeCode('workspace:\n name: "site"\n', "flow");
highlighter.dispose();
The canonical language IDs are flow, esh, and json. Flow and ESH also
accept evin-flow, evin-esh, and leading-dot file extensions such as
.flow. resolveCodeLanguage(language) returns the canonical ID or null;
supportedCodeLanguages lists the canonical IDs.
Each token contains its source text, most specific scope (or null), and
full TextMate scopes stack. Unknown language IDs return the original source
as one unscoped token. Initialize one highlighter per app and reuse it; call
dispose() when that app no longer needs it. The convenience tokenizeCode
function is asynchronous and shares a lazily initialized highlighter.
Exported types
The root entry exports TypeScript interfaces for EvinDocsManifest,
EvinDocsRoute, EvinDocsRouteData, EvinDocsPage, EvinDocsRuntime,
EvinDocsSearchArtifact, EvinDocsSearchIndex, and EvinDocsSearchRecord.
The highlighter subpath exports EvinCodeLanguage, EvinCodeToken, and
EvinCodeHighlighter types.
The Vite subpath exports EvinDocsViteOptions. The virtual module types are
included with everyinit/vite; add /// <reference types="everyinit/vite" />
to a TypeScript app's environment declaration if its editor does not discover
the virtual modules automatically.