Function Signature Description parseCapture(json: string, limits?: Partial<WebSketchLimits>) => WebSketchCaptureParse and validate a JSON capture string. Throws WebSketchException on error. validateCapture(data: unknown, limits?: Partial<WebSketchLimits>) => WebSketchValidationIssue[]Validate a capture object against the schema. Returns an array of issues (empty = valid). Does not throw. isSupportedSchemaVersion(version: unknown) => version is stringCheck whether a schema version string is supported by this library.
Function Signature Description renderAscii(capture: WebSketchCapture, options?: AsciiRenderOptions) => stringRender a capture as an ASCII wireframe (default 80x24 grid with box-drawing borders). renderNodeAscii(node: UINode, options?: AsciiRenderOptions) => stringRender a single node subtree to ASCII without capture metadata. renderForLLM(capture: WebSketchCapture) => stringLLM-optimized view with URL, viewport header, ASCII body, and legend footer. renderStructure(capture: WebSketchCapture, width?: number, height?: number) => stringCompact structure-only view (no text, no semantics, ASCII-style borders). generateLegend() => stringGenerate a compact legend mapping role abbreviations to full names. renderJSON(capture: WebSketchCapture, options?: RenderJSONOptions) => stringMinimal JSON tree for LLM tool-calling. Strips internal fields, keeps role/bbox/text/interactive. Available from main entry and /codegen. renderMarkdown(capture: WebSketchCapture, options?: RenderMarkdownOptions) => stringReadable Markdown mapping roles to idiomatic constructs (headings, tables, blockquotes). Available from /codegen.
Option Type Default Description widthnumber80Grid width in characters heightnumber24Grid height in characters showRolesUIRole[]Important roles Which roles to render showSemanticsbooleantrueShow semantic labels showTextLenbooleantrueShow text length indicators borderStyle"box" | "ascii" | "none""box"Border drawing style showLegendbooleanfalseAppend role abbreviation legend
Function Signature Description diff(a: WebSketchCapture, b: WebSketchCapture, options?: DiffOptions) => DiffResultStructural diff between two captures. Matches by geometry + role + semantics. formatDiff(result: DiffResult) => stringHuman-readable diff report with change counts and top changes. formatDiffJson(result: DiffResult) => stringMachine-readable JSON diff report. formatDiffForLLM(result: DiffResult) => stringConcise one-line change summary for LLM context windows. Available from @mcptoolshop/websketch-ir/codegen. prepareDiff(capture: WebSketchCapture) => PreparedCapturePre-flatten and pre-fingerprint a capture for repeated diffing against many variants.
Returned by prepareDiff. Contains the original capture, a pre-computed flat node list, and its fingerprint. Pass to diff() instead of a raw capture to skip redundant work.
Option Type Default Description includeTextbooleantrueInclude text hash in matching includeNamebooleantrueInclude name hash in matching matchThresholdnumber0.5Minimum similarity to consider a match topChangesLimitnumber10Max changes in topChanges moveThresholdnumber0.01Bbox movement below this is noise resizeThresholdnumber0.01Bbox resize below this is noise
Function Signature Description fingerprintCapture(capture: WebSketchCapture) => stringFull structural fingerprint — roles + geometry + text + viewport aspect. fingerprintLayout(capture: WebSketchCapture) => stringLayout-only fingerprint that ignores text content changes. hashNodeShallow(node: UINode, options?: HashOptions) => stringHash a single node without children. hashNodeDeep(node: UINode, options?: HashOptions) => stringHash a node and its entire subtree. generateNodeId(node: UINode, parentPath?: string) => stringGenerate a content-addressed node ID. assignNodeIds(node: UINode, parentPath?: string) => voidAssign IDs to all nodes in a tree (mutates in place). nodeSimilarity(a: UINode, b: UINode) => numberCompute similarity score (0-1) between two nodes. bboxSimilarity(a: BBox01, b: BBox01) => numberCompute IoU-like overlap between two bounding boxes. quantizeBbox(bbox: BBox01, step?: number) => BBox01Quantize bbox values to reduce subpixel noise. bboxToString(bbox: BBox01, precision?: number) => stringSerialize bbox for hashing.
Function Signature Description normalizeText(text: string) => stringTrim, collapse whitespace, lowercase, strip invisible characters. sha256(text: string) => Promise<string>Async SHA-256 hash (browser SubtleCrypto or Node crypto). hashSync(text: string) => stringSynchronous FNV-1a 64-bit hash for structural fingerprinting. classifyText(normalizedText: string) => TextKindClassify text as none, short, sentence, or paragraph. isMixedContent(rawText: string) => booleanCheck if text contains multiple paragraphs. createTextSignal(rawText: string) => Promise<TextSignal>Generate a TextSignal from raw text (async). createTextSignalSync(rawText: string) => TextSignalGenerate a TextSignal from raw text (sync). isMeaningfulText(text: string) => booleanCheck if text has at least one alphanumeric character.
Function Signature Description formatWebSketchError(err: WebSketchError) => stringMulti-line, human-readable error string with code, message, details, and hint. isWebSketchException(err: unknown) => err is WebSketchExceptionType guard for WebSketchException.
import { emitHTML, emitNodeHTML, roleToElement } from ' @mcptoolshop/websketch-ir/codegen ' ;
Function Signature Description emitHTML(capture: WebSketchCapture, options?: EmitHTMLOptions) => stringGenerate semantic HTML from a capture with data-wsk-* attributes. emitNodeHTML(node: UINode, options?: EmitHTMLOptions) => stringGenerate HTML for a single node and its children. roleToElement(role: UIRole) => stringGet the HTML element name mapped to a UIRole.
Option Type Default Description indentstring" "Indentation string (2 spaces) includeBboxbooleantrueInclude data-wsk-bbox geometry attributes includeHandlersbooleantrueEmit data-wsk-on-* for event handlers includeBindingsbooleantrueEmit data-wsk-bind-* for reactive bindings includeStatebooleantrueEmit data-wsk-state for state signals includeStylebooleantrueEmit data-wsk-style for visual intent includePatternbooleantrueEmit data-wsk-pattern for recognized patterns includeSemanticsbooleantrueEmit data-wsk-semantic for semantic hints includeRoleClassbooleantrueInclude CSS class with role name (e.g., wsk-button) fullDocumentbooleanfalseWrap output in full HTML document with head/body
The main entry point re-exports everything you need for typical usage:
// Main entry point — parsing, rendering, diffing, fingerprinting, errors
import { parseCapture, renderAscii, diff, WebSketchException } from ' @mcptoolshop/websketch-ir ' ;
Optional sub-path imports are available for tree-shaking or when you only need a specific module:
// Types only — no runtime code pulled in
import type { UINode, UIRole, PatternSignal, HandlerSignal } from ' @mcptoolshop/websketch-ir/grammar ' ;
// Just the codegen module
import { emitHTML, emitNodeHTML, roleToElement } from ' @mcptoolshop/websketch-ir/codegen ' ;
// Error types only (also re-exported from the main entry point)
import { WebSketchException, isWebSketchException } from ' @mcptoolshop/websketch-ir/errors ' ;
Constant Value Description CURRENT_SCHEMA_VERSION"0.1"Schema version produced by this library SUPPORTED_SCHEMA_VERSIONSSet(["0.1"])All versions this library can read DEFAULT_LIMITS{ maxNodes: 10000, maxDepth: 50, maxStringLength: 10000 }Default resource limits for validation MAX_DEPTH8Maximum tree depth MAX_CHILDREN200Maximum children per node BBOX_QUANT_STEP0.001Quantization step for bbox hashing COLLAPSE_TOLERANCE0.002Collapse tolerance for near-equal bboxes VALID_EVENT_TYPESReadonlySet<string>All valid EventType values (click, hover, focus, blur, submit, change, input, keydown, scroll, drag, custom) VALID_STATE_ACCESS_KINDSReadonlySet<string>All valid StateAccessKind values (read, write, readwrite, condition) VALID_STATE_SCOPESReadonlySet<string>All valid state scope values (local, global, url) VALID_STYLE_INTENT_TOKENSReadonlySet<string>All valid StyleIntentToken values VALID_DENSITIESReadonlySet<string>Valid density values (compact, normal, spacious) VALID_SIZESReadonlySet<string>Valid size values (xs, sm, md, lg, xl) VALID_PATTERN_KINDSReadonlySet<string>All valid PatternKind values