@gjsify/domparser 0.3.20 → 0.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/esm/index.js +1 -1
  2. package/package.json +3 -3
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- var e=class{nodeType;nodeName;nodeValue;parentNode=null;childNodes=[];constructor(e,t,n=null){this.nodeType=e,this.nodeName=t,this.nodeValue=n}get textContent(){return this.nodeType===3||this.nodeType===4?this.nodeValue??``:this.childNodes.map(e=>e.textContent??``).join(``)}},t=class extends e{tagName;localName;_attrs=new Map;constructor(e){super(1,e.toUpperCase()),this.tagName=e.toLowerCase(),this.localName=this.tagName}get children(){return this.childNodes.filter(e=>e.nodeType===1)}getAttribute(e){return this._attrs.has(e)?this._attrs.get(e)??null:null}setAttribute(e,t){this._attrs.set(e,t)}hasAttribute(e){return this._attrs.has(e)}get attributes(){return Array.from(this._attrs.entries()).map(([e,t])=>({name:e,value:t}))}get innerHTML(){return this.childNodes.map(e=>e.nodeType===1?e.outerHTML:e.nodeType===3?e.nodeValue??``:e.nodeType===4?`<![CDATA[`+(e.nodeValue??``)+`]]>`:``).join(``)}get outerHTML(){let e=Array.from(this._attrs.entries()).map(([e,t])=>` `+e+`="`+t.replace(/"/g,`&quot;`)+`"`).join(``);return this.childNodes.length===0?`<`+this.tagName+e+`/>`:`<`+this.tagName+e+`>`+this.innerHTML+`</`+this.tagName+`>`}querySelector(e){let t=e.trim().split(/\s*>\s*/);if(t.length>1)return this._queryChildChain(t);let n=e.trim().split(/\s+/);return n.length>1?this._queryDescendantChain(n):this._find(e.trim().toLowerCase())??null}querySelectorAll(e){let t=e.trim().toLowerCase(),n=[];return this._findAll(t,n),n}_find(e){for(let t of this.children){if(t.tagName===e)return t;let n=t._find(e);if(n)return n}}_findAll(e,t){for(let n of this.children)n.tagName===e&&t.push(n),n._findAll(e,t)}_queryChildChain(e){let[t,...n]=e,r=this.children.filter(e=>e.tagName===t.trim().toLowerCase());if(n.length===0)return r[0]??null;for(let e of r){let t=e._queryChildChain(n);if(t)return t}return null}_queryDescendantChain(e){let[t,...n]=e,r=[];if(this._findAll(t.trim().toLowerCase(),r),n.length===0)return r[0]??null;for(let e of r){let t=e._queryDescendantChain(n);if(t)return t}return null}},n=class extends t{documentElement=null;constructor(){super(`#document`),this.nodeType=9,this.nodeName=`#document`}querySelector(e){if(this.documentElement){let t=e.trim().toLowerCase();return this.documentElement.tagName===t?this.documentElement:this.documentElement.querySelector(e)}return super.querySelector(e)}querySelectorAll(e){let t=e.trim().toLowerCase(),n=[];return this.documentElement&&(this.documentElement.tagName===t&&n.push(this.documentElement),this.documentElement._findAll(t,n)),n}};const r=/\s+([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/g;function i(e,t){let n;for(r.lastIndex=0;(n=r.exec(e))!==null;)t.setAttribute(n[1],n[2]??n[3]??n[4]??``)}function a(r){let a=new n,s=[a],c=0,l=r.length;for(;c<l;){let n=r.indexOf(`<`,c);if(n===-1){let t=r.slice(c);if(t.trim()){let n=new e(3,`#text`,t),r=s[s.length-1];n.parentNode=r,r.childNodes.push(n)}break}if(n>c){let t=r.slice(c,n);if(t.trim()){let n=new e(3,`#text`,t),r=s[s.length-1];n.parentNode=r,r.childNodes.push(n)}}if(r.startsWith(`<![CDATA[`,n)){let t=r.indexOf(`]]>`,n);if(t===-1)break;let i=new e(4,`#cdata-section`,r.slice(n+9,t)),a=s[s.length-1];i.parentNode=a,a.childNodes.push(i),c=t+3;continue}if(r.startsWith(`<!--`,n)){let e=r.indexOf(`-->`,n);c=e===-1?l:e+3;continue}if(r.startsWith(`<?`,n)||r.startsWith(`<!`,n)){let e=r.indexOf(`>`,n);c=e===-1?l:e+1;continue}let u=o(r,n+1);if(u===-1)break;let d=r.slice(n+1,u);if(d.startsWith(`/`)){s.length>1&&s.pop(),c=u+1;continue}let f=d.endsWith(`/`),p=f?d.slice(0,-1):d,m=p.search(/\s/),h=(m===-1?p:p.slice(0,m)).trim();if(!h){c=u+1;continue}let g=new t(h);m!==-1&&i(p.slice(m),g);let _=s[s.length-1];g.parentNode=_,_.childNodes.push(g),_===a&&!a.documentElement&&(a.documentElement=g),f||s.push(g),c=u+1}return a}function o(e,t){let n=!1,r=!1;for(let i=t;i<e.length;i++){let t=e[i];if(t===`"`&&!n){r=!r;continue}if(t===`'`&&!r){n=!n;continue}if(t===`>`&&!n&&!r)return i}return-1}var s=class{parseFromString(e,t){return a(e)}};export{n as DOMDocument,t as DOMElement,e as DOMNode,s as DOMParser};
1
+ var DOMNode=class{nodeType;nodeName;nodeValue;parentNode=null;childNodes=[];constructor(e,t,n=null){this.nodeType=e,this.nodeName=t,this.nodeValue=n}get textContent(){return this.nodeType===3||this.nodeType===4?this.nodeValue??``:this.childNodes.map(e=>e.textContent??``).join(``)}},DOMElement=class extends DOMNode{tagName;localName;_attrs=new Map;constructor(e){super(1,e.toUpperCase()),this.tagName=e.toLowerCase(),this.localName=this.tagName}get children(){return this.childNodes.filter(e=>e.nodeType===1)}getAttribute(e){return this._attrs.has(e)?this._attrs.get(e)??null:null}setAttribute(e,t){this._attrs.set(e,t)}hasAttribute(e){return this._attrs.has(e)}get attributes(){return Array.from(this._attrs.entries()).map(([e,t])=>({name:e,value:t}))}get innerHTML(){return this.childNodes.map(e=>e.nodeType===1?e.outerHTML:e.nodeType===3?e.nodeValue??``:e.nodeType===4?`<![CDATA[`+(e.nodeValue??``)+`]]>`:``).join(``)}get outerHTML(){let e=Array.from(this._attrs.entries()).map(([e,t])=>` `+e+`="`+t.replace(/"/g,`&quot;`)+`"`).join(``);return this.childNodes.length===0?`<`+this.tagName+e+`/>`:`<`+this.tagName+e+`>`+this.innerHTML+`</`+this.tagName+`>`}querySelector(e){let t=e.trim().split(/\s*>\s*/);if(t.length>1)return this._queryChildChain(t);let n=e.trim().split(/\s+/);return n.length>1?this._queryDescendantChain(n):this._find(e.trim().toLowerCase())??null}querySelectorAll(e){let t=e.trim().toLowerCase(),n=[];return this._findAll(t,n),n}_find(e){for(let t of this.children){if(t.tagName===e)return t;let n=t._find(e);if(n)return n}}_findAll(e,t){for(let n of this.children)n.tagName===e&&t.push(n),n._findAll(e,t)}_queryChildChain(e){let[t,...n]=e,r=this.children.filter(e=>e.tagName===t.trim().toLowerCase());if(n.length===0)return r[0]??null;for(let e of r){let t=e._queryChildChain(n);if(t)return t}return null}_queryDescendantChain(e){let[t,...n]=e,r=[];if(this._findAll(t.trim().toLowerCase(),r),n.length===0)return r[0]??null;for(let e of r){let t=e._queryDescendantChain(n);if(t)return t}return null}},DOMDocument=class extends DOMElement{documentElement=null;constructor(){super(`#document`),this.nodeType=9,this.nodeName=`#document`}querySelector(e){if(this.documentElement){let t=e.trim().toLowerCase();return this.documentElement.tagName===t?this.documentElement:this.documentElement.querySelector(e)}return super.querySelector(e)}querySelectorAll(e){let t=e.trim().toLowerCase(),n=[];return this.documentElement&&(this.documentElement.tagName===t&&n.push(this.documentElement),this.documentElement._findAll(t,n)),n}};const e=/\s+([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/g;function parseAttributes(t,n){let r;for(e.lastIndex=0;(r=e.exec(t))!==null;)n.setAttribute(r[1],r[2]??r[3]??r[4]??``)}function parseXml(e){let t=new DOMDocument,n=[t],r=0,i=e.length;for(;r<i;){let a=e.indexOf(`<`,r);if(a===-1){let t=e.slice(r);if(t.trim()){let e=new DOMNode(3,`#text`,t),r=n[n.length-1];e.parentNode=r,r.childNodes.push(e)}break}if(a>r){let t=e.slice(r,a);if(t.trim()){let e=new DOMNode(3,`#text`,t),r=n[n.length-1];e.parentNode=r,r.childNodes.push(e)}}if(e.startsWith(`<![CDATA[`,a)){let t=e.indexOf(`]]>`,a);if(t===-1)break;let i=new DOMNode(4,`#cdata-section`,e.slice(a+9,t)),o=n[n.length-1];i.parentNode=o,o.childNodes.push(i),r=t+3;continue}if(e.startsWith(`<!--`,a)){let t=e.indexOf(`-->`,a);r=t===-1?i:t+3;continue}if(e.startsWith(`<?`,a)||e.startsWith(`<!`,a)){let t=e.indexOf(`>`,a);r=t===-1?i:t+1;continue}let o=findTagEnd(e,a+1);if(o===-1)break;let s=e.slice(a+1,o);if(s.startsWith(`/`)){n.length>1&&n.pop(),r=o+1;continue}let c=s.endsWith(`/`),l=c?s.slice(0,-1):s,u=l.search(/\s/),d=(u===-1?l:l.slice(0,u)).trim();if(!d){r=o+1;continue}let f=new DOMElement(d);u!==-1&&parseAttributes(l.slice(u),f);let p=n[n.length-1];f.parentNode=p,p.childNodes.push(f),p===t&&!t.documentElement&&(t.documentElement=f),c||n.push(f),r=o+1}return t}function findTagEnd(e,t){let n=!1,r=!1;for(let i=t;i<e.length;i++){let t=e[i];if(t===`"`&&!n){r=!r;continue}if(t===`'`&&!r){n=!n;continue}if(t===`>`&&!n&&!r)return i}return-1}var DOMParser=class{parseFromString(e,t){return parseXml(e)}};export{DOMDocument,DOMElement,DOMNode,DOMParser};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/domparser",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "DOMParser for GJS — self-contained XML parser with minimal DOM (querySelector, getAttribute, children)",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -40,8 +40,8 @@
40
40
  "web-api"
41
41
  ],
42
42
  "devDependencies": {
43
- "@gjsify/cli": "^0.3.20",
44
- "@gjsify/unit": "^0.3.20",
43
+ "@gjsify/cli": "^0.3.21",
44
+ "@gjsify/unit": "^0.3.21",
45
45
  "@types/node": "^25.6.2",
46
46
  "typescript": "^6.0.3"
47
47
  }