Path: blob/main/src/vs/base/browser/dompurify/dompurify.d.ts
3294 views
// Type definitions for DOM Purify 3.01// Project: https://github.com/cure53/DOMPurify2// Definitions by: Dave Taylor https://github.com/davetayls3// Samira Bazuzi <https://github.com/bazuzi>4// FlowCrypt <https://github.com/FlowCrypt>5// Exigerr <https://github.com/Exigerr>6// Piotr Błażejewicz <https://github.com/peterblazejewicz>7// Nicholas Ellul <https://github.com/NicholasEllul>8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped9// Minimum TypeScript Version: 4.51011export default DOMPurify;1213declare const DOMPurify: createDOMPurifyI;1415type WindowLike = Pick<16typeof globalThis,17| 'NodeFilter'18| 'Node'19| 'Element'20| 'HTMLTemplateElement'21| 'DocumentFragment'22| 'HTMLFormElement'23| 'DOMParser'24| 'NamedNodeMap'25>;2627interface createDOMPurifyI extends DOMPurify.DOMPurifyI {28(window?: Window | WindowLike): DOMPurify.DOMPurifyI;29}3031declare namespace DOMPurify {32interface DOMPurifyI {33sanitize(source: string | Node): string;34sanitize(source: string | Node, config: Config & { RETURN_TRUSTED_TYPE: true }): TrustedHTML;35sanitize(36source: string | Node,37config: Config & { RETURN_DOM_FRAGMENT?: false | undefined; RETURN_DOM?: false | undefined },38): string;39sanitize(source: string | Node, config: Config & { RETURN_DOM_FRAGMENT: true }): DocumentFragment;40sanitize(source: string | Node, config: Config & { RETURN_DOM: true }): HTMLElement;41sanitize(source: string | Node, config: Config): string | HTMLElement | DocumentFragment;4243addHook(44hook: 'uponSanitizeElement',45cb: (currentNode: Element, data: SanitizeElementHookEvent, config: Config) => void,46): void;47addHook(48hook: 'uponSanitizeAttribute',49cb: (currentNode: Element, data: SanitizeAttributeHookEvent, config: Config) => void,50): void;51addHook(hook: HookName, cb: (currentNode: Element, data: HookEvent, config: Config) => void): void;5253setConfig(cfg: Config): void;54clearConfig(): void;55isValidAttribute(tag: string, attr: string, value: string): boolean;5657removeHook(entryPoint: HookName): void;58removeHooks(entryPoint: HookName): void;59removeAllHooks(): void;6061version: string;62removed: any[];63isSupported: boolean;64}6566interface Config {67ADD_ATTR?: string[] | undefined;68ADD_DATA_URI_TAGS?: string[] | undefined;69ADD_TAGS?: string[] | undefined;70ADD_URI_SAFE_ATTR?: string[] | undefined;71ALLOW_ARIA_ATTR?: boolean | undefined;72ALLOW_DATA_ATTR?: boolean | undefined;73ALLOW_UNKNOWN_PROTOCOLS?: boolean | undefined;74ALLOW_SELF_CLOSE_IN_ATTR?: boolean | undefined;75ALLOWED_ATTR?: string[] | undefined;76ALLOWED_TAGS?: string[] | undefined;77ALLOWED_NAMESPACES?: string[] | undefined;78ALLOWED_URI_REGEXP?: RegExp | undefined;79FORBID_ATTR?: string[] | undefined;80FORBID_CONTENTS?: string[] | undefined;81FORBID_TAGS?: string[] | undefined;82FORCE_BODY?: boolean | undefined;83IN_PLACE?: boolean | undefined;84KEEP_CONTENT?: boolean | undefined;85/**86* change the default namespace from HTML to something different87*/88NAMESPACE?: string | undefined;89PARSER_MEDIA_TYPE?: string | undefined;90RETURN_DOM_FRAGMENT?: boolean | undefined;91/**92* This defaults to `true` starting DOMPurify 2.2.0. Note that setting it to `false`93* might cause XSS from attacks hidden in closed shadowroots in case the browser94* supports Declarative Shadow: DOM https://web.dev/declarative-shadow-dom/95*/96RETURN_DOM_IMPORT?: boolean | undefined;97RETURN_DOM?: boolean | undefined;98RETURN_TRUSTED_TYPE?: boolean | undefined;99SAFE_FOR_TEMPLATES?: boolean | undefined;100SANITIZE_DOM?: boolean | undefined;101/** @default false */102SANITIZE_NAMED_PROPS?: boolean | undefined;103USE_PROFILES?:104| false105| {106mathMl?: boolean | undefined;107svg?: boolean | undefined;108svgFilters?: boolean | undefined;109html?: boolean | undefined;110}111| undefined;112WHOLE_DOCUMENT?: boolean | undefined;113CUSTOM_ELEMENT_HANDLING?: {114tagNameCheck?: RegExp | ((tagName: string) => boolean) | null | undefined;115attributeNameCheck?: RegExp | ((lcName: string) => boolean) | null | undefined;116allowCustomizedBuiltInElements?: boolean | undefined;117};118}119120type HookName =121| 'beforeSanitizeElements'122| 'uponSanitizeElement'123| 'afterSanitizeElements'124| 'beforeSanitizeAttributes'125| 'uponSanitizeAttribute'126| 'afterSanitizeAttributes'127| 'beforeSanitizeShadowDOM'128| 'uponSanitizeShadowNode'129| 'afterSanitizeShadowDOM';130131type HookEvent = SanitizeElementHookEvent | SanitizeAttributeHookEvent | null;132133interface SanitizeElementHookEvent {134tagName: string;135allowedTags: { [key: string]: boolean };136}137138interface SanitizeAttributeHookEvent {139attrName: string;140attrValue: string;141keepAttr: boolean;142allowedAttributes: { [key: string]: boolean };143forceKeepAttr?: boolean | undefined;144}145}146147148