!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).slimdom={})}(this,(function(t){"use strict";class n{constructor(t,n,e,r){this.source=null,this.observer=t,this.node=n,this.options=e,this.source=r||null,r&&t.t.push(this)}collectInterestedObservers(t,n,e,r,o){if(this.node!==n&&!this.options.subtree)return;if("attributes"===t&&!this.options.attributes)return;if("characterData"===t&&!this.options.characterData)return;if("childList"===t&&!this.options.childList)return;let i=r.indexOf(this.observer);i<0&&(i=r.length,r.push(this.observer),o.push(void 0)),("attributes"===t&&this.options.attributeOldValue||"characterData"===t&&this.options.characterDataOldValue)&&(o[i]=e.oldValue)}}class e{constructor(t){this.o=[],this.i=t}register(t,e){const r=this.o;let o=!1;r.forEach((n=>{n.observer===t&&(o=!0,function(t){for(let n=t.observer.t.length-1;n>=0;--n){const e=t.observer.t[n];if(e.source!==t)return;e.node.o.removeTransientRegisteredObserver(e),t.observer.t.splice(n,1)}}(n),n.options=e)})),o||(this.o.push(new n(t,this.i,e)),t.u.push(this.i))}removeTransientRegisteredObserver(t){this.o.splice(this.o.indexOf(t),1)}removeForObserver(t){let n=0;for(let e=0,r=this.o.length;e{i.collectInterestedObservers(t,n,e,r,o)}))}appendTransientRegisteredObservers(t){this.o.forEach((n=>{n.options.subtree&&t.o.registerTransient(n)}))}registerTransient(t){this.o.push(new n(t.observer,this.i,t.options,t))}}function r(t,n,...e){"function"!=typeof queueMicrotask?Promise.resolve().then((()=>t.apply(n,e))):queueMicrotask((()=>t.apply(n,e)))}class o{constructor(){this.l=new Set,this.h=!1}appendRecord(t,n){t.m.push(n),this.l.add(t)}queueMutationObserverMicrotask(){this.h||(this.h=!0,r((()=>{this.p()}),this))}p(){this.h=!1;const t=Array.from(this.l);this.l.clear(),t.forEach((t=>{r((t=>{const n=t.takeRecords();var e;(e=t).t.forEach((t=>{t.node.o.removeTransientRegisteredObserver(t)})),e.t.length=0,n.length>0&&t.g(n,t)}),this,t)}))}}class i{constructor(t){this.v=t}deref(){return this.v}}const s=new class{constructor(){this.l=new o,this.N=[],this.S=new WeakSet}forEachRange(t){let n=this.N.length;for(let e=n-1;e>=0;--e){const r=this.N[e].deref(),o=null==r,i=!o&&!this.S.has(r);o||i?(this.N[e]=this.N[n-1],this.N.pop(),n-=1):t(r)}}addRange(t){const n=(e=t,"function"==typeof WeakRef?new WeakRef(e):new i(e));var e;this.N.push(n),this.S.add(t)}removeRange(t){this.S.delete(t)}};function u(t){return s}function l(t,...n){return n.some((n=>t.nodeType===n))}function c(t){return 2===t.nodeType}function a(t){return 3===t.nodeType||4===t.nodeType||8===t.nodeType||7===t.nodeType}function h(t){return 3===t.nodeType||4===t.nodeType}function f(t){return 1===t.nodeType}function d(t){return 10===t.nodeType}function m(t){switch(t.nodeType){case 3:case 7:case 8:return t.data.length;default:return t.childNodes.length}}function p(t){let n=t,e=[];for(;n;)e.unshift(n),n=n.parentNode;return e}function g(t){return l(t,9)?t:t.ownerDocument}function w(t){return t.parentNode.childNodes.indexOf(t)}function y(t){for(;t.parentNode;)t=t.parentNode;return t}function b(t,n){n(t);for(let e=t.firstChild;e;e=e.nextSibling)b(e,n)}function v(t,n){const e=[];return b(n,(r=>{if(r===n||1!==r.nodeType)return;const o=r;"*"!==t&&o.nodeName!==t||e.push(o)})),e}function x(t,n,e){""===t&&(t=null);const r=[];return b(e,(o=>{if(o===e||1!==o.nodeType)return;const i=o;"*"!==t&&i.namespaceURI!==t||"*"!==n&&i.localName!==n||r.push(i)})),r}function N(t,n,e){e||(e=g(t));let r=t.T(e);if(n)for(let n=t.firstChild;n;n=n.nextSibling)r.appendChild(N(n,!0,e));return r}function S(t,n){if(t.length{const u=o[s],l=new O(t,n);void 0!==e.name&&void 0!==e.namespace&&(l.attributeName=e.name,l.attributeNamespace=e.namespace),void 0!==u&&(l.oldValue=u),void 0!==e.addedNodes&&(l.addedNodes=e.addedNodes),void 0!==e.removedNodes&&(l.removedNodes=e.removedNodes),void 0!==e.previousSibling&&(l.previousSibling=e.previousSibling),void 0!==e.nextSibling&&(l.nextSibling=e.nextSibling),i.l.appendRecord(r,l)})),i.l.queueMutationObserverMicrotask()}function V(t){const n=[];for(let e=t.firstElementChild;e;e=e.nextElementSibling)n.push(e);return n}function _(t){for(let n=t.previousSibling;n;n=n.previousSibling)if(f(n))return n;return null}function F(t){for(let n=t.nextSibling;n;n=n.nextSibling)if(f(n))return n;return null}function U(t,n){const e=t.previousSibling,r=t.nextSibling,o=l(t,1),i=o?t.previousElementSibling:null,s=o?t.nextElementSibling:null;if(t.parentNode=null,t.previousSibling=null,t.nextSibling=null,e?e.nextSibling=r:n.firstChild=r,r?r.previousSibling=e:n.lastChild=e,n.childNodes.splice(n.childNodes.indexOf(t),1),o){const e=function(t){return l(t,1,9,11)?t:null}(n);e&&(e.firstElementChild===t&&(e.firstElementChild=s),e.lastElementChild===t&&(e.lastElementChild=i),e.childElementCount-=1)}if(l(n,9)){const e=n;l(t,1)?e.documentElement=null:l(t,10)&&(e.doctype=null)}}function q(t,n,e){if(l(n,9,11,1)||D("parent must be a Document, DocumentFragment or Element node"),t.contains(n)&&D("node must not be an inclusive ancestor of parent"),e&&e.parentNode!==n&&R("child is not a child of parent"),l(t,11,10,1,3,4,7,8)||D("node must be a DocumentFragment, DocumentType, Element, Text, ProcessingInstruction or Comment node"),l(t,3)&&l(n,9)&&D("can not insert a Text node under a Document"),l(t,10)&&!l(n,9)&&D("can only insert a DocumentType node under a Document"),l(n,9)){const r=n;switch(t.nodeType){case 11:const n=t;n.firstElementChild!==n.lastElementChild&&D("can not insert more than one element under a Document"),Array.from(n.childNodes).some((t=>l(t,3)))&&D("can not insert a Text node under a Document"),n.firstElementChild&&(r.documentElement||e&&l(e,10)||e&&r.doctype&&w(e)H(t,!0))),z("childList",t,{removedNodes:i})),null!==e){const t=w(e);u().forEachRange((e=>{e.startContainer===n&&e.startOffset>t&&(e.startOffset+=s),e.endContainer===n&&e.endOffset>t&&(e.endOffset+=s)}))}let l=null===e?n.lastChild:e.previousSibling;i.forEach((t=>{!function(t,n,e){t.parentNode=n;const r=null===e?n.lastChild:e.previousSibling,o=null===e?null:e;if(t.previousSibling=r,t.nextSibling=o,r?r.nextSibling=t:n.firstChild=t,o?(o.previousSibling=t,n.childNodes.splice(n.childNodes.indexOf(o),0,t)):(n.lastChild=t,n.childNodes.push(t)),f(t)){const e=n;let i=null;for(let t=r;t;t=t.previousSibling){if(f(t)){i=t;break}const n=t;if(!d(n)){i=n.previousElementSibling;break}}let s=null;for(let t=o;t;t=t.nextSibling){if(f(t)){s=t;break}s=t.nextElementSibling;break}i||(e.firstElementChild=t),s||(e.lastElementChild=t),e.childElementCount+=1}(function(t){return 9===t.nodeType})(n)&&(f(t)?n.documentElement=t:d(t)&&(n.doctype=t))}(t,n,e)})),r||z("childList",n,{addedNodes:i,nextSibling:e,previousSibling:l})}function X(t,n){return B(t,n,null)}function Y(t,n,e){if(l(e,9,11,1)||D("Can not replace under a non-parent node"),n.contains(e)&&D("Can not insert a node under its own descendant"),t.parentNode!==e&&R("child is not a child of parent"),l(n,11,10,1,3,4,7,8)||D("Can not insert a node that isn't a DocumentFragment, DocumentType, Element, Text, ProcessingInstruction or Comment"),l(n,3)&&l(e,9)&&D("can not insert a Text node under a Document"),l(n,10)&&!l(e,9)&&D("can only insert a DocumentType node under a Document"),l(e,9)){const r=e;switch(n.nodeType){case 11:const e=n;e.firstElementChild!==e.lastElementChild&&D("can not insert more than one element under a Document"),Array.from(e.childNodes).some((t=>l(t,3)))&&D("can not insert a Text node under a Document"),e.firstElementChild&&(r.documentElement&&r.documentElement!==t||t&&r.doctype&&w(t){r.push(t)})):r.push(t)),e.forEach((t=>{H(t,!0)})),null!==t&&W(t,n,null,!0),(r.length>0||e.length>0)&&z("childList",n,{addedNodes:r,removedNodes:e})}function H(t,n=!1){const e=t.parentNode,r=w(t);u().forEachRange((n=>{t.contains(n.startContainer)&&(n.startContainer=e,n.startOffset=r),t.contains(n.endContainer)&&(n.endContainer=e,n.endOffset=r),n.startContainer===e&&n.startOffset>r&&(n.startOffset-=1),n.endContainer===e&&n.endOffset>r&&(n.endOffset-=1)}));const o=t.previousSibling,i=t.nextSibling;U(t,e);for(let n=e;n;n=n.parentNode)n.o.appendTransientRegisteredObservers(t);n||z("childList",e,{removedNodes:[t],nextSibling:i,previousSibling:o})}function Q(t,n){const e=g(t);t.parentNode&&H(t),n!==e&&b(t,(t=>{if(t.ownerDocument=n,l(t,1))for(const e of t.attributes)e.ownerDocument=n}))}function K(t){const n=[];return b(t,(t=>{l(t,3,4)&&n.push(t.data)})),n.join("")}function G(t,n){let e=null;if(""!==n){e=new(u().Text)(n)}j(e,t)}function J(t,n){const e=t.map((t=>t instanceof Node?t:n.createTextNode(String(t))));if(1===e.length)return e[0];{const t=n.createDocumentFragment();return e.forEach((n=>{t.appendChild(n)})),t}}function Z(t,n){B(J(n,g(t)),t,t.firstChild)}function tt(t,n){X(J(n,g(t)),t)}function nt(t,n){const e=J(n,g(t));q(e,t,null),j(e,t)}function et(t,n){const e=t.parentNode;if(null===e)return;let r=t.previousSibling;for(;null!==r&&n.indexOf(r)>=0;)r=r.previousSibling;B(J(n,g(t)),e,null===r?e.firstChild:r.nextSibling)}function rt(t,n){const e=t.parentNode;if(null===e)return;let r=t.nextSibling;for(;null!==r&&n.indexOf(r)>=0;)r=r.nextSibling;B(J(n,g(t)),e,r)}function ot(t,n){const e=t.parentNode;if(null===e)return;let r=t.nextSibling;for(;null!==r&&n.indexOf(r)>=0;)r=r.nextSibling;const o=J(n,g(t));t.parentNode===e?Y(t,o,e):B(o,e,r)}function it(t){null!==t.parentNode&&H(t)}function st(t,n){const e=n.startContainer;l(e,7)&&D("Can not insert into a processing instruction"),l(e,8)&&D("Can not insert into a comment"),h(e)&&null===e.parentNode&&D("Can not insert into a text node without a parent");let r=null;r=h(e)?e:e.childNodes[n.startOffset]||null;const o=null===r?e:r.parentNode;q(t,o,r),h(e)&&(r=e.splitText(n.startOffset)),t===r&&(r=r.nextSibling),null!==t.parentNode&&H(t);let i=null===r?m(o):w(r);l(t,11)?i+=m(t):i+=1,B(t,o,r),n.collapsed&&n.setEnd(o,i)}function ut(t){return t>>>0}function lt(t){return null===t?"":String(t)}function ct(t){return null==t?"":String(t)}function at(t,n){return function(t,n){if(!(t instanceof n))throw new TypeError(`Value should be an instance of ${n.name}`)}(t,n),t}function ht(t,n){return null==t?null:at(t,n)}function ft(t){return void 0===t?null:t}const dt=new WeakMap;function mt(t){let n=dt.get(t);return void 0===n&&(n=Math.random(),dt.set(t,n)),n}class Node{constructor(){this.ownerDocument=null,this.parentNode=null,this.childNodes=[],this.firstChild=null,this.lastChild=null,this.previousSibling=null,this.nextSibling=null,this.o=new e(this)}get parentElement(){return this.parentNode&&l(this.parentNode,1)?this.parentNode:null}hasChildNodes(){return!!this.childNodes.length}normalize(){let t=this.firstChild,n=0;for(g(this);t;){let e=t.nextSibling;if(!l(t,3)){t.normalize(),t=e;continue}const r=t;let o=r.length;if(0===o){H(t),--n,t=e;continue}let i="";const s=[];for(let t=r.nextSibling;t&&l(t,3);t=t.nextSibling)i+=t.data,s.push(t);i&&r.replaceData(o,0,i);const c=u();for(let t=0,e=s.length;t{t.startContainer===e&&(t.startOffset+=o,t.startContainer=r),t.endContainer===e&&(t.endOffset+=o,t.endContainer=r),t.startContainer===this&&t.startOffset===i&&(t.startContainer=r,t.startOffset=o),t.endContainer===this&&t.endOffset===i&&(t.endContainer=r,t.endOffset=o)})),o+=e.length}for(;s.length;)H(s.shift());t=t.nextSibling,++n}}cloneNode(t=!1){return N(this,t)}compareDocumentPosition(t){if(S(arguments,1),this===(t=at(t,Node)))return 0;let n=t,e=this,r=null,o=null;if(c(n)&&(r=n,n=r.ownerElement),c(e)&&(o=e,e=o.ownerElement,null!==r&&null!==n&&e===n))for(const t of e.attributes){if(t===r)return Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC|Node.DOCUMENT_POSITION_PRECEDING;if(t===o)return Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC|Node.DOCUMENT_POSITION_FOLLOWING}if(null===n||null===e)return Node.DOCUMENT_POSITION_DISCONNECTED|Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC|(mt(n||r)>mt(e||o)?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING);const i=p(n),s=p(e);if(i[0]!==s[0])return Node.DOCUMENT_POSITION_DISCONNECTED|Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC|(mt(i[0])>mt(s[0])?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING);let u=0;for(;uo&&$("can not replace data past the node's length"),n+e>o&&(e=o-n),z("characterData",t,{oldValue:t.data});const i=t.data,s=i.substring(0,n)+r+i.substring(n+e);t.D=s;u().forEachRange((o=>{o.startContainer===t&&o.startOffset>n&&o.startOffset<=n+e&&(o.startOffset=n),o.endContainer===t&&o.endOffset>n&&o.endOffset<=n+e&&(o.endOffset=n),o.startContainer===t&&o.startOffset>n+e&&(o.startOffset=o.startOffset+r.length-e),o.endContainer===t&&o.endOffset>n+e&&(o.endOffset=o.endOffset+r.length-e)}))}function xt(t,n,e){n=ut(n),e=ut(e);const r=t.length;return n>r&&$("can not substring data past the node's length"),n+e>r?t.data.substring(n):t.data.substring(n,n+e)}class Text extends CharacterData{get nodeType(){return 3}get nodeName(){return"#text"}constructor(t=""){super(t);const n=u();this.ownerDocument=n.document}splitText(t){return S(arguments,1),function(t,n){const e=t.length;n>e&&$("can not split past the node's length");const r=e-n,o=xt(t,n,r),i=new(u().Text)(o);i.ownerDocument=t.ownerDocument;const s=t.parentNode;if(null!==s){W(i,s,t.nextSibling);const e=w(t)+1;u().forEachRange((r=>{r.startContainer===t&&r.startOffset>n&&(r.startContainer=i,r.startOffset-=n),r.endContainer===t&&r.endOffset>n&&(r.endContainer=i,r.endOffset-=n),r.startContainer===s&&r.startOffset===e&&(r.startOffset+=1),r.endContainer===s&&r.endOffset===e&&(r.endOffset+=1)}))}return vt(t,n,r,""),i}(this,t=ut(t))}T(t){const n=new(u().Text)(this.data);return n.ownerDocument=t,n}get wholeText(){const t=[this.data];let n=this.previousSibling;for(;null!==n&&l(n,3,4);){const e=n.data;t.unshift(e),n=n.previousSibling}let e=this.nextSibling;for(;null!==e&&l(e,3,4);){const n=e.data;t.push(n),e=e.nextSibling}return t.join("")}}class CDATASection extends Text{get nodeType(){return 4}get nodeName(){return"#cdata-section"}constructor(t){super(t)}T(t){const n=new(u().CDATASection)(this.data);return n.ownerDocument=t,n}}class Nt extends CharacterData{get nodeType(){return 8}get nodeName(){return"#comment"}constructor(t=""){super(t);const n=u();this.ownerDocument=n.document}T(t){const n=new(u().Comment)(this.data);return n.ownerDocument=t,n}}class DocumentType extends Node{get nodeType(){return 10}get nodeName(){return this.name}get nodeValue(){return null}set nodeValue(t){}get textContent(){return null}set textContent(t){}lookupPrefix(t){return S(arguments,1),null}lookupNamespaceURI(t){return S(arguments,1),null}before(...t){et(this,t)}after(...t){rt(this,t)}replaceWith(...t){ot(this,t)}remove(){it(this)}constructor(t,n="",e=""){super(),this.name=t,this.publicId=n,this.systemId=e}T(t){const n=new(u().DocumentType)(this.name,this.publicId,this.systemId);return n.ownerDocument=t,n}}function St(t,n,e,r,o){return new Attr(t,n,e,r,o)}function Tt(t,n,e,r=null){return uo(t,n,e,r)}const Et="http://www.w3.org/1999/xhtml",Ct="http://www.w3.org/XML/1998/namespace",Dt="http://www.w3.org/2000/xmlns/";function $t(t){(function(t){const n=t.split(":");return!(n.length>2)&&n.every((t=>qr(t)))})(t)||A("The qualified name is not a valid QName")}function At(t,n){""===t&&(t=null),$t(n);let e=null,r=n;const o=n.indexOf(":");return o>=0&&(e=n.substring(0,o),r=n.substring(o+1)),null!==e&&null===t&&M("Qualified name with prefix can not have a null namespace"),"xml"===e&&t!==Ct&&M("xml prefix can only be used for the XML namespace"),"xmlns"!==n&&"xmlns"!==e||t===Dt||M("xmlns prefix or qualifiedName must use the XMLNS namespace"),t===Dt&&"xmlns"!==n&&"xmlns"!==e&&M("xmlns prefix or qualifiedName must be used for the XMLNS namespace"),{namespace:t,prefix:e,localName:r}}function It(t,n){if(t.namespaceURI===n&&null!==t.prefix)return t.prefix;const e=Array.from(t.attributes).find((t=>"xmlns"===t.prefix&&t.value===n));return e?e.localName:null!==t.parentElement?It(t.parentElement,n):null}class kt{constructor(t,n,e){this.$=null,this.A=0,this.I=t,this.k=t,this.M=n,this.R=e}enter(t,n){var e;const r=null!==(e=this.$)&&void 0!==e?e:t;if(this.k+=n,this.k>this.M){this.k/this.I>this.R&&_r("too much entity expansion",r)}this.$=r,this.A+=1}exit(){this.A-=1,0===this.A&&(this.$=null)}}function Mt(t,n){return{success:!0,offset:t,value:n}}function Rt(t){return Mt(t,void 0)}function Pt(t,n,e=!1){return{success:!1,offset:t,expected:n,fatal:e}}function Lt(t){return(n,e)=>{const r=e+t.length;return n.slice(e,r)===t?Mt(r,t):Pt(e,[t])}}function Ot(t,n){return(e,r)=>{const o=e.codePointAt(r);return void 0!==o&&t(o)?Rt(r+function(t){return t>65535?2:1}(o)):Pt(r,n)}}function zt(t,n){return(e,r)=>{const o=r;for(;;){const n=e.codePointAt(r);if(void 0===n)break;if(!t(n))break;r+=n>65535?2:1}return void 0!==n&&r===o?Pt(r,n):Rt(r)}}function Vt(t,n,e){return Ot((e=>t<=e&&e<=n),e||[`${String.fromCodePoint(t)}-${String.fromCodePoint(n)}`])}function _t(t,n){return(e,r)=>{const o=t(e,r);return o.success?Mt(o.offset,n(o.value)):o}}function Ft(t){return _t(t,(()=>{}))}function Ut(t,n,e,r){return(o,i)=>{const s=t(o,i);return s.success?n(s.value)?s:Pt(i,e,r):s}}function qt(t,n){return(e,r)=>{let o=null;for(const i of t){const t=i(e,r);if(t.success)return t;if(null===o||t.offset>o.offset?o=t:t.offset===o.offset&&void 0===n&&(o.expected=o.expected.concat(t.expected)),t.fatal)return t}return n=n||(null==o?void 0:o.expected)||[],o&&(o.expected=n),o||Pt(r,n)}}function Bt(t){return(n,e)=>{const r=t(n,e);return r.success||r.fatal?r:Mt(e,null)}}function Wt(t){return(n,e)=>{let r=[],o=e;for(;;){const e=t(n,o);if(!e.success){if(e.fatal)return e;break}if(r.push(e.value),e.offset===o)break;o=e.offset}return Mt(o,r)}}function Xt(t){return(n,e)=>{let r=e;for(;;){const e=t(n,r);if(!e.success){if(e.fatal)return e;break}if(e.offset===r)break;r=e.offset}return Rt(r)}}function Yt(t,n,e){return(r,o)=>{const i=t(r,o);if(!i.success)return i;const s=n(r,i.offset);return s.success?Mt(s.offset,e(i.value,s.value)):s}}function jt(...t){return(n,e)=>{const r=[];for(const o of t){const t=o(n,e);if(!t.success)return t;e=t.offset,r.push(t.value)}return Mt(e,r)}}function Ht(...t){return(n,e)=>{for(const r of t){const t=r(n,e);if(!t.success)return t;e=t.offset}return Rt(e)}}function Qt(t,n){return t}function Kt(t,n){return n}function Gt(t){return Yt(t,Xt(t),Kt)}function Jt(t,n){return Yt(t,n,Kt)}function Zt(t,n){return Yt(t,n,Qt)}function tn(t,n,e,r=!1){return Jt(t,r?un(Zt(n,e)):Zt(n,e))}function nn(t){return(n,e)=>{const r=t(n,e);return r.success?Mt(r.offset,n.slice(e,r.offset)):r}}function en(t){return(n,e)=>{const r=t(n,e);return r.success?Mt(e,r.value):r}}function rn(t,n){return(e,r)=>t(e,r).success?Pt(r,n):Rt(r)}function on(t,n,e){return Jt(rn(n,e),t)}function sn(t,n,e=0,r=[]){return(o,i)=>{const s=o.codePointAt(i+e);if(void 0===s)return Pt(i,r);const u=t[s];return void 0===u?void 0===n?Pt(i,r):n(o,i):u(o,i)}}function un(t){return(n,e)=>{const r=t(n,e);return r.success?r:Pt(r.offset,r.expected,!0)}}const ln=(t,n)=>t.length===n?Rt(n):Pt(n,["end of input"]);function cn(t){return Yt(t,ln,Qt)}class an{constructor(t,n){this.P=0,this.L=0,this.O=t,this.V=n}next(){if(this.P>=this.V.length)return{done:!0,value:ln(this.O,this.L)};const{parser:t,type:n}=this.V[this.P],e=t(this.O,this.L);return e.success?(this.L=e.offset,1!==n&&(this.P+=1),void 0===e.value?this.next():{done:!1,value:e.value}):0===n||e.fatal?{done:!0,value:e}:(this.P+=1,this.next())}}function hn(t){return(n,e)=>{const r=e,o=t(n,e);return o.success?Mt(o.offset,Object.assign({input:n,start:r,end:o.offset},o.value)):o}}const fn=Lt("_"),dn=Lt("-"),mn=Lt("."),pn=Lt('"'),gn=Lt("'"),wn=Lt("<"),yn=Lt(">"),bn=Lt("&"),vn=Lt("="),xn=Lt("["),Nn=Lt("]"),Sn=Lt(";"),Tn=Lt("%"),En=Lt("("),Cn=Lt(")"),Dn=Lt("+"),$n=Lt(","),An=Lt("?"),In=Lt("*"),kn=Lt("|"),Mn=Lt("]]>"),Rn=Lt("\x3c!--"),Pn=Lt("--\x3e"),Ln=Lt(""),zn=Lt("1."),Vn=Lt("version"),_n=Lt("encoding"),Fn=Lt("standalone"),Un=Lt("yes"),qn=Lt("no"),Bn=Lt(""),Qn=Lt("&#"),Kn=Lt("&#x"),Gn=Lt("!t.includes(":")),["name must not contain colon"],!0),Te=nn(zt(ve,["valid name character"])),Ee=hn(_t(Ut(qt([_t(tn(Kn,nn(Gt(fe)),Sn,!0),(t=>parseInt(t,16))),_t(tn(Qn,nn(Gt(he)),Sn,!0),(t=>parseInt(t,10)))]),(t=>de(t)),["character reference must reference a valid character"],!0),(t=>({type:0,cp:t})))),Ce=qt([hn(_t(tn(bn,Se,un(Sn)),(t=>({type:1,name:t})))),Ee]),De=hn(_t(tn(Tn,Se,Sn),(t=>({type:2,name:t})))),$e=38,Ae=qt([tn(pn,Wt(qt([nn(zt((t=>37!==t&&t!==$e&&t!==Ie&&de(t)),[])),De,Ce])),pn,!0),tn(gn,Wt(qt([nn(zt((t=>37!==t&&t!==$e&&t!==ke&&de(t)),[])),De,Ce])),gn,!0)]),Ie=34,ke=39,Me=sn({[Ie]:tn(pn,Wt(sn({[$e]:Ce},nn(zt((t=>t!==Ve&&t!==$e&&t!==Ie&&de(t)),[])))),pn,!0),[ke]:tn(gn,Wt(sn({[$e]:Ce},nn(zt((t=>t!==Ve&&t!==$e&&t!==ke&&de(t)),[])))),gn,!0)},void 0,0,["quoted attribute value"]),Re=cn(Wt(qt([nn(zt((t=>t!==Ve&&t!==$e&&de(t)),[])),Ce]))),Pe=Ut(qt([tn(pn,nn(zt((t=>t!==Ie&&de(t)))),pn),tn(gn,nn(zt((t=>t!==ke&&de(t)))),gn)]),(t=>!t.includes("#")),["system identifier must not contain a fragment identifier"],!0);function Le(t){return 32===t||13===t||10===t||97<=t&&t<=122||65<=t&&t<=90||48<=t&&t<=57||33<=t&&t<=47&&34!==t&&38!==t||58<=t&&t<=64&&60!==t&&62!==t||95===t}const Oe=cn(zt(Le)),ze=qt([tn(pn,nn(zt((t=>t!==Ie&&Le(t)))),pn,!0),tn(gn,nn(zt((t=>t!==ke&&Le(t)))),gn,!0)]),Ve=60,_e=nn(Gt(qt([zt((t=>t!==Ve&&t!==$e&&93!==t&&de(t)),[]),on(Ft(Nn),Mn,[])],["character data"]))),Comment=_t(tn(Rn,nn(Xt(qt([zt((t=>45!==t&&de(t)),[]),Zt(Ft(dn),rn(dn,["comment content may not contain --"]))]))),Pn,!0),(t=>({type:3,data:t}))),Fe=Ut(Se,(t=>"xml"!==t.toLowerCase()),['processing instruction target must not be "xml"'],!0),Ue=tn(Ln,Yt(Fe,Bt(Jt(ge,nn(Xt(qt([zt((t=>63!==t&&de(t)),[]),Zt(Ft(An),rn(yn,["PI data"]))]))))),((t,n)=>({type:4,target:t,data:n}))),On,!0),qe=Lt("93!==t&&de(t)),[]),on(Ft(Nn),Mn,["CData"])]))),We=hn(_t(tn(qe,Be,Mn,!0),(t=>({type:5,data:t})))),Xe=tn(Bt(ge),vn,Bt(ge)),Ye=nn(Jt(zn,Gt(he))),je=Jt(ge,Jt(Vn,Jt(Xe,qt([tn(pn,Ye,pn,!0),tn(gn,Ye,gn,!0)])))),He=nn(Jt(qt([ce,ae]),Xt(qt([ce,ae,he,Ft(mn),Ft(fn),Ft(dn)])))),Qe=Jt(ge,Jt(_n,Jt(Xe,qt([tn(pn,He,pn,!0),tn(gn,He,gn,!0)])))),Ke=qt([_t(Un,(()=>!0)),_t(qn,(()=>!1))]),Ge=Jt(ge,Jt(Fn,un(Jt(Xe,qt([tn(pn,Ke,pn,!0),tn(gn,Ke,gn,!0)]))))),Je=tn(Zt(Bn,en(ge)),Zt(Yt(je,Yt(Bt(Qe),Bt(Ge),((t,n)=>[t,n])),((t,[n,e])=>({type:6,version:t,encoding:n,standalone:e}))),Bt(ge)),On,!0),Ze=hn(_t(xe,(t=>({name:t})))),tr=Yt(Ze,Jt(un(Xe),un(Me)),((t,n)=>({name:t,value:n}))),nr=_t(jt(wn,Ze,un(Zt(Wt(Jt(ge,tr)),Bt(ge))),un(sn({47:_t(Hn,(()=>!0))},_t(yn,(()=>!1)),0,[">","/>"]))),(([t,n,e,r])=>({type:r?9:7,name:n,attributes:e}))),er=hn(_t(tn(jn,Zt(xe,Bt(ge)),yn,!0),(t=>({type:8,name:t})))),rr=qt([An,In,Dn]),or=Zt(qt([Ft(xe),function(t,n){return ir(t,n)},function(t,n){return sr(t,n)}]),Ft(Bt(rr))),ir=Ht(En,Bt(ge),or,Gt(jt(Bt(ge),kn,Bt(ge),un(or))),Bt(ge),Cn);const sr=Ht(En,Bt(ge),or,Xt(jt(Bt(ge),$n,Bt(ge),un(or))),Bt(ge),Cn);const ur=Zt(qt([ir,sr]),Bt(rr)),lr=Ht(En,Bt(ge),te,qt([Ht(Xt(Ht(Bt(ge),kn,Bt(ge),xe)),Bt(ge),Cn,In),Ft(Zt(Bt(ge),Cn))])),cr=Zt(Gn,un(Ht(ge,xe,ge,qt([Ft(Jn),Ft(Zn),Ft(lr),Ft(ur)]),Bt(ge),yn))),ar=Lt("CDATA"),hr=qt([Lt("IDREFS"),Lt("IDREF"),Lt("ID"),Lt("ENTITY"),Lt("ENTITIES"),Lt("NMTOKENS"),Lt("NMTOKEN")]),fr=qt([Zt(ee,un(Ht(ge,En,Bt(ge),Se,Xt(Ht(Bt(ge),kn,Bt(ge),Se)),Bt(ge),Cn))),Zt(En,un(Ht(Bt(ge),Te,Xt(Ht(Bt(ge),kn,Bt(ge),Te)),Bt(ge),Cn)))]),dr=qt([_t(ar,(()=>!0)),_t(hr,(()=>!1)),_t(fr,(()=>!1))]),mr=qt([_t(re,(()=>({type:0}))),_t(oe,(()=>({type:1}))),Yt(_t(Bt(Zt(ie,ge)),(t=>null!==t)),Me,((t,n)=>({type:2,fixed:t,value:n})))]),pr=Yt(Jt(ge,Ze),un(Yt(Jt(ge,dr),Jt(ge,mr),((t,n)=>({isCData:t,def:n})))),((t,{isCData:n,def:e})=>({name:t,isCData:n,def:e}))),gr=tn(Zt(ne,ge),Yt(xe,un(Wt(pr)),((t,n)=>({type:0,name:t,attdefs:n}))),Jt(Bt(ge),yn),!0),wr=qt([_t(Jt(Xn,un(Jt(ge,Pe))),(t=>({publicId:null,systemId:t}))),Jt(Yn,Yt(un(Jt(ge,ze)),Jt(ge,Pe),((t,n)=>({publicId:t,systemId:n}))))]),yr=qt([Ae,Yt(wr,Bt(Jt(tn(ge,ue,ge),Se)),((t,n)=>({ids:t,ndata:n})))]),br=tn(se,Yt(Jt(ge,Se),un(Jt(ge,yr)),((t,n)=>({type:1,name:t,value:n}))),Jt(Bt(ge),yn)),vr=qt([Ae,Ft(wr)]),xr=tn(Zt(se,Jt(ge,Tn)),Yt(Jt(ge,Se),un(Jt(ge,vr)),((t,n)=>n?{type:2,name:t,value:n}:void 0)),Jt(Bt(ge),yn),!0),Nr=Jt(en(se),un(qt([br,xr]))),Sr=tn(Zt(Bn,en(ge)),Zt(Yt(Bt(je),Qe,((t,n)=>({type:6,version:t,encoding:n,standalone:null}))),Bt(ge)),On,!0),Tr=_t(Zt(Zt(Yn,ge),un(ze)),(t=>({publicId:t,systemId:null}))),Er=tn(le,Yt(tn(ge,Se,ge),qt([Ft(wr),Ft(Tr)]),(()=>{})),Jt(Bt(ge),yn),!0),Cr=qt([Ft(cr),gr,Nr,Ft(Er),Ft(Ue),Ft(Comment)]),Dr=qt([Ft(De),Ft(ge)]),$r=function(t){return _t(t,(t=>t.filter((t=>void 0!==t))))}(Wt(qt([Cr,Dr]))),Ar=Jt(Wn,un(_t(jt(ge,xe,Bt(Jt(ge,wr)),Bt(ge),Bt(Zt(tn(xn,$r,Nn,!0),Bt(ge))),yn),(([t,n,e,r,o,i])=>({type:10,name:n,ids:e,intSubset:o}))))),Ir={parser:sn({[Ve]:sn({47:er,33:qt([Comment,We]),63:Ue},nr,1),[$e]:Ce},_e),type:1};function kr(t){return new an(t,[Ir])}const Mr=qt([Comment,Ue,ge]),Rr=[...[{parser:Je,type:2},{parser:Mr,type:1},{parser:Ar,type:2},{parser:Mr,type:1}],...[{parser:nr,type:0},Ir]];function Pr(t){return new an(t,Rr)}const Lr=[{parser:Sr,type:2},Ir];function Or(t){return new an(t,Lr)}function zr(t){return Array.from(t,(t=>Ur(t)?t:"[invalid character]")).join("")}function Vr(t,n,e){const r=Array.from(t);if(r.length65535?2:1,10===n&&(e++,r=1)}return{line:e,char:r}}(n.input,n.start);throw new Error(`${t}\n${`At line ${e}, character ${r}:`}\n\n${function(t,n,e){const r=Vr(zr(t.substring(n,e)),2,30),o=t.lastIndexOf("\n",n),i=Vr(zr(t.substring(o+1,n)),0,55-r.length),s=t.indexOf("\n",e),u=Vr(zr(s>0?t.substring(e,s):t.substring(e)),1,80-r.length-i.length),l=Array.from(i,(t=>Br(t)?t:" ")).join("");return`${i}${r}${u}\n${l}${"^".repeat(Math.max(Array.from(r).length,1))}`}(n.input,n.start,n.end)}`)}function Fr(t,n,e,r){const o=Array.from(new Set(e),(t=>t.includes('"')?`'${t}'`:`"${t}"`)),i=n.codePointAt(r),s=i?String.fromCodePoint(i):"";_r(`Parsing ${t} failed, expected ${o.length>1?"one of "+o.join(", "):o[0]}`,{input:n,start:r,end:r+Math.max(s.length,1)})}function Ur(t){return me(t,0).success}function qr(t){return Ne(t,0).success}function Br(t){return we(t,0).success}function Wr(t){const n=[];for(const e of t)if("string"!=typeof e)switch(e.type){case 0:n.push(String.fromCodePoint(e.cp));break;case 1:n.push(`&${e.name};`);break;case 2:_r(`reference to parameter entity "${e.name}" must not occur in an entity declaration in the internal subset`,e)}else n.push(e);return n.join("")}class Xr{constructor(t){if(this._=new Map,this.F=new Map,this.U=new Set,this.q=new Set,t.intSubset)for(const n of t.intSubset)switch(n.type){case 0:{for(const t of n.attdefs)if(2===t.def.type)for(const n of t.def.value)"string"!=typeof n&&1===n.type&&(this.F.has(n.name)||this.U.has(n.name)||this.q.has(n.name)||_r(`default value of attribute "${t.name.name}" contains reference to undefined entity "${n.name}"`,n),this.U.has(n.name)&&_r(`default value of attribute "${t.name.name}" must not contain reference to external entity "${n.name}"`,n));let t=this._.get(n.name);void 0===t&&(t=new Map,this._.set(n.name,t));for(const e of n.attdefs)t.has(e.name.name)||t.set(e.name.name,e);break}case 2:if(Array.isArray(n.value))for(const t of n.value)"string"!=typeof t&&2===t.type&&_r(`reference to parameter entity "${t.name}" must not occur in an entity declaration in the internal subset`,t);break;case 1:if(this.F.has(n.name)||this.U.has(n.name))continue;Array.isArray(n.value)?this.F.set(n.name,Wr(n.value)):null===n.value.ndata?this.U.add(n.name):this.q.add(n.name)}}getAttlist(t){return this._.get(t.name)}getEntityReplacementText(t,n){const e=this.F.get(t.name);if(void 0===e&&(this.q.has(t.name)&&_r(`reference to binary entity "${t.name}" is not allowed`,t),this.U.has(t.name))){if(n)return"";_r(`reference to external entity "${t.name}" is not allowed in attribute value`,t)}return e}}const Yr=new Map([["lt","<"],["gt",">"],["amp","&"],["apos","'"],["quot",'"']]);function jr(t,n,e,r,o){for(const i of n){if("string"==typeof i){t.push(i.replace(/[\r\n\t]/g," "));continue}if(0===i.type){t.push(String.fromCodePoint(i.cp));continue}null!==r&&r.includes(i.name)&&_r(`reference to entity "${i.name}" must not be recursive`,i);let n=Yr.get(i.name);void 0===n&&null!==e&&(n=e.getEntityReplacementText(i,!1)),void 0===n&&_r(`reference to unknown entity "${i.name}" in attribute value`,i),o.enter(i,n.length);const s=Re(n,0);s.success||Fr(`replacement text for entity "${i.name}"`,n,s.expected,s.offset),jr(t,s.value,e,r?[i.name,...r]:[i.name],o),o.exit()}}function Hr(t,n,e,r){const o=[];return jr(o,t,e,null,r),n&&!n.isCData?o.join("").replace(/[ ]+/g," ").replace(/^[ ]+|[ ]+$/g,""):o.join("")}function Qr(t,n){const e=t.name,r=n.get(e);if(void 0!==r)return r;let o=null,i=e;const s=e.indexOf(":");s>=0&&(o=e.substring(0,s),i=e.substring(s+1)),(""===o||""===i||i.includes(":"))&&_r(`the name "${e}" is not a valid qualified name`,t);const u={prefix:o,localName:i};return n.set(e,u),u}class Kr{constructor(t,n=null){var e;this.B=new Map,this.W=null,this.X=t,this.W=null!==(e=null!=n?n:null==t?void 0:t.W)&&void 0!==e?e:null}getForElement(t,n){"xmlns"===t&&_r('element names must not have the prefix "xmlns"',n);for(let n=this;null!==n;n=n.X){const e=n.B.get(t);if(void 0!==e)return e}if(null!==t&&this.W){const n=this.W(t);if(void 0!==n)return n}_r(`use of undeclared element prefix "${t}"`,n)}getForAttribute(t,n,e){if(null===t)return"xmlns"===n?Dt:null;for(let n=this;null!==n;n=n.X){const e=n.B.get(t);if(void 0!==e)return e}if(this.W){const n=this.W(t);if(void 0!==n)return n}_r(`use of undeclared attribute prefix ${t}`,e)}static fromAttrs(t,n,e,r,o,i){let s=t,u=!1;const l=(n,e,r)=>{null!==n||e!==Ct&&e!==Dt||_r(`the namespace "${e}" must not be used as the default namespace`,r),e===Dt&&_r(`the namespace "${Dt}" must not be bound to a prefix`,r),e===Ct&&"xml"!==n&&_r(`the namespace "${Ct}" must be bound only to the prefix "xml"`,r),e!==Ct&&"xml"===n&&_r(`the xml namespace prefix must not be bound to any namespace other than "${Ct}"`,r),null!==n&&null===e&&_r(`the prefix "${n}" must not be undeclared`,r),u||(s=new Kr(t),u=!0),s.B.set(n,e)},c=(t,n)=>{const{prefix:c,localName:a}=Qr(t,o),h=null==e?void 0:e.get(t.name);if(null!==c||"xmlns"!==a||u&&s.B.has(null)){if(!("xmlns"!==c||u&&s.B.has(a))){"xmlns"===a&&_r('the "xmlns" namespace prefix must not be declared',t);const e=Hr(n,h,r,i)||null;l(a,e,t)}}else{const e=Hr(n,h,r,i)||null;l(null,e,t)}};for(const t of n.attributes)c(t.name,t.value);if(e)for(const t of e.values()){const n=t.def;2===n.type&&c(t.name,n.value)}return s}static default(t){const n=new Kr(null,t);return n.B.set(null,null),n.B.set("xml",Ct),n.B.set("xmlns",Dt),n}}const Gr=Kr.default(null);function Jr(t,n){W(n,t,null,!0)}function Zr(t,n,e,r,{entityExpansionMaxAmplification:o=100,entityExpansionThreshold:i=4194304,treatCDataAsText:s=!1}){var u,l;const c=g(r);let a={parent:null,root:r,namespaces:e,entityRoot:!0},h=null;const d=new Map;let m=[];function p(){if(m.length>0){const t=m.join("");if(a.root===c){if(!Br(t))throw new Error("document must not contain text outside of elements")}else Jr(a.root,c.createTextNode(m.join("")));m.length=0}}t=function(t){return t.replace(/\r\n?/g,"\n")}(t=t.replace(/^\ufeff/,""));const w=new kt(t.length,i,o);let y={parent:null,entity:null,iterator:n(t)};for(;y;){let n=y.iterator.next();for(;!n.done;n=y.iterator.next()){const t=n.value;if("string"!=typeof t){switch(t.type){case 0:a.root===c&&null!==c.documentElement&&_r("character reference must not appear after the document element",t),m.push(String.fromCodePoint(t.cp));continue;case 1:{a.root===c&&null!==c.documentElement&&_r(`reference to entity "${t.name}" must not appear after the document element`,t);for(let n=y;n;n=n.parent)n.entity===t.name&&_r(`reference to entity "${t.name}" must not be recursive`,t);let n=Yr.get(t.name);void 0===n&&null!==h&&(n=h.getEntityReplacementText(t,!0)),void 0===n&&_r(`reference to unknown entity "${t.name}" in content`,t),w.enter(t,n.length),a={parent:a,root:a.root,namespaces:a.namespaces,entityRoot:!0},y={parent:y,entity:t.name,iterator:kr(n)};continue}case 5:if(s){m.push(t.data);continue}}switch(p(),t.type){case 5:a.root===c&&null!==c.documentElement&&_r("CData section must not appear after the document element",t),Jr(a.root,c.createCDATASection(t.data));continue;case 3:Jr(a.root,c.createComment(t.data));continue;case 10:h=new Xr(t),Jr(a.root,c.implementation.createDocumentType(t.name,(null===(u=t.ids)||void 0===u?void 0:u.publicId)||"",(null===(l=t.ids)||void 0===l?void 0:l.systemId)||""));continue;case 4:Jr(a.root,c.createProcessingInstruction(t.target,t.data||""));continue;case 7:case 9:{a.root===c&&null!==c.documentElement&&_r(`document must contain a single root element, but found "${c.documentElement.nodeName}" and "${t.name.name}"`,t.name);const n=h?h.getAttlist(t.name):void 0,e=Kr.fromAttrs(a.namespaces,t,n,h,d,w),{prefix:r,localName:o}=Qr(t.name,d),i=e.getForElement(r,t.name),s=Tt(c,o,i,r);for(const r of t.attributes){const{prefix:o,localName:i}=Qr(r.name,d),u=e.getForAttribute(o,i,r.name),l=null==n?void 0:n.get(r.name.name);s.hasAttributeNS(u,i)&&_r(`attribute "${r.name.name}" must not appear multiple times on element "${t.name.name}"`,r.name);wt(St(u,o,i,Hr(r.value,l,h,w),s),s,!0)}if(n)for(const t of n.values()){const n=t.def;if(2!==n.type)continue;const{prefix:r,localName:o}=Qr(t.name,d),i=e.getForAttribute(r,o,t.name);if(s.hasAttributeNS(i,o))continue;wt(St(i,r,o,Hr(n.value,t,h,w),s),s,!0)}Jr(a.root,s),7===t.type&&(a={parent:a,root:s,namespaces:e,entityRoot:!1,event:t});continue}case 8:f(a.root)&&a.root.nodeName===t.name||_r(`non-well-formed element: found end tag "${t.name}" but expected ${f(a.root)?`"${a.root.nodeName}"`:"no such tag"}`,t),a=a.parent;continue}}else m.push(t)}n.value.success||Fr(y.entity?`replacement text for entity ${y.entity}`:r===c?"document":"fragment",t,n.value.expected,n.value.offset),a.entityRoot||_r(`${y.entity?`replacement text for entity "${y.entity}"`:r===c?"document":"fragment"} is not well-formed - element "${a.root.nodeName}" is missing a closing tag`,a.event.name),y=y.parent,y&&(w.exit(),a=a.parent)}p()}function to(t,n={}){const e=new Document;return Zr(t,Pr,Gr,e,n),e}class no{constructor(t){this.Y=new Map,this.j=new Map,this.X=t}static new(){const t=new no(null);return t.add(null,null),t.add("xml",Ct),t.add("xmlns",Dt),t}add(t,n){const e=this.j.get(n);void 0===e?this.j.set(n,[t]):e.push(t),this.Y.set(t,n)}recordNamespaceInformation(t){const n=new no(this);for(const e of t.attributes){if(e.namespaceURI!==Dt)continue;const t=""===e.value?null:e.value,r=null===e.prefix?null:e.localName;n.add(r,t)}return n}H(t){return this.Y.get(t)}K(t){var n;return null===(n=this.X)||void 0===n?void 0:n.prefixToNamespace(t)}prefixToNamespace(t){const n=this.H(t);return void 0!==n?n:this.K(t)}shouldSerializeDeclaration(t,n){return this.prefixToNamespace(t)===n&&this.K(t)!==n}G(t,n){let e=this;for(;e;){const r=e.j.get(t);if(void 0!==r)for(let e=r.length-1;e>=0;--e){const o=r[e];if((n||null!==o)&&this.prefixToNamespace(o)===t)return o}e=e.X}}getPreferredPrefix(t,n){var e;if(t.namespaceURI===Ct)return"xml";const r=c(t);if(t.namespaceURI===Dt)return r&&null===t.prefix?null:"xmlns";if(r&&null===t.namespaceURI)return null;if(!r){let n=null!==(e=this.K(null))&&void 0!==e?e:null;if(t.namespaceURI===n)return null}if((!r||null!==t.prefix)&&this.prefixToNamespace(t.prefix)===t.namespaceURI)return t.prefix;const o=this.G(t.namespaceURI,!r);if(void 0!==o)return o;if(r){const e=this.H(t.prefix);if(!(null!==t.prefix&&(void 0===e||e===t.namespaceURI)))for(;;){const t=`ns${n.value}`;if(n.value+=1,void 0===this.H(t))return t}}return t.prefix}}const eo=["area","base","basefont","bgsound","br","col","embed","frame","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"];function ro(t,n,e=!1){const r=e?[t]:t.childNodes,o=[];for(const t of r)oo(t,n,o);return o.join("")}function oo(t,n,e){const r=no.new(),o={value:1};try{io(t,r,o,n,e)}catch(t){return k(t.message)}}function io(t,n,e,r,o){switch(t.nodeType){case 1:return void function(t,n,e,r,o){const i=t;if(r&&(i.localName.indexOf(":")>=0||!qr(i.localName)))throw new Error(`Can not serialize an element because the localName "${i.localName}" is not allowed.`);o.push("<");let s="",u=!1;const l=n.recordNamespaceInformation(i);if("xmlns"===i.prefix&&r)throw new Error('Can not serialize an element with prefix "xmlns" because it will not legally round-trip in a conforming XML parser.');const c=l.getPreferredPrefix(i,e);null!==c&&(s+=`${c}:`);s+=i.localName,o.push(s),l.prefixToNamespace(c)!==i.namespaceURI&&(l.add(c,i.namespaceURI),null===c?o.push(' xmlns="'):o.push(" xmlns:",c,'="'),o.push(so(i.namespaceURI,r),'"'));(function(t,n,e,r,o){const i=[];for(const s of t.attributes){let t=n.getPreferredPrefix(s,e);if(s.namespaceURI===Dt){const t=""===s.value?null:s.value;if(r&&t===Dt)throw new Error("The serialization of this attribute would produce invalid XML because the XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing.");if(t===Ct||t===Dt)continue;const e=null===s.prefix?null:s.localName;if(r&&null!==s.prefix&&""===s.value)throw new Error("Namespace prefix declarations cannot be used to undeclare a namespace. Use a default namespace declaration instead.");if(!n.shouldSerializeDeclaration(e,t))continue}if(r&&i.find((t=>t.localName===s.localName&&t.namespaceURI===s.namespaceURI)))throw new Error(`Can not serialize a duplicate attribute for namespaceURI "${s.namespaceURI}", localName "${s.localName}".`);if(i.push({namespaceURI:s.namespaceURI,localName:s.localName}),r&&(s.localName.indexOf(":")>=0||!qr(s.localName)||"xmlns"===s.localName&&null===s.namespaceURI))throw new Error(`Can not serialize an attribute because the localName "${s.localName}" is not allowed.`);null!==t&&n.prefixToNamespace(t)!==s.namespaceURI&&(o.push(" xmlns:",t,'="',so(s.namespaceURI,r),'"'),n.add(t,s.namespaceURI)),o.push(" "),null!==t&&o.push(t,":"),o.push(s.localName,'="',so(s.value,r),'"')}})(i,l,e,r,o),i.namespaceURI===Et&&!i.hasChildNodes()&&eo.indexOf(i.localName)>=0&&(o.push(" /"),u=!0);i.namespaceURI===Et||i.hasChildNodes()||(o.push("/"),u=!0);if(o.push(">"),u)return;for(const n of t.childNodes)io(n,l,e,r,o);o.push("")}(t,n,e,r,o);case 9:return void function(t,n,e,r,o){const i=t;if(r&&null===i.documentElement)throw new Error("Can not serialize a document with no documentElement.");for(const t of i.childNodes)io(t,n,e,r,o)}(t,n,e,r,o);case 8:return void function(t,n,e){const r=t;if(n&&(!Ur(r.data)||r.data.indexOf("--")>=0||r.data.endsWith("-")))throw new Error("Can not serialize a comment because it contains invalid characters.");e.push("\x3c!--",r.data,"--\x3e")}(t,r,o);case 4:return void function(t,n,e){const r=t;e.push("")}(t,0,o);case 3:return void function(t,n,e){const r=t;if(n&&!Ur(r.data))throw new Error("Can not serialize a text node because it contains invalid characters.");let o=r.data;o=o.replace(/&/g,"&"),o=o.replace(//g,">"),e.push(o)}(t,r,o);case 11:return void function(t,n,e,r,o){for(const i of t.childNodes)io(i,n,e,r,o)}(t,n,e,r,o);case 10:return void function(t,n,e){const r=t;if(n&&(o=r.publicId,!Oe(o,0).success))throw new Error("Can not serialize a document type because the publicId contains invalid characters.");var o;if(n&&(!Ur(r.systemId)||r.systemId.indexOf('"')>=0&&r.systemId.indexOf("'")>=0))throw new Error("Can not serialize a document type because the systemId contains invalid characters.");e.push("")}(t,r,o);case 7:return void function(t,n,e){const r=t;if(n){if(r.target.indexOf(":")>=0)throw new Error(`Can not serialize a processing instruction because the target "${r.target}" may not contain ":".`);if("xml"===r.target.toLowerCase())throw new Error('Can not serialize a processing instruction because "xml" may not be used as target.')}if(n&&(!Ur(r.data)||r.data.indexOf("?>")>=0))throw new Error("Can not serialize a processing instruction because the data contains invalid characters.");e.push("")}(t,r,o);case 2:return;default:throw new TypeError("Only Nodes and Attr objects can be serialized by this algorithm.")}}function so(t,n){if(n&&null!==t&&!Ur(t))throw new Error("Can not serialize an attribute value because it contains invalid characters.");return null===t?"":t.replace(/&/g,"&").replace(/"/g,""").replace(//g,">").replace(/\t/g," ").replace(/\n/g," ").replace(/\r/g," ")}class Element extends Node{get nodeType(){return 1}get nodeName(){return this.tagName}get nodeValue(){return null}set nodeValue(t){}get textContent(){return K(this)}set textContent(t){G(this,t=ct(t))}lookupPrefix(t){return S(arguments,1),null===(t=ft(t))||""===t?null:It(this,t)}lookupNamespaceURI(t){if(S(arguments,1),""===(t=ft(t))&&(t=null),null!==this.namespaceURI&&this.prefix===t)return this.namespaceURI;let n=null;if(null!==t){const e=this.getAttributeNodeNS(Dt,t);e&&"xmlns"===e.prefix&&(n=e.value)}else{const t=this.getAttributeNodeNS(Dt,"xmlns");t&&null===t.prefix&&(n=t.value)}if(null!==n)return""!==n?n:null;const e=this.parentElement;return null===e?null:e.lookupNamespaceURI(t)}before(...t){et(this,t)}after(...t){rt(this,t)}replaceWith(...t){ot(this,t)}remove(){it(this)}get children(){return V(this)}prepend(...t){Z(this,t)}append(...t){tt(this,t)}replaceChildren(...t){nt(this,t)}get previousElementSibling(){return _(this)}get nextElementSibling(){return F(this)}constructor(t,n,e){super(),this.firstElementChild=null,this.lastElementChild=null,this.childElementCount=0,this.attributes=[],this.namespaceURI=t,this.prefix=n,this.localName=e,this.tagName=null===n?e:`${n}:${e}`}hasAttributes(){return this.attributes.length>0}getAttribute(t){S(arguments,1);const n=lo(t=String(t),this);return null===n?null:n.value}getAttributeNS(t,n){S(arguments,2);const e=co(t=ft(t),n=String(n),this);return null===e?null:e.value}setAttribute(t,n){S(arguments,2),t=String(t),n=String(n),qr(t)||A("The qualified name does not match the Name production");const e=lo(t,this);if(null===e){const e=new(u().Attr)(null,null,t,n,this);return e.ownerDocument=this.ownerDocument,void wt(e,this)}gt(e,n)}setAttributeNS(t,n,e){S(arguments,3),t=ft(t),n=String(n),e=String(e);const{namespace:r,prefix:o,localName:i}=At(t,n);!function(t,n,e,r,o){const i=co(o,n,t);if(null===i){const i=new(u().Attr)(o,r,n,e,t);return i.ownerDocument=t.ownerDocument,void wt(i,t)}gt(i,e)}(this,i,e,o,r)}removeAttribute(t){S(arguments,1),ho(t=String(t),this)}removeAttributeNS(t,n){S(arguments,2),function(t,n,e){const r=co(t,n,e);null!==r&&yt(r)}(t=ft(t),n=String(n),this)}toggleAttribute(t,n){qr(t)||A("The qualified name does not match the Name production");if(null===lo(t,this)){if(void 0===n||!0===n){const n=new(u().Attr)(null,null,t,"",this);return n.ownerDocument=this.ownerDocument,wt(n,this),!0}return!1}return void 0!==n&&!1!==n||(ho(t,this),!1)}hasAttribute(t){return S(arguments,1),null!==lo(t=String(t),this)}hasAttributeNS(t,n){return S(arguments,2),null!==co(t=ft(t),n=String(n),this)}getAttributeNode(t){return S(arguments,1),lo(t=String(t),this)}getAttributeNodeNS(t,n){return S(arguments,2),co(t=ft(t),n=String(n),this)}setAttributeNode(t){return S(arguments,1),ao(t=at(t,Attr),this)}setAttributeNodeNS(t){return S(arguments,1),ao(t=at(t,Attr),this)}removeAttributeNode(t){return S(arguments,1),t=at(t,Attr),this.attributes.indexOf(t)<0&&R("the specified attribute does not exist"),yt(t),t}getElementsByTagName(t){return S(arguments,1),v(t=String(t),this)}getElementsByTagNameNS(t,n){return S(arguments,2),x(t=ft(t),n=String(n),this)}T(t){const n=uo(t,this.localName,this.namespaceURI,this.prefix);for(const e of this.attributes){const r=e.T(t);n.setAttributeNode(r)}return n}get innerHTML(){return ro(this,!0)}get outerHTML(){return ro(this,!0,!0)}}function uo(t,n,e,r=null){let o=null;return o=new(u().Element)(e,r,n),o.ownerDocument=t,o}function lo(t,n){return n.attributes.find((n=>n.name===t))||null}function co(t,n,e){return""===t&&(t=null),e.attributes.find((e=>e.namespaceURI===t&&e.localName===n))||null}function ao(t,n){null!==t.ownerElement&&t.ownerElement!==n&&function(t){throw C("InUseAttributeError",t)}("attribute is in use by another element");const e=co(t.namespaceURI,t.localName,n);return e===t?t:(null!==e?function(t,n){const e=t.ownerElement;pt(t,e,t.value,n.value),e.attributes.splice(e.attributes.indexOf(t),1,n),n.ownerElement=e,t.ownerElement=null}(e,t):wt(t,n),e)}function ho(t,n){const e=lo(t,n);return null!==e&&yt(e),e}function fo(t,n,e){const{namespace:r,prefix:o,localName:i}=At(n,e);return uo(t,i,r,o)}class DOMImplementation{constructor(t){this.J=t}createDocumentType(t,n,e){S(arguments,3),t=String(t),n=String(n),e=String(e),$t(t);const r=new(u(this.J).DocumentType)(t,n,e);return r.ownerDocument=this.J,r}createDocument(t,n,e=null){S(arguments,2),t=ft(t),n=lt(n),e=ht(e,DocumentType);const r=new(u(this.J).XMLDocument);let o=null;return""!==n&&(o=fo(r,t,n)),e&&r.appendChild(e),o&&r.appendChild(o),r}createHTMLDocument(t){t=ft(t);const n=u(this.J),e=new n.Document,r=new n.DocumentType("html");r.ownerDocument=e,e.appendChild(r);const o=uo(e,"html",Et);e.appendChild(o);const i=uo(e,"head",Et);if(o.appendChild(i),null!==t){const n=uo(e,"title",Et);i.appendChild(n),n.appendChild(e.createTextNode(t))}return o.appendChild(uo(e,"body",Et)),e}}class Document extends Node{get nodeType(){return 9}get nodeName(){return"#document"}get nodeValue(){return null}set nodeValue(t){}get textContent(){return null}set textContent(t){}lookupPrefix(t){return S(arguments,1),null!==this.documentElement?this.documentElement.lookupPrefix(t):null}lookupNamespaceURI(t){return S(arguments,1),null===this.documentElement?null:this.documentElement.lookupNamespaceURI(t)}get children(){return V(this)}prepend(...t){Z(this,t)}append(...t){tt(this,t)}replaceChildren(...t){nt(this,t)}constructor(){super(),this.firstElementChild=null,this.lastElementChild=null,this.childElementCount=0,this.implementation=new DOMImplementation(this),this.doctype=null,this.documentElement=null}getElementsByTagName(t){return S(arguments,1),v(t=String(t),this)}getElementsByTagNameNS(t,n){return S(arguments,2),x(t=ft(t),n=String(n),this)}createElement(t){S(arguments,1),qr(t=String(t))||A("The local name is not a valid Name");return uo(this,t,null,null)}createElementNS(t,n){return S(arguments,2),fo(this,t=ft(t),n=String(n))}createDocumentFragment(){const t=new(u().DocumentFragment);return t.ownerDocument=this,t}createTextNode(t){S(arguments,1),t=String(t);const n=new(u().Text)(t);return n.ownerDocument=this,n}createCDATASection(t){S(arguments,1),(t=String(t)).indexOf("]]>")>=0&&A('Data must not contain the string "]]>"');const n=new(u().CDATASection)(t);return n.ownerDocument=this,n}createComment(t){S(arguments,1),t=String(t);const n=new(u().Comment)(t);return n.ownerDocument=this,n}createProcessingInstruction(t,n){S(arguments,2),t=String(t),n=String(n),qr(t)||A("The target is not a valid Name"),n.indexOf("?>")>=0&&A('Data must not contain the string "?>"');const e=new(u().ProcessingInstruction)(t,n);return e.ownerDocument=this,e}importNode(t,n=!1){return S(arguments,1),l(t=at(t,Node),9)&&P("importing a Document node is not supported"),N(t,n,this)}adoptNode(t){return S(arguments,1),l(t=at(t,Node),9)&&P("adopting a Document node is not supported"),Q(t,this),t}createAttribute(t){S(arguments,1),qr(t=String(t))||A("The local name is not a valid Name");const n=new(u().Attr)(null,null,t,"",null);return n.ownerDocument=this,n}createAttributeNS(t,n){S(arguments,2),t=ft(t),n=String(n);const{namespace:e,prefix:r,localName:o}=At(t,n),i=new(u().Attr)(e,r,o,"",null);return i.ownerDocument=this,i}createRange(){const t=new(u().Range);return t.startContainer=this,t.startOffset=0,t.endContainer=this,t.endOffset=0,t}T(t){return new(u().Document)}}class DocumentFragment extends Node{get nodeType(){return 11}get nodeName(){return"#document-fragment"}get nodeValue(){return null}set nodeValue(t){}get textContent(){return K(this)}set textContent(t){G(this,t=ct(t))}lookupPrefix(t){return S(arguments,1),null}lookupNamespaceURI(t){return S(arguments,1),null}get children(){return V(this)}prepend(...t){Z(this,t)}append(...t){tt(this,t)}replaceChildren(...t){nt(this,t)}constructor(){super(),this.firstElementChild=null,this.lastElementChild=null,this.childElementCount=0;const t=u();this.ownerDocument=t.document}T(t){const n=new(u().DocumentFragment);return n.ownerDocument=t,n}}class ProcessingInstruction extends CharacterData{get nodeType(){return 7}get nodeName(){return this.target}constructor(t,n){super(n),this.target=t}T(t){const n=new(u().ProcessingInstruction)(this.target,this.data);return n.ownerDocument=t,n}}function mo(t,n){if(t.collapsed)return;const e=p(t.startContainer),r=p(t.endContainer);let o=0;for(;o=o;--t)for(let o=e[t].nextSibling;o&&o!==i&&o!==r[t];o=o.nextSibling)n(o);for(let t=o;t{if(n){X(t.cloneNode(!0),r)}else X(t,r)})),v&&a(v)){const t=v.cloneNode();t.data=v.substringData(0,u),X(t,r),n||v.replaceData(0,u,"")}else if(null!==v){const t=v.cloneNode();X(t,r);const o=e.createRange();o.setStart(v,0),o.setEnd(s,u);const i=po(o,n);o.detach(),X(i,t)}return n||(t.setStart(E,C),t.collapse(!0)),r}class Range{get collapsed(){return(t=this).startContainer===t.endContainer&&t.startOffset===t.endOffset;var t}constructor(){const t=u();this.startContainer=t.document,this.startOffset=0,this.endContainer=t.document,this.endOffset=0,t.addRange(this)}get commonAncestorContainer(){const t=p(this.startContainer),n=p(this.endContainer);let e=t[0],r=0;for(;rm(t)&&$("Can not set a range past the end of the node");bo(this)===y(t)&&yo(t,n,this.endContainer,this.endOffset)!==wo||(this.endContainer=t,this.endOffset=n),this.startContainer=t,this.startOffset=n}setEnd(t,n){S(arguments,2),t=at(t,Node),n=ut(n),l(t,10)&&I("Can not set a range under a doctype node"),n>m(t)&&$("Can not set a range past the end of the node");bo(this)===y(t)&&yo(t,n,this.startContainer,this.startOffset)!==go||(this.startContainer=t,this.startOffset=n),this.endContainer=t,this.endOffset=n}setStartBefore(t){S(arguments,1);const n=(t=at(t,Node)).parentNode;if(null===n)return I("Can not set range before node without a parent");this.setStart(n,w(t))}setStartAfter(t){S(arguments,1);const n=(t=at(t,Node)).parentNode;if(null===n)return I("Can not set range before node without a parent");this.setStart(n,w(t)+1)}setEndBefore(t){S(arguments,1);const n=(t=at(t,Node)).parentNode;if(null===n)return I("Can not set range before node without a parent");this.setEnd(n,w(t))}setEndAfter(t){S(arguments,1);const n=(t=at(t,Node)).parentNode;if(null===n)return I("Can not set range before node without a parent");this.setEnd(n,w(t)+1)}collapse(t=!1){t?(this.endContainer=this.startContainer,this.endOffset=this.startOffset):(this.startContainer=this.endContainer,this.startOffset=this.endOffset)}selectNode(t){S(arguments,1);let n=(t=at(t,Node)).parentNode;if(null===n)return I("Can not select node with null parent");const e=w(t);this.startContainer=n,this.startOffset=e,this.endContainer=n,this.endOffset=e+1}selectNodeContents(t){S(arguments,1),l(t=at(t,Node),10)&&I("Can not place range inside a doctype node");const n=m(t);this.startContainer=t,this.startOffset=0,this.endContainer=t,this.endOffset=n}compareBoundaryPoints(t,n){switch(S(arguments,2),n=at(n,Range),t!==Range.START_TO_START&&t!==Range.START_TO_END&&t!==Range.END_TO_END&&t!==Range.END_TO_START&&P("Unsupported comparison type"),bo(this)!==bo(n)&&L("Can not compare positions of ranges in different trees"),t){case Range.START_TO_START:return yo(this.startContainer,this.startOffset,n.startContainer,n.startOffset);case Range.START_TO_END:return yo(this.endContainer,this.endOffset,n.startContainer,n.startOffset);case Range.END_TO_END:return yo(this.endContainer,this.endOffset,n.endContainer,n.endOffset);default:return yo(this.startContainer,this.startOffset,n.endContainer,n.endOffset)}}deleteContents(){if(this.collapsed)return;const t=this.startContainer,n=this.startOffset,e=this.endContainer,r=this.endOffset;if(t===e&&a(t))return void t.replaceData(n,r-n,"");const o=[];let i,s;if(mo(this,(t=>{o.push(t)})),t.contains(e))i=t,s=n;else{let n=t;for(;null!==n.parentNode&&!n.parentNode.contains(e);)n=n.parentNode;i=n.parentNode,s=1+w(n)}a(t)&&t.replaceData(n,t.length-n,""),o.forEach((t=>{H(t)})),a(e)&&e.replaceData(0,r,""),this.setStart(i,s),this.collapse(!0)}extractContents(){return po(this,!1)}cloneContents(){return po(this,!0)}insertNode(t){S(arguments,1),st(t=at(t,Node),this)}surroundContents(t){S(arguments,1),t=at(t,Node);(h(this.startContainer)?this.startContainer.parentNode:this.startContainer)!==(h(this.endContainer)?this.endContainer.parentNode:this.endContainer)&&k("Can not use surroundContents on a range that has partially selected a non-Text node"),l(t,9,10,11)&&I("Can not use Document, DocumentType, or DocumentFragment as a parent node in surroundContents");const n=po(this,!1);t.firstChild&&j(null,t),st(t,this),X(n,t),this.selectNode(t)}cloneRange(){const t=new(u().Range);return t.startContainer=this.startContainer,t.startOffset=this.startOffset,t.endContainer=this.endContainer,t.endOffset=this.endOffset,t}detach(){u().removeRange(this)}isPointInRange(t,n){return S(arguments,2),t=at(t,Node),n=ut(n),y(t)===bo(this)&&(l(t,10)&&I("Point can not be under a doctype"),n>m(t)&&$("Offset should not be past the end of node"),yo(t,n,this.startContainer,this.startOffset)!==go&&yo(t,n,this.endContainer,this.endOffset)!==wo)}comparePoint(t,n){return S(arguments,2),t=at(t,Node),n=ut(n),y(t)!==bo(this)&&L("Can not compare point to range in different trees"),l(t,10)&&I("Point can not be under a doctype"),n>m(t)&&$("Offset should not be past the end of node"),yo(t,n,this.startContainer,this.startOffset)===go?-1:yo(t,n,this.endContainer,this.endOffset)===wo?1:0}intersectsNode(t){if(S(arguments,1),y(t=at(t,Node))!==bo(this))return!1;const n=t.parentNode;if(null===n)return!0;const e=w(t);return yo(n,e,this.endContainer,this.endOffset)===go&&yo(n,e+1,this.startContainer,this.startOffset)===wo}toString(){let t=[];const n=this.startContainer;if(h(n)){if(this.startContainer===this.endContainer)return n.substringData(this.startOffset,this.endOffset-this.startOffset);t.push(n.substringData(this.startOffset,n.length-this.startOffset))}mo(this,(n=>{b(n,(n=>{h(n)&&t.push(n.data)}))}));const e=this.endContainer;return h(e)&&t.push(e.substringData(0,this.endOffset)),t.join("")}}Range.START_TO_START=0,Range.START_TO_END=1,Range.END_TO_END=2,Range.END_TO_START=3;const go=-1,wo=1;function yo(t,n,e,r){if(t!==e){const o=p(t),i=p(e);for(;o[0]&&i[0]&&o[0]===i[0];)o.shift(),i.shift();o.length&&(n=w(o[0])+.5),i.length&&(r=w(i[0])+.5)}return n===r?0:nt.o.removeForObserver(this))),this.u.length=0,this.m.length=0}takeRecords(){const t=this.m.concat();return this.m.length=0,t}},t.MutationRecord=O,t.Node=Node,t.ProcessingInstruction=ProcessingInstruction,t.Range=Range,t.StaticRange=class{constructor(t){l(t.startContainer,10,2)&&I("StaticRange startContainer must not be a doctype or attribute node"),l(t.endContainer,10,2)&&I("StaticRange endContainer must not be a doctype or attribute node"),this.startContainer=t.startContainer,this.startOffset=t.startOffset,this.endContainer=t.endContainer,this.endOffset=t.endOffset,this.collapsed=this.startContainer===this.endContainer&&this.startOffset===this.endOffset}},t.Text=Text,t.XMLDocument=XMLDocument,t.XMLSerializer=class{constructor(){}serializeToString(t){const n=[];return oo(t=at(t,Node),!1,n),n.join("")}},t.document=vo,t.parseXmlDocument=to,t.parseXmlFragment=function(t,n={}){const e=(new Document).createDocumentFragment();return Zr(t,Or,n.resolveNamespacePrefix?Kr.default(n.resolveNamespacePrefix):Gr,e,n),e},t.serializeToWellFormedString=function(t){const n=[];return oo(t=at(t,Node),!0,n),n.join("")},t.unsafeAppendAttribute=function(t,n){wt(t,n)},t.unsafeCreateAttribute=St,t.unsafeCreateElement=Tt,Object.defineProperty(t,"Z",{value:!0})})); //# sourceMappingURL=slimdom.umd.cjs.map