/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any */
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
function wrap(el) {
    return { node: el };
}
function raw(el) {
    return el.node;
}
export function parseXml(xml) {
    return wrap(new DOMParser().parseFromString(xml, 'text/xml'));
}
export function serializeXml(doc) {
    return new XMLSerializer().serializeToString(raw(doc));
}
export function getElementsByTagName(parent, tag) {
    const elements = raw(parent).getElementsByTagName(tag);
    return Array.from(elements).map((el) => wrap(el));
}
export function getAttribute(el, name) {
    return raw(el).getAttribute(name) ?? '';
}
export function setAttribute(el, name, value) {
    raw(el).setAttribute(name, value);
}
export function getChildElements(el, tag) {
    const elements = raw(el).getElementsByTagName(tag);
    return Array.from(elements).map((child) => wrap(child));
}
export function getFirstChild(el, tag) {
    const elements = raw(el).getElementsByTagName(tag);
    return elements.length > 0 ? wrap(elements[0]) : null;
}
export function getFloatAttr(el, name, fallback = 0) {
    return parseFloat(getAttribute(el, name) || String(fallback));
}
//# sourceMappingURL=xml-parser.js.map