import{isElement as e,sortNodes as t,getNextIndex as n,getPrevIndex as s}from"./utils.js";function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e}).apply(this,arguments)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class a{constructor(){var a=this;d(this,"descendants",new Map),d(this,"register",(t=>{if(null!=t)return e(t)?this.registerNode(t):e=>{this.registerNode(e,t)}})),d(this,"unregister",(e=>{this.descendants.delete(e);var n=t(Array.from(this.descendants.keys()));this.assignIndex(n)})),d(this,"destroy",(()=>{this.descendants.clear()})),d(this,"assignIndex",(e=>{this.descendants.forEach((t=>{var n=e.indexOf(t.node);t.index=n,t.node.dataset.index=t.index.toString()}))})),d(this,"count",(()=>this.descendants.size)),d(this,"enabledCount",(()=>this.enabledValues().length)),d(this,"values",(()=>Array.from(this.descendants.values()).sort(((e,t)=>e.index-t.index)))),d(this,"enabledValues",(()=>this.values().filter((e=>!e.disabled)))),d(this,"item",(e=>{if(0!==this.count())return this.values()[e]})),d(this,"enabledItem",(e=>{if(0!==this.enabledCount())return this.enabledValues()[e]})),d(this,"first",(()=>this.item(0))),d(this,"firstEnabled",(()=>this.enabledItem(0))),d(this,"last",(()=>this.item(this.descendants.size-1))),d(this,"lastEnabled",(()=>{var e=this.enabledValues().length-1;return this.enabledItem(e)})),d(this,"indexOf",(e=>{var t,n;return e&&null!=(t=null==(n=this.descendants.get(e))?void 0:n.index)?t:-1})),d(this,"enabledIndexOf",(e=>null==e?-1:this.enabledValues().findIndex((t=>t.node.isSameNode(e))))),d(this,"next",(function(e,t){void 0===t&&(t=!0);var s=n(e,a.count(),t);return a.item(s)})),d(this,"nextEnabled",(function(e,t){void 0===t&&(t=!0);var s=a.item(e);if(s){var i=a.enabledIndexOf(s.node),d=n(i,a.enabledCount(),t);return a.enabledItem(d)}})),d(this,"prev",(function(e,t){void 0===t&&(t=!0);var n=s(e,a.count()-1,t);return a.item(n)})),d(this,"prevEnabled",(function(e,t){void 0===t&&(t=!0);var n=a.item(e);if(n){var i=a.enabledIndexOf(n.node),d=s(i,a.enabledCount()-1,t);return a.enabledItem(d)}})),d(this,"registerNode",((e,n)=>{if(e&&!this.descendants.has(e)){var s=Array.from(this.descendants.keys()).concat(e),d=t(s);null!=n&&n.disabled&&(n.disabled=!!n.disabled);var a=i({node:e,index:-1},n);this.descendants.set(e,a),this.assignIndex(d)}}))}}export{a as DescendantsManager};
//# sourceMappingURL=descendant.js.map
