@rgrove/parse-xml 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/lib/StringScanner.ts", "../src/lib/syntax.ts", "../src/lib/XmlNode.ts", "../src/lib/XmlText.ts", "../src/lib/XmlCdata.ts", "../src/lib/XmlComment.ts", "../src/lib/XmlDeclaration.ts", "../src/lib/XmlElement.ts", "../src/lib/XmlDocument.ts", "../src/lib/XmlDocumentType.ts", "../src/lib/XmlError.ts", "../src/lib/XmlProcessingInstruction.ts", "../src/lib/Parser.ts"],
4
- "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDeclaration } from './lib/XmlDeclaration.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlDocumentType } from './lib/XmlDocumentType.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlError } from './lib/XmlError.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options?: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(count = 1): string {\n let chars = this.peek(count);\n this.advance(count);\n return chars;\n }\n\n /**\n * Consumes a match for the given sticky regex, advances the scanner, updates\n * the `lastIndex` property of the regex, and returns the matching string.\n *\n * The regex must have a sticky flag (\"y\") so that its `lastIndex` prop can be\n * used to anchor the match at the current scanner position.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeMatch(regex: RegExp): string {\n if (!regex.sticky) {\n throw new Error('`regex` must have a sticky flag (\"y\")');\n }\n\n regex.lastIndex = this.charIndexToByteIndex();\n\n let result = regex.exec(this.string);\n\n if (result === null || result.length === 0) {\n return emptyString;\n }\n\n let match = result[0] as string;\n this.advance(this.charLength(match));\n return match;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns a\n * truthy value, stopping on the first falsy return value or if the end of the\n * input is reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let char;\n let match = emptyString;\n\n while ((char = this.peek()) && fn(char)) {\n match += char;\n this.advance();\n }\n\n return match;\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n if (this.consumeStringFast(stringToConsume)) {\n return stringToConsume;\n }\n\n if (this.multiByteMode) {\n let { length } = stringToConsume;\n let charLengthToMatch = this.charLength(stringToConsume);\n\n if (charLengthToMatch !== length\n && stringToConsume === this.peek(charLengthToMatch)) {\n\n this.advance(charLengthToMatch);\n return stringToConsume;\n }\n }\n\n return emptyString;\n }\n\n /**\n * Does the same thing as `consumeString()`, but doesn't support consuming\n * multibyte characters. This can be faster if you only need to match single\n * byte characters.\n */\n consumeStringFast(stringToConsume: string): string {\n let { length } = stringToConsume;\n\n if (this.peek(length) === stringToConsume) {\n this.advance(length);\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let restOfString = this.string.slice(this.charIndexToByteIndex());\n let matchByteIndex = restOfString.search(regex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = restOfString.slice(0, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let { string } = this;\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = string.indexOf(searchString, byteIndex);\n\n if (matchByteIndex <= 0) {\n return emptyString;\n }\n\n let result = string.slice(byteIndex, matchByteIndex);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, multiByteMode, string } = this;\n\n if (multiByteMode) {\n // Inlining this comparison instead of checking `this.isEnd` improves perf\n // slightly since `peek()` is called so frequently.\n if (charIndex >= this.charCount) {\n return emptyString;\n }\n\n return string.slice(\n this.charIndexToByteIndex(charIndex),\n this.charIndexToByteIndex(charIndex + count),\n );\n }\n\n return string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[^\"&<]+/y;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /[^'&<]+/y;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /\\r\\n|[\\n\\r\\t]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = getCodePoint(char);\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || (cp >= 0x203F && cp <= 0x2040)\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || (cp >= 0x200C && cp <= 0x200D)\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = getCodePoint(char);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return cp === 0x9\n || cp === 0xA\n || cp === 0xD\n || (cp >= 0x20 && cp <= 0xD7FF)\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n\n/**\n * Returns the Unicode code point value of the given character, or `-1` if\n * _char_ is empty.\n */\nfunction getCodePoint(char: string): number {\n return char.codePointAt(0) || -1;\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlDocumentType` node.\n */\n static readonly TYPE_DOCUMENT_TYPE = 'doctype';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Type value for an `XmlDeclaration` node.\n */\n static readonly TYPE_XML_DECLARATION = 'xmldecl';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Starting byte offset of this node in the original XML string, or `-1` if\n * the offset is unknown.\n */\n start = -1;\n\n /**\n * Ending byte offset of this node in the original XML string, or `-1` if the\n * offset is unknown.\n */\n end = -1;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document (also known as the\n * document element).\n */\n get isRootNode(): boolean {\n return this.parent !== null\n && this.parent === this.document\n && this.type === XmlNode.TYPE_ELEMENT;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return !!this.parent?.preserveWhitespace;\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n if (this.start !== -1) {\n json.start = this.start;\n json.end = this.end;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * An XML declaration within an XML document.\n *\n * @example\n *\n * ```xml\n * <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n * ```\n */\nexport class XmlDeclaration extends XmlNode {\n /**\n * Value of the encoding declaration in this XML declaration, or `null` if no\n * encoding declaration was present.\n */\n encoding: string | null;\n\n /**\n * Value of the standalone declaration in this XML declaration, or `null` if\n * no standalone declaration was present.\n */\n standalone: 'yes' | 'no' | null;\n\n /**\n * Value of the version declaration in this XML declaration.\n */\n version: string;\n\n constructor(\n version: string,\n encoding?: string,\n standalone?: typeof XmlDeclaration.prototype.standalone,\n ) {\n super();\n\n this.version = version;\n this.encoding = encoding ?? null;\n this.standalone = standalone ?? null;\n }\n\n override get type() {\n return XmlNode.TYPE_XML_DECLARATION;\n }\n\n override toJSON() {\n let json = XmlNode.prototype.toJSON.call(this);\n json.version = this.version;\n\n for (let key of ['encoding', 'standalone'] as const) {\n if (this[key] !== null) {\n json[key] = this[key];\n }\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlDeclaration } from './XmlDeclaration.js';\nimport type { XmlDocumentType } from './XmlDocumentType.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlDeclaration | XmlDocumentType | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlDeclaration | XmlDocumentType | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A document type declaration within an XML document.\n *\n * @example\n *\n * ```xml\n * <!DOCTYPE kittens [\n * <!ELEMENT kittens (#PCDATA)>\n * ]>\n * ```\n */\nexport class XmlDocumentType extends XmlNode {\n /**\n * Name of the root element described by this document type declaration.\n */\n name: string;\n\n /**\n * Public identifier of the external subset of this document type declaration,\n * or `null` if no public identifier was present.\n */\n publicId: string | null;\n\n /**\n * System identifier of the external subset of this document type declaration,\n * or `null` if no system identifier was present.\n */\n systemId: string | null;\n\n /**\n * Internal subset of this document type declaration, or `null` if no internal\n * subset was present.\n */\n internalSubset: string | null;\n\n constructor(\n name: string,\n publicId?: string,\n systemId?: string,\n internalSubset?: string,\n ) {\n super();\n this.name = name;\n this.publicId = publicId ?? null;\n this.systemId = systemId ?? null;\n this.internalSubset = internalSubset ?? null;\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT_TYPE;\n }\n\n override toJSON() {\n let json = XmlNode.prototype.toJSON.call(this);\n json.name = this.name;\n\n for (let key of ['publicId', 'systemId', 'internalSubset'] as const) {\n if (this[key] !== null) {\n json[key] = this[key];\n }\n }\n\n return json;\n }\n}\n", "/**\n * An error that occurred while parsing XML.\n */\nexport class XmlError extends Error {\n /**\n * Character column at which this error occurred (1-based).\n */\n readonly column: number;\n\n /**\n * Short excerpt from the input string that contains the problem.\n */\n readonly excerpt: string;\n\n /**\n * Line number at which this error occurred (1-based).\n */\n readonly line: number;\n\n /**\n * Character position at which this error occurred relative to the beginning\n * of the input (0-based).\n */\n readonly pos: number;\n\n constructor(\n message: string,\n charIndex: number,\n xml: string,\n ) {\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n super(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n this.column = column;\n this.excerpt = excerpt;\n this.line = line;\n this.name = 'XmlError';\n this.pos = charIndex;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDeclaration } from './XmlDeclaration.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlDocumentType } from './XmlDocumentType.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlError } from './XmlError.js';\nimport { XmlNode } from './XmlNode.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n let doc = this.document = new XmlDocument();\n let scanner = this.scanner = new StringScanner(xml);\n\n this.currentNode = doc;\n this.options = options;\n\n if (this.options.includeOffsets) {\n doc.start = 0;\n doc.end = xml.length;\n }\n\n scanner.consumeStringFast('\\uFEFF'); // byte order mark\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode, charIndex: number) {\n node.parent = this.currentNode;\n\n if (this.options.includeOffsets) {\n node.start = this.scanner.charIndexToByteIndex(charIndex);\n node.end = this.scanner.charIndexToByteIndex();\n }\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n return true;\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n */\n addText(text: string, charIndex: number) {\n let { children } = this.currentNode;\n let { length } = children;\n\n text = normalizeLineBreaks(text);\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode?.type === XmlNode.TYPE_TEXT) {\n let textNode = prevNode as XmlText;\n\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n textNode.text += text;\n\n if (this.options.includeOffsets) {\n textNode.end = this.scanner.charIndexToByteIndex();\n }\n\n return true;\n }\n }\n\n return this.addNode(new XmlText(text), charIndex);\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n case emptyString:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeStringFast(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n return this.options.preserveCdata\n ? this.addNode(new XmlCdata(normalizeLineBreaks(text)), startIndex)\n : this.addText(text, startIndex);\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n return this.addText(charData, startIndex);\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n return this.options.preserveComments\n ? this.addNode(new XmlComment(normalizeLineBreaks(content)), startIndex)\n : true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let startIndex = this.scanner.charIndex;\n let ref = this.consumeReference();\n\n return ref\n ? this.addText(ref, startIndex)\n : false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<!DOCTYPE')) {\n return false;\n }\n\n let name = this.consumeWhitespace()\n && this.consumeName();\n\n if (!name) {\n throw this.error('Expected a name');\n }\n\n let publicId;\n let systemId;\n\n if (this.consumeWhitespace()) {\n if (scanner.consumeStringFast('PUBLIC')) {\n publicId = this.consumeWhitespace()\n && this.consumePubidLiteral();\n\n if (publicId === false) {\n throw this.error('Expected a public identifier');\n }\n\n this.consumeWhitespace();\n }\n\n if (publicId !== undefined || scanner.consumeStringFast('SYSTEM')) {\n this.consumeWhitespace();\n systemId = this.consumeSystemLiteral();\n\n if (systemId === false) {\n throw this.error('Expected a system identifier');\n }\n\n this.consumeWhitespace();\n }\n }\n\n let internalSubset;\n\n if (scanner.consumeStringFast('[')) {\n // The internal subset may contain comments that contain `]` characters,\n // so we can't use `consumeUntilString()` here.\n internalSubset = scanner.consumeUntilMatch(/\\][\\x20\\t\\r\\n]*>/);\n\n if (!scanner.consumeStringFast(']')) {\n throw this.error('Unclosed internal subset');\n }\n\n this.consumeWhitespace();\n }\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return this.options.preserveDocumentType\n ? this.addNode(new XmlDocumentType(name, publicId, systemId, internalSubset), startIndex)\n : true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(startIndex);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = !!scanner.consumeStringFast('/>');\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeStringFast('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeStringFast('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n return this.addNode(element, startIndex);\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeStringFast('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(startIndex);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeStringFast('?>')) {\n return this.addNode(new XmlProcessingInstruction(name), startIndex);\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n return this.addNode(new XmlProcessingInstruction(name, normalizeLineBreaks(content)), startIndex);\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return startIndex < scanner.charIndex;\n }\n\n /**\n * Consumes a public identifier literal if possible.\n *\n * @returns\n * Value of the public identifier literal minus quotes, or `false` if\n * nothing was consumed. An empty string indicates that a public id literal\n * was consumed but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PubidLiteral\n */\n consumePubidLiteral(): string | false {\n let startIndex = this.scanner.charIndex;\n let value = this.consumeSystemLiteral();\n\n if (value !== false && !/^[-\\x20\\r\\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(value)) {\n this.scanner.reset(startIndex);\n throw this.error('Invalid character in public identifier');\n }\n\n return value;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeStringFast('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeStringFast('\"') || scanner.consumeStringFast(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeStringFast(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return !!this.scanner.consumeMatchFn(syntax.isWhitespace);\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeStringFast('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = !!scanner.consumeStringFast('version')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n let encoding;\n let standalone;\n\n if (this.consumeWhitespace()) {\n encoding = !!scanner.consumeStringFast('encoding')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n this.consumeWhitespace();\n }\n\n standalone = !!scanner.consumeStringFast('standalone')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeStringFast('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return this.options.preserveXmlDeclaration\n ? this.addNode(new XmlDeclaration(\n version,\n encoding || undefined,\n (standalone as 'yes' | 'no' | false) || undefined,\n ), startIndex)\n : true;\n }\n\n /**\n * Returns an `XmlError` for the current scanner position.\n */\n error(message: string) {\n let { scanner } = this;\n return new XmlError(message, scanner.charIndex, scanner.string);\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes line breaks in the given text by replacing CRLF sequences and lone\n * CR characters with LF characters.\n */\nfunction normalizeLineBreaks(text: string): string {\n let i = 0;\n\n while ((i = text.indexOf('\\r', i)) !== -1) {\n text = text[i + 1] === '\\n'\n ? text.slice(0, i) + text.slice(i + 1)\n : text.slice(0, i) + '\\n' + text.slice(i + 1);\n }\n\n return text;\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, the starting and ending byte offsets of each node in the input\n * string will be made available via `start` and `end` properties on the node.\n *\n * @default false\n */\n includeOffsets?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When `true`, a document type declaration (if present) will be preserved in\n * the document as an `XmlDocumentType` node. Otherwise the declaration will\n * not be included in the node tree.\n *\n * Note that when this is `true` and a document type declaration is present,\n * the DTD will precede the root node in the node tree (normally the root\n * node would be first).\n *\n * @default false\n */\n preserveDocumentType?: boolean;\n\n /**\n * When `true`, an XML declaration (if present) will be preserved in the\n * document as an `XmlDeclaration` node. Otherwise the declaration will not be\n * included in the node tree.\n *\n * Note that when this is `true` and an XML declaration is present, the\n * XML declaration will be the first child of the document (normally the root\n * node would be first).\n *\n * @default false\n */\n preserveXmlDeclaration?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAGf,IAAM,gBAAN,MAAoB;AAAA,EASzB,YAAY,QAAgB;AAC1B,SAAKA,IAAY,KAAKC,EAAW,QAAQ,IAAI;AAC7C,SAAKC,IAAY;AACjB,SAAK,SAAS,OAAO;AACrB,SAAKC,IAAgB,KAAKH,MAAc,KAAK;AAC7C,SAAKI,IAAS;AAEd,QAAI,KAAKD,GAAe;AACtB,UAAI,eAAe,CAAC;AAKpB,eAAS,YAAY,GAAG,YAAY,GAAG,YAAY,KAAKH,GAAW,EAAE,WAAW;AAC9E,qBAAa,SAAS,IAAI;AAC1B,qBAAc,OAAO,YAAY,SAAS,IAAe,QAAQ,IAAI;AAAA,MACvE;AAEA,WAAKK,IAAe;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAIC,IAAQ;AACV,WAAO,KAAKJ,KAAa,KAAKF;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQUC,EAAW,QAAgB,gBAAgB,KAAKE,GAAuB;AAI/E,WAAO,gBACH,OAAO,QAAQ,eAAe,GAAG,EAAE,SACnC,OAAO;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQAI,EAAQ,QAAQ,GAAG;AACjB,SAAKL,IAAY,KAAK,IAAI,KAAKF,GAAW,KAAKE,IAAY,KAAK;A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AAA;AAAA;AAAA,EAMAjB,EAAc,QAAgB;AAC5B,QAAI,EAAE,OAAO,IAAI;AAEjB,aAAS,IAAI,GAAG,IAAI,QAAQ,EAAE,GAAG;AAC/B,UAAI,KAAK,OAAO,YAAY,CAAC;AAE7B,UAAI,CAAQ,eAAe,EAAE,GAAG;AAC9B,aAAKpB,EAAQgC,EAAM,EAAE,CAAE,GAAG,MAAO,EAAE,SAAS,EAAE;AAC9C,cAAM,KAAK1B,EAAM,mBAAmB;AAAA,MACtC;AAEA,UAAI,KAAK,OAAO;AACd,aAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACF;AAQA,SAAS,oBAAoB,MAAsB;AACjD,MAAI,IAAI;AAER,UAAQ,IAAI,KAAK,QAAQ,MAAM,CAAC,OAAO,IAAI;AACzC,WAAO,KAAK,IAAI,CAAC,MAAM,OACnB,KAAK,MAAM,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IACnC,KAAK,MAAM,GAAG,CAAC,IAAI,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,EAChD;AAEA,SAAO;AACT;;;AbjxBO,SAAS,SAAS,KAAa,SAAyB;AAC7D,SAAQ,IAAI,OAAO,KAAK,OAAO,EAAG;AACpC;",
6
- "names": ["charCount", "charLength", "charIndex", "multiByteMode", "string", "charsToBytes", "isEnd", "advance", "charIndexToByteIndex", "consume", "peek", "consumeMatch", "consumeMatchFn", "consumeString", "consumeStringFast", "consumeUntilMatch", "consumeUntilString", "reset", "emptyString", "scanner", "currentNode", "options", "consumeStringFast", "consumeProlog", "consumeElement", "error", "consumeMisc", "isEnd", "addNode", "charIndexToByteIndex", "addText", "consumeAttributes", "consumeWhitespace", "consumeName", "consumeEqual", "consumeAttributeValue", "peek", "advance", "consumeMatch", "validateChars", "consumeReference", "consumeCdataSection", "charIndex", "consumeUntilString", "consumeCharData", "consumeUntilMatch", "consumeComment", "consumeContentReference", "consumeDoctypeDeclaration", "consumePubidLiteral", "consumeSystemLiteral", "reset", "consumeProcessingInstruction", "consumeMatchFn", "consumeXmlDeclaration", "consume", "string"]
4
+ "sourcesContent": ["import { Parser } from './lib/Parser.js';\n\nimport type { ParserOptions } from './lib/Parser.js';\n\nexport * from './lib/types.js';\nexport { XmlCdata } from './lib/XmlCdata.js';\nexport { XmlComment } from './lib/XmlComment.js';\nexport { XmlDeclaration } from './lib/XmlDeclaration.js';\nexport { XmlDocument } from './lib/XmlDocument.js';\nexport { XmlDocumentType } from './lib/XmlDocumentType.js';\nexport { XmlElement } from './lib/XmlElement.js';\nexport { XmlError } from './lib/XmlError.js';\nexport { XmlNode } from './lib/XmlNode.js';\nexport { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';\nexport { XmlText } from './lib/XmlText.js';\n\nexport type { ParserOptions } from './lib/Parser.js';\n\n/**\n * Parses the given XML string and returns an `XmlDocument` instance\n * representing the document tree.\n *\n * @example\n *\n * import { parseXml } from '@rgrove/parse-xml';\n * let doc = parseXml('<kittens fuzzy=\"yes\">I like fuzzy kittens.</kittens>');\n *\n * @param xml XML string to parse.\n * @param options Parser options.\n */\nexport function parseXml(xml: string, options?: ParserOptions) {\n return (new Parser(xml, options)).document;\n}\n", "const emptyString = '';\nconst surrogatePair = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\n/** @private */\nexport class StringScanner {\n charIndex: number;\n readonly string: string;\n\n private readonly charCount: number;\n private readonly charsToBytes: number[] | undefined;\n private readonly length: number;\n private readonly multiByteMode: boolean;\n\n constructor(string: string) {\n this.charCount = this.charLength(string, true);\n this.charIndex = 0;\n this.length = string.length;\n this.multiByteMode = this.charCount !== this.length;\n this.string = string;\n\n if (this.multiByteMode) {\n let charsToBytes = [];\n\n // Create a mapping of character indexes to byte indexes. Since the string\n // contains multibyte characters, a byte index may not necessarily align\n // with a character index.\n for (let byteIndex = 0, charIndex = 0; charIndex < this.charCount; ++charIndex) {\n charsToBytes[charIndex] = byteIndex;\n byteIndex += (string.codePointAt(byteIndex) as number) > 65535 ? 2 : 1;\n }\n\n this.charsToBytes = charsToBytes;\n }\n }\n\n /**\n * Whether the current character index is at the end of the input string.\n */\n get isEnd() {\n return this.charIndex >= this.charCount;\n }\n\n // -- Protected Methods ------------------------------------------------------\n\n /**\n * Returns the number of characters in the given string, which may differ from\n * the byte length if the string contains multibyte characters.\n */\n protected charLength(string: string, multiByteSafe = this.multiByteMode): number {\n // We could get the char length with `[ ...string ].length`, but that's\n // actually slower than replacing surrogate pairs with single-byte\n // characters and then counting the result.\n return multiByteSafe\n ? string.replace(surrogatePair, '_').length\n : string.length;\n }\n\n // -- Public Methods ---------------------------------------------------------\n\n /**\n * Advances the scanner by the given number of characters, stopping if the end\n * of the string is reached.\n */\n advance(count = 1) {\n this.charIndex = Math.min(this.charCount, this.charIndex + count);\n }\n\n /**\n * Returns the byte index of the given character index in the string. The two\n * may differ in strings that contain multibyte characters.\n */\n charIndexToByteIndex(charIndex: number = this.charIndex): number {\n return this.multiByteMode\n ? (this.charsToBytes as number[])[charIndex] ?? Infinity\n : charIndex;\n }\n\n /**\n * Consumes and returns the given number of characters if possible, advancing\n * the scanner and stopping if the end of the string is reached.\n *\n * If no characters could be consumed, an empty string will be returned.\n */\n consume(charCount = 1): string {\n let chars = this.peek(charCount);\n this.advance(charCount);\n return chars;\n }\n\n /**\n * Consumes and returns the given number of bytes if possible, advancing the\n * scanner and stopping if the end of the string is reached.\n *\n * It's up to the caller to ensure that the given byte count doesn't split a\n * multibyte character.\n *\n * If no bytes could be consumed, an empty string will be returned.\n */\n consumeBytes(byteCount: number): string {\n let byteIndex = this.charIndexToByteIndex();\n let result = this.string.slice(byteIndex, byteIndex + byteCount);\n this.advance(this.charLength(result));\n return result;\n }\n\n /**\n * Consumes and returns all characters for which the given function returns\n * `true`, stopping when `false` is returned or the end of the input is\n * reached.\n */\n consumeMatchFn(fn: (char: string) => boolean): string {\n let { length, multiByteMode, string } = this;\n let startByteIndex = this.charIndexToByteIndex();\n let endByteIndex = startByteIndex;\n\n if (multiByteMode) {\n while (endByteIndex < length) {\n let char = string[endByteIndex] as string;\n let isSurrogatePair = char >= '\\uD800' && char <= '\\uDBFF';\n\n if (isSurrogatePair) {\n char += string[endByteIndex + 1];\n }\n\n if (!fn(char)) {\n break;\n }\n\n endByteIndex += isSurrogatePair ? 2 : 1;\n }\n } else {\n while (endByteIndex < length && fn(string[endByteIndex] as string)) {\n ++endByteIndex;\n }\n }\n\n return this.consumeBytes(endByteIndex - startByteIndex);\n }\n\n /**\n * Consumes the given string if it exists at the current character index, and\n * advances the scanner.\n *\n * If the given string doesn't exist at the current character index, an empty\n * string will be returned and the scanner will not be advanced.\n */\n consumeString(stringToConsume: string): string {\n let { length } = stringToConsume;\n let byteIndex = this.charIndexToByteIndex();\n\n if (stringToConsume === this.string.slice(byteIndex, byteIndex + length)) {\n this.advance(length === 1 ? 1 : this.charLength(stringToConsume));\n return stringToConsume;\n }\n\n return emptyString;\n }\n\n /**\n * Consumes characters until the given global regex is matched, advancing the\n * scanner up to (but not beyond) the beginning of the match. If the regex\n * doesn't match, nothing will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilMatch(regex: RegExp): string {\n let matchByteIndex = this.string\n .slice(this.charIndexToByteIndex())\n .search(regex);\n\n return matchByteIndex > 0\n ? this.consumeBytes(matchByteIndex)\n : emptyString;\n }\n\n /**\n * Consumes characters until the given string is found, advancing the scanner\n * up to (but not beyond) that point. If the string is never found, nothing\n * will be consumed.\n *\n * Returns the consumed string, or an empty string if nothing was consumed.\n */\n consumeUntilString(searchString: string): string {\n let byteIndex = this.charIndexToByteIndex();\n let matchByteIndex = this.string.indexOf(searchString, byteIndex);\n\n return matchByteIndex > 0\n ? this.consumeBytes(matchByteIndex - byteIndex)\n : emptyString;\n }\n\n /**\n * Returns the given number of characters starting at the current character\n * index, without advancing the scanner and without exceeding the end of the\n * input string.\n */\n peek(count = 1): string {\n let { charIndex, string } = this;\n\n return this.multiByteMode\n ? string.slice(this.charIndexToByteIndex(charIndex), this.charIndexToByteIndex(charIndex + count))\n : string.slice(charIndex, charIndex + count);\n }\n\n /**\n * Resets the scanner position to the given character _index_, or to the start\n * of the input string if no index is given.\n *\n * If _index_ is negative, the scanner position will be moved backward by that\n * many characters, stopping if the beginning of the string is reached.\n */\n reset(index = 0) {\n this.charIndex = index >= 0\n ? Math.min(this.charCount, index)\n : Math.max(0, this.charIndex + index);\n }\n}\n", "/**\n * Regular expression that matches one or more `AttValue` characters in a\n * double-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharDoubleQuote = /[\"&<]/;\n\n/**\n * Regular expression that matches one or more `AttValue` characters in a\n * single-quoted attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\nexport const attValueCharSingleQuote = /['&<]/;\n\n/**\n * Regular expression that matches a whitespace character that should be\n * normalized to a space character in an attribute value.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize\n */\nexport const attValueNormalizedWhitespace = /\\r\\n|[\\n\\r\\t]/g;\n\n/**\n * Regular expression that matches one or more characters that signal the end of\n * XML `CharData` content.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\nexport const endCharData = /<|&|]]>/;\n\n/**\n * Mapping of predefined entity names to their replacement values.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent\n */\nexport const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {\n amp: '&',\n apos: \"'\",\n gt: '>',\n lt: '<',\n quot: '\"',\n}));\n\n/**\n * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar\n */\nexport function isNameChar(char: string): boolean {\n let cp = char.codePointAt(0) as number;\n\n // Including the most common NameStartChars here improves performance\n // slightly.\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || (cp >= 0x30 && cp <= 0x39) // 0-9\n || cp === 0x2D // -\n || cp === 0x2E // .\n || cp === 0xB7\n || (cp >= 0x300 && cp <= 0x36F)\n || cp === 0x203F\n || cp === 0x2040\n || isNameStartChar(char, cp);\n}\n\n/**\n * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar\n */\nexport function isNameStartChar(char: string, cp = char.codePointAt(0) as number): boolean {\n return (cp >= 0x61 && cp <= 0x7A) // a-z\n || (cp >= 0x41 && cp <= 0x5A) // A-Z\n || cp === 0x3A // :\n || cp === 0x5F // _\n || (cp >= 0xC0 && cp <= 0xD6)\n || (cp >= 0xD8 && cp <= 0xF6)\n || (cp >= 0xF8 && cp <= 0x2FF)\n || (cp >= 0x370 && cp <= 0x37D)\n || (cp >= 0x37F && cp <= 0x1FFF)\n || cp === 0x200C\n || cp === 0x200D\n || (cp >= 0x2070 && cp <= 0x218F)\n || (cp >= 0x2C00 && cp <= 0x2FEF)\n || (cp >= 0x3001 && cp <= 0xD7FF)\n || (cp >= 0xF900 && cp <= 0xFDCF)\n || (cp >= 0xFDF0 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0xEFFFF);\n}\n\n/**\n * Returns `true` if _char_ is a valid reference character (which may appear\n * between `&` and `;` in a reference), `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references\n */\nexport function isReferenceChar(char: string): boolean {\n return char === '#' || isNameChar(char);\n}\n\n/**\n * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\nexport function isWhitespace(char: string): boolean {\n let cp = char.codePointAt(0);\n\n return cp === 0x20\n || cp === 0x9\n || cp === 0xA\n || cp === 0xD;\n}\n\n/**\n * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`\n * otherwise.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char\n */\nexport function isXmlCodePoint(cp: number): boolean {\n return (cp >= 0x20 && cp <= 0xD7FF)\n || cp === 0xA\n || cp === 0x9\n || cp === 0xD\n || (cp >= 0xE000 && cp <= 0xFFFD)\n || (cp >= 0x10000 && cp <= 0x10FFFF);\n}\n", "import type { JsonObject } from './types.js';\nimport type { XmlDocument } from './XmlDocument.js';\nimport type { XmlElement } from './XmlElement.js';\n\n/**\n * Base interface for a node in an XML document.\n */\nexport class XmlNode {\n /**\n * Type value for an `XmlCdata` node.\n */\n static readonly TYPE_CDATA = 'cdata';\n\n /**\n * Type value for an `XmlComment` node.\n */\n static readonly TYPE_COMMENT = 'comment';\n\n /**\n * Type value for an `XmlDocument` node.\n */\n static readonly TYPE_DOCUMENT = 'document';\n\n /**\n * Type value for an `XmlDocumentType` node.\n */\n static readonly TYPE_DOCUMENT_TYPE = 'doctype';\n\n /**\n * Type value for an `XmlElement` node.\n */\n static readonly TYPE_ELEMENT = 'element';\n\n /**\n * Type value for an `XmlProcessingInstruction` node.\n */\n static readonly TYPE_PROCESSING_INSTRUCTION = 'pi';\n\n /**\n * Type value for an `XmlText` node.\n */\n static readonly TYPE_TEXT = 'text';\n\n /**\n * Type value for an `XmlDeclaration` node.\n */\n static readonly TYPE_XML_DECLARATION = 'xmldecl';\n\n /**\n * Parent node of this node, or `null` if this node has no parent.\n */\n parent: XmlDocument | XmlElement | null = null;\n\n /**\n * Starting byte offset of this node in the original XML string, or `-1` if\n * the offset is unknown.\n */\n start = -1;\n\n /**\n * Ending byte offset of this node in the original XML string, or `-1` if the\n * offset is unknown.\n */\n end = -1;\n\n /**\n * Document that contains this node, or `null` if this node is not associated\n * with a document.\n */\n get document(): XmlDocument | null {\n return this.parent?.document ?? null;\n }\n\n /**\n * Whether this node is the root node of the document (also known as the\n * document element).\n */\n get isRootNode(): boolean {\n return this.parent !== null\n && this.parent === this.document\n && this.type === XmlNode.TYPE_ELEMENT;\n }\n\n /**\n * Whether whitespace should be preserved in the content of this element and\n * its children.\n *\n * This is influenced by the value of the special `xml:space` attribute, and\n * will be `true` for any node whose `xml:space` attribute is set to\n * \"preserve\". If a node has no such attribute, it will inherit the value of\n * the nearest ancestor that does (if any).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space\n */\n get preserveWhitespace(): boolean {\n return !!this.parent?.preserveWhitespace;\n }\n\n /**\n * Type of this node.\n *\n * The value of this property is a string that matches one of the static\n * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,\n * `TYPE_TEXT`, etc.).\n *\n * The `XmlNode` class itself is a base class and doesn't have its own type\n * name.\n */\n get type() {\n return '';\n }\n\n /**\n * Returns a JSON-serializable object representing this node, minus properties\n * that could result in circular references.\n */\n toJSON(): JsonObject {\n let json: JsonObject = {\n type: this.type,\n };\n\n if (this.isRootNode) {\n json.isRootNode = true;\n }\n\n if (this.preserveWhitespace) {\n json.preserveWhitespace = true;\n }\n\n if (this.start !== -1) {\n json.start = this.start;\n json.end = this.end;\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * Text content within an XML document.\n */\nexport class XmlText extends XmlNode {\n /**\n * Text content of this node.\n */\n text: string;\n\n constructor(text = '') {\n super();\n this.text = text;\n }\n\n override get type() {\n return XmlNode.TYPE_TEXT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n text: this.text,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\nimport { XmlText } from './XmlText.js';\n\n/**\n * A CDATA section within an XML document.\n */\nexport class XmlCdata extends XmlText {\n override get type() {\n return XmlNode.TYPE_CDATA;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A comment within an XML document.\n */\nexport class XmlComment extends XmlNode {\n /**\n * Content of this comment.\n */\n content: string;\n\n constructor(content = '') {\n super();\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_COMMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n content: this.content,\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * An XML declaration within an XML document.\n *\n * @example\n *\n * ```xml\n * <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n * ```\n */\nexport class XmlDeclaration extends XmlNode {\n /**\n * Value of the encoding declaration in this XML declaration, or `null` if no\n * encoding declaration was present.\n */\n encoding: string | null;\n\n /**\n * Value of the standalone declaration in this XML declaration, or `null` if\n * no standalone declaration was present.\n */\n standalone: 'yes' | 'no' | null;\n\n /**\n * Value of the version declaration in this XML declaration.\n */\n version: string;\n\n constructor(\n version: string,\n encoding?: string,\n standalone?: typeof XmlDeclaration.prototype.standalone,\n ) {\n super();\n\n this.version = version;\n this.encoding = encoding ?? null;\n this.standalone = standalone ?? null;\n }\n\n override get type() {\n return XmlNode.TYPE_XML_DECLARATION;\n }\n\n override toJSON() {\n let json = XmlNode.prototype.toJSON.call(this);\n json.version = this.version;\n\n for (let key of ['encoding', 'standalone'] as const) {\n if (this[key] !== null) {\n json[key] = this[key];\n }\n }\n\n return json;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\nimport type { JsonObject } from './types.js';\nimport type { XmlCdata } from './XmlCdata.js';\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport type { XmlText } from './XmlText.js';\n\n/**\n * Element in an XML document.\n */\nexport class XmlElement extends XmlNode {\n /**\n * Attributes on this element.\n */\n attributes: {[attrName: string]: string};\n\n /**\n * Child nodes of this element.\n */\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;\n\n /**\n * Name of this element.\n */\n name: string;\n\n constructor(\n name: string,\n attributes: {[attrName: string]: string} = Object.create(null),\n children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText> = [],\n ) {\n super();\n\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n\n /**\n * Whether this element is empty (meaning it has no children).\n */\n get isEmpty(): boolean {\n return this.children.length === 0;\n }\n\n override get preserveWhitespace(): boolean {\n let node: XmlNode | null = this; // eslint-disable-line @typescript-eslint/no-this-alias\n\n while (node instanceof XmlElement) {\n if ('xml:space' in node.attributes) {\n return node.attributes['xml:space'] === 'preserve';\n }\n\n node = node.parent;\n }\n\n return false;\n }\n\n /**\n * Text content of this element and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_ELEMENT;\n }\n\n override toJSON(): JsonObject {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n attributes: this.attributes,\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlElement } from './XmlElement.js';\nimport { XmlNode } from './XmlNode.js';\n\nimport type { XmlComment } from './XmlComment.js';\nimport type { XmlDeclaration } from './XmlDeclaration.js';\nimport type { XmlDocumentType } from './XmlDocumentType.js';\nimport type { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\n\n/**\n * Represents an XML document. All elements within the document are descendants\n * of this node.\n */\nexport class XmlDocument extends XmlNode {\n /**\n * Child nodes of this document.\n */\n readonly children: Array<XmlComment | XmlDeclaration | XmlDocumentType | XmlProcessingInstruction | XmlElement>;\n\n constructor(children: Array<XmlComment | XmlDeclaration | XmlDocumentType | XmlElement | XmlProcessingInstruction> = []) {\n super();\n this.children = children;\n }\n\n override get document() {\n return this;\n }\n\n /**\n * Root element of this document, or `null` if this document is empty.\n */\n get root(): XmlElement | null {\n for (let child of this.children) {\n if (child instanceof XmlElement) {\n return child;\n }\n }\n\n return null;\n }\n\n /**\n * Text content of this document and all its descendants.\n */\n get text(): string {\n return this.children\n .map(child => 'text' in child ? child.text : '')\n .join('');\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n children: this.children.map(child => child.toJSON()),\n });\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A document type declaration within an XML document.\n *\n * @example\n *\n * ```xml\n * <!DOCTYPE kittens [\n * <!ELEMENT kittens (#PCDATA)>\n * ]>\n * ```\n */\nexport class XmlDocumentType extends XmlNode {\n /**\n * Name of the root element described by this document type declaration.\n */\n name: string;\n\n /**\n * Public identifier of the external subset of this document type declaration,\n * or `null` if no public identifier was present.\n */\n publicId: string | null;\n\n /**\n * System identifier of the external subset of this document type declaration,\n * or `null` if no system identifier was present.\n */\n systemId: string | null;\n\n /**\n * Internal subset of this document type declaration, or `null` if no internal\n * subset was present.\n */\n internalSubset: string | null;\n\n constructor(\n name: string,\n publicId?: string,\n systemId?: string,\n internalSubset?: string,\n ) {\n super();\n this.name = name;\n this.publicId = publicId ?? null;\n this.systemId = systemId ?? null;\n this.internalSubset = internalSubset ?? null;\n }\n\n override get type() {\n return XmlNode.TYPE_DOCUMENT_TYPE;\n }\n\n override toJSON() {\n let json = XmlNode.prototype.toJSON.call(this);\n json.name = this.name;\n\n for (let key of ['publicId', 'systemId', 'internalSubset'] as const) {\n if (this[key] !== null) {\n json[key] = this[key];\n }\n }\n\n return json;\n }\n}\n", "/**\n * An error that occurred while parsing XML.\n */\nexport class XmlError extends Error {\n /**\n * Character column at which this error occurred (1-based).\n */\n readonly column: number;\n\n /**\n * Short excerpt from the input string that contains the problem.\n */\n readonly excerpt: string;\n\n /**\n * Line number at which this error occurred (1-based).\n */\n readonly line: number;\n\n /**\n * Character position at which this error occurred relative to the beginning\n * of the input (0-based).\n */\n readonly pos: number;\n\n constructor(\n message: string,\n charIndex: number,\n xml: string,\n ) {\n let column = 1;\n let excerpt = '';\n let line = 1;\n\n // Find the line and column where the error occurred.\n for (let i = 0; i < charIndex; ++i) {\n let char = xml[i];\n\n if (char === '\\n') {\n column = 1;\n excerpt = '';\n line += 1;\n } else {\n column += 1;\n excerpt += char;\n }\n }\n\n let eol = xml.indexOf('\\n', charIndex);\n\n excerpt += eol === -1\n ? xml.slice(charIndex)\n : xml.slice(charIndex, eol);\n\n let excerptStart = 0;\n\n // Keep the excerpt below 50 chars, but always keep the error position in\n // view.\n if (excerpt.length > 50) {\n if (column < 40) {\n excerpt = excerpt.slice(0, 50);\n } else {\n excerptStart = column - 20;\n excerpt = excerpt.slice(excerptStart, column + 30);\n }\n }\n\n super(\n `${message} (line ${line}, column ${column})\\n`\n + ` ${excerpt}\\n`\n + ' '.repeat(column - excerptStart + 1) + '^\\n',\n );\n\n this.column = column;\n this.excerpt = excerpt;\n this.line = line;\n this.name = 'XmlError';\n this.pos = charIndex;\n }\n}\n", "import { XmlNode } from './XmlNode.js';\n\n/**\n * A processing instruction within an XML document.\n */\nexport class XmlProcessingInstruction extends XmlNode {\n /**\n * Content of this processing instruction.\n */\n content: string;\n\n /**\n * Name of this processing instruction. Also sometimes referred to as the\n * processing instruction \"target\".\n */\n name: string;\n\n constructor(name: string, content = '') {\n super();\n\n this.name = name;\n this.content = content;\n }\n\n override get type() {\n return XmlNode.TYPE_PROCESSING_INSTRUCTION;\n }\n\n override toJSON() {\n return Object.assign(XmlNode.prototype.toJSON.call(this), {\n name: this.name,\n content: this.content,\n });\n }\n}\n", "import { StringScanner } from './StringScanner.js';\nimport * as syntax from './syntax.js';\nimport { XmlCdata } from './XmlCdata.js';\nimport { XmlComment } from './XmlComment.js';\nimport { XmlDeclaration } from './XmlDeclaration.js';\nimport { XmlDocument } from './XmlDocument.js';\nimport { XmlDocumentType } from './XmlDocumentType.js';\nimport { XmlElement } from './XmlElement.js';\nimport { XmlError } from './XmlError.js';\nimport { XmlNode } from './XmlNode.js';\nimport { XmlProcessingInstruction } from './XmlProcessingInstruction.js';\nimport { XmlText } from './XmlText.js';\n\nconst emptyString = '';\n\n/**\n * Parses an XML string into an `XmlDocument`.\n *\n * @private\n */\nexport class Parser {\n readonly document: XmlDocument;\n\n private currentNode: XmlDocument | XmlElement;\n private readonly options: ParserOptions;\n private readonly scanner: StringScanner;\n\n /**\n * @param xml XML string to parse.\n * @param options Parser options.\n */\n constructor(xml: string, options: ParserOptions = {}) {\n let doc = this.document = new XmlDocument();\n\n this.currentNode = doc;\n this.options = options;\n this.scanner = new StringScanner(xml);\n\n if (this.options.includeOffsets) {\n doc.start = 0;\n doc.end = xml.length;\n }\n\n this.parse();\n }\n\n /**\n * Adds the given `XmlNode` as a child of `this.currentNode`.\n */\n addNode(node: XmlNode, charIndex: number) {\n node.parent = this.currentNode;\n\n if (this.options.includeOffsets) {\n node.start = this.scanner.charIndexToByteIndex(charIndex);\n node.end = this.scanner.charIndexToByteIndex();\n }\n\n // @ts-expect-error: XmlDocument has a more limited set of possible children\n // than XmlElement so TypeScript is unhappy, but we always do the right\n // thing.\n this.currentNode.children.push(node);\n return true;\n }\n\n /**\n * Adds the given _text_ to the document, either by appending it to a\n * preceding `XmlText` node (if possible) or by creating a new `XmlText` node.\n *\n * When _normalize_ is `true` (the default), line breaks in _text_ are\n * normalized per section 2.11 of the XML spec. This must be `false` for text\n * that comes from a character or entity reference, since references aren't\n * subject to line break normalization.\n */\n addText(text: string, charIndex: number, normalize = true) {\n let { children } = this.currentNode;\n let { length } = children;\n\n if (normalize) {\n text = normalizeLineBreaks(text);\n }\n\n if (length > 0) {\n let prevNode = children[length - 1];\n\n if (prevNode?.type === XmlNode.TYPE_TEXT) {\n let textNode = prevNode as XmlText;\n\n // The previous node is a text node, so we can append to it and avoid\n // creating another node.\n textNode.text += text;\n\n if (this.options.includeOffsets) {\n textNode.end = this.scanner.charIndexToByteIndex();\n }\n\n return true;\n }\n }\n\n return this.addNode(new XmlText(text), charIndex);\n }\n\n /**\n * Consumes element attributes.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags\n */\n consumeAttributes(): Record<string, string> {\n let attributes = Object.create(null);\n\n while (this.consumeWhitespace()) {\n let attrName = this.consumeName();\n\n if (!attrName) {\n break;\n }\n\n let attrValue = this.consumeEqual() && this.consumeAttributeValue();\n\n if (attrValue === false) {\n throw this.error('Attribute value expected');\n }\n\n if (attrName in attributes) {\n throw this.error(`Duplicate attribute: ${attrName}`);\n }\n\n if (attrName === 'xml:space'\n && attrValue !== 'default'\n && attrValue !== 'preserve') {\n\n throw this.error('Value of the `xml:space` attribute must be \"default\" or \"preserve\"');\n }\n\n attributes[attrName] = attrValue;\n }\n\n if (this.options.sortAttributes) {\n let attrNames = Object.keys(attributes).sort();\n let sortedAttributes = Object.create(null);\n\n for (let i = 0; i < attrNames.length; ++i) {\n let attrName = attrNames[i] as string;\n sortedAttributes[attrName] = attributes[attrName];\n }\n\n attributes = sortedAttributes;\n }\n\n return attributes;\n }\n\n /**\n * Consumes an `AttValue` (attribute value) if possible.\n *\n * @returns\n * Contents of the `AttValue` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that an `AttValue` was consumed but\n * was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue\n */\n consumeAttributeValue(): string | false {\n let { scanner } = this;\n let quote = scanner.peek();\n\n if (quote !== '\"' && quote !== \"'\") {\n return false;\n }\n\n scanner.advance();\n\n let chars;\n let isClosed = false;\n let value = emptyString;\n let regex = quote === '\"'\n ? syntax.attValueCharDoubleQuote\n : syntax.attValueCharSingleQuote;\n\n matchLoop: while (!scanner.isEnd) {\n chars = scanner.consumeUntilMatch(regex);\n\n if (chars) {\n this.validateChars(chars);\n value += chars.replace(syntax.attValueNormalizedWhitespace, ' ');\n }\n\n switch (scanner.peek()) {\n case quote:\n isClosed = true;\n break matchLoop;\n\n case '&':\n value += this.consumeReference();\n continue;\n\n case '<':\n throw this.error('Unescaped `<` is not allowed in an attribute value');\n\n default:\n break matchLoop;\n }\n }\n\n if (!isClosed) {\n throw this.error('Unclosed attribute');\n }\n\n scanner.advance();\n return value;\n }\n\n /**\n * Consumes a CDATA section if possible.\n *\n * @returns Whether a CDATA section was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect\n */\n consumeCdataSection(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<![CDATA[')) {\n return false;\n }\n\n let text = scanner.consumeUntilString(']]>');\n this.validateChars(text);\n\n if (!scanner.consumeString(']]>')) {\n throw this.error('Unclosed CDATA section');\n }\n\n return this.options.preserveCdata\n ? this.addNode(new XmlCdata(normalizeLineBreaks(text)), startIndex)\n : this.addText(text, startIndex);\n }\n\n /**\n * Consumes character data if possible.\n *\n * @returns Whether character data was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata\n */\n consumeCharData(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n let charData = scanner.consumeUntilMatch(syntax.endCharData);\n\n if (!charData) {\n return false;\n }\n\n this.validateChars(charData);\n\n if (scanner.peek(3) === ']]>') {\n throw this.error('Element content may not contain the CDATA section close delimiter `]]>`');\n }\n\n return this.addText(charData, startIndex);\n }\n\n /**\n * Consumes a comment if possible.\n *\n * @returns Whether a comment was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment\n */\n consumeComment(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<!--')) {\n return false;\n }\n\n let content = scanner.consumeUntilString('--');\n this.validateChars(content);\n\n if (!scanner.consumeString('-->')) {\n if (scanner.peek(2) === '--') {\n throw this.error(\"The string `--` isn't allowed inside a comment\");\n }\n\n throw this.error('Unclosed comment');\n }\n\n return this.options.preserveComments\n ? this.addNode(new XmlComment(normalizeLineBreaks(content)), startIndex)\n : true;\n }\n\n /**\n * Consumes a reference in a content context if possible.\n *\n * This differs from `consumeReference()` in that a consumed reference will be\n * added to the document as a text node instead of returned.\n *\n * @returns Whether a reference was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc\n */\n consumeContentReference(): boolean {\n let startIndex = this.scanner.charIndex;\n let ref = this.consumeReference();\n\n return ref\n ? this.addText(ref, startIndex, false)\n : false;\n }\n\n /**\n * Consumes a doctype declaration if possible.\n *\n * This is a loose implementation since doctype declarations are currently\n * discarded without further parsing.\n *\n * @returns Whether a doctype declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd\n */\n consumeDoctypeDeclaration(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<!DOCTYPE')) {\n return false;\n }\n\n let name = this.consumeWhitespace()\n && this.consumeName();\n\n if (!name) {\n throw this.error('Expected a name');\n }\n\n let publicId;\n let systemId;\n\n if (this.consumeWhitespace()) {\n if (scanner.consumeString('PUBLIC')) {\n publicId = this.consumeWhitespace()\n && this.consumePubidLiteral();\n\n if (publicId === false) {\n throw this.error('Expected a public identifier');\n }\n\n this.consumeWhitespace();\n }\n\n if (publicId !== undefined || scanner.consumeString('SYSTEM')) {\n this.consumeWhitespace();\n systemId = this.consumeSystemLiteral();\n\n if (systemId === false) {\n throw this.error('Expected a system identifier');\n }\n\n this.consumeWhitespace();\n }\n }\n\n let internalSubset;\n\n if (scanner.consumeString('[')) {\n // The internal subset may contain comments that contain `]` characters,\n // so we can't use `consumeUntilString()` here.\n internalSubset = scanner.consumeUntilMatch(/\\][\\x20\\t\\r\\n]*>/);\n\n if (!scanner.consumeString(']')) {\n throw this.error('Unclosed internal subset');\n }\n\n this.consumeWhitespace();\n }\n\n if (!scanner.consumeString('>')) {\n throw this.error('Unclosed doctype declaration');\n }\n\n return this.options.preserveDocumentType\n ? this.addNode(new XmlDocumentType(name, publicId, systemId, internalSubset), startIndex)\n : true;\n }\n\n /**\n * Consumes an element if possible.\n *\n * @returns Whether an element was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element\n */\n consumeElement(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (!name) {\n scanner.reset(startIndex);\n return false;\n }\n\n let attributes = this.consumeAttributes();\n let isEmpty = !!scanner.consumeString('/>');\n let element = new XmlElement(name, attributes);\n\n element.parent = this.currentNode;\n\n if (!isEmpty) {\n if (!scanner.consumeString('>')) {\n throw this.error(`Unclosed start tag for element \\`${name}\\``);\n }\n\n this.currentNode = element;\n\n do {\n this.consumeCharData();\n } while (\n this.consumeElement()\n || this.consumeContentReference()\n || this.consumeCdataSection()\n || this.consumeProcessingInstruction()\n || this.consumeComment()\n );\n\n let endTagMark = scanner.charIndex;\n let endTagName;\n\n if (!scanner.consumeString('</')\n || !(endTagName = this.consumeName())\n || endTagName !== name) {\n\n scanner.reset(endTagMark);\n throw this.error(`Missing end tag for element ${name}`);\n }\n\n this.consumeWhitespace();\n\n if (!scanner.consumeString('>')) {\n throw this.error(`Unclosed end tag for element ${name}`);\n }\n\n this.currentNode = element.parent;\n }\n\n return this.addNode(element, startIndex);\n }\n\n /**\n * Consumes an `Eq` production if possible.\n *\n * @returns Whether an `Eq` production was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq\n */\n consumeEqual(): boolean {\n this.consumeWhitespace();\n\n if (this.scanner.consumeString('=')) {\n this.consumeWhitespace();\n return true;\n }\n\n return false;\n }\n\n /**\n * Consumes `Misc` content if possible.\n *\n * @returns Whether anything was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc\n */\n consumeMisc(): boolean {\n return this.consumeComment()\n || this.consumeProcessingInstruction()\n || this.consumeWhitespace();\n }\n\n /**\n * Consumes one or more `Name` characters if possible.\n *\n * @returns `Name` characters, or an empty string if none were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name\n */\n consumeName(): string {\n return syntax.isNameStartChar(this.scanner.peek())\n ? this.scanner.consumeMatchFn(syntax.isNameChar)\n : emptyString;\n }\n\n /**\n * Consumes a processing instruction if possible.\n *\n * @returns Whether a processing instruction was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi\n */\n consumeProcessingInstruction(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<?')) {\n return false;\n }\n\n let name = this.consumeName();\n\n if (name) {\n if (name.toLowerCase() === 'xml') {\n scanner.reset(startIndex);\n throw this.error(\"XML declaration isn't allowed here\");\n }\n } else {\n throw this.error('Invalid processing instruction');\n }\n\n if (!this.consumeWhitespace()) {\n if (scanner.consumeString('?>')) {\n return this.addNode(new XmlProcessingInstruction(name), startIndex);\n }\n\n throw this.error('Whitespace is required after a processing instruction name');\n }\n\n let content = scanner.consumeUntilString('?>');\n this.validateChars(content);\n\n if (!scanner.consumeString('?>')) {\n throw this.error('Unterminated processing instruction');\n }\n\n return this.addNode(new XmlProcessingInstruction(name, normalizeLineBreaks(content)), startIndex);\n }\n\n /**\n * Consumes a prolog if possible.\n *\n * @returns Whether a prolog was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd\n */\n consumeProlog(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n this.consumeXmlDeclaration();\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (this.consumeDoctypeDeclaration()) {\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n }\n\n return startIndex < scanner.charIndex;\n }\n\n /**\n * Consumes a public identifier literal if possible.\n *\n * @returns\n * Value of the public identifier literal minus quotes, or `false` if\n * nothing was consumed. An empty string indicates that a public id literal\n * was consumed but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PubidLiteral\n */\n consumePubidLiteral(): string | false {\n let startIndex = this.scanner.charIndex;\n let value = this.consumeSystemLiteral();\n\n if (value !== false && !/^[-\\x20\\r\\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(value)) {\n this.scanner.reset(startIndex);\n throw this.error('Invalid character in public identifier');\n }\n\n return value;\n }\n\n /**\n * Consumes a reference if possible.\n *\n * This differs from `consumeContentReference()` in that a consumed reference\n * will be returned rather than added to the document.\n *\n * @returns\n * Parsed reference value, or `false` if nothing was consumed (to\n * distinguish from a reference that resolves to an empty string).\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference\n */\n consumeReference(): string | false {\n let { scanner } = this;\n\n if (!scanner.consumeString('&')) {\n return false;\n }\n\n let ref = scanner.consumeMatchFn(syntax.isReferenceChar);\n\n if (scanner.consume() !== ';') {\n throw this.error('Unterminated reference (a reference must end with `;`)');\n }\n\n let parsedValue;\n\n if (ref[0] === '#') {\n // This is a character reference.\n let codePoint = ref[1] === 'x'\n ? parseInt(ref.slice(2), 16) // Hex codepoint.\n : parseInt(ref.slice(1), 10); // Decimal codepoint.\n\n if (isNaN(codePoint)) {\n throw this.error('Invalid character reference');\n }\n\n if (!syntax.isXmlCodePoint(codePoint)) {\n throw this.error('Character reference resolves to an invalid character');\n }\n\n parsedValue = String.fromCodePoint(codePoint);\n } else {\n // This is an entity reference.\n parsedValue = syntax.predefinedEntities[ref];\n\n if (parsedValue === undefined) {\n let {\n ignoreUndefinedEntities,\n resolveUndefinedEntity,\n } = this.options;\n\n let wrappedRef = `&${ref};`; // for backcompat with <= 2.x\n\n if (resolveUndefinedEntity) {\n let resolvedValue = resolveUndefinedEntity(wrappedRef);\n\n if (resolvedValue !== null && resolvedValue !== undefined) {\n let type = typeof resolvedValue;\n\n if (type !== 'string') {\n throw new TypeError(`\\`resolveUndefinedEntity()\\` must return a string, \\`null\\`, or \\`undefined\\`, but returned a value of type ${type}`);\n }\n\n return resolvedValue;\n }\n }\n\n if (ignoreUndefinedEntities) {\n return wrappedRef;\n }\n\n scanner.reset(-wrappedRef.length);\n throw this.error(`Named entity isn't defined: ${wrappedRef}`);\n }\n }\n\n return parsedValue;\n }\n\n /**\n * Consumes a `SystemLiteral` if possible.\n *\n * A `SystemLiteral` is similar to an attribute value, but allows the\n * characters `<` and `&` and doesn't replace references.\n *\n * @returns\n * Value of the `SystemLiteral` minus quotes, or `false` if nothing was\n * consumed. An empty string indicates that a `SystemLiteral` was consumed\n * but was empty.\n *\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral\n */\n consumeSystemLiteral(): string | false {\n let { scanner } = this;\n let quote = scanner.consumeString('\"') || scanner.consumeString(\"'\");\n\n if (!quote) {\n return false;\n }\n\n let value = scanner.consumeUntilString(quote);\n this.validateChars(value);\n\n if (!scanner.consumeString(quote)) {\n throw this.error('Missing end quote');\n }\n\n return value;\n }\n\n /**\n * Consumes one or more whitespace characters if possible.\n *\n * @returns Whether any whitespace characters were consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white\n */\n consumeWhitespace(): boolean {\n return !!this.scanner.consumeMatchFn(syntax.isWhitespace);\n }\n\n /**\n * Consumes an XML declaration if possible.\n *\n * @returns Whether an XML declaration was consumed.\n * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl\n */\n consumeXmlDeclaration(): boolean {\n let { scanner } = this;\n let startIndex = scanner.charIndex;\n\n if (!scanner.consumeString('<?xml')) {\n return false;\n }\n\n if (!this.consumeWhitespace()) {\n throw this.error('Invalid XML declaration');\n }\n\n let version = !!scanner.consumeString('version')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (version === false) {\n throw this.error('XML version is missing or invalid');\n } else if (!/^1\\.[0-9]+$/.test(version)) {\n throw this.error('Invalid character in version number');\n }\n\n let encoding;\n let standalone;\n\n if (this.consumeWhitespace()) {\n encoding = !!scanner.consumeString('encoding')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (encoding) {\n if (!/^[A-Za-z][\\w.-]*$/.test(encoding)) {\n throw this.error('Invalid character in encoding name');\n }\n this.consumeWhitespace();\n }\n\n standalone = !!scanner.consumeString('standalone')\n && this.consumeEqual()\n && this.consumeSystemLiteral();\n\n if (standalone) {\n if (standalone !== 'yes' && standalone !== 'no') {\n throw this.error('Only \"yes\" and \"no\" are permitted as values of `standalone`');\n }\n\n this.consumeWhitespace();\n }\n }\n\n if (!scanner.consumeString('?>')) {\n throw this.error('Invalid or unclosed XML declaration');\n }\n\n return this.options.preserveXmlDeclaration\n ? this.addNode(new XmlDeclaration(\n version,\n encoding || undefined,\n (standalone as 'yes' | 'no' | false) || undefined,\n ), startIndex)\n : true;\n }\n\n /**\n * Returns an `XmlError` for the current scanner position.\n */\n error(message: string) {\n let { scanner } = this;\n return new XmlError(message, scanner.charIndex, scanner.string);\n }\n\n /**\n * Parses the XML input.\n */\n parse() {\n this.scanner.consumeString('\\uFEFF'); // byte order mark\n this.consumeProlog();\n\n if (!this.consumeElement()) {\n throw this.error('Root element is missing or invalid');\n }\n\n while (this.consumeMisc()) {} // eslint-disable-line no-empty\n\n if (!this.scanner.isEnd) {\n throw this.error('Extra content at the end of the document');\n }\n }\n\n /**\n * Throws an invalid character error if any character in the given _string_\n * isn't a valid XML character.\n */\n validateChars(string: string) {\n let { length } = string;\n\n for (let i = 0; i < length; ++i) {\n let cp = string.codePointAt(i) as number;\n\n if (!syntax.isXmlCodePoint(cp)) {\n this.scanner.reset(-([ ...string ].length - i));\n throw this.error('Invalid character');\n }\n\n if (cp > 65535) {\n i += 1;\n }\n }\n }\n}\n\n// -- Private Functions --------------------------------------------------------\n\n/**\n * Normalizes line breaks in the given text by replacing CRLF sequences and lone\n * CR characters with LF characters.\n */\nfunction normalizeLineBreaks(text: string): string {\n let i = 0;\n\n while ((i = text.indexOf('\\r', i)) !== -1) {\n text = text[i + 1] === '\\n'\n ? text.slice(0, i) + text.slice(i + 1)\n : text.slice(0, i) + '\\n' + text.slice(i + 1);\n }\n\n return text;\n}\n\n// -- Types --------------------------------------------------------------------\nexport type ParserOptions = {\n /**\n * When `true`, an undefined named entity (like \"&bogus;\") will be left in the\n * output as is instead of causing a parse error.\n *\n * @default false\n */\n ignoreUndefinedEntities?: boolean;\n\n /**\n * When `true`, the starting and ending byte offsets of each node in the input\n * string will be made available via `start` and `end` properties on the node.\n *\n * @default false\n */\n includeOffsets?: boolean;\n\n /**\n * When `true`, CDATA sections will be preserved in the document as `XmlCdata`\n * nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,\n * which keeps the node tree simpler and easier to work with.\n *\n * @default false\n */\n preserveCdata?: boolean;\n\n /**\n * When `true`, comments will be preserved in the document as `XmlComment`\n * nodes. Otherwise comments will not be included in the node tree.\n *\n * @default false\n */\n preserveComments?: boolean;\n\n /**\n * When `true`, a document type declaration (if present) will be preserved in\n * the document as an `XmlDocumentType` node. Otherwise the declaration will\n * not be included in the node tree.\n *\n * Note that when this is `true` and a document type declaration is present,\n * the DTD will precede the root node in the node tree (normally the root\n * node would be first).\n *\n * @default false\n */\n preserveDocumentType?: boolean;\n\n /**\n * When `true`, an XML declaration (if present) will be preserved in the\n * document as an `XmlDeclaration` node. Otherwise the declaration will not be\n * included in the node tree.\n *\n * Note that when this is `true` and an XML declaration is present, the\n * XML declaration will be the first child of the document (normally the root\n * node would be first).\n *\n * @default false\n */\n preserveXmlDeclaration?: boolean;\n\n /**\n * When an undefined named entity is encountered, this function will be called\n * with the entity as its only argument. It should return a string value with\n * which to replace the entity, or `null` or `undefined` to treat the entity\n * as undefined (which may result in a parse error depending on the value of\n * `ignoreUndefinedEntities`).\n */\n resolveUndefinedEntity?: (entity: string) => string | null | undefined;\n\n /**\n * When `true`, attributes in an element's `attributes` object will be sorted\n * in alphanumeric order by name. Otherwise they'll retain their original\n * order as found in the XML.\n *\n * @default false\n */\n sortAttributes?: boolean;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAGf,IAAM,gBAAN,MAAoB;AAAA,EASzB,YAAY,QAAgB;AAC1B,SAAKA,IAAY,KAAKC,EAAW,QAAQ,IAAI;AAC7C,SAAKC,IAAY;AACjB,SAAK,SAAS,OAAO;AACrB,SAAKC,IAAgB,KAAKH,MAAc,KAAK;AAC7C,SAAKI,IAAS;AAEd,QAAI,KAAKD,GAAe;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advance", "charIndexToByteIndex", "consume", "peek", "consumeBytes", "consumeMatchFn", "consumeString", "consumeUntilMatch", "consumeUntilString", "reset", "emptyString", "currentNode", "options", "scanner", "addNode", "charIndexToByteIndex", "addText", "consumeAttributes", "consumeWhitespace", "consumeName", "consumeEqual", "consumeAttributeValue", "error", "peek", "advance", "isEnd", "consumeUntilMatch", "validateChars", "consumeReference", "consumeCdataSection", "charIndex", "consumeString", "consumeUntilString", "consumeCharData", "consumeComment", "consumeContentReference", "consumeDoctypeDeclaration", "consumePubidLiteral", "consumeSystemLiteral", "consumeElement", "reset", "consumeProcessingInstruction", "consumeMisc", "consumeMatchFn", "consumeProlog", "consumeXmlDeclaration", "consume", "string"]
7
7
  }
