@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
90 lines (89 loc) • 2.74 kB
TypeScript
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
import { type Document } from './htmlparser.js';
/**
* The default animation for text nodes. It is a smooth fade-in animation from 0 to 1 opacity.
*/
export declare const DEFAULT_FADE_IN_ANIMATION = "animation: ck-html-streamer-fade-in .3s";
/**
* A class that streams arbitrary HTML content into a target DOM element in an incremental manner.
*
* It uses a virtual DOM to avoid flickering of images and other dynamic content.
*/
export declare class HTMLStreamer {
/**
* Creates an instance of HTMLStreamer.
*/
constructor(options?: HTMLStreamerOptions);
/**
* Incrementally streams the HTML string into provided target DOM element.
*
* **Note**: This method can be called repeatedly with a new document to continue the previous call. The new parsed document
* must be an extension of the previous document (only growing, never shrinking).
*
* ## Basic example
*
* ```ts
* const document = parse( '<p>foo bar</p>' );
*
* const htmlStreamer = new HTMLStreamer( {
* targetElement,
* textNodeStyle: 'animation: my-animation .5s'
* } );
*
* await htmlStreamer.stream( { document } );
* ```
*
* after 10ms will stream:
*
* ```html
* <p></p>
* ```
*
* and after 20ms:
*
* ```html
* <p><span data-ck-html-streamer-word-chunk="" style="animation: my-animation .5s">foo </span></p>
* ```
*
* and after 30ms:
*
* ```html
* <p>
* <span data-ck-html-streamer-word-chunk="" style="animation: my-animation .5s">foo </span>
* <span data-ck-html-streamer-word-chunk="" style="animation: my-animation .5s">bar</span>
* </p>
* ```
*/
stream({ document, targetElement, abortSignal }: {
document: Document;
targetElement: HTMLElement;
abortSignal?: AbortSignal;
}): Promise<void>;
/**
* Resets the HTMLStreamer to its initial state.
*/
reset(): void;
/**
* Cleans up the animation `<span>` elements from the configured target element with minimum DOM manipulation.
*/
cleanUpAnimations({ targetElement }: {
targetElement: HTMLElement;
}): void;
}
/**
* Options for the HTMLStreamer.
*/
interface HTMLStreamerOptions {
/**
* Delay between `stream()` updates in milliseconds. Default is 10ms.
*/
delay?: number;
/**
* The `style` attribute value for `<span>` elements that wrap text nodes.
*/
textNodeStyle?: string;
}
export {};