UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

525 lines (524 loc) 16.7 kB
export declare type _XmlWriteState = 'Initial' | 'StartDocument' | 'EndDocument' | 'StartElement' | 'EndElement' | 'ElementContent'; export declare type _NamespaceKind = 'Written' | 'NeedToWrite' | 'Implied' | 'Special'; /** * Provides XML writing functionality for generating well formed XML documents with support for * namespaces, elements, attributes, and text content. * * @private */ export declare class _XmlWriter { /** * Internal text buffer that accumulates XML before flushing to bytes. * * @private * @type {string} */ _bufferText: string; /** * Internal byte buffer containing the serialized XML document. * * @private * @type {Uint8Array} */ _buffer: Uint8Array; /** * Current writer state used to validate write operations. * * @private * @type {_XmlWriteState} */ _currentState: _XmlWriteState; /** * Stack of namespace records used while writing elements and attributes. * * @private * @type {_Namespace[]} */ _namespaceStack: _Namespace[]; /** * Stack of open XML elements. * * @private * @type {_XmlElement[]} */ _elementStack: _XmlElement[]; /** * Position marker used for compact empty element detection. * * @private * @type {number} */ _position: number; /** * Currently collected attributes for the active element. * * @private * @type {_XmlAttribute[]} */ _attributeStack: _XmlAttribute[]; /** * Flag to skip writing namespace declarations (appearance mode). * * @private * @type {boolean} */ _skipNamespace: boolean; /** * Gets the serialized XML buffer containing all written content. * * @private * @returns {Uint8Array} The complete XML document as a byte array. */ readonly buffer: Uint8Array; /** * Initializes a new instance of the _XmlWriter class with optional appearance mode. * * @private * @param {boolean} [isAppearance=false] Whether to initialize in appearance mode, skipping namespace handling. * @returns {void} */ constructor(isAppearance?: boolean); /** * Writes the XML document declaration to the output buffer. * * @private * @param {boolean} [standalone] Optional flag indicating if the document is standalone. * @returns {void} * @throws {Error} Throws an error if called in an invalid state or if the buffer is undefined. */ _writeStartDocument(standalone?: boolean): void; /** * Writes the start tag of an XML element with optional prefix and namespace. * * @private * @param {string} localName The local name of the element to write. * @param {string} [prefix] Optional namespace prefix for the element. * @param {string} [namespace] Optional namespace URI for the element. * @returns {void} * @throws {Error} Throws an error if localName is invalid, undefined, null, or empty. */ _writeStartElement(localName: string, prefix?: string, namespace?: string): void; /** * Writes the end tag of the current XML element and closes it. * * @private * @returns {void} */ _writeEndElement(): void; /** * Writes an XML element with text content in a single operation. * * @private * @param {string} localName The local name of the element. * @param {string} value The text content of the element. * @param {string} [prefix] Optional namespace prefix for the element. * @param {string} [namespace] Optional namespace URI for the element. * @returns {void} */ _writeElementString(localName: string, value: string, prefix?: string, namespace?: string): void; /** * Writes an XML attribute with the specified name and value. * * @private * @param {string} localName The local name of the attribute. * @param {string} value The value of the attribute. * @param {string} [prefix] Optional namespace prefix for the attribute. * @param {string} [namespace] Optional namespace URI for the attribute. * @returns {void} */ _writeAttributeString(localName: string, value: string, prefix?: string, namespace?: string): void; /** * Writes text content to the current XML element. * * @private * @param {string} text The text content to write. * @returns {void} */ _writeString(text: string): void; /** * Writes raw XML text without escaping special characters. * * @private * @param {string} text The raw XML text to write. * @returns {void} */ _writeRaw(text: string): void; /** * Writes text to the current XML element with optional raw string mode. * * @private * @param {string} text The text to write. * @param {boolean} isRawString Whether to write as raw text without escaping special characters. * @returns {void} * @throws {Error} Throws an error if called in an invalid state. */ _writeInternal(text: string, isRawString: boolean): void; /** * Saves the XML document and returns the complete serialized byte array. * * @private * @returns {Uint8Array} The complete XML document as a byte array. */ _save(): Uint8Array; /** * Destroys the XML writer and cleans up all internal resources. * * @private * @returns {void} */ _destroy(): void; /** * Flushes the internal text buffer to the byte array buffer. * * @private * @returns {void} */ _flush(): void; /** * Writes the start of an XML attribute with validation. * * @private * @param {string} localName The local name of the attribute. * @param {string} value The value of the attribute. * @param {string} prefix The namespace prefix for the attribute. * @param {string} namespace The namespace URI for the attribute. * @returns {void} * @throws {Error} Throws an error if the localName is invalid or if not in the correct state. */ _writeStartAttribute(localName: string, value: string, prefix: string, namespace: string): void; /** * Writes the start of an XML attribute with prefix and namespace resolution. * * @private * @param {string} localName The local name of the attribute. * @param {string} value The value of the attribute. * @param {string} [prefix] Optional namespace prefix for the attribute. * @param {string} [namespace] Optional namespace URI for the attribute. * @returns {void} */ _writeStartAttributePrefixAndNameSpace(localName: string, value: string, prefix?: string, namespace?: string): void; /** * Writes the start of an XML attribute with special attribute handling. * * @private * @param {string} prefix The namespace prefix for the attribute. * @param {string} localName The local name of the attribute. * @param {string} namespace The namespace URI for the attribute. * @param {string} value The value of the attribute. * @returns {void} * @throws {Error} Throws an error for invalid namespace declarations or special attributes. */ _writeStartAttributeSpecialAttribute(prefix: string, localName: string, namespace: string, value: string): void; /** * Writes the end of an XML attribute. * * @private * @returns {void} */ _writeEndAttribute(): void; /** * Internally writes the start tag of an XML element and manages namespace stack. * * @private * @param {string} prefix The namespace prefix for the element. * @param {string} localName The local name of the element. * @param {string} namespace The namespace URI for the element. * @returns {void} */ _writeStartElementInternal(prefix: string, localName: string, namespace: string): void; /** * Internally writes the end tag of an XML element. * * @private * @param {string} prefix The namespace prefix of the element being closed. * @param {string} localName The local name of the element being closed. * @returns {void} */ _writeEndElementInternal(prefix: string, localName: string): void; /** * Internally writes the start of an XML attribute. * * @private * @param {string} prefix The namespace prefix for the attribute. * @param {string} localName The local name of the attribute. * @returns {void} */ _writeStartAttributeInternal(prefix: string, localName: string): void; /** * Writes an XML namespace declaration. * * @private * @param {string} prefix The namespace prefix to declare. * @param {string} namespaceUri The namespace URI for the declaration. * @returns {void} */ _writeNamespaceDeclaration(prefix: string, namespaceUri: string): void; /** * Writes the start of an XML namespace declaration. * * @private * @param {string} prefix The namespace prefix to declare. * @returns {void} */ _writeStartNamespaceDeclaration(prefix: string): void; /** * Internally writes text with proper XML character escaping. * * @private * @param {string} text The text to write. * @param {boolean} inAttributeValue Whether the text is being written as an attribute value. * @returns {void} */ _writeStringInternal(text: string, inAttributeValue: boolean): void; /** * Internally handles the start of element content and writes pending namespace declarations. * * @private * @returns {void} */ _startElementContent(): void; /** * Writes raw text directly to the buffer without any processing. * * @private * @param {string} text The raw text to write. * @returns {void} */ _rawText(text: string): void; /** * Adds a namespace entry to the internal namespace stack. * * @private * @param {string} prefix The namespace prefix. * @param {string} ns The namespace URI. * @param {_NamespaceKind} kind The classification of the namespace entry. * @returns {void} */ _addNamespace(prefix: string, ns: string, kind: _NamespaceKind): void; /** * Looks up the prefix associated with a namespace URI. * * @private * @param {string} namespace The namespace URI to find a prefix for. * @returns {string} The prefix if found, otherwise undefined. */ _lookupPrefix(namespace: string): string; /** * Looks up the namespace URI associated with a prefix. * * @private * @param {string} prefix The prefix to look up. * @returns {string} The namespace URI if found, otherwise undefined. */ _lookupNamespace(prefix: string): string; /** * Looks up the index of a namespace entry in the namespace stack. * * @private * @param {string} prefix The namespace prefix to find. * @returns {number} The index of the namespace in the stack or -1 when not found. */ _lookupNamespaceIndex(prefix: string): number; /** * Pushes an implicit namespace declaration to the stack, validating conflicts. * * @private * @param {string} prefix The namespace prefix. * @param {string} ns The namespace URI. * @returns {void} * @throws {Error} When invalid namespace configurations are detected. */ _pushNamespaceImplicit(prefix: string, ns: string): void; /** * Pushes an explicit namespace declaration to the stack. * * @private * @param {string} prefix The namespace prefix. * @param {string} ns The namespace URI. * @returns {void} */ _pushNamespaceExplicit(prefix: string, ns: string): void; /** * Adds an attribute record to the current attribute stack and checks for duplicates. * * @private * @param {string} prefix The attribute namespace prefix. * @param {string} localName The attribute local name. * @param {string} namespaceName The attribute namespace URI. * @returns {void} * @throws {Error} When a duplicate attribute name is detected. */ _addAttribute(prefix: string, localName: string, namespaceName: string): void; /** * Adds attribute metadata and writes its start without pushing a namespace entry. * * @private * @param {string} prefix The attribute prefix. * @param {string} localName The attribute local name. * @param {string} namespace The attribute namespace URI. * @returns {void} */ _skipPushAndWrite(prefix: string, localName: string, namespace: string): void; /** * Validates an XML name for invalid characters and throws on failure. * * @private * @param {string} text The name to validate. * @returns {void} * @throws {Error} When the name contains invalid characters. */ _checkName(text: string): void; } /** * Represents an internal namespace entry used by the XML writer. * * @private */ export declare class _Namespace { /** * Namespace prefix. * * @private * @type {string} */ _prefix: string; /** * Namespace URI. * * @private * @type {string} */ _namespaceUri: string; /** * Classification of the namespace entry. * * @private * @type {_NamespaceKind} */ _kind: _NamespaceKind; /** * Sets namespace properties. * * @private * @param {string} prefix The namespace prefix. * @param {string} namespaceUri The namespace URI. * @param {_NamespaceKind} kind The namespace kind. * @returns {void} */ _set(prefix: string, namespaceUri: string, kind: _NamespaceKind): void; /** * Destroys the namespace entry and clears references. * * @private * @returns {void} */ _destroy(): void; } /** * Represents an internal XML element frame used while writing nested elements. * * @private */ export declare class _XmlElement { /** * Previous top index of the namespace stack at the time the element was opened. * * @private * @type {number} */ _previousTop: number; /** * The element's namespace prefix. * * @private * @type {string} */ _prefix: string; /** * The element's local name. * * @private * @type {string} */ _localName: string; /** * The element's namespace URI. * * @private * @type {string} */ _namespaceUri: string; /** * Sets properties for the element frame. * * @private * @param {string} prefix Element prefix. * @param {string} localName Element local name. * @param {string} namespaceUri Element namespace URI. * @param {number} previousTop Previous namespace stack top index. * @returns {void} */ _set(prefix: string, localName: string, namespaceUri: string, previousTop: number): void; /** * Destroys the element frame and clears references. * * @private * @returns {void} */ _destroy(): void; } /** * Represents an internal XML attribute record. * * @private */ export declare class _XmlAttribute { /** * The attribute namespace prefix. * * @private * @type {string} */ _prefix: string; /** * The attribute namespace URI. * * @private * @type {string} */ _namespaceUri: string; /** * The attribute local name. * * @private * @type {string} */ _localName: string; /** * Sets attribute properties. * * @private * @param {string} prefix The attribute prefix. * @param {string} localName The attribute local name. * @param {string} namespaceUri The attribute namespace URI. * @returns {void} */ _set(prefix: string, localName: string, namespaceUri: string): void; /** * Checks whether this attribute would be a duplicate of another attribute. * * @private * @param {string} prefix Prefix to compare. * @param {string} localName Local name to compare. * @param {string} namespaceUri Namespace URI to compare. * @returns {boolean} True if duplicate; otherwise false. */ _isDuplicate(prefix: string, localName: string, namespaceUri: string): boolean; /** * Destroys the attribute record and clears references. * * @private * @returns {void} */ _destroy(): void; }