pseudo-dom 0.15.0 → 0.16.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.
@@ -10,6 +10,7 @@ import { PseudoDOMTokenList } from './PseudoDOMTokenList';
10
10
  import { PseudoShadowRoot } from './PseudoShadowRoot';
11
11
  import { PseudoHTMLCollection } from './PseudoHTMLCollection';
12
12
  import { PseudoAnimation } from './PseudoAnimation';
13
+ import { PseudoAttr } from './PseudoAttr';
13
14
  /**
14
15
  * Simulate the behaviour of the Element Class when there is no DOM available.
15
16
  * @author Joshua Heagle <joshuaheagle@gmail.com>
@@ -540,15 +541,23 @@ export interface PseudoElement extends PseudoNode {
540
541
  /**
541
542
  * Retrieves the node representation of the named attribute from the current node and returns it as an Attr.
542
543
  */
543
- getAttributeNode(): string;
544
+ getAttributeNode(attributeName: string): PseudoAttr | null;
544
545
  /**
545
- * Retrieves the node representation of the attribute with the specified name and namespace, from the current node and returns it as an Attr.
546
+ * Retrieves the node representation of the attribute with the specified name and namespace, from the current
547
+ * node and returns it as an Attr. There is no real namespace parsing here, so this ignores the namespace and
548
+ * behaves exactly like getAttributeNode.
549
+ * @param {string} namespace Ignored
550
+ * @param {string} attributeName
546
551
  */
547
- getAttributeNodeNS(): string;
552
+ getAttributeNodeNS(namespace: string, attributeName: string): PseudoAttr | null;
548
553
  /**
549
- * Retrieves the value of the attribute with the specified namespace and name from the current node and returns it as a string.
554
+ * Retrieves the value of the attribute with the specified namespace and name from the current node and returns
555
+ * it as a string. There is no real namespace parsing here, so this ignores the namespace and behaves exactly
556
+ * like getAttribute.
557
+ * @param {string} namespace Ignored
558
+ * @param {string} attributeName
550
559
  */
551
- getAttributeNS(): string;
560
+ getAttributeNS(namespace: string, attributeName: string): string | null;
552
561
  /**
553
562
  * Returns the size of an element and its position relative to the viewport. Settable directly
554
563
  * (boundingClientRect) rather than really computed - there is no layout engine here.
@@ -596,9 +605,13 @@ export interface PseudoElement extends PseudoNode {
596
605
  */
597
606
  hasAttribute(attributeName: string): boolean;
598
607
  /**
599
- * Returns a boolean value indicating if the element has the specified attribute, in the specified namespace, or not.
608
+ * Returns a boolean value indicating if the element has the specified attribute, in the specified namespace, or
609
+ * not. There is no real namespace parsing here, so this ignores the namespace and behaves exactly like
610
+ * hasAttribute.
611
+ * @param {string} namespace Ignored
612
+ * @param {string} attributeName
600
613
  */
601
- hasAttributeNS(): string;
614
+ hasAttributeNS(namespace: string, attributeName: string): boolean;
602
615
  /**
603
616
  * Returns a boolean value indicating if the element has one or more HTML attributes present.
604
617
  * @returns {boolean}
@@ -667,13 +680,17 @@ export interface PseudoElement extends PseudoNode {
667
680
  */
668
681
  removeAttribute(attributeName: string): void;
669
682
  /**
670
- * Removes the node representation of the named attribute from the current node.
683
+ * Removes the node representation of the named attribute from the current node, and returns it.
684
+ * @throws {Error} When the element has no attribute matching attr.name
671
685
  */
672
- removeAttributeNode(): string;
686
+ removeAttributeNode(attr: PseudoAttr): PseudoAttr;
673
687
  /**
674
- * Removes the attribute with the specified name and namespace, from the current node.
688
+ * Removes the attribute with the specified name and namespace, from the current node. There is no real
689
+ * namespace parsing here, so this ignores the namespace and behaves exactly like removeAttribute.
690
+ * @param {string} namespace Ignored
691
+ * @param {string} attributeName
675
692
  */
676
- removeAttributeNS(): string;
693
+ removeAttributeNS(namespace: string, attributeName: string): void;
677
694
  /**
678
695
  * Replaces the existing children of a Node with a specified new set of children.
679
696
  */
