import{t as r,c as y}from"./vc-shell-vendor-domelementtype32435.js";class p{constructor(){this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}get parentNode(){return this.parent}set parentNode(t){this.parent=t}get previousSibling(){return this.prev}set previousSibling(t){this.prev=t}get nextSibling(){return this.next}set nextSibling(t){this.next=t}cloneNode(t=!1){return N(this,t)}}class h extends p{constructor(t){super(),this.data=t}get nodeValue(){return this.data}set nodeValue(t){this.data=t}}class l extends h{constructor(){super(...arguments),this.type=r.Text}get nodeType(){return 3}}class x extends h{constructor(){super(...arguments),this.type=r.Comment}get nodeType(){return 8}}class m extends h{constructor(t,n){super(n),this.name=t,this.type=r.Directive}get nodeType(){return 1}}class c extends p{constructor(t){super(),this.children=t}get firstChild(){var t;return(t=this.children[0])!==null&&t!==void 0?t:null}get lastChild(){return this.children.length>0?this.children[this.children.length-1]:null}get childNodes(){return this.children}set childNodes(t){this.children=t}}class f extends c{constructor(){super(...arguments),this.type=r.CDATA}get nodeType(){return 4}}class d extends c{constructor(){super(...arguments),this.type=r.Root}get nodeType(){return 9}}class g extends c{constructor(t,n,s=[],i=t==="script"?r.Script:t==="style"?r.Style:r.Tag){super(s),this.name=t,this.attribs=n,this.type=i}get nodeType(){return 1}get tagName(){return this.name}set tagName(t){this.name=t}get attributes(){return Object.keys(this.attribs).map(t=>{var n,s;return{name:t,value:this.attribs[t],namespace:(n=this["x-attribsNamespace"])===null||n===void 0?void 0:n[t],prefix:(s=this["x-attribsPrefix"])===null||s===void 0?void 0:s[t]}})}}function b(e){return y(e)}function w(e){return e.type===r.CDATA}function I(e){return e.type===r.Text}function v(e){return e.type===r.Comment}function C(e){return e.type===r.Directive}function S(e){return e.type===r.Root}function k(e){return Object.prototype.hasOwnProperty.call(e,"children")}function N(e,t=!1){let n;if(I(e))n=new l(e.data);else if(v(e))n=new x(e.data);else if(b(e)){const s=t?a(e.children):[],i=new g(e.name,{...e.attribs},s);s.forEach(o=>o.parent=i),e.namespace!=null&&(i.namespace=e.namespace),e["x-attribsNamespace"]&&(i["x-attribsNamespace"]={...e["x-attribsNamespace"]}),e["x-attribsPrefix"]&&(i["x-attribsPrefix"]={...e["x-attribsPrefix"]}),n=i}else if(w(e)){const s=t?a(e.children):[],i=new f(s);s.forEach(o=>o.parent=i),n=i}else if(S(e)){const s=t?a(e.children):[],i=new d(s);s.forEach(o=>o.parent=i),e["x-mode"]&&(i["x-mode"]=e["x-mode"]),n=i}else if(C(e)){const s=new m(e.name,e.data);e["x-name"]!=null&&(s["x-name"]=e["x-name"],s["x-publicId"]=e["x-publicId"],s["x-systemId"]=e["x-systemId"]),n=s}else throw new Error(`Not implemented yet: ${e.type}`);return n.startIndex=e.startIndex,n.endIndex=e.endIndex,e.sourceCodeLocation!=null&&(n.sourceCodeLocation=e.sourceCodeLocation),n}function a(e){const t=e.map(n=>N(n,!0));for(let n=1;n<t.length;n++)t[n].prev=t[n-1],t[n-1].next=t[n];return t}const u={withStartIndices:!1,withEndIndices:!1,xmlMode:!1};class E{constructor(t,n,s){this.dom=[],this.root=new d(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null,typeof n=="function"&&(s=n,n=u),typeof t=="object"&&(n=t,t=void 0),this.callback=t??null,this.options=n??u,this.elementCB=s??null}onparserinit(t){this.parser=t}onreset(){this.dom=[],this.root=new d(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null}onend(){this.done||(this.done=!0,this.parser=null,this.handleCallback(null))}onerror(t){this.handleCallback(t)}onclosetag(){this.lastNode=null;const t=this.tagStack.pop();this.options.withEndIndices&&(t.endIndex=this.parser.endIndex),this.elementCB&&this.elementCB(t)}onopentag(t,n){const s=this.options.xmlMode?r.Tag:void 0,i=new g(t,n,void 0,s);this.addNode(i),this.tagStack.push(i)}ontext(t){const{lastNode:n}=this;if(n&&n.type===r.Text)n.data+=t,this.options.withEndIndices&&(n.endIndex=this.parser.endIndex);else{const s=new l(t);this.addNode(s),this.lastNode=s}}oncomment(t){if(this.lastNode&&this.lastNode.type===r.Comment){this.lastNode.data+=t;return}const n=new x(t);this.addNode(n),this.lastNode=n}oncommentend(){this.lastNode=null}oncdatastart(){const t=new l(""),n=new f([t]);this.addNode(n),t.parent=n,this.lastNode=t}oncdataend(){this.lastNode=null}onprocessinginstruction(t,n){const s=new m(t,n);this.addNode(s)}handleCallback(t){if(typeof this.callback=="function")this.callback(t,this.dom);else if(t)throw t}addNode(t){const n=this.tagStack[this.tagStack.length-1],s=n.children[n.children.length-1];this.options.withStartIndices&&(t.startIndex=this.parser.startIndex),this.options.withEndIndices&&(t.endIndex=this.parser.endIndex),n.children.push(t),s&&(t.prev=s,s.next=t),t.parent=n,this.lastNode=null}}export{v as C,k as D,E,w as I,N,C as T,b,x as f,g,d as h,l as o,S as v,I as w,m as x};
