import{extend}from"./array.js";const XML_SCHEMA_INSTANCE_URI="http://www.w3.org/2001/XMLSchema-instance";function createElementNS(e,t){return getDocument().createElementNS(e,t)}function getAllTextContent(e,t){return getAllTextContent_(e,t,[]).join("")}function getAllTextContent_(t,n,r){if(t.nodeType==Node.CDATA_SECTION_NODE||t.nodeType==Node.TEXT_NODE)n?r.push(String(t.nodeValue).replace(/(\r\n|\r|\n)/g,"")):r.push(t.nodeValue);else{let e;for(e=t.firstChild;e;e=e.nextSibling)getAllTextContent_(e,n,r)}return r}function isDocument(e){return"documentElement"in e}function getAttributeNS(e,t,n){return e.getAttributeNS(t,n)||""}function parse(e){return(new DOMParser).parseFromString(e,"application/xml")}function makeArrayExtender(n,r){return function(e,t){e=n.call(void 0!==r?r:this,e,t);void 0!==e&&(t=t[t.length-1],extend(t,e))}}function makeArrayPusher(r,i){return function(e,t){e=r.call(void 0!==i?i:this,e,t);if(void 0!==e){const n=t[t.length-1];n.push(e)}}}function makeReplacer(n,r){return function(e,t){e=n.call(void 0!==r?r:this,e,t);void 0!==e&&(t[t.length-1]=e)}}function makeObjectPropertyPusher(e,o,l){return function(t,n){var r=e.call(void 0!==l?l:this,t,n);if(void 0!==r){const i=n[n.length-1];n=void 0!==o?o:t.localName;let e;n in i?e=i[n]:(e=[],i[n]=e),e.push(r)}}}function makeObjectPropertySetter(i,o,l){return function(e,t){var n=i.call(void 0!==l?l:this,e,t);if(void 0!==n){const r=t[t.length-1];t=void 0!==o?o:e.localName;r[t]=n}}}function makeChildAppender(i,o){return function(e,t,n){i.call(void 0!==o?o:this,e,t,n);const r=n[n.length-1].node;r.appendChild(e)}}function makeArraySerializer(i,e){let o,l;return function(e,t,n){if(void 0===o){o={};const r={};r[e.localName]=i,o[e.namespaceURI]=r,l=makeSimpleNodeFactory(e.localName)}serialize(o,l,t,n)}}function makeSimpleNodeFactory(e,i){const o=e;return function(e,t,n){t=t[t.length-1].node;let r=o;return void 0===r&&(r=n),createElementNS(void 0!==i?i:t.namespaceURI,r)}}const OBJECT_PROPERTY_NODE_FACTORY=makeSimpleNodeFactory();function makeSequence(t,n){var r=n.length;const i=new Array(r);for(let e=0;e<r;++e)i[e]=t[n[e]];return i}function makeStructureNS(e,t,n){const r=void 0!==n?n:{};let i,o;for(i=0,o=e.length;i<o;++i)r[e[i]]=t;return r}function parseNode(e,t,n,r){let i;for(i=t.firstElementChild;i;i=i.nextElementSibling){var o=e[i.namespaceURI];if(void 0!==o){const l=o[i.localName];void 0!==l&&l.call(r,i,n)}}}function pushParseAndPop(e,t,n,r,i){return r.push(e),parseNode(t,n,r,i),r.pop()}function serialize(t,n,r,i,o,l){var a,c,u=(void 0!==o?o:r).length;for(let e=0;e<u;++e)void 0!==(a=r[e])&&void 0!==(c=n.call(void 0!==l?l:this,a,i,void 0!==o?o[e]:void 0))&&t[c.namespaceURI][c.localName].call(l,c,a,i)}function pushSerializeAndPop(e,t,n,r,i,o,l){return i.push(e),serialize(t,n,r,i,o,l),i.pop()}let xmlSerializer_=void 0;function registerXMLSerializer(e){xmlSerializer_=e}function getXMLSerializer(){return xmlSerializer_=void 0===xmlSerializer_&&"undefined"!=typeof XMLSerializer?new XMLSerializer:xmlSerializer_}let document_=void 0;function registerDocument(e){document_=e}function getDocument(){return document_=void 0===document_&&"undefined"!=typeof document?document.implementation.createDocument("","",null):document_}export{XML_SCHEMA_INSTANCE_URI,createElementNS,getAllTextContent,getAllTextContent_,isDocument,getAttributeNS,parse,makeArrayExtender,makeArrayPusher,makeReplacer,makeObjectPropertyPusher,makeObjectPropertySetter,makeChildAppender,makeArraySerializer,makeSimpleNodeFactory,OBJECT_PROPERTY_NODE_FACTORY,makeSequence,makeStructureNS,parseNode,pushParseAndPop,serialize,pushSerializeAndPop,registerXMLSerializer,getXMLSerializer,registerDocument,getDocument};