import { o as ParentNode } from "./tree-builder-fO9Gka1f.mjs"; //#region src/main/core.d.ts /** * A parse adapter turns untrusted HTML into the common `{type,name,attrs,children}` * tree the policy engine consumes. This is the ONLY pluggable seam: every entry * supplies an environment-appropriate default (the bundled WHATWG parser in Node, * native `DOMParser` in the browser), and `Sanitizer.builder().parser(adapter)` * overrides it with any other, e.g. the `parse5` adapter from `neosanitize/parse5`, * or your own. The policy + serializer are reused verbatim regardless of parser. */ type ParseAdapter = (html: string) => ParentNode; declare const version = "0.0.0-dev"; interface Policy { /** Allowed element names. Deny-by-default: everything else is dropped. */ readonly tags: ReadonlySet; /** Allowed attributes, per tag (`*` = any tag). */ readonly attrs: ReadonlyMap>; /** * When false (the safe default), an inviolable baseline still strips * known-unsafe constructs (script, event handlers, javascript: URLs, …) even * if `tags`/`attrs` would allow them. `sanitizeUnsafe()` sets this true. */ readonly allowUnsafe: boolean; } /** A partial policy or a named preset, accepted anywhere a policy is. */ type PolicyInput = Partial | Preset; /** * Brand symbol identifying a value as a built {@link Preset}. Exported so preset * modules (e.g. `neosanitize/presets/*`) and advanced users authoring their own * presets can stamp it, the `UNSAFE_` name signals that hand-stamping bypasses * normal `Sanitizer` construction and is the caller's responsibility. */ declare const UNSAFE_PRESET_SYMBOL: unique symbol; interface Preset { readonly [UNSAFE_PRESET_SYMBOL]: true; readonly name: string; readonly policy: Policy; } interface MutablePolicy { tags: Iterable; attrs: Record>; allowUnsafe: boolean; } interface TrustedHTML { toString(): string; } /** One element/attribute/value removed during sanitization (report mode). */ interface Removal { readonly kind: 'tag' | 'attr' | 'url' | 'style'; readonly name: string; readonly reason: string; } /** Result of {@link SanitizerCore.sanitizeWithReport}. */ interface SanitizeReport { readonly html: string; readonly removed: Removal[]; } /** A destination for {@link SanitizerCore.sanitizeTo}: either a chunk callback or * any object with a Node-style `write` (an HTTP response, `fs` write stream, …). */ type SanitizeSink = ((chunk: string) => void) | { write(chunk: string): unknown; }; /** Options for {@link SanitizerCore.sanitizeTo}. */ interface SanitizeToOptions { /** Target write size in characters; fragments are batched up to this before a * flush, so the sink isn't hit with a write per tag. Default 16384. */ readonly chunkSize?: number; } declare class SanitizerCore { /** Compiled, immutable policy. */ readonly policy: Policy; /** The environment default parser, supplied by the concrete entry subclass * (bundled WHATWG parser in Node, native `DOMParser` in the browser). */ private readonly defaultParse; /** An explicit per-instance override from `.parser(adapter)`, or `null` to use * the environment default. Carried through `sanitizeUnsafe`'s re-parse. */ private readonly parserOverride; /** Per-tag serialize cache, built once from the policy. Holds ONLY tags that * serialize as "keep" (allow-listed and not baseline-dropped); a miss routes * to the slow drop/unwrap path. Collapses the per-element baseline/allow-list/ * void/raw-text `Set.has` chain and the open/close-tag concatenations into one * `Map.get` plus field reads on the serialize hot path. */ private readonly tagCache; constructor(policy?: Policy, defaultParse?: ParseAdapter, parserOverride?: ParseAdapter | null); /** * Parse untrusted HTML into the common `{type,name,attrs,children}` tree, via * the active adapter: an explicit `.parser()` override if set, else the * environment default. This is the ONLY pluggable seam, the policy engine and * serializer downstream are identical for every parser. */ protected parse(html: string): ParentNode; /** Sanitize to a string. Always applies the inviolable safe baseline. */ sanitize(html: string): string; /** Sanitize and report what was removed and why (debug / audit / telemetry). */ sanitizeWithReport(html: string): SanitizeReport; /** * Stream the sanitized HTML to a sink instead of returning one string. `sink` is * either a callback `(chunk) => void` or any object with a Node-style * `write(chunk)` method (an HTTP response, an `fs` write stream, your own). * * Same parse, same inviolable baseline, same bytes as {@link sanitize}, just * delivered incrementally, so no single large result string is built and large * documents stay friendlier on memory. Fragments are batched into * ~`chunkSize`-character writes (default 16 KB) so the sink isn't hit per tag. * * Synchronous: the sink is called inline while the tree is walked, and the whole * input is parsed first (a faithful tree is required), so this streams *output*, * not input. Backpressure is not awaited; for a slow consumer, buffer as needed. */ sanitizeTo(html: string, sink: SanitizeSink, opts?: SanitizeToOptions): void; /** Strip all markup to plain text (raw-text/script content excluded). */ sanitizeToText(html: string): string; /** * Sanitize directly into a `DocumentFragment` (browser only), builds DOM nodes * from the sanitized tree, skipping the non-idempotent serialize→reparse step * (the strongest-safety path). Throws outside a DOM environment. */ sanitizeToFragment(html: string): DocumentFragment; /** * Sanitize and return a `TrustedHTML` via a Trusted Types policy when available * (browser w/ CSP Trusted Types), else the sanitized string. The string is * already safe; the wrapper just satisfies a TrustedHTML sink. */ sanitizeToTrustedHTML(html: string): TrustedHTML | string; private static ttPolicy; private buildDom; private static collectText; /** What to do with an element: drop (with content), unwrap (drop the tag, keep * sanitized children), or keep. */ private elementAction; /** Filtered, sanitized attributes for a kept element; records drops if `removed`. * Lazily allocates: when nothing is dropped or rewritten (the common case) it * returns `el.attrs` itself, so attribute-clean elements cost zero allocations. */ private filterAttrs; private emitChildren; private emitElement; private attrAllowed; private static attrUnsafe; private static dangerousUrl; private static sanitizeStyle; /** Split a declaration list on top-level ';' (not inside parens or strings). */ private static splitDeclarations; private static unsafeCssValue; private static serializeAttrName; private static escapeText; private static escapeAttr; /** Escape hatch: skip the inviolable baseline (mirrors `setHTMLUnsafe`). */ sanitizeUnsafe(html: string): string; /** * Class-based factory, the entry point: `Sanitizer.builder().preset(…).build()`. * Polymorphic over the concrete subclass: `Sanitizer.builder()` yields a builder * whose `.build()` returns that same `Sanitizer` (so the correct parser is wired). */ static builder(this: new (policy?: Policy, parser?: ParseAdapter | null) => T, base?: PolicyInput): SanitizerBuilder; } declare class SanitizerBuilder { private readonly ctor; private _tags; private _attrs; private _allowUnsafe; private _parser; /** @param ctor the concrete `Sanitizer` subclass to instantiate at `build()`. */ constructor(ctor: new (policy?: Policy, parser?: ParseAdapter | null) => T); /** * Override the parser. Pass an adapter (e.g. `parse5Adapter` from * `neosanitize/parse5`, or your own `(html) => ParentNode`) to parse with it * instead of the environment default. Pass `null` to restore the default. */ parser(adapter: ParseAdapter | null): this; /** Start from a preset (or another policy), then refine. */ preset(p: PolicyInput): this; /** Allow a tag (optionally with attributes). */ allow(tag: string, attrs?: Iterable): this; /** Remove a tag from the allow-list. */ deny(tag: string): this; /** Compile the accumulated config into a reusable `Sanitizer` (once). */ build(): T; /** Resolve a preset or partial-policy input into an immutable `Policy`. */ private static resolve; } //#endregion export { Removal as a, SanitizeToOptions as c, TrustedHTML as d, UNSAFE_PRESET_SYMBOL as f, Preset as i, SanitizerBuilder as l, Policy as n, SanitizeReport as o, version as p, PolicyInput as r, SanitizeSink as s, ParseAdapter as t, SanitizerCore as u }; //# sourceMappingURL=core-ynMpvzgT.d.mts.map