/** * Utilities for detecting AMPscript and GTL region boundaries within a document. */ /** Classification of a script body, separate from its surrounding HTML. */ export type ScriptKind = 'ampscript' | 'ssjs' | 'browser-classic' | 'browser-module' | 'non-js'; /** All offsets are UTF-16, zero-based, and end-exclusive. */ export interface ScriptRegion { kind: ScriptKind; tagStart: number; tagEnd: number; bodyStart: number; bodyEnd: number; /** Null for an unfinished body; otherwise the complete closing tag range. */ closeTagStart: number | null; closeTagEnd: number | null; /** Lowercase attribute names, original values; the first duplicate wins. */ attributes: Readonly>; } /** A full-length projection plus the selected blocks in document order. */ export interface ScriptExtraction { text: string; regions: ScriptRegion[]; } /** * Classify script bodies without scanning nested script-looking text in raw bodies. * HTML comments and quoted attributes are skipped. Unfinished opening tags produce * no region; unfinished bodies extend to EOF. HTML raw-text closing tags terminate * bodies even when they occur inside a JavaScript string or comment. * @param text - Full mixed document. * @returns Script metadata in document order. */ export declare function getScriptRegions(text: string): ScriptRegion[]; /** * Keep only selected script bodies, masking everything else with spaces. Each * UTF-16 code unit keeps its original offset, including astral characters, and * CR/LF line endings are preserved throughout the document. Bodies are not * sanitized: consumers remain responsible for template interpolation handling. * @param text - Full mixed document. * @param kinds - Script classifications to retain. * @returns Offset-preserving text and retained block metadata. */ export declare function extractScriptBodies(text: string, kinds: readonly ScriptKind[]): ScriptExtraction; /** One delimiter-level item found by {@link scanAmpscriptDelimiters}. Offsets are UTF-16, zero-based, and end-exclusive. - `block` / `inline`: `closed` regions span opener through closing delimiter; an unclosed one covers only its three-character opener. - `personalization`: a complete `%%name%%` string (plain text, never a delimiter). - `block-close` / `inline-close`: a stray `]%%` / `=%%` outside any region. */ export interface AmpscriptDelimiterRegion { kind: 'block' | 'inline' | 'personalization' | 'block-close' | 'inline-close'; start: number; end: number; closed: boolean; } /** * Scan a template left to right for AMPscript delimiters. At a `%%` outside any * region, `%%[` opens a block ending at the first following `]%%` and `%%=` opens * an inline expression ending at the first following `=%%`; otherwise a * personalisation string (`%%name%%` on one line) is skipped as a whole, so neither * of its `%%` can form a delimiter; any other `%%` is literal text. Scanning * resumes right after an opener that has no closing delimiter. Outside a region, * the body of a ` tag body. * @param text - Full document text. * @param offset - Character offset to test. * @returns True if the offset is inside an AMPscript region. */ export declare function isInsideAmpscript(text: string, offset: number): boolean; /** * Returns true when the given character offset falls inside a GTL {{...}} expression. * @param text - Full document text. * @param offset - Character offset to test. * @returns True if the offset is inside a GTL expression. */ export declare function isInsideGtl(text: string, offset: number): boolean; /** * Returns true when the given character offset falls inside a Handlebars {{...}} * expression (Handlebars for Marketing Cloud Next). The syntax is identical to * GTL, but the two are mutually exclusive: GTL is detected only in Engagement * mode, Handlebars only in MCN Next mode. * @param text - Full document text. * @param offset - Character offset to test. * @returns True if the offset is inside a Handlebars expression. */ export declare function isInsideHandlebars(text: string, offset: number): boolean; /** * Returns a copy of the document where every AMPscript region (%%[...]%%, * %%=...=%%, and