@@ -297,7 +297,21 @@ interface DOMPurify {
297297 * @param entryPoint entry point for the hook to add
298298 * @param hookFunction function to execute
299299 */
300- addHook ( entryPoint : BasicHookName , hookFunction : Hook ) : void ;
300+ addHook ( entryPoint : BasicHookName , hookFunction : NodeHook ) : void ;
301+ /**
302+ * Adds a DOMPurify hook.
303+ *
304+ * @param entryPoint entry point for the hook to add
305+ * @param hookFunction function to execute
306+ */
307+ addHook ( entryPoint : ElementHookName , hookFunction : ElementHook ) : void ;
308+ /**
309+ * Adds a DOMPurify hook.
310+ *
311+ * @param entryPoint entry point for the hook to add
312+ * @param hookFunction function to execute
313+ */
314+ addHook ( entryPoint : DocumentFragmentHookName , hookFunction : DocumentFragmentHook ) : void ;
301315 /**
302316 * Adds a DOMPurify hook.
303317 *
@@ -319,7 +333,23 @@ interface DOMPurify {
319333 * @param entryPoint entry point for the hook to remove
320334 * @returns removed(popped) hook
321335 */
322- removeHook ( entryPoint : BasicHookName ) : Hook | undefined ;
336+ removeHook ( entryPoint : BasicHookName ) : NodeHook | undefined ;
337+ /**
338+ * Remove a DOMPurify hook at a given entryPoint
339+ * (pops it from the stack of hooks if more are present)
340+ *
341+ * @param entryPoint entry point for the hook to remove
342+ * @returns removed(popped) hook
343+ */
344+ removeHook ( entryPoint : ElementHookName ) : ElementHook | undefined ;
345+ /**
346+ * Remove a DOMPurify hook at a given entryPoint
347+ * (pops it from the stack of hooks if more are present)
348+ *
349+ * @param entryPoint entry point for the hook to remove
350+ * @returns removed(popped) hook
351+ */
352+ removeHook ( entryPoint : DocumentFragmentHookName ) : DocumentFragmentHook | undefined ;
323353 /**
324354 * Remove a DOMPurify hook at a given entryPoint
325355 * (pops it from the stack of hooks if more are present)
@@ -369,13 +399,17 @@ interface RemovedAttribute {
369399 */
370400 from : Node ;
371401}
372- type BasicHookName = 'beforeSanitizeElements' | 'afterSanitizeElements' | 'beforeSanitizeAttributes' | 'afterSanitizeAttributes' | 'beforeSanitizeShadowDOM' | 'uponSanitizeShadowNode' | 'afterSanitizeShadowDOM' ;
402+ type BasicHookName = 'beforeSanitizeElements' | 'afterSanitizeElements' | 'uponSanitizeShadowNode' ;
403+ type ElementHookName = 'beforeSanitizeAttributes' | 'afterSanitizeAttributes' ;
404+ type DocumentFragmentHookName = 'beforeSanitizeShadowDOM' | 'afterSanitizeShadowDOM' ;
373405type UponSanitizeElementHookName = 'uponSanitizeElement' ;
374406type UponSanitizeAttributeHookName = 'uponSanitizeAttribute' ;
375- type HookName = BasicHookName | UponSanitizeElementHookName | UponSanitizeAttributeHookName ;
376- type Hook = ( this : DOMPurify , currentNode : Node , hookEvent : null , config : Config ) => void ;
407+ type HookName = BasicHookName | ElementHookName | DocumentFragmentHookName | UponSanitizeElementHookName | UponSanitizeAttributeHookName ;
408+ type NodeHook = ( this : DOMPurify , currentNode : Node , hookEvent : null , config : Config ) => void ;
409+ type ElementHook = ( this : DOMPurify , currentNode : Element , hookEvent : null , config : Config ) => void ;
410+ type DocumentFragmentHook = ( this : DOMPurify , currentNode : DocumentFragment , hookEvent : null , config : Config ) => void ;
377411type UponSanitizeElementHook = ( this : DOMPurify , currentNode : Node , hookEvent : UponSanitizeElementHookEvent , config : Config ) => void ;
378- type UponSanitizeAttributeHook = ( this : DOMPurify , currentNode : Node , hookEvent : UponSanitizeAttributeHookEvent , config : Config ) => void ;
412+ type UponSanitizeAttributeHook = ( this : DOMPurify , currentNode : Element , hookEvent : UponSanitizeAttributeHookEvent , config : Config ) => void ;
379413interface UponSanitizeElementHookEvent {
380414 tagName : string ;
381415 allowedTags : Record < string , boolean > ;
@@ -396,4 +430,4 @@ type WindowLike = Pick<typeof globalThis, 'DocumentFragment' | 'HTMLTemplateElem
396430 trustedTypes ?: typeof window . trustedTypes ;
397431} ;
398432
399- export { type Config , type DOMPurify , type Hook , type HookName , type RemovedAttribute , type RemovedElement , type UponSanitizeAttributeHook , type UponSanitizeAttributeHookEvent , type UponSanitizeElementHook , type UponSanitizeElementHookEvent , type WindowLike , _default as default } ;
433+ export { type Config , type DOMPurify , type DocumentFragmentHook , type ElementHook , type HookName , type NodeHook , type RemovedAttribute , type RemovedElement , type UponSanitizeAttributeHook , type UponSanitizeAttributeHookEvent , type UponSanitizeElementHook , type UponSanitizeElementHookEvent , type WindowLike , _default as default } ;
0 commit comments