@@ -1,11 +1,11 @@
1
- /*! @rgrove/parse-xml v4.1.0 | ISC License | Copyright Ryan Grove */
2
- "use strict";var parseXml=(()=>{var T=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var e in t)T(n,e,{get:t[e],enumerable:!0})},V=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of L(t))!$.call(n,i)&&i!==e&&T(n,i,{get:()=>t[i],enumerable:!(r=R(t,i))||r.enumerable});return n};var W=n=>V(T({},"__esModule",{value:!0}),n);var Q={};k(Q,{XmlCdata:()=>d,XmlComment:()=>p,XmlDeclaration:()=>x,XmlDocument:()=>g,XmlDocumentType:()=>y,XmlElement:()=>h,XmlError:()=>b,XmlNode:()=>s,XmlProcessingInstruction:()=>f,XmlText:()=>u,parseXml:()=>z});var c="",B=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,E=class{constructor(t){if(this.m=this.x(t,!0),this.i=0,this.length=t.length,this.f=this.m!==this.length,this.c=t,this.f){let e=[];for(let r=0,i=0;i<this.m;++i)e[i]=r,r+=t.codePointAt(r)>65535?2:1;this.O=e}}get T(){return this.i>=this.m}x(t,e=this.f){return e?t.replace(B,"_").length:t.length}o(t=1){this.i=Math.min(this.m,this.i+t)}a(t=this.i){var e;return this.f?(e=this.O[t])!=null?e:1/0:t}I(t=1){let e=this.l(t);return this.o(t),e}j(t){if(!t.sticky)throw new Error('`regex` must have a sticky flag ("y")');t.lastIndex=this.a();let e=t.exec(this.c);if(e===null||e.length===0)return c;let r=e[0];return this.o(this.x(r)),r}X(t){let e,r=c;for(;(e=this.l())&&t(e);)r+=e,this.o();return r}$(t){if(this.e(t))return t;if(this.f){let{length:e}=t,r=this.x(t);if(r!==e&&t===this.l(r))return this.o(r),t}return c}e(t){let{length:e}=t;return this.l(e)===t?(this.o(e),t):c}D(t){let e=this.c.slice(this.a()),r=e.search(t);if(r<=0)return c;let i=e.slice(0,r);return this.o(this.x(i)),i}b(t){let{c:e}=this,r=this.a(),i=e.indexOf(t,r);if(i<=0)return c;let o=e.slice(r,i);return this.o(this.x(o)),o}l(t=1){let{i:e,f:r,c:i}=this;return r?e>=this.m?c:i.slice(this.a(e),this.a(e+t)):i.slice(e,e+t)}d(t=0){this.i=t>=0?Math.min(this.m,t):Math.max(0,this.i+t)}};var S=/[^"&<]+/y,A=/[^'&<]+/y,M=/\r\n|[\n\r\t]/g,_=/<|&|]]>/,J=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function D(n){let t=P(n);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===45||t===46||t===183||t>=768&&t<=879||t>=8255&&t<=8256||C(n,t)}function C(n,t=P(n)){return t>=97&&t<=122||t>=65&&t<=90||t===58||t===95||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8204&&t<=8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function U(n){return n==="#"||D(n)}function Y(n){let t=P(n);return t===32||t===9||t===10||t===13}function N(n){return n===9||n===10||n===13||n>=32&&n<=55295||n>=57344&&n<=65533||n>=65536&&n<=1114111}function P(n){return n.codePointAt(0)||-1}var F=class{constructor(){this.parent=null;this.start=-1;this.end=-1}get document(){var t,e;return(e=(t=this.parent)==null?void 0:t.document)!=null?e:null}get isRootNode(){return this.parent!==null&&this.parent===this.document&&this.type===F.TYPE_ELEMENT}get preserveWhitespace(){var t;return!!((t=this.parent)!=null&&t.preserveWhitespace)}get type(){return""}toJSON(){let t={type:this.type};return this.isRootNode&&(t.isRootNode=!0),this.preserveWhitespace&&(t.preserveWhitespace=!0),this.start!==-1&&(t.start=this.start,t.end=this.end),t}},s=F;s.TYPE_CDATA="cdata",s.TYPE_COMMENT="comment",s.TYPE_DOCUMENT="document",s.TYPE_DOCUMENT_TYPE="doctype",s.TYPE_ELEMENT="element",s.TYPE_PROCESSING_INSTRUCTION="pi",s.TYPE_TEXT="text",s.TYPE_XML_DECLARATION="xmldecl";var u=class extends s{constructor(e=""){super();this.text=e}get type(){return s.TYPE_TEXT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{text:this.text})}};var d=class extends u{get type(){return s.TYPE_CDATA}};var p=class extends s{constructor(e=""){super();this.content=e}get type(){return s.TYPE_COMMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{content:this.content})}};var x=class extends s{constructor(e,r,i){super();this.version=e,this.encoding=r!=null?r:null,this.standalone=i!=null?i:null}get type(){return s.TYPE_XML_DECLARATION}toJSON(){let e=s.prototype.toJSON.call(this);e.version=this.version;for(let r of["encoding","standalone"])this[r]!==null&&(e[r]=this[r]);return e}};var h=class extends s{constructor(e,r=Object.create(null),i=[]){super();this.name=e,this.attributes=r,this.children=i}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let e=this;for(;e instanceof h;){if("xml:space"in e.attributes)return e.attributes["xml:space"]==="preserve";e=e.parent}return!1}get text(){return this.children.map(e=>"text"in e?e.text:"").join("")}get type(){return s.TYPE_ELEMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(e=>e.toJSON())})}};var g=class extends s{constructor(e=[]){super();this.children=e}get document(){return this}get root(){for(let e of this.children)if(e instanceof h)return e;return null}get text(){return this.children.map(e=>"text"in e?e.text:"").join("")}get type(){return s.TYPE_DOCUMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{children:this.children.map(e=>e.toJSON())})}};var y=class extends s{constructor(e,r,i,o){super();this.name=e,this.publicId=r!=null?r:null,this.systemId=i!=null?i:null,this.internalSubset=o!=null?o:null}get type(){return s.TYPE_DOCUMENT_TYPE}toJSON(){let e=s.prototype.toJSON.call(this);e.name=this.name;for(let r of["publicId","systemId","internalSubset"])this[r]!==null&&(e[r]=this[r]);return e}};var b=class extends Error{constructor(e,r,i){let o=1,l="",a=1;for(let O=0;O<r;++O){let j=i[O];j===`
3
- `?(o=1,l="",a+=1):(o+=1,l+=j)}let m=i.indexOf(`
4
- `,r);l+=m===-1?i.slice(r):i.slice(r,m);let w=0;l.length>50&&(o<40?l=l.slice(0,50):(w=o-20,l=l.slice(w,o+30)));super(`${e} (line ${a}, column ${o})
5
- ${l}
6
- `+" ".repeat(o-w+1)+`^
7
- `);this.column=o,this.excerpt=l,this.line=a,this.name="XmlError",this.pos=r}};var f=class extends s{constructor(e,r=""){super();this.name=e,this.content=r}get type(){return s.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,content:this.content})}};var I="",v=class{constructor(t,e={}){let r=this.document=new g,i=this.r=new E(t);if(this.u=r,this.s=e,this.s.includeOffsets&&(r.start=0,r.end=t.length),i.e("\uFEFF"),this.S(),!this.C())throw this.t("Root element is missing or invalid");for(;this.v(););if(!i.T)throw this.t("Extra content at the end of the document")}h(t,e){return t.parent=this.u,this.s.includeOffsets&&(t.start=this.r.a(e),t.end=this.r.a()),this.u.children.push(t),!0}w(t,e){let{children:r}=this.u,{length:i}=r;if(t=X(t),i>0){let o=r[i-1];if((o==null?void 0:o.type)===s.TYPE_TEXT){let l=o;return l.text+=t,this.s.includeOffsets&&(l.end=this.r.a()),!0}}return this.h(new u(t),e)}A(){let t=Object.create(null);for(;this.n();){let e=this.g();if(!e)break;let r=this.E()&&this.J();if(r===!1)throw this.t("Attribute value expected");if(e in t)throw this.t(`Duplicate attribute: ${e}`);if(e==="xml:space"&&r!=="default"&&r!=="preserve")throw this.t('Value of the `xml:space` attribute must be "default" or "preserve"');t[e]=r}if(this.s.sortAttributes){let e=Object.keys(t).sort(),r=Object.create(null);for(let i=0;i<e.length;++i){let o=e[i];r[o]=t[o]}t=r}return t}J(){let{r:t}=this,e=t.l();if(e!=='"'&&e!=="'")return!1;t.o();let r,i=!1,o=I,l=e==='"'?S:A;t:for(;!t.T;)switch(r=t.j(l),r&&(this.p(r),o+=r.replace(M," ")),t.l()){case e:i=!0;break t;case"&":o+=this.N();continue;case"<":throw this.t("Unescaped `<` is not allowed in an attribute value");case I:break t}if(!i)throw this.t("Unclosed attribute");return t.o(),o}M(){let{r:t}=this,e=t.i;if(!t.e("<![CDATA["))return!1;let r=t.b("]]>");if(this.p(r),!t.e("]]>"))throw this.t("Unclosed CDATA section");return this.s.preserveCdata?this.h(new d(X(r)),e):this.w(r,e)}_(){let{r:t}=this,e=t.i,r=t.D(_);if(!r)return!1;if(this.p(r),t.l(3)==="]]>")throw this.t("Element content may not contain the CDATA section close delimiter `]]>`");return this.w(r,e)}P(){let{r:t}=this,e=t.i;if(!t.e("<!--"))return!1;let r=t.b("--");if(this.p(r),!t.e("-->"))throw t.l(2)==="--"?this.t("The string `--` isn't allowed inside a comment"):this.t("Unclosed comment");return this.s.preserveComments?this.h(new p(X(r)),e):!0}U(){let t=this.r.i,e=this.N();return e?this.w(e,t):!1}Y(){let{r:t}=this,e=t.i;if(!t.e("<!DOCTYPE"))return!1;let r=this.n()&&this.g();if(!r)throw this.t("Expected a name");let i,o;if(this.n()){if(t.e("PUBLIC")){if(i=this.n()&&this.R(),i===!1)throw this.t("Expected a public identifier");this.n()}if(i!==void 0||t.e("SYSTEM")){if(this.n(),o=this.y(),o===!1)throw this.t("Expected a system identifier");this.n()}}let l;if(t.e("[")){if(l=t.D(/\][\x20\t\r\n]*>/),!t.e("]"))throw this.t("Unclosed internal subset");this.n()}if(!t.e(">"))throw this.t("Unclosed doctype declaration");return this.s.preserveDocumentType?this.h(new y(r,i,o,l),e):!0}C(){let{r:t}=this,e=t.i;if(!t.e("<"))return!1;let r=this.g();if(!r)return t.d(e),!1;let i=this.A(),o=!!t.e("/>"),l=new h(r,i);if(l.parent=this.u,!o){if(!t.e(">"))throw this.t(`Unclosed start tag for element \`${r}\``);this.u=l;do this._();while(this.C()||this.U()||this.M()||this.F()||this.P());let a=t.i,m;if(!t.e("</")||!(m=this.g())||m!==r)throw t.d(a),this.t(`Missing end tag for element ${r}`);if(this.n(),!t.e(">"))throw this.t(`Unclosed end tag for element ${r}`);this.u=l.parent}return this.h(l,e)}E(){return this.n(),this.r.e("=")?(this.n(),!0):!1}v(){return this.P()||this.F()||this.n()}g(){return C(this.r.l())?this.r.X(D):I}F(){let{r:t}=this,e=t.i;if(!t.e("<?"))return!1;let r=this.g();if(r){if(r.toLowerCase()==="xml")throw t.d(e),this.t("XML declaration isn't allowed here")}else throw this.t("Invalid processing instruction");if(!this.n()){if(t.e("?>"))return this.h(new f(r),e);throw this.t("Whitespace is required after a processing instruction name")}let i=t.b("?>");if(this.p(i),!t.e("?>"))throw this.t("Unterminated processing instruction");return this.h(new f(r,X(i)),e)}S(){let{r:t}=this,e=t.i;for(this.L();this.v(););if(this.Y())for(;this.v(););return e<t.i}R(){let t=this.r.i,e=this.y();if(e!==!1&&!/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(e))throw this.r.d(t),this.t("Invalid character in public identifier");return e}N(){let{r:t}=this;if(!t.e("&"))return!1;let e=t.X(U);if(t.I()!==";")throw this.t("Unterminated reference (a reference must end with `;`)");let r;if(e[0]==="#"){let i=e[1]==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10);if(isNaN(i))throw this.t("Invalid character reference");if(!N(i))throw this.t("Character reference resolves to an invalid character");r=String.fromCodePoint(i)}else if(r=J[e],r===void 0){let{ignoreUndefinedEntities:i,resolveUndefinedEntity:o}=this.s,l=`&${e};`;if(o){let a=o(l);if(a!=null){let m=typeof a;if(m!=="string")throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${m}`);return a}}if(i)return l;throw t.d(-l.length),this.t(`Named entity isn't defined: ${l}`)}return r}y(){let{r:t}=this,e=t.e('"')||t.e("'");if(!e)return!1;let r=t.b(e);if(this.p(r),!t.e(e))throw this.t("Missing end quote");return r}n(){return!!this.r.X(Y)}L(){let{r:t}=this,e=t.i;if(!t.e("<?xml"))return!1;if(!this.n())throw this.t("Invalid XML declaration");let r=!!t.e("version")&&this.E()&&this.y();if(r===!1)throw this.t("XML version is missing or invalid");if(!/^1\.[0-9]+$/.test(r))throw this.t("Invalid character in version number");let i,o;if(this.n()&&(i=!!t.e("encoding")&&this.E()&&this.y(),i&&this.n(),o=!!t.e("standalone")&&this.E()&&this.y(),o)){if(o!=="yes"&&o!=="no")throw this.t('Only "yes" and "no" are permitted as values of `standalone`');this.n()}if(!t.e("?>"))throw this.t("Invalid or unclosed XML declaration");return this.s.preserveXmlDeclaration?this.h(new x(r,i||void 0,o||void 0),e):!0}t(t){let{r:e}=this;return new b(t,e.i,e.c)}p(t){let{length:e}=t;for(let r=0;r<e;++r){let i=t.codePointAt(r);if(!N(i))throw this.r.d(-([...t].length-r)),this.t("Invalid character");i>65535&&(r+=1)}}};function X(n){let t=0;for(;(t=n.indexOf("\r",t))!==-1;)n=n[t+1]===`
8
- `?n.slice(0,t)+n.slice(t+1):n.slice(0,t)+`
9
- `+n.slice(t+1);return n}function z(n,t){return new v(n,t).document}return W(Q);})();
1
+ /*! @rgrove/parse-xml v4.2.1 | ISC License | Copyright Ryan Grove */
2
+ "use strict";var parseXml=(()=>{var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var $=(s,t)=>{for(var e in t)T(s,e,{get:t[e],enumerable:!0})},L=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of R(t))!_.call(s,i)&&i!==e&&T(s,i,{get:()=>t[i],enumerable:!(r=Y(t,i))||r.enumerable});return s};var B=s=>L(T({},"__esModule",{value:!0}),s);var z={};$(z,{XmlCdata:()=>d,XmlComment:()=>p,XmlDeclaration:()=>x,XmlDocument:()=>g,XmlDocumentType:()=>y,XmlElement:()=>c,XmlError:()=>b,XmlNode:()=>o,XmlProcessingInstruction:()=>f,XmlText:()=>u,parseXml:()=>k});var O="",V=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,E=class{constructor(t){if(this.m=this.E(t,!0),this.i=0,this.length=t.length,this.u=this.m!==this.length,this.l=t,this.u){let e=[];for(let r=0,i=0;i<this.m;++i)e[i]=r,r+=t.codePointAt(r)>65535?2:1;this.D=e}}get C(){return this.i>=this.m}E(t,e=this.u){return e?t.replace(V,"_").length:t.length}p(t=1){this.i=Math.min(this.m,this.i+t)}s(t=this.i){var e;return this.u?(e=this.D[t])!=null?e:1/0:t}j(t=1){let e=this.c(t);return this.p(t),e}X(t){let e=this.s(),r=this.l.slice(e,e+t);return this.p(this.E(r)),r}v(t){let{length:e,u:r,l:i}=this,n=this.s(),l=n;if(r)for(;l<e;){let a=i[l],h=a>="\uD800"&&a<="\uDBFF";if(h&&(a+=i[l+1]),!t(a))break;l+=h?2:1}else for(;l<e&&t(i[l]);)++l;return this.X(l-n)}e(t){let{length:e}=t,r=this.s();return t===this.l.slice(r,r+e)?(this.p(e===1?1:this.E(t)),t):O}w(t){let e=this.l.slice(this.s()).search(t);return e>0?this.X(e):O}y(t){let e=this.s(),r=this.l.indexOf(t,e);return r>0?this.X(r-e):O}c(t=1){let{i:e,l:r}=this;return this.u?r.slice(this.s(e),this.s(e+t)):r.slice(e,e+t)}f(t=0){this.i=t>=0?Math.min(this.m,t):Math.max(0,this.i+t)}};var F=/["&<]/,I=/['&<]/,j=/\r\n|[\n\r\t]/g,A=/<|&|]]>/,S=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function D(s){let t=s.codePointAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===45||t===46||t===183||t>=768&&t<=879||t===8255||t===8256||C(s,t)}function C(s,t=s.codePointAt(0)){return t>=97&&t<=122||t>=65&&t<=90||t===58||t===95||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t===8204||t===8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function M(s){return s==="#"||D(s)}function J(s){let t=s.codePointAt(0);return t===32||t===9||t===10||t===13}function N(s){return s>=32&&s<=55295||s===10||s===9||s===13||s>=57344&&s<=65533||s>=65536&&s<=1114111}var m=class m{constructor(){this.parent=null;this.start=-1;this.end=-1}get document(){var t,e;return(e=(t=this.parent)==null?void 0:t.document)!=null?e:null}get isRootNode(){return this.parent!==null&&this.parent===this.document&&this.type===m.TYPE_ELEMENT}get preserveWhitespace(){var t;return!!((t=this.parent)!=null&&t.preserveWhitespace)}get type(){return""}toJSON(){let t={type:this.type};return this.isRootNode&&(t.isRootNode=!0),this.preserveWhitespace&&(t.preserveWhitespace=!0),this.start!==-1&&(t.start=this.start,t.end=this.end),t}};m.TYPE_CDATA="cdata",m.TYPE_COMMENT="comment",m.TYPE_DOCUMENT="document",m.TYPE_DOCUMENT_TYPE="doctype",m.TYPE_ELEMENT="element",m.TYPE_PROCESSING_INSTRUCTION="pi",m.TYPE_TEXT="text",m.TYPE_XML_DECLARATION="xmldecl";var o=m;var u=class extends o{constructor(t=""){super(),this.text=t}get type(){return o.TYPE_TEXT}toJSON(){return Object.assign(o.prototype.toJSON.call(this),{text:this.text})}};var d=class extends u{get type(){return o.TYPE_CDATA}};var p=class extends o{constructor(t=""){super(),this.content=t}get type(){return o.TYPE_COMMENT}toJSON(){return Object.assign(o.prototype.toJSON.call(this),{content:this.content})}};var x=class extends o{constructor(t,e,r){super(),this.version=t,this.encoding=e!=null?e:null,this.standalone=r!=null?r:null}get type(){return o.TYPE_XML_DECLARATION}toJSON(){let t=o.prototype.toJSON.call(this);t.version=this.version;for(let e of["encoding","standalone"])this[e]!==null&&(t[e]=this[e]);return t}};var c=class s extends o{constructor(t,e=Object.create(null),r=[]){super(),this.name=t,this.attributes=e,this.children=r}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let t=this;for(;t instanceof s;){if("xml:space"in t.attributes)return t.attributes["xml:space"]==="preserve";t=t.parent}return!1}get text(){return this.children.map(t=>"text"in t?t.text:"").join("")}get type(){return o.TYPE_ELEMENT}toJSON(){return Object.assign(o.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(t=>t.toJSON())})}};var g=class extends o{constructor(t=[]){super(),this.children=t}get document(){return this}get root(){for(let t of this.children)if(t instanceof c)return t;return null}get text(){return this.children.map(t=>"text"in t?t.text:"").join("")}get type(){return o.TYPE_DOCUMENT}toJSON(){return Object.assign(o.prototype.toJSON.call(this),{children:this.children.map(t=>t.toJSON())})}};var y=class extends o{constructor(t,e,r,i){super(),this.name=t,this.publicId=e!=null?e:null,this.systemId=r!=null?r:null,this.internalSubset=i!=null?i:null}get type(){return o.TYPE_DOCUMENT_TYPE}toJSON(){let t=o.prototype.toJSON.call(this);t.name=this.name;for(let e of["publicId","systemId","internalSubset"])this[e]!==null&&(t[e]=this[e]);return t}};var b=class extends Error{constructor(t,e,r){let i=1,n="",l=1;for(let w=0;w<e;++w){let P=r[w];P===`
3
+ `?(i=1,n="",l+=1):(i+=1,n+=P)}let a=r.indexOf(`
4
+ `,e);n+=a===-1?r.slice(e):r.slice(e,a);let h=0;n.length>50&&(i<40?n=n.slice(0,50):(h=i-20,n=n.slice(h,i+30))),super(`${t} (line ${l}, column ${i})
5
+ ${n}
6
+ `+" ".repeat(i-h+1)+`^
7
+ `),this.column=i,this.excerpt=n,this.line=l,this.name="XmlError",this.pos=e}};var f=class extends o{constructor(t,e=""){super(),this.name=t,this.content=e}get type(){return o.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(o.prototype.toJSON.call(this),{name:this.name,content:this.content})}};var U="",v=class{constructor(t,e={}){let r=this.document=new g;this.h=r,this.o=e,this.r=new E(t),this.o.includeOffsets&&(r.start=0,r.end=t.length),this.parse()}a(t,e){return t.parent=this.h,this.o.includeOffsets&&(t.start=this.r.s(e),t.end=this.r.s()),this.h.children.push(t),!0}T(t,e,r=!0){let{children:i}=this.h,{length:n}=i;if(r&&(t=X(t)),n>0){let l=i[n-1];if((l==null?void 0:l.type)===o.TYPE_TEXT){let a=l;return a.text+=t,this.o.includeOffsets&&(a.end=this.r.s()),!0}}return this.a(new u(t),e)}A(){let t=Object.create(null);for(;this.n();){let e=this.x();if(!e)break;let r=this.b()&&this.S();if(r===!1)throw this.t("Attribute value expected");if(e in t)throw this.t(`Duplicate attribute: ${e}`);if(e==="xml:space"&&r!=="default"&&r!=="preserve")throw this.t('Value of the `xml:space` attribute must be "default" or "preserve"');t[e]=r}if(this.o.sortAttributes){let e=Object.keys(t).sort(),r=Object.create(null);for(let i=0;i<e.length;++i){let n=e[i];r[n]=t[n]}t=r}return t}S(){let{r:t}=this,e=t.c();if(e!=='"'&&e!=="'")return!1;t.p();let r,i=!1,n=U,l=e==='"'?F:I;t:for(;!t.C;)switch(r=t.w(l),r&&(this.d(r),n+=r.replace(j," ")),t.c()){case e:i=!0;break t;case"&":n+=this.N();continue;case"<":throw this.t("Unescaped `<` is not allowed in an attribute value");default:break t}if(!i)throw this.t("Unclosed attribute");return t.p(),n}J(){let{r:t}=this,e=t.i;if(!t.e("<![CDATA["))return!1;let r=t.y("]]>");if(this.d(r),!t.e("]]>"))throw this.t("Unclosed CDATA section");return this.o.preserveCdata?this.a(new d(X(r)),e):this.T(r,e)}M(){let{r:t}=this,e=t.i,r=t.w(A);if(!r)return!1;if(this.d(r),t.c(3)==="]]>")throw this.t("Element content may not contain the CDATA section close delimiter `]]>`");return this.T(r,e)}P(){let{r:t}=this,e=t.i;if(!t.e("<!--"))return!1;let r=t.y("--");if(this.d(r),!t.e("-->"))throw t.c(2)==="--"?this.t("The string `--` isn't allowed inside a comment"):this.t("Unclosed comment");return this.o.preserveComments?this.a(new p(X(r)),e):!0}U(){let t=this.r.i,e=this.N();return e?this.T(e,t,!1):!1}Y(){let{r:t}=this,e=t.i;if(!t.e("<!DOCTYPE"))return!1;let r=this.n()&&this.x();if(!r)throw this.t("Expected a name");let i,n;if(this.n()){if(t.e("PUBLIC")){if(i=this.n()&&this.R(),i===!1)throw this.t("Expected a public identifier");this.n()}if(i!==void 0||t.e("SYSTEM")){if(this.n(),n=this.g(),n===!1)throw this.t("Expected a system identifier");this.n()}}let l;if(t.e("[")){if(l=t.w(/\][\x20\t\r\n]*>/),!t.e("]"))throw this.t("Unclosed internal subset");this.n()}if(!t.e(">"))throw this.t("Unclosed doctype declaration");return this.o.preserveDocumentType?this.a(new y(r,i,n,l),e):!0}F(){let{r:t}=this,e=t.i;if(!t.e("<"))return!1;let r=this.x();if(!r)return t.f(e),!1;let i=this.A(),n=!!t.e("/>"),l=new c(r,i);if(l.parent=this.h,!n){if(!t.e(">"))throw this.t(`Unclosed start tag for element \`${r}\``);this.h=l;do this.M();while(this.F()||this.U()||this.J()||this.I()||this.P());let a=t.i,h;if(!t.e("</")||!(h=this.x())||h!==r)throw t.f(a),this.t(`Missing end tag for element ${r}`);if(this.n(),!t.e(">"))throw this.t(`Unclosed end tag for element ${r}`);this.h=l.parent}return this.a(l,e)}b(){return this.n(),this.r.e("=")?(this.n(),!0):!1}O(){return this.P()||this.I()||this.n()}x(){return C(this.r.c())?this.r.v(D):U}I(){let{r:t}=this,e=t.i;if(!t.e("<?"))return!1;let r=this.x();if(r){if(r.toLowerCase()==="xml")throw t.f(e),this.t("XML declaration isn't allowed here")}else throw this.t("Invalid processing instruction");if(!this.n()){if(t.e("?>"))return this.a(new f(r),e);throw this.t("Whitespace is required after a processing instruction name")}let i=t.y("?>");if(this.d(i),!t.e("?>"))throw this.t("Unterminated processing instruction");return this.a(new f(r,X(i)),e)}_(){let{r:t}=this,e=t.i;for(this.$();this.O(););if(this.Y())for(;this.O(););return e<t.i}R(){let t=this.r.i,e=this.g();if(e!==!1&&!/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(e))throw this.r.f(t),this.t("Invalid character in public identifier");return e}N(){let{r:t}=this;if(!t.e("&"))return!1;let e=t.v(M);if(t.j()!==";")throw this.t("Unterminated reference (a reference must end with `;`)");let r;if(e[0]==="#"){let i=e[1]==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10);if(isNaN(i))throw this.t("Invalid character reference");if(!N(i))throw this.t("Character reference resolves to an invalid character");r=String.fromCodePoint(i)}else if(r=S[e],r===void 0){let{ignoreUndefinedEntities:i,resolveUndefinedEntity:n}=this.o,l=`&${e};`;if(n){let a=n(l);if(a!=null){let h=typeof a;if(h!=="string")throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${h}`);return a}}if(i)return l;throw t.f(-l.length),this.t(`Named entity isn't defined: ${l}`)}return r}g(){let{r:t}=this,e=t.e('"')||t.e("'");if(!e)return!1;let r=t.y(e);if(this.d(r),!t.e(e))throw this.t("Missing end quote");return r}n(){return!!this.r.v(J)}$(){let{r:t}=this,e=t.i;if(!t.e("<?xml"))return!1;if(!this.n())throw this.t("Invalid XML declaration");let r=!!t.e("version")&&this.b()&&this.g();if(r===!1)throw this.t("XML version is missing or invalid");if(!/^1\.[0-9]+$/.test(r))throw this.t("Invalid character in version number");let i,n;if(this.n()){if(i=!!t.e("encoding")&&this.b()&&this.g(),i){if(!/^[A-Za-z][\w.-]*$/.test(i))throw this.t("Invalid character in encoding name");this.n()}if(n=!!t.e("standalone")&&this.b()&&this.g(),n){if(n!=="yes"&&n!=="no")throw this.t('Only "yes" and "no" are permitted as values of `standalone`');this.n()}}if(!t.e("?>"))throw this.t("Invalid or unclosed XML declaration");return this.o.preserveXmlDeclaration?this.a(new x(r,i||void 0,n||void 0),e):!0}t(t){let{r:e}=this;return new b(t,e.i,e.l)}parse(){if(this.r.e("\uFEFF"),this._(),!this.F())throw this.t("Root element is missing or invalid");for(;this.O(););if(!this.r.C)throw this.t("Extra content at the end of the document")}d(t){let{length:e}=t;for(let r=0;r<e;++r){let i=t.codePointAt(r);if(!N(i))throw this.r.f(-([...t].length-r)),this.t("Invalid character");i>65535&&(r+=1)}}};function X(s){let t=0;for(;(t=s.indexOf("\r",t))!==-1;)s=s[t+1]===`
8
+ `?s.slice(0,t)+s.slice(t+1):s.slice(0,t)+`
9
+ `+s.slice(t+1);return s}function k(s,t){return new v(s,t).document}return B(z);})();
10
10
  parseXml=parseXml.parseXml
11
11
  //# sourceMappingURL=global.min.js.map