domtranslator
Version:
Simple and powerful DOM translator.
47 lines (46 loc) • 1.86 kB
TypeScript
import { NodeTranslationState } from './NodesTranslator';
import { DOMTranslationDispatcher, DOMTranslationScheduler, ProcessedNodeCallback, StateStorage } from './types';
export interface IDomTranslator extends DOMTranslationDispatcher, StateStorage<NodeTranslationState> {
restore(node: Node, callback?: (node: Node) => void): void;
}
type Config = {
/**
* If is provided, nodes can be translated delayed - after intersect the viewport
*/
scheduler?: DOMTranslationScheduler;
/**
* Determines which nodes should be translated
*/
filter?: (node: Node) => boolean;
};
/**
* Translates DOM tree with filtering and optionally in lazy mode
*/
export declare class DOMTranslator implements IDomTranslator {
private readonly nodesTranslator;
private readonly config;
constructor(nodesTranslator: DOMTranslationDispatcher & StateStorage<NodeTranslationState>, config?: Config);
/**
* Translates DOM tree.
*
* If passed Element, all nested nodes (like Text, Attr, etc.) will be processed recursively.
*
* @param callback - Fires for each node, once it has been translated. Target node is passed as first argument
*/
translate(node: Node, callback?: ProcessedNodeCallback): void;
/**
* Restores the original nodes values in passed tree
*
* @param callback - Fires for each node, once it has been restored. Target node is passed as first argument
*/
restore(node: Node, callback?: (node: Node) => void): void;
/**
* Re-translates a node after it has been modified.
*
* @param callback - Called asynchronously with the translated node once the update is complete
*/
update(node: Node, callback?: ProcessedNodeCallback): void;
has(node: Node): boolean;
getState(node: Node): NodeTranslationState | null;
}
export {};