/** * Copyright (c) 2023-2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Adam Midlik */ import { Kind, Subtree, SubtreeOfKind, Tree, TreeFor, TreeSchema, TreeSchemaWithAllRequired } from './tree-schema.js'; /** Run DFS (depth-first search) algorithm on a rooted tree. * Runs `visit` function when a node is discovered (before visiting any descendants). * Runs `postVisit` function when leaving a node (after all descendants have been visited). */ export declare function dfs(root: TTree, visit?: (node: Subtree, parent?: Subtree) => any, postVisit?: (node: Subtree, parent?: Subtree) => any): void; /** Convert a tree into a pretty-printed string. */ export declare function treeToString(tree: Tree): string; /** Convert object to a human-friendly string (similar to JSON.stringify but without quoting keys) */ export declare function formatObject(obj: {} | undefined): string; /** Create a copy of a tree node, ignoring children. */ export declare function copyNodeWithoutChildren(node: TTree): TTree; /** Create a copy of a tree node, including a shallow copy of children. */ export declare function copyNode(node: TTree): TTree; /** Create a deep copy of a tree. */ export declare function copyTree(root: T): T; /** Set of rules for converting a tree of one schema into a different schema. * Each rule defines how to convert a node of a specific kind, e.g. * `{A: node => [], B: node => [{kind: 'X',...}], C: node => [{kind: 'Y',...}, {kind: 'Z',...}]}`: * nodes of kind `A` will be deleted (their children moved to parent), * nodes of kind `B` will be converted to kind `X`, * nodes of kind `C` will be converted to `Y` with a child `Z` (original children moved to `Z`), * nodes of other kinds will just be copied. */ export type ConversionRules = { [kind in Kind>]?: (node: SubtreeOfKind, parent?: Subtree) => { subtree: Subtree[]; }; }; /** Apply a set of conversion rules to a tree to change to a different schema. */ export declare function convertTree(root: A, conversions: ConversionRules): Subtree; /** Create a copy of the tree where twins (siblings of the same kind with the same params) are merged into one node. * Applies only to the node kinds listed in `condenseNodes` (or all if undefined) except node kinds in `skipNodes`. */ export declare function condenseTree(root: T, condenseNodes?: Set>, skipNodes?: Set>): T; /** Create a copy of the tree where missing optional params for each node are added based on `defaults`. */ export declare function addDefaults(tree: TreeFor, treeSchema: S): TreeFor>; /** Resolve any URI params in a tree, in place. URI params are those listed in `uriParamNames`. * Relative URIs are treated as relative to `baseUri`, which can in turn be relative to the window URL (if available). */ export declare function resolveUris(tree: T, baseUri: string, uriParamNames: string[]): void; /** Resolve a sequence of URI references (relative URIs), where each reference is either absolute or relative to the next one * (i.e. the last one is the base URI). Skip any `undefined`. * E.g. `resolveUri('./unexpected.png', '/spanish/inquisition/expectations.html', 'https://example.org/spam/spam/spam')` * returns `'https://example.org/spanish/inquisition/unexpected.png'`. */ export declare function resolveUri(...refs: (string | undefined)[]): string | undefined; /** Gather any URI params in a tree. URI params are those listed in `uriParamNames`. */ export declare function findUris(tree: T, uriParamNames: string[], out?: Set): Set; /** Replace any URI params in a tree using the given `uriMapping`, in place. URI params are those listed in `uriParamNames`. */ export declare function replaceUris(tree: T, uriMapping: { [oldUri: string]: string; }, uriParamNames: string[]): void; /** Return URL of the current page when running in a browser; or file:// URL of the current working directory when running in Node. */ export declare function windowUrl(): string | undefined;