Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/aria/folk/injected/ariaSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const defaultBox: aria.AriaBox = { visible: true, inline: false }
// capture – DOM -> AriaNode tree
// ---------------------------------------------------------------------------

/**
* Captures the ARIA tree for a DOM subtree.
*
* The returned tree is the low-level structure used by ARIA snapshot matching.
*/
export function generateAriaTree(rootElement: Element): aria.AriaNode {
const visited = new Set<Node>()

Expand Down Expand Up @@ -310,6 +315,9 @@ export function renderNodeLines(
}
}

/**
* Renders a captured ARIA tree to the textual snapshot format.
*/
export function renderAriaTree(root: aria.AriaNode): string {
const lines: string[] = []
const nodesToRender = root.role === 'fragment' ? root.children : [root]
Expand Down
9 changes: 8 additions & 1 deletion src/aria/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import {
} from './folk/isomorphic/ariaSnapshot'
import * as yaml from './yaml'

export type { AriaNode, AriaTemplateNode } from './folk/isomorphic/ariaSnapshot'
export type {
AriaNode,
AriaTemplateNode,
AriaRole,
} from './folk/isomorphic/ariaSnapshot'

export { generateAriaTree, renderAriaTree } from './folk/injected/ariaSnapshot'

export { renderAriaTemplate } from './template'

export { matchAriaTree } from './match'

/**
* Parses textual ARIA snapshot syntax into a template tree.
*/
export function parseAriaTemplate(text: string): AriaTemplateNode {
return parseAriaSnapshotUnsafe(yaml, text)
}
6 changes: 6 additions & 0 deletions src/aria/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export interface MatchAriaResult {
resolved: string
}

/**
* Matches a captured ARIA tree against a parsed template.
*
* Returns whether the match passed and the resolved output used for diffing
* and snapshot updates.
*/
export function matchAriaTree(
root: AriaNode,
template: AriaTemplateNode
Expand Down
3 changes: 3 additions & 0 deletions src/aria/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export function formatNameValue(name: AriaRegex | string): string {
return `/${name.pattern}/`
}

/**
* Renders an ARIA template back to its textual snapshot representation.
*/
export function renderAriaTemplate(template: AriaTemplateNode): string {
const lines: string[] = []
if (template.kind === 'text') {
Expand Down
Loading