@gjsify/dom-elements 0.40.0 → 0.42.0

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.
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Node as e}from"./node.js";import{Comment as t}from"./comment.js";import{Text as n}from"./text.js";import{DocumentFragment as r}from"./document-fragment.js";import{HTMLElement as i}from"./html-element.js";import{HTMLImageElement as a}from"./html-image-element.js";import{HTMLVideoElement as o}from"./html-video-element.js";import{HTMLCanvasElement as s}from"./html-canvas-element.js";import{Event as c}from"@gjsify/dom-events";var l=class Document extends e{static{this._elementFactories=new Map}constructor(){super(),this.body=new i,this.head=new i,this.documentElement=new i,this.appendChild(this.documentElement),this.documentElement.appendChild(this.body)}static registerElementFactory(e,t){Document._elementFactories.set(e.toLowerCase(),t)}createElementNS(e,t){let n=t.toLowerCase();switch(n){case`img`:return new a;case`video`:return new o;case`canvas`:return new s;default:{let e=Document._elementFactories.get(n);return e?e():new i}}}createElement(e){return this.createElementNS(`http://www.w3.org/1999/xhtml`,e)}createTextNode(e){return new n(e)}createComment(e){return new t(e)}createDocumentFragment(){return new r}createEvent(e){return new c(e)}getElementById(e){return this._findById(this.body,e)}_findById(e,t){if(e.id===t)return e;for(let n of e.children){let e=this._findById(n,t);if(e)return e}return null}get[Symbol.toStringTag](){return`Document`}};const u=new l;export{l as Document,u as document};
1
+ import"./_virtual/_rolldown/runtime.js";import{localName as e,namespaceURI as t,tagName as n}from"./property-symbol.js";import{Node as r}from"./node.js";import{Comment as i}from"./comment.js";import{Text as a}from"./text.js";import{DocumentFragment as o}from"./document-fragment.js";import{NamespaceURI as s}from"./namespace-uri.js";import{HTMLElement as c}from"./html-element.js";import{HTMLImageElement as l}from"./html-image-element.js";import{HTMLVideoElement as u}from"./html-video-element.js";import{HTMLCanvasElement as d}from"./html-canvas-element.js";import{Event as f}from"@gjsify/dom-events";var p=class Document extends r{static{this._elementFactories=new Map}constructor(){super(),this.body=new c,this.head=new c,this.documentElement=new c,this.appendChild(this.documentElement),this.documentElement.appendChild(this.body)}static registerElementFactory(e,t){Document._elementFactories.set(e.toLowerCase(),t)}createElementNS(r,i){let a=i.toLowerCase(),o=(()=>{switch(a){case`img`:return new l;case`video`:return new u;case`canvas`:return new d;default:{let e=Document._elementFactories.get(a);return e?e():new c}}})();return o[e]=a,o[n]=a.toUpperCase(),o[t]=r??s.html,o}createElement(e){return this.createElementNS(`http://www.w3.org/1999/xhtml`,e)}createTextNode(e){return new a(e)}createComment(e){return new i(e)}createDocumentFragment(){return new o}createEvent(e){return new f(e)}getElementById(e){return this._findById(this.body,e)}_findById(e,t){if(e.id===t)return e;for(let n of e.children){let e=this._findById(n,t);if(e)return e}return null}get[Symbol.toStringTag](){return`Document`}};const m=new p;export{p as Document,m as document};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{attributes as e,childNodesList as t,elementChildren as n,localName as r,namespaceURI as i,nodeType as a,parentNode as o,prefix as s,propertyEventListeners as c,tagName as l}from"./property-symbol.js";import{NodeType as u}from"./node-type.js";import{Node as d}from"./node.js";import{NamespaceURI as f}from"./namespace-uri.js";import{NamedNodeMap as p}from"./named-node-map.js";let m,h,g,_,v,y;var Element=class extends d{constructor(){super(),this[m]=``,this[h]=``,this[g]=f.html,this[_]=null,this[v]=new p(this),this[y]=new Map,this._resizeSubscribers=null,this._allocatedClientWidth=0,this._allocatedClientHeight=0,this._pointerCaptures=new Set,this[a]=u.ELEMENT_NODE}get tagName(){return this[l]}get localName(){return this[r]}get namespaceURI(){return this[i]}get prefix(){return this[s]}get nodeName(){return this[l]}get attributes(){return this[e]}get id(){return this.getAttribute(`id`)??``}set id(e){this.setAttribute(`id`,e)}get className(){return this.getAttribute(`class`)??``}set className(e){this.setAttribute(`class`,e)}get children(){return this[n]}get childElementCount(){return this[n].length}get firstElementChild(){return this[n][0]??null}get lastElementChild(){let e=this[n];return e[e.length-1]??null}get previousElementSibling(){let e=this[o];if(!e)return null;let t=e[n],r=t.indexOf(this);return r>0?t[r-1]:null}get nextElementSibling(){let e=this[o];if(!e)return null;let t=e[n],r=t.indexOf(this);return r!==-1&&r<t.length-1?t[r+1]:null}get textContent(){let e=``;for(let n of this[t])n.textContent!==null&&(e+=n.textContent);return e}set textContent(e){let n=this[t];for(;n.length>0;)this.removeChild(n[0])}getAttribute(t){let n=this[e].getNamedItem(t);return n?n.value:null}getAttributeNS(t,n){let r=this[e].getNamedItemNS(t,n);return r?r.value:null}setAttribute(t,n){this[e]._setNamedItem(t,String(n))}setAttributeNS(t,n,r){let i=t===``?null:t,a=n.split(`:`),o=a.length>1?a[0]:null;this[e]._setNamedItem(n,String(r),i,o)}removeAttribute(t){this[e]._removeNamedItem(t)}removeAttributeNS(t,n){let r=t===``?null:t;this[e]._removeNamedItemNS(r,n)}hasAttribute(t){return this[e].getNamedItem(t)!==null}hasAttributeNS(t,n){return this[e].getNamedItemNS(t,n)!==null}getAttributeNode(t){return this[e].getNamedItem(t)}setAttributeNode(t){return this[e].setNamedItem(t)}removeAttributeNode(t){let n=this[e].getNamedItem(t.name);if(!n)throw new DOMException(`Failed to execute 'removeAttributeNode' on 'Element': The attribute is not owned by this element.`,`NotFoundError`);return this[e].removeNamedItem(n.name),n}toggleAttribute(e,t){return t===void 0?this.hasAttribute(e)?(this.removeAttribute(e),!1):(this.setAttribute(e,``),!0):t?(this.setAttribute(e,``),!0):(this.removeAttribute(e),!1)}hasAttributes(){return this[e].length>0}dispatchEvent(e){let t=super.dispatchEvent(e),n=this[c].get(`on`+e.type);return typeof n==`function`&&n.call(this,e),t}querySelector(e){return null}querySelectorAll(e){return[]}matches(e){return!1}closest(e){return null}getElementsByTagName(e){let n=[],r=e.toUpperCase(),walk=i=>{for(let o of i[t])if(o[a]===u.ELEMENT_NODE){let t=o;(e===`*`||t[l]===r)&&n.push(t),walk(t)}};return walk(this),n}getElementsByClassName(e){let n=[],r=e.split(/\s+/).filter(Boolean),walk=e=>{for(let i of e[t])if(i[a]===u.ELEMENT_NODE){let e=i,t=e.className.split(/\s+/);r.every(e=>t.includes(e))&&n.push(e),walk(e)}};return walk(this),n}cloneNode(n=!1){let a=super.cloneNode(!1);a[l]=this[l],a[r]=this[r],a[i]=this[i],a[s]=this[s];for(let t of this[e])a.setAttributeNS(t.namespaceURI,t.name,t.value);if(n)for(let e of this[t])a.appendChild(e.cloneNode(!0));return a}_onResize(e){let t=this._resizeSubscribers??=new Set;return t.add(e),()=>{t.delete(e),t.size===0&&(this._resizeSubscribers=null)}}_fireResizeSubscribers(e,t){let n=this._resizeSubscribers;if(!(!n||n.size===0))for(let r of[...n])try{r(e,t)}catch(e){console.error(`ResizeObserver subscriber threw:`,e)}}setPointerCapture(e){this._pointerCaptures.add(e)}releasePointerCapture(e){this._pointerCaptures.delete(e)}hasPointerCapture(e){return this._pointerCaptures.has(e)}get[(m=l,h=r,g=i,_=s,v=e,y=c,Symbol.toStringTag)](){return`Element`}};export{Element};
1
+ import"./_virtual/_rolldown/runtime.js";import{attributes as e,childNodesList as t,elementChildren as n,localName as r,namespaceURI as i,nodeType as a,parentNode as o,prefix as s,propertyEventListeners as c,tagName as l}from"./property-symbol.js";import{NodeType as u}from"./node-type.js";import{Node as d}from"./node.js";import{elementAdapter as f}from"./selector-adapter.js";import{NamespaceURI as p}from"./namespace-uri.js";import{NamedNodeMap as m}from"./named-node-map.js";import{closestSelector as h,matchesSelector as g,selectAll as _,selectOne as v}from"@gjsify/domparser/selectors";let y,b,x,S,C,w;var Element=class extends d{constructor(){super(),this[y]=``,this[b]=``,this[x]=p.html,this[S]=null,this[C]=new m(this),this[w]=new Map,this._resizeSubscribers=null,this._allocatedClientWidth=0,this._allocatedClientHeight=0,this._pointerCaptures=new Set,this[a]=u.ELEMENT_NODE}get tagName(){return this[l]}get localName(){return this[r]}get namespaceURI(){return this[i]}get prefix(){return this[s]}get nodeName(){return this[l]}get attributes(){return this[e]}get id(){return this.getAttribute(`id`)??``}set id(e){this.setAttribute(`id`,e)}get className(){return this.getAttribute(`class`)??``}set className(e){this.setAttribute(`class`,e)}get children(){return this[n]}get childElementCount(){return this[n].length}get firstElementChild(){return this[n][0]??null}get lastElementChild(){let e=this[n];return e[e.length-1]??null}get previousElementSibling(){let e=this[o];if(!e)return null;let t=e[n],r=t.indexOf(this);return r>0?t[r-1]:null}get nextElementSibling(){let e=this[o];if(!e)return null;let t=e[n],r=t.indexOf(this);return r!==-1&&r<t.length-1?t[r+1]:null}get textContent(){let e=``;for(let n of this[t])n.textContent!==null&&(e+=n.textContent);return e}set textContent(e){let n=this[t];for(;n.length>0;)this.removeChild(n[0])}getAttribute(t){let n=this[e].getNamedItem(t);return n?n.value:null}getAttributeNS(t,n){let r=this[e].getNamedItemNS(t,n);return r?r.value:null}setAttribute(t,n){this[e]._setNamedItem(t,String(n))}setAttributeNS(t,n,r){let i=t===``?null:t,a=n.split(`:`),o=a.length>1?a[0]:null;this[e]._setNamedItem(n,String(r),i,o)}removeAttribute(t){this[e]._removeNamedItem(t)}removeAttributeNS(t,n){let r=t===``?null:t;this[e]._removeNamedItemNS(r,n)}hasAttribute(t){return this[e].getNamedItem(t)!==null}hasAttributeNS(t,n){return this[e].getNamedItemNS(t,n)!==null}getAttributeNode(t){return this[e].getNamedItem(t)}setAttributeNode(t){return this[e].setNamedItem(t)}removeAttributeNode(t){let n=this[e].getNamedItem(t.name);if(!n)throw new DOMException(`Failed to execute 'removeAttributeNode' on 'Element': The attribute is not owned by this element.`,`NotFoundError`);return this[e].removeNamedItem(n.name),n}toggleAttribute(e,t){return t===void 0?this.hasAttribute(e)?(this.removeAttribute(e),!1):(this.setAttribute(e,``),!0):t?(this.setAttribute(e,``),!0):(this.removeAttribute(e),!1)}hasAttributes(){return this[e].length>0}dispatchEvent(e){let t=super.dispatchEvent(e),n=this[c].get(`on`+e.type);return typeof n==`function`&&n.call(this,e),t}querySelector(e){return v(e,this,f)}querySelectorAll(e){return _(e,this,f)}matches(e){return g(e,this,f)}closest(e){return h(e,this,f)}getElementsByTagName(e){let n=[],r=e.toUpperCase(),walk=i=>{for(let o of i[t])if(o[a]===u.ELEMENT_NODE){let t=o;(e===`*`||t[l]===r)&&n.push(t),walk(t)}};return walk(this),n}getElementsByClassName(e){let n=[],r=e.split(/\s+/).filter(Boolean),walk=e=>{for(let i of e[t])if(i[a]===u.ELEMENT_NODE){let e=i,t=e.className.split(/\s+/);r.every(e=>t.includes(e))&&n.push(e),walk(e)}};return walk(this),n}cloneNode(n=!1){let a=super.cloneNode(!1);a[l]=this[l],a[r]=this[r],a[i]=this[i],a[s]=this[s];for(let t of this[e])a.setAttributeNS(t.namespaceURI,t.name,t.value);if(n)for(let e of this[t])a.appendChild(e.cloneNode(!0));return a}_onResize(e){let t=this._resizeSubscribers??=new Set;return t.add(e),()=>{t.delete(e),t.size===0&&(this._resizeSubscribers=null)}}_fireResizeSubscribers(e,t){let n=this._resizeSubscribers;if(!(!n||n.size===0))for(let r of[...n])try{r(e,t)}catch(e){console.error(`ResizeObserver subscriber threw:`,e)}}setPointerCapture(e){this._pointerCaptures.add(e)}releasePointerCapture(e){this._pointerCaptures.delete(e)}hasPointerCapture(e){return this._pointerCaptures.has(e)}get[(y=l,b=r,x=i,S=s,C=e,w=c,Symbol.toStringTag)](){return`Element`}};export{Element};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{childNodesList as e,localName as t,nodeType as n}from"./property-symbol.js";import{NodeType as r}from"./node-type.js";const i={isTag(e){return e[n]===r.ELEMENT_NODE},getName(e){return e[t]??``},getParent(e){return e.parentNode},getChildren(t){return t[e]},getSiblings(t){let n=t.parentNode;return n?n[e]:[t]},getAttributeValue(e,t){return e[n]===r.ELEMENT_NODE?e.getAttribute(t):null},getText(e){return e.textContent??``},caseSensitive:!1};export{i as elementAdapter};
@@ -23,7 +23,19 @@ export declare class Document extends Node {
23
23
  * Example: `Document.registerElementFactory('iframe', () => new HTMLIFrameElement())`
24
24
  */
25
25
  static registerElementFactory(tagName: string, factory: ElementFactory): void;
26
- createElementNS(_namespace: string | null, tagName: string): HTMLElement;
26
+ /**
27
+ * Create an element — and NAME it.
28
+ *
29
+ * The naming is the part that was missing: every element this factory
30
+ * returned carried the class default `''` for `tagName`, `localName` and
31
+ * therefore `nodeName`. Nothing failed, because nothing asked — until
32
+ * something did: `getElementsByTagName('li')` compared `'' === 'LI'` and
33
+ * answered 0 for a tree full of `li`, and `querySelector('li')` inherited
34
+ * the same silence the moment the selector engine started reading real
35
+ * names (ADR 0026 § Decision 2). Both are the shape where a method answers
36
+ * confidently and wrongly rather than failing.
37
+ */
38
+ createElementNS(namespace: string | null, tagName: string): HTMLElement;
27
39
  createElement(tagName: string): HTMLElement;
28
40
  createTextNode(data: string): Text;
29
41
  createComment(data: string): Comment;
@@ -47,10 +47,10 @@ export declare class Element extends Node {
47
47
  toggleAttribute(qualifiedName: string, force?: boolean): boolean;
48
48
  hasAttributes(): boolean;
49
49
  dispatchEvent(event: Event): boolean;
50
- querySelector(_selectors: string): Element | null;
51
- querySelectorAll(_selectors: string): Element[];
52
- matches(_selectors: string): boolean;
53
- closest(_selectors: string): Element | null;
50
+ querySelector(selectors: string): Element | null;
51
+ querySelectorAll(selectors: string): Element[];
52
+ matches(selectors: string): boolean;
53
+ closest(selectors: string): Element | null;
54
54
  getElementsByTagName(tagName: string): Element[];
55
55
  getElementsByClassName(className: string): Element[];
56
56
  cloneNode(deep?: boolean): Element;
@@ -0,0 +1,11 @@
1
+ import type { Adapter } from '@gjsify/domparser/selectors';
2
+ import type { Node } from './node.js';
3
+ /**
4
+ * The adapter, over `Node` rather than `Element`.
5
+ *
6
+ * Sibling and child lists contain text and comment nodes too, and the engine
7
+ * needs to see them: `:nth-child` counts elements, but `+` and `~` have to skip
8
+ * what lies between, and `:empty` asks whether any character data is there at
9
+ * all. Handing it a pre-filtered element list would answer those three wrong.
10
+ */
11
+ export declare const elementAdapter: Adapter<Node>;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/dom-elements",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "DOM element hierarchy (Node, Element, HTMLElement, HTMLImageElement) for GJS",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -71,15 +71,16 @@
71
71
  "@girs/gdkpixbuf-2.0": "^4.1.0",
72
72
  "@girs/gjs": "^4.1.0",
73
73
  "@girs/glib-2.0": "^4.1.0",
74
- "@gjsify/abort-controller": "^0.40.0",
75
- "@gjsify/canvas2d-core": "^0.40.0",
76
- "@gjsify/dom-events": "^0.40.0",
77
- "@gjsify/fetch": "^0.40.0"
74
+ "@gjsify/abort-controller": "^0.42.0",
75
+ "@gjsify/canvas2d-core": "^0.42.0",
76
+ "@gjsify/dom-events": "^0.42.0",
77
+ "@gjsify/domparser": "^0.42.0",
78
+ "@gjsify/fetch": "^0.42.0"
78
79
  },
79
80
  "devDependencies": {
80
81
  "@girs/gst-1.0": "^4.1.0",
81
- "@gjsify/cli": "^0.40.0",
82
- "@gjsify/unit": "^0.40.0",
82
+ "@gjsify/cli": "^0.42.0",
83
+ "@gjsify/unit": "^0.42.0",
83
84
  "@types/node": "^25.9.2",
84
85
  "typescript": "^6.0.3"
85
86
  },