@@ -737,17 +754,24 @@ export interface PseudoElement extends PseudoNode {
737
754
  */
738
755
  setAttribute(attributeName: string, attributeValue: string): void;
739
756
  /**
740
- * Sets the node representation of the named attribute from the current node.
757
+ * Sets the node representation of the named attribute from the current node, returning any previous Attr with
758
+ * the same name (or null when there was none).
741
759
  */
742
- setAttributeNode(): string;
760
+ setAttributeNode(attr: PseudoAttr): PseudoAttr | null;
743
761
  /**
744
762
  * Sets the node representation of the attribute with the specified name and namespace, from the current node.
763
+ * There is no real namespace parsing here, so this behaves exactly like setAttributeNode (Attr.name already
764
+ * carries any prefix).
745
765
  */
746
- setAttributeNodeNS(): string;
766
+ setAttributeNodeNS(attr: PseudoAttr): PseudoAttr | null;
747
767
  /**
748
- * Sets the value of the attribute with the specified name and namespace, from the current node.
768
+ * Sets the value of the attribute with the specified name and namespace, from the current node. There is no
769
+ * real namespace parsing here, so this ignores the namespace and behaves exactly like setAttribute.
770
+ * @param {string} namespace Ignored
771
+ * @param {string} attributeName
772
+ * @param {string} attributeValue
749
773
  */
750
- setAttributeNS(): string;
774
+ setAttributeNS(namespace: string, attributeName: string, attributeValue: string): void;
751
775
  /**
752
776
  * Designates a specific element as the capture target of future pointer events.
753
777
  * @param {number} pointerId
@@ -8,6 +8,7 @@ import { PseudoElement } from '../interfaces/PseudoElement';
8
8
  import { NodeService } from './NodeService';
9
9
  import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
10
10
  import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
11
+ import { AttrService } from './AttrService';
11
12
  import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
12
13
  import { PseudoShadowRoot } from '../interfaces/PseudoShadowRoot';
13
14
  type attribute = {
@@ -248,6 +249,74 @@ export declare class ElementService extends NodeService implements Partial<Pseud
248
249
  * @returns {boolean}
249
250
  */
250
251
  hasAttributes(): boolean;
252
+ /**
253
+ * Retrieve the node representation of an attribute.
254
+ * @param {string} attributeName
255
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
256
+ */
257
+ getAttributeNode(attributeName: string): AttrService | null;
258
+ /**
259
+ * Retrieve the node representation of an attribute. There is no real namespace parsing here, so this ignores
260
+ * the namespace and behaves exactly like getAttributeNode.
261
+ * @param {string} namespace Ignored
262
+ * @param {string} attributeName
263
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
264
+ */
265
+ getAttributeNodeNS(namespace: string, attributeName: string): AttrService | null;
266
+ /**
267
+ * Retrieve the value of an attribute. There is no real namespace parsing here, so this ignores the namespace
268
+ * and behaves exactly like getAttribute.
269
+ * @param {string} namespace Ignored
270
+ * @param {string} attributeName
271
+ * @returns {string|null} The value, or null when there is no such attribute
272
+ */
273
+ getAttributeNS(namespace: string, attributeName: string): string | null;
274
+ /**
275
+ * Check whether the element has an attribute by that name. There is no real namespace parsing here, so this
276
+ * ignores the namespace and behaves exactly like hasAttribute.
277
+ * @param {string} namespace Ignored
278
+ * @param {string} attributeName
279
+ * @returns {boolean}
280
+ */
281
+ hasAttributeNS(namespace: string, attributeName: string): boolean;
282
+ /**
283
+ * Remove the node representation of an attribute from the element, and return it.
284
+ * @param {AttrService} attr
285
+ * @returns {AttrService} The removed Attr
286
+ * @throws {Error} When the element has no attribute matching attr.name
287
+ */
288
+ removeAttributeNode(attr: AttrService): AttrService;
289
+ /**
290
+ * Remove an attribute from the element. There is no real namespace parsing here, so this ignores the namespace
291
+ * and behaves exactly like removeAttribute.
292
+ * @param {string} namespace Ignored
293
+ * @param {string} attributeName
294
+ * @returns {undefined}
295
+ */
296
+ removeAttributeNS(namespace: string, attributeName: string): void;
297
+ /**
298
+ * Set the node representation of an attribute, adding the attribute if it did not exist. Returns any previous
299
+ * Attr that had the same name, or null when there was none.
300
+ * @param {AttrService} attr
301
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
302
+ */
303
+ setAttributeNode(attr: AttrService): AttrService | null;
304
+ /**
305
+ * Set the node representation of an attribute. There is no real namespace parsing here, so this behaves
306
+ * exactly like setAttributeNode (Attr.name already carries any prefix).
307
+ * @param {AttrService} attr
308
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
309
+ */
310
+ setAttributeNodeNS(attr: AttrService): AttrService | null;
311
+ /**
312
+ * Set the value of an attribute, adding the attribute if it did not exist. There is no real namespace parsing
313
+ * here, so this ignores the namespace and behaves exactly like setAttribute.
314
+ * @param {string} namespace Ignored
315
+ * @param {string} attributeName
316
+ * @param {string} attributeValue
317
+ * @returns {undefined}
318
+ */
319
+ setAttributeNS(namespace: string, attributeName: string, attributeValue: string): void;
251
320
  /**
252
321
  * Add the attribute (with an empty value) when it is not present, or remove it when it is - unless force says
253
322
  * which of those to do instead. Returns whether the attribute is present after the call.
@@ -538,6 +538,108 @@ class ElementService extends NodeService_1.NodeService {
538
538
  return this.attributeList.length > 0
539
539
  }
540
540
 
541
+ /**
542
+ * Retrieve the node representation of an attribute.
543
+ * @param {string} attributeName
544
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
545
+ */
546
+ getAttributeNode (attributeName) {
547
+ return this.hasAttribute(attributeName) ? new AttrService_1.AttrService(attributeName, this.getAttribute(attributeName) || '', this) : null
548
+ }
549
+
550
+ /**
551
+ * Retrieve the node representation of an attribute. There is no real namespace parsing here, so this ignores
552
+ * the namespace and behaves exactly like getAttributeNode.
553
+ * @param {string} namespace Ignored
554
+ * @param {string} attributeName
555
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
556
+ */
557
+ getAttributeNodeNS (namespace, attributeName) {
558
+ return this.getAttributeNode(attributeName)
559
+ }
560
+
561
+ /**
562
+ * Retrieve the value of an attribute. There is no real namespace parsing here, so this ignores the namespace
563
+ * and behaves exactly like getAttribute.
564
+ * @param {string} namespace Ignored
565
+ * @param {string} attributeName
566
+ * @returns {string|null} The value, or null when there is no such attribute
567
+ */
568
+ getAttributeNS (namespace, attributeName) {
569
+ return this.getAttribute(attributeName)
570
+ }
571
+
572
+ /**
573
+ * Check whether the element has an attribute by that name. There is no real namespace parsing here, so this
574
+ * ignores the namespace and behaves exactly like hasAttribute.
575
+ * @param {string} namespace Ignored
576
+ * @param {string} attributeName
577
+ * @returns {boolean}
578
+ */
579
+ hasAttributeNS (namespace, attributeName) {
580
+ return this.hasAttribute(attributeName)
581
+ }
582
+
583
+ /**
584
+ * Remove the node representation of an attribute from the element, and return it.
585
+ * @param {AttrService} attr
586
+ * @returns {AttrService} The removed Attr
587
+ * @throws {Error} When the element has no attribute matching attr.name
588
+ */
589
+ removeAttributeNode (attr) {
590
+ if (!this.hasAttribute(attr.name)) {
591
+ throw new Error(`Failed to execute 'removeAttributeNode': The node provided is owned by another element (no attribute named '${attr.name}')`)
592
+ }
593
+ const removed = this.getAttributeNode(attr.name)
594
+ this.removeAttribute(attr.name)
595
+ return removed
596
+ }
597
+
598
+ /**
599
+ * Remove an attribute from the element. There is no real namespace parsing here, so this ignores the namespace
600
+ * and behaves exactly like removeAttribute.
601
+ * @param {string} namespace Ignored
602
+ * @param {string} attributeName
603
+ * @returns {undefined}
604
+ */
605
+ removeAttributeNS (namespace, attributeName) {
606
+ this.removeAttribute(attributeName)
607
+ }
608
+
609
+ /**
610
+ * Set the node representation of an attribute, adding the attribute if it did not exist. Returns any previous
611
+ * Attr that had the same name, or null when there was none.
612
+ * @param {AttrService} attr
613
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
614
+ */
615
+ setAttributeNode (attr) {
616
+ const existing = this.getAttributeNode(attr.name)
617
+ this.setAttribute(attr.name, attr.value)
618
+ return existing
619
+ }
620
+
621
+ /**
622
+ * Set the node representation of an attribute. There is no real namespace parsing here, so this behaves
623
+ * exactly like setAttributeNode (Attr.name already carries any prefix).
624
+ * @param {AttrService} attr
625
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
626
+ */
627
+ setAttributeNodeNS (attr) {
628
+ return this.setAttributeNode(attr)
629
+ }
630
+
631
+ /**
632
+ * Set the value of an attribute, adding the attribute if it did not exist. There is no real namespace parsing
633
+ * here, so this ignores the namespace and behaves exactly like setAttribute.
634
+ * @param {string} namespace Ignored
635
+ * @param {string} attributeName
636
+ * @param {string} attributeValue
637
+ * @returns {undefined}
638
+ */
639
+ setAttributeNS (namespace, attributeName, attributeValue) {
640
+ this.setAttribute(attributeName, attributeValue)
641
+ }
642
+
541
643
  /**
542
644
  * Add the attribute (with an empty value) when it is not present, or remove it when it is - unless force says
543
645
  * which of those to do instead. Returns whether the attribute is present after the call.
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js"),require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),HTMLCollectionService_1=require("./HTMLCollectionService"),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual")),query_1=require("../factories/query"),ShadowRootService_1=require("./ShadowRootService"),serializeHTML_1=require("../factories/serializeHTML"),zeroRect=()=>({x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0});class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.boundingClientRect=zeroRect(),this.clientRects=[],this.animations=[],this.isVisible=!0,this.capturedPointers=new Set,this.shadowRootInstance=null,this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"clientHeight",value:0},{name:"clientLeft",value:0},{name:"clientTop",value:0},{name:"clientWidth",value:0},{name:"scrollHeight",value:0},{name:"scrollLeft",value:0},{name:"scrollTop",value:0},{name:"scrollWidth",value:0}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get localName(){return this.tag}get prefix(){return null}get innerHTML(){return(0,serializeHTML_1.serializeChildren)(this)}get outerHTML(){return(0,serializeHTML_1.serializeOuter)(this)}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}get children(){return new HTMLCollectionService_1.HTMLCollectionService(this)}get childElementCount(){return this.children.length}get firstElementChild(){return this.children.item(0)}get lastElementChild(){const e=this.children;return e.item(e.length-1)}get nextElementSibling(){let e=this.nextSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.nextSibling;return e}get previousElementSibling(){let e=this.previousSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.previousSibling;return e}insertAdjacentElement(e,t){return this.insertAdjacent(e,t)}insertAdjacentText(e,t){this.insertAdjacent(e,t)}insertAdjacent(e,t){switch(e){case"beforebegin":return this.parentNode?(this.before(t),t):null;case"afterbegin":return this.prepend(t),t;case"beforeend":return this.append(t),t;case"afterend":return this.parentNode?(this.after(t),t):null;default:throw new Error(`"${e}" is not one of beforebegin, afterbegin, beforeend or afterend.`)}}insertAdjacentHTML(e,t){throw new Error("ElementService.insertAdjacentHTML() is not implemented yet.")}matches(e){return(0,query_1.matches)(this,e)}closest(e){return(0,query_1.closest)(this,e)}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}getAttributeNames(){return this.currentAttributes().map(({name:e})=>e)}hasAttributes(){return this.attributeList.length>0}toggleAttribute(e,t){const r=this.hasAttribute(e),i="boolean"==typeof t?t:!r;return i&&!r?this.setAttribute(e,""):!i&&r&&this.removeAttribute(e),i}getBoundingClientRect(){return this.boundingClientRect}getClientRects(){return this.clientRects}getAnimations(){return this.animations}checkVisibility(){return this.isVisible}computedStyleMap(){const e=this.style;return{get:t=>{const r=e?e.getPropertyValue(t):"";return""===r?void 0:r}}}hasPointerCapture(e){return this.capturedPointers.has(e)}setPointerCapture(e){this.capturedPointers.add(e)}releasePointerCapture(e){this.capturedPointers.delete(e)}scroll(e=0,t=0){if("number"==typeof e)return this.scrollLeft=e,void(this.scrollTop=t);"number"==typeof e.left&&(this.scrollLeft=e.left),"number"==typeof e.top&&(this.scrollTop=e.top)}scrollTo(e=0,t=0){this.scroll(e,t)}scrollBy(e=0,t=0){"number"!=typeof e?this.scroll({left:this.scrollLeft+(e.left||0),top:this.scrollTop+(e.top||0)}):this.scroll(this.scrollLeft+e,this.scrollTop+t)}scrollIntoView(){}requestFullscreen(){return Promise.resolve()}requestPointerLock(){return Promise.resolve()}attachShadow(e){if(this.shadowRootInstance)throw new Error("Shadow root cannot be created on a host which already hosts a shadow tree.");const t=new ShadowRootService_1.ShadowRootService;return t.host=this,t.mode=e.mode,this.shadowRootInstance=t,t}get shadowRoot(){return this.shadowRootInstance&&"open"===this.shadowRootInstance.mode?this.shadowRootInstance:null}getAriaAttribute(e){return this.getAttribute(e)||""}setAriaAttribute(e,t){this.setAttribute(e,t)}get ariaAtomic(){return this.getAriaAttribute("aria-atomic")}set ariaAtomic(e){this.setAriaAttribute("aria-atomic",e)}get ariaAutoComplete(){return this.getAriaAttribute("aria-autocomplete")}set ariaAutoComplete(e){this.setAriaAttribute("aria-autocomplete",e)}get ariaBusy(){return this.getAriaAttribute("aria-busy")}set ariaBusy(e){this.setAriaAttribute("aria-busy",e)}get ariaChecked(){return this.getAriaAttribute("aria-checked")}set ariaChecked(e){this.setAriaAttribute("aria-checked",e)}get ariaColCount(){return this.getAriaAttribute("aria-colcount")}set ariaColCount(e){this.setAriaAttribute("aria-colcount",e)}get ariaColIndex(){return this.getAriaAttribute("aria-colindex")}set ariaColIndex(e){this.setAriaAttribute("aria-colindex",e)}get ariaColSpan(){return this.getAriaAttribute("aria-colspan")}set ariaColSpan(e){this.setAriaAttribute("aria-colspan",e)}get ariaCurrent(){return this.getAriaAttribute("aria-current")}set ariaCurrent(e){this.setAriaAttribute("aria-current",e)}get ariaDescription(){return this.getAriaAttribute("aria-description")}set ariaDescription(e){this.setAriaAttribute("aria-description",e)}get ariaDisabled(){return this.getAriaAttribute("aria-disabled")}set ariaDisabled(e){this.setAriaAttribute("aria-disabled",e)}get ariaExpanded(){return this.getAriaAttribute("aria-expanded")}set ariaExpanded(e){this.setAriaAttribute("aria-expanded",e)}get ariaHasPopup(){return this.getAriaAttribute("aria-haspopup")}set ariaHasPopup(e){this.setAriaAttribute("aria-haspopup",e)}get ariaHidden(){return this.getAriaAttribute("aria-hidden")}set ariaHidden(e){this.setAriaAttribute("aria-hidden",e)}get ariaKeyShortcuts(){return this.getAriaAttribute("aria-keyshortcuts")}set ariaKeyShortcuts(e){this.setAriaAttribute("aria-keyshortcuts",e)}get ariaLabel(){return this.getAriaAttribute("aria-label")}set ariaLabel(e){this.setAriaAttribute("aria-label",e)}get ariaLevel(){return this.getAriaAttribute("aria-level")}set ariaLevel(e){this.setAriaAttribute("aria-level",e)}get ariaLive(){return this.getAriaAttribute("aria-live")}set ariaLive(e){this.setAriaAttribute("aria-live",e)}get ariaModal(){return this.getAriaAttribute("aria-modal")}set ariaModal(e){this.setAriaAttribute("aria-modal",e)}get ariaMultiline(){return this.getAriaAttribute("aria-multiline")}set ariaMultiline(e){this.setAriaAttribute("aria-multiline",e)}get ariaMultiSelectable(){return this.getAriaAttribute("aria-multiselectable")}set ariaMultiSelectable(e){this.setAriaAttribute("aria-multiselectable",e)}get ariaOrientation(){return this.getAriaAttribute("aria-orientation")}set ariaOrientation(e){this.setAriaAttribute("aria-orientation",e)}get ariaPlaceholder(){return this.getAriaAttribute("aria-placeholder")}set ariaPlaceholder(e){this.setAriaAttribute("aria-placeholder",e)}get ariaPosInSet(){return this.getAriaAttribute("aria-posinset")}set ariaPosInSet(e){this.setAriaAttribute("aria-posinset",e)}get ariaPressed(){return this.getAriaAttribute("aria-pressed")}set ariaPressed(e){this.setAriaAttribute("aria-pressed",e)}get ariaReadOnly(){return this.getAriaAttribute("aria-readonly")}set ariaReadOnly(e){this.setAriaAttribute("aria-readonly",e)}get ariaRequired(){return this.getAriaAttribute("aria-required")}set ariaRequired(e){this.setAriaAttribute("aria-required",e)}get ariaRoleDescription(){return this.getAriaAttribute("aria-roledescription")}set ariaRoleDescription(e){this.setAriaAttribute("aria-roledescription",e)}get ariaRowCount(){return this.getAriaAttribute("aria-rowcount")}set ariaRowCount(e){this.setAriaAttribute("aria-rowcount",e)}get ariaRowIndex(){return this.getAriaAttribute("aria-rowindex")}set ariaRowIndex(e){this.setAriaAttribute("aria-rowindex",e)}get ariaRowSpan(){return this.getAriaAttribute("aria-rowspan")}set ariaRowSpan(e){this.setAriaAttribute("aria-rowspan",e)}get ariaSelected(){return this.getAriaAttribute("aria-selected")}set ariaSelected(e){this.setAriaAttribute("aria-selected",e)}get ariaSetSize(){return this.getAriaAttribute("aria-setsize")}set ariaSetSize(e){this.setAriaAttribute("aria-setsize",e)}get ariaSort(){return this.getAriaAttribute("aria-sort")}set ariaSort(e){this.setAriaAttribute("aria-sort",e)}get ariaValueMax(){return this.getAriaAttribute("aria-valuemax")}set ariaValueMax(e){this.setAriaAttribute("aria-valuemax",e)}get ariaValueMin(){return this.getAriaAttribute("aria-valuemin")}set ariaValueMin(e){this.setAriaAttribute("aria-valuemin",e)}get ariaValueNow(){return this.getAriaAttribute("aria-valuenow")}set ariaValueNow(e){this.setAriaAttribute("aria-valuenow",e)}get ariaValueText(){return this.getAriaAttribute("aria-valuetext")}set ariaValueText(e){this.setAriaAttribute("aria-valuetext",e)}}exports.ElementService=ElementService;
1
+ "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js"),require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),HTMLCollectionService_1=require("./HTMLCollectionService"),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual")),query_1=require("../factories/query"),ShadowRootService_1=require("./ShadowRootService"),serializeHTML_1=require("../factories/serializeHTML"),zeroRect=()=>({x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0});class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.boundingClientRect=zeroRect(),this.clientRects=[],this.animations=[],this.isVisible=!0,this.capturedPointers=new Set,this.shadowRootInstance=null,this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"clientHeight",value:0},{name:"clientLeft",value:0},{name:"clientTop",value:0},{name:"clientWidth",value:0},{name:"scrollHeight",value:0},{name:"scrollLeft",value:0},{name:"scrollTop",value:0},{name:"scrollWidth",value:0}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get localName(){return this.tag}get prefix(){return null}get innerHTML(){return(0,serializeHTML_1.serializeChildren)(this)}get outerHTML(){return(0,serializeHTML_1.serializeOuter)(this)}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}get children(){return new HTMLCollectionService_1.HTMLCollectionService(this)}get childElementCount(){return this.children.length}get firstElementChild(){return this.children.item(0)}get lastElementChild(){const e=this.children;return e.item(e.length-1)}get nextElementSibling(){let e=this.nextSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.nextSibling;return e}get previousElementSibling(){let e=this.previousSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.previousSibling;return e}insertAdjacentElement(e,t){return this.insertAdjacent(e,t)}insertAdjacentText(e,t){this.insertAdjacent(e,t)}insertAdjacent(e,t){switch(e){case"beforebegin":return this.parentNode?(this.before(t),t):null;case"afterbegin":return this.prepend(t),t;case"beforeend":return this.append(t),t;case"afterend":return this.parentNode?(this.after(t),t):null;default:throw new Error(`"${e}" is not one of beforebegin, afterbegin, beforeend or afterend.`)}}insertAdjacentHTML(e,t){throw new Error("ElementService.insertAdjacentHTML() is not implemented yet.")}matches(e){return(0,query_1.matches)(this,e)}closest(e){return(0,query_1.closest)(this,e)}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}getAttributeNames(){return this.currentAttributes().map(({name:e})=>e)}hasAttributes(){return this.attributeList.length>0}getAttributeNode(e){return this.hasAttribute(e)?new AttrService_1.AttrService(e,this.getAttribute(e)||"",this):null}getAttributeNodeNS(e,t){return this.getAttributeNode(t)}getAttributeNS(e,t){return this.getAttribute(t)}hasAttributeNS(e,t){return this.hasAttribute(t)}removeAttributeNode(e){if(!this.hasAttribute(e.name))throw new Error(`Failed to execute 'removeAttributeNode': The node provided is owned by another element (no attribute named '${e.name}')`);const t=this.getAttributeNode(e.name);return this.removeAttribute(e.name),t}removeAttributeNS(e,t){this.removeAttribute(t)}setAttributeNode(e){const t=this.getAttributeNode(e.name);return this.setAttribute(e.name,e.value),t}setAttributeNodeNS(e){return this.setAttributeNode(e)}setAttributeNS(e,t,r){this.setAttribute(t,r)}toggleAttribute(e,t){const r=this.hasAttribute(e),i="boolean"==typeof t?t:!r;return i&&!r?this.setAttribute(e,""):!i&&r&&this.removeAttribute(e),i}getBoundingClientRect(){return this.boundingClientRect}getClientRects(){return this.clientRects}getAnimations(){return this.animations}checkVisibility(){return this.isVisible}computedStyleMap(){const e=this.style;return{get:t=>{const r=e?e.getPropertyValue(t):"";return""===r?void 0:r}}}hasPointerCapture(e){return this.capturedPointers.has(e)}setPointerCapture(e){this.capturedPointers.add(e)}releasePointerCapture(e){this.capturedPointers.delete(e)}scroll(e=0,t=0){if("number"==typeof e)return this.scrollLeft=e,void(this.scrollTop=t);"number"==typeof e.left&&(this.scrollLeft=e.left),"number"==typeof e.top&&(this.scrollTop=e.top)}scrollTo(e=0,t=0){this.scroll(e,t)}scrollBy(e=0,t=0){"number"!=typeof e?this.scroll({left:this.scrollLeft+(e.left||0),top:this.scrollTop+(e.top||0)}):this.scroll(this.scrollLeft+e,this.scrollTop+t)}scrollIntoView(){}requestFullscreen(){return Promise.resolve()}requestPointerLock(){return Promise.resolve()}attachShadow(e){if(this.shadowRootInstance)throw new Error("Shadow root cannot be created on a host which already hosts a shadow tree.");const t=new ShadowRootService_1.ShadowRootService;return t.host=this,t.mode=e.mode,this.shadowRootInstance=t,t}get shadowRoot(){return this.shadowRootInstance&&"open"===this.shadowRootInstance.mode?this.shadowRootInstance:null}getAriaAttribute(e){return this.getAttribute(e)||""}setAriaAttribute(e,t){this.setAttribute(e,t)}get ariaAtomic(){return this.getAriaAttribute("aria-atomic")}set ariaAtomic(e){this.setAriaAttribute("aria-atomic",e)}get ariaAutoComplete(){return this.getAriaAttribute("aria-autocomplete")}set ariaAutoComplete(e){this.setAriaAttribute("aria-autocomplete",e)}get ariaBusy(){return this.getAriaAttribute("aria-busy")}set ariaBusy(e){this.setAriaAttribute("aria-busy",e)}get ariaChecked(){return this.getAriaAttribute("aria-checked")}set ariaChecked(e){this.setAriaAttribute("aria-checked",e)}get ariaColCount(){return this.getAriaAttribute("aria-colcount")}set ariaColCount(e){this.setAriaAttribute("aria-colcount",e)}get ariaColIndex(){return this.getAriaAttribute("aria-colindex")}set ariaColIndex(e){this.setAriaAttribute("aria-colindex",e)}get ariaColSpan(){return this.getAriaAttribute("aria-colspan")}set ariaColSpan(e){this.setAriaAttribute("aria-colspan",e)}get ariaCurrent(){return this.getAriaAttribute("aria-current")}set ariaCurrent(e){this.setAriaAttribute("aria-current",e)}get ariaDescription(){return this.getAriaAttribute("aria-description")}set ariaDescription(e){this.setAriaAttribute("aria-description",e)}get ariaDisabled(){return this.getAriaAttribute("aria-disabled")}set ariaDisabled(e){this.setAriaAttribute("aria-disabled",e)}get ariaExpanded(){return this.getAriaAttribute("aria-expanded")}set ariaExpanded(e){this.setAriaAttribute("aria-expanded",e)}get ariaHasPopup(){return this.getAriaAttribute("aria-haspopup")}set ariaHasPopup(e){this.setAriaAttribute("aria-haspopup",e)}get ariaHidden(){return this.getAriaAttribute("aria-hidden")}set ariaHidden(e){this.setAriaAttribute("aria-hidden",e)}get ariaKeyShortcuts(){return this.getAriaAttribute("aria-keyshortcuts")}set ariaKeyShortcuts(e){this.setAriaAttribute("aria-keyshortcuts",e)}get ariaLabel(){return this.getAriaAttribute("aria-label")}set ariaLabel(e){this.setAriaAttribute("aria-label",e)}get ariaLevel(){return this.getAriaAttribute("aria-level")}set ariaLevel(e){this.setAriaAttribute("aria-level",e)}get ariaLive(){return this.getAriaAttribute("aria-live")}set ariaLive(e){this.setAriaAttribute("aria-live",e)}get ariaModal(){return this.getAriaAttribute("aria-modal")}set ariaModal(e){this.setAriaAttribute("aria-modal",e)}get ariaMultiline(){return this.getAriaAttribute("aria-multiline")}set ariaMultiline(e){this.setAriaAttribute("aria-multiline",e)}get ariaMultiSelectable(){return this.getAriaAttribute("aria-multiselectable")}set ariaMultiSelectable(e){this.setAriaAttribute("aria-multiselectable",e)}get ariaOrientation(){return this.getAriaAttribute("aria-orientation")}set ariaOrientation(e){this.setAriaAttribute("aria-orientation",e)}get ariaPlaceholder(){return this.getAriaAttribute("aria-placeholder")}set ariaPlaceholder(e){this.setAriaAttribute("aria-placeholder",e)}get ariaPosInSet(){return this.getAriaAttribute("aria-posinset")}set ariaPosInSet(e){this.setAriaAttribute("aria-posinset",e)}get ariaPressed(){return this.getAriaAttribute("aria-pressed")}set ariaPressed(e){this.setAriaAttribute("aria-pressed",e)}get ariaReadOnly(){return this.getAriaAttribute("aria-readonly")}set ariaReadOnly(e){this.setAriaAttribute("aria-readonly",e)}get ariaRequired(){return this.getAriaAttribute("aria-required")}set ariaRequired(e){this.setAriaAttribute("aria-required",e)}get ariaRoleDescription(){return this.getAriaAttribute("aria-roledescription")}set ariaRoleDescription(e){this.setAriaAttribute("aria-roledescription",e)}get ariaRowCount(){return this.getAriaAttribute("aria-rowcount")}set ariaRowCount(e){this.setAriaAttribute("aria-rowcount",e)}get ariaRowIndex(){return this.getAriaAttribute("aria-rowindex")}set ariaRowIndex(e){this.setAriaAttribute("aria-rowindex",e)}get ariaRowSpan(){return this.getAriaAttribute("aria-rowspan")}set ariaRowSpan(e){this.setAriaAttribute("aria-rowspan",e)}get ariaSelected(){return this.getAriaAttribute("aria-selected")}set ariaSelected(e){this.setAriaAttribute("aria-selected",e)}get ariaSetSize(){return this.getAriaAttribute("aria-setsize")}set ariaSetSize(e){this.setAriaAttribute("aria-setsize",e)}get ariaSort(){return this.getAriaAttribute("aria-sort")}set ariaSort(e){this.setAriaAttribute("aria-sort",e)}get ariaValueMax(){return this.getAriaAttribute("aria-valuemax")}set ariaValueMax(e){this.setAriaAttribute("aria-valuemax",e)}get ariaValueMin(){return this.getAriaAttribute("aria-valuemin")}set ariaValueMin(e){this.setAriaAttribute("aria-valuemin",e)}get ariaValueNow(){return this.getAriaAttribute("aria-valuenow")}set ariaValueNow(e){this.setAriaAttribute("aria-valuenow",e)}get ariaValueText(){return this.getAriaAttribute("aria-valuetext")}set ariaValueText(e){this.setAriaAttribute("aria-valuetext",e)}}exports.ElementService=ElementService;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pseudo-dom",
3
3
  "description": "Mock the DOM on the server side for managing state and testing",
4
- "version": "0.15.0",
4
+ "version": "0.16.0",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
7
7
  "author": "Joshua Heagle",