(function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r.index={}))})(this,function(r){"use strict";const i=(...t)=>e=>t.reduce((o,n)=>n(o),e),I=(t,e)=>{const o=[[t,e]];let n=!0;for(;o.length;){const[s,d]=o.pop();if(s==null||d===null||d===void 0){if(s!==d){n=!1;break}}else if(Array.isArray(s)&&Array.isArray(d))if(s.length!==d.length){n=!1;break}else for(let c=0;ce=>e.path.includes(t),T=t=>e=>e.children.includes(t),y=(t,e)=>({id:e,children:[],parentId:"",path:[],value:t}),N=(t,e,o)=>({id:e,children:[],parentId:o.id,path:[...o.path,o.id],value:t}),b=t=>e=>T(t)(e)?e:{...e,children:[...e.children,t]},u=t=>e=>T(t)(e)?{...e,children:e.children.filter(o=>o!==t)}:e,k=t=>t.children.length?{...t,children:[]}:t,m=t=>e=>I(e.path,t)?e:{...e,path:t},j=t=>e=>e.parentId===t?e:{...e,parentId:t},P=t=>({rootId:t.id,nodeMap:{[t.id]:t}}),v=t=>e=>{const{[t]:o,...n}=e.nodeMap;return o!=null&&o.parentId?{rootId:e.rootId,nodeMap:n}:e},O=t=>e=>{var s;let o=e;const n=(s=e.nodeMap[t])==null?void 0:s.parentId;if(n){const d=e.nodeMap[n];d&&(o={...e,nodeMap:{...e.nodeMap,[n]:u(t)(d)}})}return o},A=t=>e=>{let o=e;const n=e.nodeMap[t],s=n==null?void 0:n.children;if(s&&s.length){const{path:d}=n,c={...e.nodeMap};for(let a=0;aB===t);s.push(...p.children),c[l]={...p,path:[...d,...p.path.slice(M)]}}o={rootId:e.rootId,nodeMap:c}}return o},h=t=>e=>e.nodeMap[t.id]===t?e:{rootId:e.rootId,nodeMap:{...e.nodeMap,[t.id]:t}},C=t=>e=>i(f(t),O(t),v(t))(e),f=t=>e=>{let o=e;const n=e.nodeMap[t];if(n!=null&&n.children.length){const s=[...n.children],d={...e.nodeMap};for(let a=0;a[a,!0]));o={rootId:e.rootId,nodeMap:Object.fromEntries(Object.entries(d).filter(([a])=>!c[a]))}}return o},w=(t,e)=>P(y(t,e)),E=(t,e,o)=>n=>{const s=n.nodeMap[o],d=n.nodeMap[e],c=d!=null&&d.parentId?n.nodeMap[d.parentId]:void 0;return s&&o!==e?i(f(e),c?h(u(e)(c)):a=>a,h(b(e)(s)),h(N(t,e,s)))(n):n},S=(t,e)=>o=>{const n=o.nodeMap[t];return n&&!I(n.value,e)?{rootId:o.rootId,nodeMap:{...o.nodeMap,[t]:{...n,value:e}}}:o},V=(t,e)=>o=>{const n=o.nodeMap[t],s=n!=null&&n.parentId?o.nodeMap[n.parentId]:void 0,d=o.nodeMap[e];return n&&s&&d&&t!==e&&!g(t)(d)?i(h(u(t)(s)),h(b(t)(d)),h(i(m([...d.path,e]),j(e))(n)),A(t))(o):o},q=(t,e=()=>1)=>{const{rootId:o,nodeMap:n}=t,s=n[o],d=[],c=[s];for(;c.length;){const a=c.pop(),l=a.children.map(p=>n[p]).sort((p,M)=>-e(p,M));d.push(a),c.push(...l)}return d};r.createTree=w,r.createTreeNode=E,r.deleteTreeNode=C,r.deleteTreeNodeChildren=f,r.getOrderedTreeNodes=q,r.updateTreeNodeParent=V,r.updateTreeNodeValue=S,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});