@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
47 lines • 2.02 kB
text/typescript
/**
* Clone a `Range` into a self-contained wrapper element with computed
* styles inlined onto every cloned descendant, so that pasting into
* rich-text targets (email, Word, Notion, etc.) preserves the source's
* visual styling without depending on the source page's stylesheet.
*
* The wrapper defaults to `<pre>` so monospace + whitespace context
* survives a copy/paste round-trip. The original ancestor chain
* between `range.commonAncestorContainer` and `root` is reconstructed
* inside the wrapper so a selection living entirely inside a styled
* descendant (e.g. one token of a syntax-highlighted line) keeps that
* wrapper in the clipboard payload.
*/
interface InlineStyleOptions {
/**
* Tag name for the wrapper element. Defaults to `'pre'` so monospace
* + whitespace context survives a copy/paste round-trip.
*/
wrapperTag?: string;
/**
* Class name applied to the wrapper. Defaults to `root.className` so
* consumers that scope styles by class keep matching when the snippet
* is pasted into a richer environment that loads the same stylesheet.
*/
className?: string;
/**
* Computed-style properties inlined onto every cloned descendant.
* Keep this list short — each property is read via
* `getComputedStyle` per node.
*/
elementStyleProps?: readonly string[];
/**
* Computed-style properties read from `root` and inlined onto the
* wrapper. Use to carry typography (font-family, font-size,
* line-height, …) onto the wrapper so the pasted block matches the
* source even when only a descendant was selected.
*/
rootStyleProps?: readonly string[];
/**
* Static CSS prepended to the wrapper's `style` attribute, before any
* computed properties. Useful for visual chrome (padding, rounded
* corners) that does not depend on the source.
*/
rootStaticStyles?: string;
}
export declare const cloneRangeWithInlineStyles: (root: HTMLElement, range: Range, options?: InlineStyleOptions) => HTMLElement;
export {};