/** * @file The Markdown VISUAL COMPONENT — part two of the package. * * Everything below this line is presentation glue; the engine * (`@jarenjs/md`) neither knows nor needs any of it. The component * layer packages the engine for hosts that render: * * - `createMdComponent()` — a batteries-included bundle: a memoized * `view()` projection for `@jarenjs/app` viewModels (reference- * stable, so unchanged sources patch in O(1)), `effects` entries * for the app effect registry (`md-load`, `md-parse`), and a * `hydrate()` pass for app-managed DOM; * - `styles/md.css` — the component's stylesheet (`.md` content * rhythm, `tok-*` token colors, mermaid placeholder), light/dark. * * The boundary is deliberate: the engine stays a headless data * toolchain (text ↔ AST ↔ vnode values), the component owns defaults, * memoization policy, CSS and app-registry shapes. See * ARCHITECTURE.md §"Engine and component". */ export type MdDocument = import('../ast.js').MdDocument; export type CompiledMd = import('../compiler.js').CompiledMd; export type MdCompileOptions = import('../compiler.js').MdCompileOptions; export type MdComponentOptions = MdCompileOptions & { base?: string | URL; fetch?: typeof globalThis.fetch; cache?: any; memoLimit?: number; policyLimit?: number; onHydrateError?: (err: any) => void; }; export type MdRenderPolicy = { /** * mint an `id` on every heading */ headingIds?: boolean; /** * prepended to every emitted heading id * and to the anchor href beside it (`''` opts out) */ slugPrefix?: string; /** * emit the copy-a-link anchor */ headingAnchors?: boolean; /** * the footnote section's heading */ footnotesLabel?: string; /** * what to do with raw HTML */ html?: 'skip' | 'text'; /** * emit patcher keys on block children */ keyed?: boolean; }; export type MdComponent = { /** * the compiled-in plugin set */ plugins: any[]; /** * memoized vnode projection, per source AND policy */ view: (sourceOrDoc: any, policy?: MdRenderPolicy) => any; /** * memoized compile */ compile: (source: string) => CompiledMd; /** * `md-load` and `md-parse` for `createApp({ effects })` */ effects: Record any>; /** * run plugin hydrate hooks * over already-mounted DOM (no-op without hydratable plugins) */ hydrate: (container: any) => void; }; /** * @typedef {import('../ast.js').MdDocument} MdDocument * @typedef {import('../compiler.js').CompiledMd} CompiledMd * @typedef {import('../compiler.js').MdCompileOptions} MdCompileOptions */ /** * @typedef {MdCompileOptions & { * base?: string | URL, * fetch?: typeof globalThis.fetch, * cache?: any, * memoLimit?: number, * policyLimit?: number, * onHydrateError?: (err: any) => void, * }} MdComponentOptions */ /** * The rendering policy a single `view()` call may name, for a host that * renders documents of different PROVENANCE through one component. Only * the options that shape the emitted vnode belong here — the parse is * provenance-independent, and `plugins`/`sanitizeUrl` are the * construction-time decisions a per-call override would quietly undo. * * The live case is heading ids: repo-authored Markdown is trusted with * the ids it mints, and text from anywhere else must not mint bare ids * into a page that owns ids of its own — so it renders with a * `slugPrefix`. Footnote ids already default to `user-content-` * (MD-FORMAT §4.6) and are unaffected. * * @typedef {object} MdRenderPolicy * @property {boolean} [headingIds] mint an `id` on every heading * @property {string} [slugPrefix] prepended to every emitted heading id * and to the anchor href beside it (`''` opts out) * @property {boolean} [headingAnchors] emit the copy-a-link anchor * @property {string} [footnotesLabel] the footnote section's heading * @property {'skip'|'text'} [html] what to do with raw HTML * @property {boolean} [keyed] emit patcher keys on block children */ /** * The component bundle. * @typedef {object} MdComponent * @property {any[]} plugins the compiled-in plugin set * @property {(sourceOrDoc: any, policy?: MdRenderPolicy) => any} view * memoized vnode projection, per source AND policy * @property {(source: string) => CompiledMd} compile memoized compile * @property {Record any>} effects * `md-load` and `md-parse` for `createApp({ effects })` * @property {(container: any) => void} hydrate run plugin hydrate hooks * over already-mounted DOM (no-op without hydratable plugins) */ /** * Create the Markdown component: one object that plugs the engine * into an `@jarenjs/app` document (or any view-owning host). * * @example * const md = createMdComponent(); * createApp(appDoc, { * effects: { ...md.effects }, * viewModel: (state) => ({ ...state, article: md.view(state.articleSource) }), * }); * // an action loads a document: * // { "effects": [{ "run": "md-load", "with": { "url": "$.url", "done": "article/loaded" } }] } * * @param {MdComponentOptions} [options] * @returns {MdComponent} */ export declare function createMdComponent(options?: MdComponentOptions): MdComponent; /** * The component's default plugin set: syntax highlighting on. A single * shared array so `buildPluginTables` (and every memo hanging off it) * compiles exactly once per process. */ export declare const DEFAULT_PLUGINS: import("../plugins/index.js").MdPlugin[];