import type { SitemapElements } from "./sitemap.js"; export type XMLAttributes = Record; type AllXMLChildren = SitemapElements | XMLDeclarationType | XMLStyleSheet; export interface XMLType { readonly tag: T; readonly attributes: A; } export class XMLElement implements XMLType { readonly tag: T; readonly attributes: A; readonly children: Array; constructor(tag: T, attributes: A, children: Array) { this.tag = tag; this.attributes = attributes; this.children = children; } } export class VoidXMLElement implements XMLType { readonly tag: T; readonly attributes: A; constructor(tag: T, attributes: A) { this.tag = tag; this.attributes = attributes; } } export class XMLDeclaration implements XMLType { readonly tag: T; readonly attributes: A; constructor(tag: T, attributes: A) { this.tag = tag; this.attributes = attributes; } } export type XMLDeclarationType = XMLDeclaration<"xml", { version: string; encoding: string }>; export const xmlDoctype: XMLDeclarationType = new XMLDeclaration("xml", { version: "1.0", encoding: "utf-8" }); export type XMLStyleSheet = XMLDeclaration<"xml-stylesheet", { href: string; type: string }>; export const xmlStylesheet = (href: string, type: string): XMLStyleSheet => new XMLDeclaration("xml-stylesheet", { href, type }); export class XMLDocument { readonly children: Array; constructor(doctype: XMLDeclarationType, children: Array) { this.children = [doctype, ...children]; } }