var u={};import*as l from"./../../core/platform/platform.js";Node.prototype.traverseNextTextNode=function(t){let e=this.traverseNextNode(t);if(!e)return null;let n={STYLE:1,SCRIPT:1,"#document-fragment":1};for(;e&&(e.nodeType!==Node.TEXT_NODE||n[e.parentNode?e.parentNode.nodeName:""]);)e=e.traverseNextNode(t);return e};Element.prototype.positionAt=function(t,e,n){let o={x:0,y:0};n&&(o=n.boxInWindow(this.ownerDocument.defaultView)),typeof t=="number"?this.style.setProperty("left",o.x+t+"px"):this.style.removeProperty("left"),typeof e=="number"?this.style.setProperty("top",o.y+e+"px"):this.style.removeProperty("top"),typeof t=="number"||typeof e=="number"?this.style.setProperty("position","absolute"):this.style.removeProperty("position")};Node.prototype.enclosingNodeOrSelfWithClass=function(t,e){return this.enclosingNodeOrSelfWithClassList([t],e)};Node.prototype.enclosingNodeOrSelfWithClassList=function(t,e){for(let n=this;n&&n!==e&&n!==this.ownerDocument;n=n.parentNodeOrShadowHost())if(n.nodeType===Node.ELEMENT_NODE){let o=!0;for(let i=0;i<t.length&&o;++i)n.classList.contains(t[i])||(o=!1);if(o)return n}return null};Node.prototype.parentElementOrShadowHost=function(){if(this.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&this.host)return this.host;let t=this.parentNode;return t?t.nodeType===Node.ELEMENT_NODE?t:t.nodeType===Node.DOCUMENT_FRAGMENT_NODE?t.host:null:null};Node.prototype.parentNodeOrShadowHost=function(){return this.parentNode?this.parentNode:this.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&this.host?this.host:null};Node.prototype.getComponentSelection=function(){let t=this.parentNode;for(;t&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE;)t=t.parentNode;return t instanceof ShadowRoot?t.getSelection():this.window().getSelection()};Node.prototype.hasSelection=function(){if(this instanceof Element){let e=this.querySelectorAll("slot");for(let n of e)if(Array.prototype.some.call(n.assignedNodes(),o=>o.hasSelection()))return!0}let t=this.getComponentSelection();return t.type!=="Range"?!1:t.containsNode(this,!0)||t.anchorNode.isSelfOrDescendant(this)||t.focusNode.isSelfOrDescendant(this)};Node.prototype.window=function(){return this.ownerDocument.defaultView};Node.prototype.removeChildren=function(){this.firstChild&&(this.textContent="")};self.createElement=function(t,e){return document.createElement(t,{is:e})};self.createTextNode=function(t){return document.createTextNode(t)};self.createDocumentFragment=function(){return document.createDocumentFragment()};DocumentFragment.prototype.createChild=Element.prototype.createChild=function(t,e){let n=document.createElement(t);return e&&(n.className=e),this.appendChild(n),n};self.AnchorBox=class{constructor(t,e,n,o){this.x=t||0,this.y=e||0,this.width=n||0,this.height=o||0}contains(t,e){return t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height}relativeTo(t){return new AnchorBox(this.x-t.x,this.y-t.y,this.width,this.height)}relativeToElement(t){return this.relativeTo(t.boxInWindow(t.ownerDocument.defaultView))}equals(t){return!!t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height}};Element.prototype.boxInWindow=function(t){t=t||this.ownerDocument.defaultView;let e=new AnchorBox,n=this,o=this.ownerDocument.defaultView;for(;o&&n&&(e.x+=n.getBoundingClientRect().left,e.y+=n.getBoundingClientRect().top,o!==t);)n=o.frameElement,o=o.parent;return e.width=Math.min(this.offsetWidth,t.innerWidth-e.x),e.height=Math.min(this.offsetHeight,t.innerHeight-e.y),e};Event.prototype.consume=function(t){this.stopImmediatePropagation(),t&&this.preventDefault(),this.handled=!0};Node.prototype.deepTextContent=function(t=!1){let e=this.childTextNodes().map(n=>n.textContent).join("");return t?e.replace(/\s+/g," "):e};Node.prototype.childTextNodes=function(){let t=this.traverseNextTextNode(this),e=[],n={STYLE:1,SCRIPT:1,"#document-fragment":1};for(;t;)n[t.parentNode?t.parentNode.nodeName:""]||e.push(t),t=t.traverseNextTextNode(this);return e};function s(t){if(![Node.ELEMENT_NODE,Node.TEXT_NODE,Node.DOCUMENT_FRAGMENT_NODE].includes(t.nodeType)||["SCRIPT","STYLE"].includes(t.nodeName))return[];if(t instanceof HTMLSlotElement)return[...t.assignedNodes()].flatMap(s);if(t instanceof Element&&t.shadowRoot)return[...t.shadowRoot.childNodes].flatMap(s);if(t instanceof DocumentFragment)return[...t.childNodes].flatMap(s);if(!(t instanceof HTMLElement))return[t];let e=[],n=!1;for(let o of t.childNodes){let i=s(o);(i.length>1||i.length===1&&i[0]!==o)&&(n=!0),e.push(...i)}return n?e:[t]}Node.prototype.deepInnerText=function(){return s(this).map(t=>t instanceof HTMLElement?t.innerText:t.textContent.trim()).filter(Boolean).join(`
`)};Node.prototype.isAncestor=function(t){if(!t)return!1;let e=t.parentNodeOrShadowHost();for(;e;){if(this===e)return!0;e=e.parentNodeOrShadowHost()}return!1};Node.prototype.isDescendant=function(t){return!!t&&t.isAncestor(this)};Node.prototype.isSelfOrAncestor=function(t){return!!t&&(t===this||this.isAncestor(t))};Node.prototype.isSelfOrDescendant=function(t){return!!t&&(t===this||this.isDescendant(t))};Node.prototype.traverseNextNode=function(t,e=!1){if(!e&&this.shadowRoot)return this.shadowRoot;let n=this instanceof HTMLSlotElement?this.assignedNodes():[];if(n.length)return n[0];if(this.firstChild)return this.firstChild;let o=this;for(;o;){if(t&&o===t)return null;let r=i(o);if(r)return r;o=o.assignedSlot||o.parentNodeOrShadowHost()}function i(r){if(!r.assignedSlot)return r.nextSibling;let h=r.assignedSlot.assignedNodes(),d=Array.prototype.indexOf.call(h,r);return d+1<h.length?h[d+1]:null}return null};Node.prototype.traversePreviousNode=function(t){if(t&&this===t)return null;let e=this.previousSibling;for(;e?.lastChild;)e=e.lastChild;return e||this.parentNodeOrShadowHost()};Node.prototype.setTextContentTruncatedIfNeeded=function(t,e){return typeof t=="string"&&t.length>1e4?(this.textContent=typeof e=="string"?e:l.StringUtilities.trimMiddle(t,1e4),!0):(this.textContent=t,!1)};Element.prototype.hasFocus=function(){let t=this.getComponentRoot();return!!t&&this.isSelfOrAncestor(t.activeElement)};Node.prototype.getComponentRoot=function(){let t=this;for(;t&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&t.nodeType!==Node.DOCUMENT_NODE;)t=t.parentNode;return t};self.onInvokeElement=function(t,e){t.addEventListener("keydown",n=>{l.KeyboardUtilities.isEnterOrSpaceKey(n)&&e(n)}),t.addEventListener("click",n=>e(n))};(function(){let t=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,n){return arguments.length===1&&(n=!this.contains(e)),t.call(this,e,!!n)}})();export{u as DOMExtension};
//# sourceMappingURL=dom_extension.js.map
