@dynamix-layout/core 0.0.2-beta.0 → 0.0.6

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.
package/dist/core.iife.js CHANGED
@@ -1 +1,57 @@
1
- var layout=function(){"use strict";const g={Row:0,Column:1,Tabset:2,Tab:3};class m{constructor(e,s,t){this.type=e,this.name=null,this.parent=t,this.weight=s,this.children=[],this.dimension=[0,0],this.coordinate=[0,0],this.prev=null,this.next=null}}class y{constructor(e,s,t){this.type=e,this.prev=s,this.next=t,this.name=`${s.name}-${t.name}`,this.dimension=[0,0],this.coordinate=[0,0],s.next=this,t.prev=this}}const E={top:g.Row,left:g.Column,right:g.Column,bottom:g.Row,cover:g.Tab},v={top:0,left:0,right:1,bottom:1,cover:0};class l{static detach(e,s){var h;const t=e.parent;if(!t)return;const n=(h=e.parent)==null?void 0:h.children.indexOf(e),o=t==null?void 0:t.children.length,a=8*100/t.dimension[t.type];if(!s)return l.fixSrc(e);if(n>0&&n<o-1){const r=(e.weight+a)/2,c=t.children[n+1],i=t.children[n-1];c.weight+=r,i.weight+=r,new y(e.type,i,c)}if(n===o-1){const r=t.children[n-1];r.weight+=e.weight+a,r.next=null}if(n===0){const r=t.children[n+1];r.weight+=e.weight+a,r.prev=null}t.children.splice(n,1)}static attach(e,s,t){const n=e.parent;if(!n)return;const o=n.children.indexOf(e);switch(E[t]){case 1-n.type:const a=o+v[t],h=8*100/n.dimension[n.type];s.weight=e.weight=(e.weight-h)/2,s.parent=n,n.children.splice(a,0,s),l.fixBond(s,n.type);break;case n.type:const r=e.weight/2,c=v[t]==0?[s,e]:[e,s],i=new m(1-n.type,e.weight,n);i.children=c,n.children[o]=i,c.forEach(u=>{u.weight=r,u.parent=i}),this.fixBond(i,n.type),this.fixBond(s,n.type),this.fixBond(e,n.type);break;case g.Tab:e.children.push(...s.children),s.children.forEach(u=>{u.parent=e});break}}static getTotalWeight(e){return e.children.reduce((s,t)=>s+t.weight,0)??100}static getTotalNodes(e){return e.children.length}static getSize(e){return e.dimension[e.type]-(this.getTotalNodes(e)-1)*8}}l.createBinaryTree=(f,e)=>{var c;const{range:s}=e,t=[...e.tabs];if(s==1){const i=new m(g.Column,100,f);f.children=[i],l.addTab(i,t);return}const n=[f],o=[];let a=1,h=1;for(;h<s||n.length;){const i=[],u=n.length;for(let w=0;w<u;w++){const d=n.shift(),T=((c=d.parent)==null?void 0:c.children.indexOf(d))??0;if(d.name=`r${o.length}/c${w}/tb${T}`,d&&(i.push(d),h<s&&(d.children[0]=new m(a,50,d),n.push(d.children[0])),h<s)){d.children[1]=new m(a,50,d),n.push(d.children[1]),h++;const b=new y(a,d.children[0],d.children[1]);b.name=`r${o.length}/c${w}/b${T}-${T+1}`}}o.push(i),a=1-a}[...o[o.length-1],...o[o.length-2]].forEach(i=>{l.addTab(i,t)})},l.fixSrc=f=>{const e=f.parent;if(!e)return;const s=e.children.indexOf(f),t=e.children[1-s],n=e.parent,o=n==null?void 0:n.children.indexOf(e);switch(t.type){case g.Tabset:const a=e.weight;n==null||n.children.splice(o,1),n==null||n.children.splice(o,0,t),t.weight=a,t.parent=n,l.fixBond(t,t.type);break;default:if(!n){e.children.splice(s,1);break}const h=t.children.length,r=8*(h-1)*100/n.dimension[t.type];t.children.forEach(u=>{u.weight=(e.weight-r)*u.weight/100});const c=t.children[0],i=t.children[h-1];n.children=[...n.children.slice(0,o),...t.children,...n.children.slice(o+1)],t.children.forEach(u=>{u.parent=n}),l.fixBond(c,t.type),l.fixBond(i,t.type);break}},l.fixBond=(f,e)=>{const s=f.parent;if(!s)return;const t=s.children.indexOf(f),n=s.children.length;t>0&&t<n-1&&(new y(e,s.children[t-1],s.children[t]),new y(e,s.children[t],s.children[t+1])),t===n-1&&(new y(e,s.children[t-1],s.children[t]),s.children[t].next=null),t===0&&(new y(e,s.children[t],s.children[t+1]),s.children[t].prev=null)},l.addTab=(f,e)=>{if(f.children.length!==0)return;f.type=g.Tabset;const s=new m(g.Tab,100,f),t=e.shift();s.name=t,f.children=[s]},l.json=f=>{var e;return{type:f.type,dimension:f.dimension,coordinate:f.coordinate,name:f.name,children:(e=f.children)==null?void 0:e.map(s=>l.json(s))}};class B{constructor(e={}){this.shiftTree=(t,n,o)=>{let a,h;if(this._tabs.forEach(c=>{c.name==n&&(a=c),c.name==t&&(h=c),c.children.forEach(i=>{i.name==n&&(a=i),i.name==t&&(h=i)})}),h==null||a==null||h.parent===null)return;const r=h.parent.children.length;return a.type==g.Tabset&&h.type==g.Tab?(l.detach(h,r>1),l.attach(a,h,o)):a.type==g.Tabset&&h.type==g.Tabset&&(l.detach(h,r>2),l.attach(a,h,o)),this.calculate(this._root,0)},this.createTree=()=>{const{layout:t}=this._settings;if(!t)return l.createBinaryTree(this._root,this._settings),console.log("create tree",JSON.stringify(this.jsonify())),this.updateTree();const n=[t],o=[this._root];for(;n.length;){const a=n.length;for(let h=0;h<a;h++){const r=n.shift(),c=o.shift();r&&r.children.forEach((i,u)=>{n.push(i),o.push(new m(i.type,i.weight,c??null)),c==null||c.children.push(o[o.length-1]),u!=0&&new y(i.type,o[o.length-2],o[o.length-1])})}}return this.updateTree(),this},this.updateTree=(t,n,o)=>{t&&n&&(this._root.dimension=[t,n]);const a=[this._root];for(this._bond=[],this._tabs=[];a.length;){const h=[],r=a.length;for(let c=0;c<r;c++){const i=a.shift(),u=l.getSize(i),w=l.getTotalWeight(i);let d=0,T=0,b=i.children[0];const x=i.dimension,_=i.coordinate;i&&(h.push(i.coordinate),i.type==g.Tabset&&this._tabs.push(i),i.children.forEach((p,$)=>{if(a.push(p),p.dimension=[...x],p.coordinate=[..._],p.weight=p.weight/w*100,$===i.children.length-1)p.dimension[i.type]=u-T,p.weight=100-d;else{p.weight=p.weight/w*100;const j=u*(p.weight/100);p.dimension[i.type]=j,d+=p.weight,T+=p.dimension[i.type]}p.dimension[i.type]=p.dimension[i.type],p.prev&&(p.coordinate[i.type]=b.coordinate[i.type]+b.dimension[i.type]+8,p.prev.dimension=[...x],p.prev.coordinate=[..._],p.prev.dimension[i.type]=8,p.prev.coordinate[i.type]=b.coordinate[i.type]+b.dimension[i.type],p.prev.type=1-i.type,b=p,this._bond.push(p.prev))}))}}return o&&o(),this.getElements()},this.getElements=()=>({tabs:this._tabs.map(t=>l.json(t)),bonds:this._bond.map(t=>l.json(t))}),this.jsonify=()=>l.json(this._root);let s=Object.assign({layout:null,range:1,dimension:[0,0],coordinate:[0,0],tabs:Array.from({length:e.range??1},(t,n)=>`tab-${n+1}`)},e);this._tabs=[],this._bond=[],this._settings=s,this._root=new m(g.Row,100,null),this._root.coordinate=this._settings.coordinate,this._root.dimension=this._settings.dimension,this.createTree()}calculate(e,s=0){s==0&&(this._bond=[],this._tabs=[]);const t=l.getSize(e),n=l.getTotalWeight(e);let o=e.children[0],a=0,h=0;e.type==g.Tabset&&this._tabs.push(e),e.children.forEach((r,c)=>{r.dimension=[...e.dimension],r.coordinate=[...e.coordinate],c===e.children.length-1?(r.dimension[e.type]=t-a,r.weight=100-h):(r.weight=r.weight/n*100,r.dimension[e.type]=t*(r.weight/100),h+=r.weight,a+=r.dimension[e.type]),c!==0&&(r.coordinate[e.type]=o.coordinate[e.type]+o.dimension[e.type]+8,r.prev&&(r.prev.dimension=[...e.dimension],r.prev.coordinate=[...e.coordinate],r.prev.dimension[e.type]=8,r.prev.coordinate[e.type]=o.coordinate[e.type]+o.dimension[e.type],this._bond.push(r.prev)),o=r)}),e.type==g.Tabset&&this._tabs.push(e),e.children.forEach(r=>{r.children.length&&this.calculate(r,s+1)})}}return B}();
1
+ this.dynamix=this.dynamix||{};this.dynamix.layout=this.dynamix.layout||{};this.dynamix.layout.core=function(w){"use strict";class N{buffer;head=0;tail=0;count=0;capacity;constructor(t=16,e=[]){this.capacity=Math.max(t,e.length),this.buffer=new Array(this.capacity),e.forEach(i=>{this.enqueue(i)})}enqueue(t){this.count===this.capacity&&this.resize(),this.buffer[this.tail]=t,this.tail=(this.tail+1)%this.capacity,this.count++}enqueueFront(t){this.count===this.capacity&&this.resize(),this.head=(this.head-1+this.capacity)%this.capacity,this.buffer[this.head]=t,this.count++}insert(t,e){if(t<0||t>this.count)return!1;if(t===0)return this.enqueueFront(e),!0;if(t===this.count)return this.enqueue(e),!0;this.count===this.capacity&&this.resize();const i=t,n=this.count-t;return i<=n?this.shiftLeft(t,e):this.shiftRight(t,e),this.count++,!0}insertArray(t,e){if(t<0||t>this.count)return!1;if(e.length===0)return!0;if(t===0){for(let d=e.length-1;d>=0;d--)this.enqueueFront(e[d]);return!0}if(t===this.count)return e.forEach(d=>this.enqueue(d)),!0;for(;this.count+e.length>this.capacity;)this.resize();const i=t,n=this.count-t,s=e.length;return i<=n?this.shiftLeftArray(t,e):this.shiftRightArray(t,e),this.count+=s,!0}insertQueue(t,e){if(t<0||t>this.count)return!1;if(e.isEmpty())return!0;const i=e.size();if(t===0){const o=e.toArray();for(let h=o.length-1;h>=0;h--)this.enqueueFront(o[h]);return!0}if(t===this.count){for(const o of e)this.enqueue(o);return!0}for(;this.count+i>this.capacity;)this.resize();const n=e.toArray(),s=t,d=this.count-t;return s<=d?this.shiftLeftArray(t,n):this.shiftRightArray(t,n),this.count+=i,!0}push(t){this.enqueue(t)}unshift(t){this.enqueueFront(t)}dequeue(){if(this.count===0)return;const t=this.buffer[this.head];return this.head=(this.head+1)%this.capacity,this.count--,t}dequeueBack(){if(this.count===0)return;this.tail=(this.tail-1+this.capacity)%this.capacity;const t=this.buffer[this.tail];return this.count--,t}indexOf(t){for(let e=0;e<this.count;e++){const i=(this.head+e)%this.capacity;if(this.buffer[i]===t)return e}return-1}remove(t){const e=this.indexOf(t);return e===-1?!1:(this.removeAt(e),!0)}removeAt(t){if(t<0||t>=this.count)return;if(t===0)return this.dequeue();if(t===this.count-1)return this.dequeueBack();const e=(this.head+t)%this.capacity,i=this.buffer[e],n=t,s=this.count-t-1;return n<=s?this.shiftRightForRemoval(t):this.shiftLeftForRemoval(t),this.count--,i}shift(){return this.dequeue()}pop(){return this.dequeueBack()}fifoAdd(t){this.enqueue(t)}fifoRemove(){return this.dequeue()}filoAdd(t){this.enqueue(t)}filoRemove(){return this.dequeueBack()}lifoAdd(t){this.enqueueFront(t)}lifoRemove(){return this.dequeue()}liloAdd(t){this.enqueueFront(t)}liloRemove(){return this.dequeueBack()}get(t){if(t<0||t>=this.count)return;const e=(this.head+t)%this.capacity;return this.buffer[e]}set(t,e){if(t<0||t>=this.count)return!1;const i=(this.head+t)%this.capacity;return this.buffer[i]=e,!0}peek(){return this.count>0?this.buffer[this.head]:void 0}peekBack(){if(this.count===0)return;const t=(this.tail-1+this.capacity)%this.capacity;return this.buffer[t]}front(){return this.peek()}back(){return this.peekBack()}size(){return this.count}getCapacity(){return this.capacity}isEmpty(){return this.count===0}isFull(){return this.count===this.capacity}clear(){this.head=0,this.tail=0,this.count=0}toArray(){const t=[];for(let e=0;e<this.count;e++){const i=(this.head+e)%this.capacity;t.push(this.buffer[i])}return t}*[Symbol.iterator](){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*forward(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*reverse(){for(let t=this.count-1;t>=0;t--){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*entries(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield[t,this.buffer[e]]}}*keys(){for(let t=0;t<this.count;t++)yield t}*values(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}toString(){return`Queue(${this.toArray().join(", ")})`}resize(){const t=this.capacity*2,e=new Array(t);for(let i=0;i<this.count;i++){const n=(this.head+i)%this.capacity;e[i]=this.buffer[n]}this.buffer=e,this.capacity=t,this.head=0,this.tail=this.count}shiftLeft(t,e){this.head=(this.head-1+this.capacity)%this.capacity;for(let n=0;n<t;n++){const s=(this.head+1+n)%this.capacity,d=(this.head+n)%this.capacity;this.buffer[d]=this.buffer[s]}const i=(this.head+t)%this.capacity;this.buffer[i]=e}shiftRight(t,e){for(let n=this.count-1;n>=t;n--){const s=(this.head+n)%this.capacity,d=(this.head+n+1)%this.capacity;this.buffer[d]=this.buffer[s]}const i=(this.head+t)%this.capacity;this.buffer[i]=e,this.tail=(this.tail+1)%this.capacity}shiftRightForRemoval(t){for(let e=t;e>0;e--){const i=(this.head+e-1)%this.capacity,n=(this.head+e)%this.capacity;this.buffer[n]=this.buffer[i]}this.head=(this.head+1)%this.capacity}shiftLeftForRemoval(t){for(let e=t;e<this.count-1;e++){const i=(this.head+e+1)%this.capacity,n=(this.head+e)%this.capacity;this.buffer[n]=this.buffer[i]}this.tail=(this.tail-1+this.capacity)%this.capacity}shiftLeftArray(t,e){const i=e.length;this.head=(this.head-i+this.capacity)%this.capacity;for(let n=0;n<t;n++){const s=(this.head+i+n)%this.capacity,d=(this.head+n)%this.capacity;this.buffer[d]=this.buffer[s]}for(let n=0;n<i;n++){const s=(this.head+t+n)%this.capacity;this.buffer[s]=e[n]}}shiftRightArray(t,e){const i=e.length;for(let n=this.count-1;n>=t;n--){const s=(this.head+n)%this.capacity,d=(this.head+n+i)%this.capacity;this.buffer[d]=this.buffer[s]}for(let n=0;n<i;n++){const s=(this.head+t+n)%this.capacity;this.buffer[s]=e[n]}this.tail=(this.tail+i)%this.capacity}}function g(I,t=(e,i)=>e===i){let e=I;const i=new Set;let n=[];const s=()=>e,d=(l,f=!1)=>{if(f){e=l;return}t(e,l)||(e=l,i.forEach(m=>m(e)),n.forEach(m=>m(e)),n=[])},o=()=>{i.forEach(l=>l(e)),n.forEach(l=>l(e)),n=[]},h=l=>(i.add(l),()=>i.delete(l)),r=()=>new Promise(l=>{n.push(l)});return{get:s,set:d,onChange:h,nextChange:r,triggerChange:o,onChangePromise:l=>{let f=!0;return(async()=>{for(;f;){const p=await r();if(!f)break;l(p)}})(),()=>{f=!1}}}}function E(I,t){if(I.size!==t.size)return!1;for(const[e,i]of I.entries()){const n=t.get(e);if(!n||!T(i,n))return!1}return!0}function T(I,t){if(I.typNode!==t.typNode||I.nodName!==t.nodName||I.uidNode!==t.uidNode||I.nodPart!==t.nodPart)return!1;const e=I.nodDims,i=t.nodDims;return e.x===i.x&&e.y===i.y&&e.w===i.w&&e.h===i.h}class a{static cache={dimMins:new Map,mapDirs:new Map,tabCnts:new Map,mapElem:new Map,tabOpts:g(new Map,E),nodOpts:g(new Map,E),bndOpts:g(new Map,E)};kids=new N;dims={w:0,h:0,x:0,y:0};unId;next=null;prev=null;type="row";name="";part=0;host=null;open="";constructor(t={}){const e={type:"row",host:null,name:"",part:100,dims:{w:0,h:0,x:0,y:0},unId:crypto.randomUUID(),open:""};this.type=t.type??e.type,this.host=t.host??e.host,this.name=t.name??e.name,this.part=t.part??e.part,this.dims=t.dims??e.dims,this.open=t.open??e.open,this.unId=t.unId||e.unId}addBond(t,e=null){if(!e)return;const i=new x(t,this,e);a.cache.mapElem.set(i.unId,i)}getReqDimension(){const t=a.cache.dimMins.get(this.unId),e=a.cache.tabCnts.get(this.unId),i=Math.max(t.minWidth,e.horizontal*c._minW+Math.max(0,e.horizontal-1)*c._bond),n=Math.max(t.minHeight,e.vertical*c._minH+Math.max(0,e.vertical-1)*c._bond);return{width:i,height:n}}calcDimensions(){const t=a.cache.mapDirs.get(this.unId);if(!this.kids)return;let e=0;const i=a.cache.dimMins.get(this.unId)||{minWidth:0,minHeight:0};let n=0;for(const o of this.kids)e+=o.part;if(e===0)return;let s;t?s=this.dims.w-i.minWidth:s=this.dims.h-i.minHeight;let d=s;for(const o of this.kids){const h=a.cache.dimMins.get(o.unId)||{minWidth:0,minHeight:0};if(this.dims.w<i.minWidth)t?(o.dims.w=h.minWidth,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond);else{const r=o.part/e,u=Math.floor(s*r);if(o===this.kids.peekBack()){t?(o.dims.w=h.minWidth+d,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight+d,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond);break}t?(o.dims.w=h.minWidth+u,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight+u,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond),d-=u}o.next&&(t?o.next.dims={w:c._bond,h:o.dims.h,x:o.dims.x+o.dims.w,y:o.dims.y}:o.next.dims={w:o.dims.w,h:c._bond,x:o.dims.x,y:o.dims.y+o.dims.h})}}toJSON(){const t=[];for(const i of this.kids)t.push(i.toJSON());const e={typNode:this.type,nodPart:this.part,nodName:this.name,uidNode:this.unId};return this.open&&(e.nodOpen=this.open),t.length>0&&(e.nodKids=t),e}}class c{static _root;static _tree;static _minW=40;static _minH=40;static _bond=10;static _inst=null;nodeOps;cntdown=null;tabsIds=new Map;constructor(t={}){const e={tabs:[],tree:null,minW:40,minH:40,bond:10,uqid:"dynamix-layout-root",tabsIds:new Map,...t};this.tabsIds=e.tabsIds,e.tree&&(c._tree=e.tree),c._root=new a({unId:e.uqid,name:e.uqid,type:"row"}),this.nodeOps=g(new Map,E),c._minW=e.minW,c._minH=e.minH,c._bond=e.bond;const i=new N(e.tabs.length,e.tabs);c._tree?this.createNodeLayout():this.createBinaryNodeTreeFromQueue(i),c._inst=this}*JSONLayoutIterator(t){const e=new N;for(e.enqueue(t);!e.isEmpty();){const i=e.dequeue();if(i&&(yield i,i.nodKids&&i.nodKids.length>0))for(const n of i.nodKids)e.enqueue(n)}}*NodeLayoutIterator(t){const e=new N;for(e.enqueue(t);!e.isEmpty();){const i=e.dequeue();if(i&&(a.cache.mapElem.set(i.unId,i),yield i,i.kids.size()>0))for(const n of i.kids)e.enqueue(n)}}*NodeLayoutRecursiveIterator(t){for(const e of t.kids)yield*this.NodeLayoutRecursiveIterator(e);yield t}updateChildDirections(t){const e=a.cache.mapDirs.get(t.unId);if(e===void 0){console.warn(`Cannot update child directions for node ${t.unId}; its own direction is not set.`);return}for(const i of t.kids)a.cache.mapDirs.set(i.unId,!e),i.kids.size()>0&&(i.host=t,this.updateChildDirections(i),i.next&&a.cache.mapDirs.set(i.next.unId,!e))}createNodeLayout(t=c._tree){const e=this.JSONLayoutIterator(t),i=this.NodeLayoutIterator(c._root);for(a.cache.mapDirs.set(c._root.unId,!0);;){const n=e.next(),s=i.next();if(n.done||s.done)break;const d=n.value,o=s.value;!d||!o||this.createNodeTreeFromJSONTree(d,o)}this.calcTabsetCountAndMinDim()}createNodeTreeFromJSONTree(t,e){const i=a.cache.mapDirs.get(e.unId);for(const n of t.nodKids||[]){const s=this.createNodeFromJSON(n),d=e.kids.peekBack();s.host=e,s.addBond(s.host,d),e.kids.enqueue(s),a.cache.mapDirs.set(s.unId,!i)}e.type==="tabset"&&a.cache.mapElem.set(e.unId,e),e.type==="tab"&&a.cache.mapElem.set(e.unId,e)}createBinaryNodeTreeFromQueue(t,e=c._root){const i=new N;for(i.enqueue(e),a.cache.mapDirs.set(c._root.unId,!0);!t.isEmpty();){const n=i.dequeue();if(!n)break;const s=a.cache.mapDirs.get(n.unId);if(t.size()==2){const u=t.dequeue(),l=t.dequeue(),f=new a({type:"tabset",host:n}),m=new a({type:"tabset",host:n}),p=new a({type:"tab",host:f,name:u,unId:this.tabsIds.get(u??"")??crypto.randomUUID()}),y=new a({type:"tab",host:m,name:l,unId:this.tabsIds.get(l??"")??crypto.randomUUID()});f.open=p.name,m.open=y.name,f.kids.enqueue(p),m.kids.enqueue(y),n.kids.enqueue(f),n.kids.enqueue(m),m.addBond(n,f),a.cache.mapDirs.set(f.unId,!s),a.cache.mapDirs.set(m.unId,!s),a.cache.mapElem.set(f.unId,f),a.cache.mapElem.set(m.unId,m),a.cache.mapDirs.set(p.unId,s),a.cache.mapDirs.set(y.unId,s),a.cache.mapElem.set(p.unId,p),a.cache.mapElem.set(y.unId,y),console.log(this.tabsIds);break}const d=t.dequeue(),o=new a({type:"tabset",host:n}),h=new a({type:"row",host:n}),r=new a({type:"tab",host:o,name:d,unId:this.tabsIds.get(d??"")??crypto.randomUUID()});o.open=r.name,o.kids.enqueue(r),n.kids.enqueue(o),n.kids.enqueue(h),h.addBond(n,o),a.cache.mapDirs.set(o.unId,!s),a.cache.mapDirs.set(h.unId,!s),a.cache.mapElem.set(o.unId,o),a.cache.mapDirs.set(r.unId,s),a.cache.mapElem.set(r.unId,r),i.enqueue(h)}this.calcTabsetCountAndMinDim()}createNodeFromJSON(t){const e=new a({type:t.typNode,name:t.nodName,unId:t.uidNode,part:t.nodPart,dims:{w:0,h:0,x:0,y:0},open:typeof t.nodOpen=="string"?t.nodOpen:""});return t.typNode==="tab"&&(e.unId=this.tabsIds.get(t.nodName)||t.uidNode),e}calcTabsetCountAndMinDim(t=c._root,e=!0){t===c._root&&e&&(a.cache.tabCnts.clear(),a.cache.dimMins.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear());for(const i of this.NodeLayoutRecursiveIterator(t)){const n=a.cache.tabCnts,s=a.cache.dimMins;a.cache.mapElem.set(i.unId,i);const d=n.set(i.unId,{horizontal:0,vertical:0}).get(i.unId),o=s.set(i.unId,{minWidth:0,minHeight:0}).get(i.unId),h=a.cache.mapDirs.get(i.unId);if(i.type==="tab"&&(a.cache.mapElem.set(i.unId,i),s.set(i.unId,{minWidth:0,minHeight:0})),i.next&&a.cache.mapElem.set(i.next.unId,i.next),i.type==="tabset"&&(a.cache.mapElem.set(i.unId,i),s.set(i.unId,{minWidth:c._minW,minHeight:c._minH}),h?n.set(i.unId,{horizontal:0,vertical:1}):n.set(i.unId,{horizontal:1,vertical:0})),i.type==="row"){for(const r of i.kids){const u=n.get(r.unId),l=s.get(r.unId);u&&(d.horizontal+=u.horizontal,d.vertical+=u.vertical,h?(o.minHeight=Math.max(o.minHeight,l.minHeight),o.minWidth+=l.minWidth):(o.minHeight+=l.minHeight,o.minWidth=Math.max(o.minWidth,l.minWidth)))}h?o.minWidth+=(i.kids.size()-1)*c._bond:o.minHeight+=(i.kids.size()-1)*c._bond}}}calculateRootAdjustment(){const t=c._root.getReqDimension();let e=!1,i=c._root.dims.w,n=c._root.dims.h;return c._root.dims.w<t.width&&(i=t.width,e=!0),c._root.dims.h<t.height&&(n=t.height,e=!0),e&&(c._root.dims.w=i,c._root.dims.h=n),{adjustedW:i,adjustedH:n,wasAdjusted:e}}calcDimensions(t=c._root,e=!1){const i=new Map,n=new Map,s=new Map;t===c._root&&this.calculateRootAdjustment();for(const d of this.NodeLayoutIterator(t)){d.calcDimensions();const o=a.cache.mapDirs.get(d.unId);if(d.type==="tabset"){const h={typNode:d.type,nodName:d.name,uidNode:d.unId,nodPart:d.part,nodOpen:d.open,nodeDir:o,nodKids:Array.from(d.kids).map(r=>{const u={typNode:r.type,nodName:r.name,uidNode:r.unId,nodPart:r.part,nodOpen:d.open===r.name,nodeDir:!o,nodDims:{...d.dims}};return s.set(r.unId,u),u}),nodDims:{...d.dims}};i.set(d.unId,h)}if(d.next&&d.type!=="tab"){const h={typNode:"bond",nodName:d.name,uidNode:d.next.unId,nodeDir:o,nodPart:0,nodDims:{...d.next.dims}};n.set(d.next.unId,h)}}a.cache.nodOpts.set(i,e),a.cache.bndOpts.set(n,e),a.cache.tabOpts.set(s,e)}updateDimension(t,e=!1,i=2){if(c._root.dims=t,e){this.calcDimensions(c._root);return}this.cntdown&&(clearTimeout(this.cntdown),this.cntdown=null),this.cntdown=setTimeout(()=>{this.cntdown=null,this.calcDimensions()},i)}updateSlider(t,e,i=!1,n=2){if(i){this.updateSliderDimension(t,e);return}this.cntdown&&(clearTimeout(this.cntdown),this.cntdown=null),this.cntdown=setTimeout(()=>{this.cntdown=null,this.updateSliderDimension(t,e)},n)}updateSliderDimension(t,e){const i=a.cache.mapElem.get(t);if(!i||!(i instanceof x)){console.warn(`Bond with id ${t} not found or is not a Bond instance`);return}const n=a.cache.mapDirs.get(i.host.unId),s=i.prev,d=i.next,o=i.host;if(!s||!d||!o){console.warn("Missing prev, next, or host node",s,d,o);return}const h=a.cache.dimMins.get(s.unId)||{minWidth:0,minHeight:0},r=a.cache.dimMins.get(d.unId)||{minWidth:0,minHeight:0},u=c._bond/2;if(n){const l=d.dims.x+d.dims.w,f=s.dims.x+h.minWidth+u,m=l-r.minWidth-u,p=Math.max(f,Math.min(m,e.x));i.dims.x=p-u,s.dims.w=i.dims.x-s.dims.x,d.dims.x=p+u,d.dims.w=l-d.dims.x;const y=Math.max(0,s.dims.w-h.minWidth),O=Math.max(0,d.dims.w-r.minWidth),k=y+O,b=s.part+d.part;k>0?(s.part=y/k*b,d.part=O/k*b):(s.part=b/2,d.part=b/2)}else{const l=d.dims.y+d.dims.h,f=s.dims.y+h.minHeight+u,m=l-r.minHeight-u,p=Math.max(f,Math.min(m,e.y));i.dims.y=p-u,s.dims.h=i.dims.y-s.dims.y,d.dims.y=p+u,d.dims.h=l-d.dims.y;const y=Math.max(0,s.dims.h-h.minHeight),O=Math.max(0,d.dims.h-r.minHeight),k=y+O,b=s.part+d.part;k>0?(s.part=y/k*b,d.part=O/k*b):(s.part=b/2,d.part=b/2)}this.calcDimensions(o)}updateTree(t,e,i){const n=a.cache.mapElem.get(t);let s=a.cache.mapElem.get(e);return!n||!(n instanceof a)||!s||!(s instanceof a)?(console.warn(`Source node ${t} not found or is not a Node instance`),!1):n?.type=="tab"&&n.host===s&&s.kids.size()<2?(console.warn("Cannot move to self as it has only one tab"),!1):n?.type=="tabset"&&s?.host===n?(console.warn("Cannot move tabset to self as it is already a child"),!1):!n||!s?(console.warn(`Source or destination node not found: ${t}, ${e}`),!1):n===s?(console.warn("Source and destination nodes are the same, no action taken."),!1):!n.host||!s.host&&s.type!=="row"?(console.warn(`Source node or destination node's host is null: ${n.unId}, ${s.unId}`),!1):s.type==="row"&&i==="contain"?(console.warn(`Cannot move to a row with 'contain' layout: ${s.unId}`),!1):n.type==="row"?!1:(s.type==="tabset"&&i==="contain"&&(s=s.kids.peekBack()||s),s.type==="tab"&&(i==="contain"||i==="left"||i==="right")?this.moveNodeAsTab(n,s,i):s.type==="row"&&i!=="contain"?this.moveRelativeToRoot(n,s,i):s.type==="tabset"&&i!=="contain"&&this.moveRelativeToTabset(n,s,i),this.calcTabsetCountAndMinDim(),this.calcDimensions(c._root,!0),!0)}moveNodeAsTab(t,e,i){if(!e||!e.host){console.warn(`Destination node ${e.unId} has no host, cannot move.`);return}this.removeNode(t);const n=e.host,s=n.kids.indexOf(e);if(s===void 0||s===-1)return;const d=i==="contain"||i==="left",o=d?s:s+1,h=n.kids.get(o+1),r=n.kids.get(o-1),u=e.next,l=e.prev;if(!d&&u?(a.cache.mapElem.delete(u.unId),a.cache.nodOpts.get().delete(u.unId)):d&&l&&(a.cache.mapElem.delete(l.unId),a.cache.nodOpts.get().delete(l.unId)),t.type=="tab")d?(r&&t.addBond(n,r),e.addBond(n,t)):(t.addBond(n,e),h&&h.addBond(n,t)),n.kids.insert(o,t),t.host=n,n.open=t.name;else if(t.type=="tabset"){const f=t.kids.peek(),m=t.kids.peekBack();d?(f&&r&&f.addBond(n,r),m&&e&&e.addBond(n,m)):(f&&e&&f.addBond(n,e),m&&h&&h.addBond(n,m)),n.kids.insertQueue(o,t.kids);for(const p of t.kids)p.host=n,p.next&&(p.next.host=n);n.open=m?m.name:""}this.updateChildDirections(n)}moveRelativeToRoot(t,e,i){this.removeNode(t);const n=a.cache.mapDirs.get(e.unId),s=i==="top"||i==="left";if(t.type==="tab"){const d=new a({type:"tabset",host:e.host});d.kids.enqueue(t),t.host=d,d.open=t.name,n==!1?i==="left"||i==="right"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s):i==="top"||i==="bottom"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s)}else t.type==="tabset"&&(n==!1?i==="left"||i==="right"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s):i==="top"||i==="bottom"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s))}moveRelativeToTabset(t,e,i){this.removeNode(t);const n=a.cache.mapDirs.get(e.unId),s=i==="top"||i==="left";if(t.type==="tab"){const d=new a({type:"tabset",host:e.host});d.kids.enqueue(t),t.host=d,d.open=t.name,n==!1?i==="top"||i==="bottom"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s):i==="left"||i==="right"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s)}else t.type==="tabset"&&(n==!1?i==="top"||i==="bottom"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s):i==="left"||i==="right"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s))}insertNode(t,e,i){const n=t.host;if(t==c._root){const l=c._root.kids.peek(),f=c._root.kids.peekBack();i?(c._root.kids.enqueueFront(e),l&&l.addBond(c._root,e)):(c._root.kids.enqueue(e),f&&e.addBond(c._root,f)),e.host=c._root,this.updateChildDirections(c._root);return}if(!n){console.warn(`Destination node ${t.unId} has no host, cannot insert.`);return}const s=n.kids.indexOf(t);if(s===-1){console.warn(`Destination node ${t.unId} not found in its host's kids.`);return}const d=a.cache.mapDirs.get(n.unId);d&&a.cache.mapDirs.set(e.unId,!d);const o=n.kids.get(s+1),h=n.kids.get(s-1),r=t.next,u=t.prev;e.host=n,i?(n.kids.insert(s,e),t.addBond(n,e),h&&e.addBond(n,h),u&&(a.cache.mapElem.delete(u.unId),a.cache.nodOpts.get().delete(u.unId))):(n.kids.insert(s+1,e),e.addBond(n,t),o&&o.addBond(n,e),r&&(a.cache.mapElem.delete(r.unId),a.cache.nodOpts.get().delete(r.unId))),this.updateChildDirections(n)}insertNodeWithNewParent(t,e,i){const n=new N,s=new a({type:"tabset",host:e.host});if(!e||!t){console.warn(`Destination node ${e.unId} has no host, cannot insert.`);return}if(e===c._root){const o=new a({type:"row",host:e});if(e.kids.size()==1&&e.kids.peek()?.type==="tabset"){const h=e.kids.dequeue();if(!h){console.warn(`No kid found in destination node ${e.unId}, cannot insert.`);return}i?(o.kids.enqueue(t),o.kids.enqueue(h),e.kids.enqueue(o),h.addBond(o,t)):(o.kids.enqueue(h),o.kids.enqueue(t),t.addBond(o,h),e.kids.enqueue(o)),t.host=o,h.host=o}else if(e.kids.size()==1&&e.kids.peek()?.type==="row"){const h=e.kids.peek(),r=h?.kids.peek(),u=h?.kids.peekBack();i&&h?(h.kids.enqueueFront(t),r&&r.addBond(h,t)):h&&(h.kids.enqueue(t),u&&t.addBond(h,u)),t.host=h}else if(e.kids.size()>1){const h=new a({type:"row",host:e}),r=new a({type:"row",host:h});for(const u of e.kids)r.kids.enqueue(u),u.host=r,u.next&&(u.next.host=r);t.host=h,e.kids.clear(),i?(h.kids.enqueueFront(t),h.kids.enqueue(r),r.addBond(h,t)):(h.kids.enqueue(r),h.kids.enqueue(t),t.addBond(h,r)),e.kids.enqueue(h)}this.updateChildDirections(e);return}t.host=e,s.host=e,s.kids=e.kids,s.open=e.open;const d=a.cache.mapDirs.get(e.unId);for(const o of s.kids)o.host=s,o.next&&(o.next.host=s),a.cache.mapDirs.set(o.unId,d);for(const o of t.kids)o.host=t,o.next&&(o.next.host=t),a.cache.mapDirs.set(o.unId,d);a.cache.mapDirs.set(s.unId,!d),a.cache.mapDirs.set(t.unId,!d),i?(n.enqueue(t),n.enqueue(s),e.kids=n,e.type="row",s.addBond(e,t)):(n.enqueue(s),n.enqueue(t),e.kids=n,e.type="row",t.addBond(e,s))}moveAdjacentNodeToGrandParent(t){if(!t.host||!t.host.host){console.warn(`Source node ${t.unId} has no host, cannot move.`);return}const e=t.host,i=t.host.host,n=i.kids.indexOf(e),s=i.kids.get(n-1),d=i.kids.get(n+1),o=t.kids.peek(),h=t.kids.peekBack();this.removeKid(e);let r=n;if(t.type=="row"&&e){s&&o&&o.addBond(i,s),d&&h&&d.addBond(i,h);for(const u of t.kids)u.host=i,u.next&&(u.next.host=i),i.kids.insert(r,u),a.cache.mapDirs.set(u.unId,!a.cache.mapDirs.get(i.unId)),a.cache.dimMins.delete(u.unId),r++}else if(t.type=="tabset"){s&&t.addBond(i,s),d&&d.addBond(i,t),i.kids.insert(r,t),t.host=i,a.cache.mapDirs.set(t.unId,!a.cache.mapDirs.get(i.unId));for(const u of t.kids)a.cache.mapDirs.set(u.unId,a.cache.mapDirs.get(i.unId)),a.cache.dimMins.delete(u.unId)}}removeRelation(t,e=!0){const i=t.host,n=t.prev,s=t.next;if(t.host=null,t.next=null,t.prev=null,n&&(n.next=null),s&&(s.prev=null),!e)return t;n&&s&&n.prev&&s.next?n.prev.addBond(i,s.next):n&&n.prev?n.prev.next=null:s&&s.next&&(s.next.prev=null)}removeNode(t){if(!t.host){console.warn("Kid node has no host, cannot remove.");return}const e=t?.host,i=e?.host;if(this.removeKid(t),t.type==="tabset"&&e.kids.size()===1){const n=e.kids.peek();n&&this.moveAdjacentNodeToGrandParent(n)}else if(t.type==="tab"&&e.kids.size()===0&&i.kids.size()===2){this.removeKid(e);const n=i?.kids.peek();n&&this.moveAdjacentNodeToGrandParent(n)}else if(t.type==="tab"&&e.kids.size()===0&&i.kids.size()>2)this.removeKid(e);else if(t.type==="tab"&&e.open===t.name&&e.kids.size()>0){const n=e.kids.peek();n&&(e.open=n.name)}}removeKid(t){if(!t.host){console.warn("Kid node has no host, cannot remove.");return}const e=t.host,i=e.kids.indexOf(t),n=e.kids.get(i+1),s=e.kids.get(i-1),d=t.next,o=t.prev;if(i===-1){console.warn("Kid node not found in its host's kids.");return}d&&(a.cache.mapElem.delete(d.unId),a.cache.nodOpts.get().delete(d.unId)),o&&(a.cache.mapElem.delete(o.unId),a.cache.nodOpts.get().delete(o.unId)),n&&s?n.addBond(e,s):n?n.prev=null:s&&(s.next=null),e.kids.removeAt(i),a.cache.mapElem.delete(t.unId),a.cache.dimMins.delete(t.unId),a.cache.mapDirs.delete(t.unId),a.cache.tabCnts.delete(t.unId),t.type==="tabset"&&a.cache.mapElem.delete(t.unId),t.type==="tab"&&a.cache.mapElem.delete(t.unId),t.host=null,t.next=null,t.prev=null}clearAllCache(){a.cache.dimMins.clear(),a.cache.mapDirs.clear(),a.cache.tabCnts.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear()}}class x{dims={w:0,h:0,x:0,y:0};unId=crypto.randomUUID();next=null;prev=null;host=null;constructor(t=null,e=null,i=null){this.host=t,this.next=e,this.prev=i,this.next&&(this.next.prev=this),this.prev&&(this.prev.next=this)}toJSON(){return{nodName:this.host?.name||"",typNode:"bond",uidNode:this.unId,nodPart:0,nodOpen:"",nodKids:[]}}}return(()=>{if(typeof window>"u")return;const I="color: #03A9F4; font-weight: bold; line-height: 1.2;",t="color: #E0E0E0; font-size: 12px;",e="color: #42a5f5; font-size: 12px;",i="color: #9E9E9E; font-size: 10px;",n=`
2
+ ██████╗ ██╗ ██╗ ███╗ ██╗ █████╗ ███╗ ███╗ ██████╗ ██╗ ██╗
3
+ ██╔══██╗╚██╗ ██╔╝ ████╗ ██║ ██╔══██╗ ████╗ ████║ ╚═██╔═╝ ╚██╗██╔╝
4
+ ██║ ██║ ╚████╔╝ ██╔██╗ ██║ ███████║ ██╔████╔██║ ██║ ╚███╔╝
5
+ ██║ ██║ ╚██╔╝ ██║╚██╗██║ ██╔══██║ ██║╚██╔╝██║ ██║ ██╔██╗
6
+ ██████╔╝ ██║ ██║ ╚████║ ██║ ██║ ██║ ╚═╝ ██║ ██████╗ ██╔╝ ██╗
7
+ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
8
+ ██╗ █████╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗
9
+ ██║ ██╔══██╗ ╚██╗ ██╔╝ ██╔═══██╗ ██║ ██║╚══██╔══╝
10
+ ██║ ███████║ ╚████╔╝ ██║ ██║ ██║ ██║ ██║
11
+ ██║ ██╔══██║ ╚██╔╝ ██║ ██║ ██║ ██║ ██║
12
+ ███████╗ ██║ ██║ ██║ ╚██████╔╝ ╚█████╔╝ ██║
13
+ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚════╝ ╚═╝
14
+ `;console.groupCollapsed("%cDYNAMIX LAYOUT (click to expand)","color: #03A9F4; font-weight: bold; font-size: 14px;"),console.log(`%c${n}`,I),console.log("%c A powerful, dynamic layout system 🚀",t),console.log(`%c ⚡ For docs and more info,
15
+ ⚡ visit: https://github.com/akash-aman/dynamix-layout`,e),console.log(`%cMIT License
16
+
17
+ Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ of this software and associated documentation files (the "Software"), to deal
21
+ in the Software without restriction, including without limitation the rights
22
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ copies of the Software, and to permit persons to whom the Software is
24
+ furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all
27
+ copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ SOFTWARE.
36
+ `,i),console.groupEnd(),typeof window<"u"&&(window.__DYNAMIX_LAYOUT__={__LICENSE__:`MIT License
37
+
38
+ Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ of this software and associated documentation files (the "Software"), to deal
42
+ in the Software without restriction, including without limitation the rights
43
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ copies of the Software, and to permit persons to whom the Software is
45
+ furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all
48
+ copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56
+ SOFTWARE.
57
+ `,__LAYOUT__:c})})(),w.Bond=x,w.DynamixLayoutCore=c,w.Node=a,w.Queue=N,w.areNodeOptionsEqual=T,w.areNodeOptionsMapEqual=E,w.createReactiveState=g,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"}),w}({});
package/dist/core.umd.js CHANGED
@@ -1 +1,57 @@
1
- (function(u,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(u=typeof globalThis<"u"?globalThis:u||self,u.layout=m())})(this,function(){"use strict";const u={Row:0,Column:1,Tabset:2,Tab:3};class m{constructor(e,s,t){this.type=e,this.name=null,this.parent=t,this.weight=s,this.children=[],this.dimension=[0,0],this.coordinate=[0,0],this.prev=null,this.next=null}}class y{constructor(e,s,t){this.type=e,this.prev=s,this.next=t,this.name=`${s.name}-${t.name}`,this.dimension=[0,0],this.coordinate=[0,0],s.next=this,t.prev=this}}const E={top:u.Row,left:u.Column,right:u.Column,bottom:u.Row,cover:u.Tab},x={top:0,left:0,right:1,bottom:1,cover:0};class l{static detach(e,s){var h;const t=e.parent;if(!t)return;const n=(h=e.parent)==null?void 0:h.children.indexOf(e),o=t==null?void 0:t.children.length,c=8*100/t.dimension[t.type];if(!s)return l.fixSrc(e);if(n>0&&n<o-1){const r=(e.weight+c)/2,a=t.children[n+1],i=t.children[n-1];a.weight+=r,i.weight+=r,new y(e.type,i,a)}if(n===o-1){const r=t.children[n-1];r.weight+=e.weight+c,r.next=null}if(n===0){const r=t.children[n+1];r.weight+=e.weight+c,r.prev=null}t.children.splice(n,1)}static attach(e,s,t){const n=e.parent;if(!n)return;const o=n.children.indexOf(e);switch(E[t]){case 1-n.type:const c=o+x[t],h=8*100/n.dimension[n.type];s.weight=e.weight=(e.weight-h)/2,s.parent=n,n.children.splice(c,0,s),l.fixBond(s,n.type);break;case n.type:const r=e.weight/2,a=x[t]==0?[s,e]:[e,s],i=new m(1-n.type,e.weight,n);i.children=a,n.children[o]=i,a.forEach(d=>{d.weight=r,d.parent=i}),this.fixBond(i,n.type),this.fixBond(s,n.type),this.fixBond(e,n.type);break;case u.Tab:e.children.push(...s.children),s.children.forEach(d=>{d.parent=e});break}}static getTotalWeight(e){return e.children.reduce((s,t)=>s+t.weight,0)??100}static getTotalNodes(e){return e.children.length}static getSize(e){return e.dimension[e.type]-(this.getTotalNodes(e)-1)*8}}l.createBinaryTree=(f,e)=>{var a;const{range:s}=e,t=[...e.tabs];if(s==1){const i=new m(u.Column,100,f);f.children=[i],l.addTab(i,t);return}const n=[f],o=[];let c=1,h=1;for(;h<s||n.length;){const i=[],d=n.length;for(let w=0;w<d;w++){const g=n.shift(),T=((a=g.parent)==null?void 0:a.children.indexOf(g))??0;if(g.name=`r${o.length}/c${w}/tb${T}`,g&&(i.push(g),h<s&&(g.children[0]=new m(c,50,g),n.push(g.children[0])),h<s)){g.children[1]=new m(c,50,g),n.push(g.children[1]),h++;const b=new y(c,g.children[0],g.children[1]);b.name=`r${o.length}/c${w}/b${T}-${T+1}`}}o.push(i),c=1-c}[...o[o.length-1],...o[o.length-2]].forEach(i=>{l.addTab(i,t)})},l.fixSrc=f=>{const e=f.parent;if(!e)return;const s=e.children.indexOf(f),t=e.children[1-s],n=e.parent,o=n==null?void 0:n.children.indexOf(e);switch(t.type){case u.Tabset:const c=e.weight;n==null||n.children.splice(o,1),n==null||n.children.splice(o,0,t),t.weight=c,t.parent=n,l.fixBond(t,t.type);break;default:if(!n){e.children.splice(s,1);break}const h=t.children.length,r=8*(h-1)*100/n.dimension[t.type];t.children.forEach(d=>{d.weight=(e.weight-r)*d.weight/100});const a=t.children[0],i=t.children[h-1];n.children=[...n.children.slice(0,o),...t.children,...n.children.slice(o+1)],t.children.forEach(d=>{d.parent=n}),l.fixBond(a,t.type),l.fixBond(i,t.type);break}},l.fixBond=(f,e)=>{const s=f.parent;if(!s)return;const t=s.children.indexOf(f),n=s.children.length;t>0&&t<n-1&&(new y(e,s.children[t-1],s.children[t]),new y(e,s.children[t],s.children[t+1])),t===n-1&&(new y(e,s.children[t-1],s.children[t]),s.children[t].next=null),t===0&&(new y(e,s.children[t],s.children[t+1]),s.children[t].prev=null)},l.addTab=(f,e)=>{if(f.children.length!==0)return;f.type=u.Tabset;const s=new m(u.Tab,100,f),t=e.shift();s.name=t,f.children=[s]},l.json=f=>{var e;return{type:f.type,dimension:f.dimension,coordinate:f.coordinate,name:f.name,children:(e=f.children)==null?void 0:e.map(s=>l.json(s))}};class B{constructor(e={}){this.shiftTree=(t,n,o)=>{let c,h;if(this._tabs.forEach(a=>{a.name==n&&(c=a),a.name==t&&(h=a),a.children.forEach(i=>{i.name==n&&(c=i),i.name==t&&(h=i)})}),h==null||c==null||h.parent===null)return;const r=h.parent.children.length;return c.type==u.Tabset&&h.type==u.Tab?(l.detach(h,r>1),l.attach(c,h,o)):c.type==u.Tabset&&h.type==u.Tabset&&(l.detach(h,r>2),l.attach(c,h,o)),this.calculate(this._root,0)},this.createTree=()=>{const{layout:t}=this._settings;if(!t)return l.createBinaryTree(this._root,this._settings),console.log("create tree",JSON.stringify(this.jsonify())),this.updateTree();const n=[t],o=[this._root];for(;n.length;){const c=n.length;for(let h=0;h<c;h++){const r=n.shift(),a=o.shift();r&&r.children.forEach((i,d)=>{n.push(i),o.push(new m(i.type,i.weight,a??null)),a==null||a.children.push(o[o.length-1]),d!=0&&new y(i.type,o[o.length-2],o[o.length-1])})}}return this.updateTree(),this},this.updateTree=(t,n,o)=>{t&&n&&(this._root.dimension=[t,n]);const c=[this._root];for(this._bond=[],this._tabs=[];c.length;){const h=[],r=c.length;for(let a=0;a<r;a++){const i=c.shift(),d=l.getSize(i),w=l.getTotalWeight(i);let g=0,T=0,b=i.children[0];const _=i.dimension,v=i.coordinate;i&&(h.push(i.coordinate),i.type==u.Tabset&&this._tabs.push(i),i.children.forEach((p,$)=>{if(c.push(p),p.dimension=[..._],p.coordinate=[...v],p.weight=p.weight/w*100,$===i.children.length-1)p.dimension[i.type]=d-T,p.weight=100-g;else{p.weight=p.weight/w*100;const j=d*(p.weight/100);p.dimension[i.type]=j,g+=p.weight,T+=p.dimension[i.type]}p.dimension[i.type]=p.dimension[i.type],p.prev&&(p.coordinate[i.type]=b.coordinate[i.type]+b.dimension[i.type]+8,p.prev.dimension=[..._],p.prev.coordinate=[...v],p.prev.dimension[i.type]=8,p.prev.coordinate[i.type]=b.coordinate[i.type]+b.dimension[i.type],p.prev.type=1-i.type,b=p,this._bond.push(p.prev))}))}}return o&&o(),this.getElements()},this.getElements=()=>({tabs:this._tabs.map(t=>l.json(t)),bonds:this._bond.map(t=>l.json(t))}),this.jsonify=()=>l.json(this._root);let s=Object.assign({layout:null,range:1,dimension:[0,0],coordinate:[0,0],tabs:Array.from({length:e.range??1},(t,n)=>`tab-${n+1}`)},e);this._tabs=[],this._bond=[],this._settings=s,this._root=new m(u.Row,100,null),this._root.coordinate=this._settings.coordinate,this._root.dimension=this._settings.dimension,this.createTree()}calculate(e,s=0){s==0&&(this._bond=[],this._tabs=[]);const t=l.getSize(e),n=l.getTotalWeight(e);let o=e.children[0],c=0,h=0;e.type==u.Tabset&&this._tabs.push(e),e.children.forEach((r,a)=>{r.dimension=[...e.dimension],r.coordinate=[...e.coordinate],a===e.children.length-1?(r.dimension[e.type]=t-c,r.weight=100-h):(r.weight=r.weight/n*100,r.dimension[e.type]=t*(r.weight/100),h+=r.weight,c+=r.dimension[e.type]),a!==0&&(r.coordinate[e.type]=o.coordinate[e.type]+o.dimension[e.type]+8,r.prev&&(r.prev.dimension=[...e.dimension],r.prev.coordinate=[...e.coordinate],r.prev.dimension[e.type]=8,r.prev.coordinate[e.type]=o.coordinate[e.type]+o.dimension[e.type],this._bond.push(r.prev)),o=r)}),e.type==u.Tabset&&this._tabs.push(e),e.children.forEach(r=>{r.children.length&&this.calculate(r,s+1)})}}return B});
1
+ (function(I,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(I=typeof globalThis<"u"?globalThis:I||self,w((I.dynamix=I.dynamix||{},I.dynamix.layout=I.dynamix.layout||{},I.dynamix.layout.core={})))})(this,function(I){"use strict";class w{buffer;head=0;tail=0;count=0;capacity;constructor(t=16,e=[]){this.capacity=Math.max(t,e.length),this.buffer=new Array(this.capacity),e.forEach(i=>{this.enqueue(i)})}enqueue(t){this.count===this.capacity&&this.resize(),this.buffer[this.tail]=t,this.tail=(this.tail+1)%this.capacity,this.count++}enqueueFront(t){this.count===this.capacity&&this.resize(),this.head=(this.head-1+this.capacity)%this.capacity,this.buffer[this.head]=t,this.count++}insert(t,e){if(t<0||t>this.count)return!1;if(t===0)return this.enqueueFront(e),!0;if(t===this.count)return this.enqueue(e),!0;this.count===this.capacity&&this.resize();const i=t,n=this.count-t;return i<=n?this.shiftLeft(t,e):this.shiftRight(t,e),this.count++,!0}insertArray(t,e){if(t<0||t>this.count)return!1;if(e.length===0)return!0;if(t===0){for(let d=e.length-1;d>=0;d--)this.enqueueFront(e[d]);return!0}if(t===this.count)return e.forEach(d=>this.enqueue(d)),!0;for(;this.count+e.length>this.capacity;)this.resize();const i=t,n=this.count-t,s=e.length;return i<=n?this.shiftLeftArray(t,e):this.shiftRightArray(t,e),this.count+=s,!0}insertQueue(t,e){if(t<0||t>this.count)return!1;if(e.isEmpty())return!0;const i=e.size();if(t===0){const o=e.toArray();for(let h=o.length-1;h>=0;h--)this.enqueueFront(o[h]);return!0}if(t===this.count){for(const o of e)this.enqueue(o);return!0}for(;this.count+i>this.capacity;)this.resize();const n=e.toArray(),s=t,d=this.count-t;return s<=d?this.shiftLeftArray(t,n):this.shiftRightArray(t,n),this.count+=i,!0}push(t){this.enqueue(t)}unshift(t){this.enqueueFront(t)}dequeue(){if(this.count===0)return;const t=this.buffer[this.head];return this.head=(this.head+1)%this.capacity,this.count--,t}dequeueBack(){if(this.count===0)return;this.tail=(this.tail-1+this.capacity)%this.capacity;const t=this.buffer[this.tail];return this.count--,t}indexOf(t){for(let e=0;e<this.count;e++){const i=(this.head+e)%this.capacity;if(this.buffer[i]===t)return e}return-1}remove(t){const e=this.indexOf(t);return e===-1?!1:(this.removeAt(e),!0)}removeAt(t){if(t<0||t>=this.count)return;if(t===0)return this.dequeue();if(t===this.count-1)return this.dequeueBack();const e=(this.head+t)%this.capacity,i=this.buffer[e],n=t,s=this.count-t-1;return n<=s?this.shiftRightForRemoval(t):this.shiftLeftForRemoval(t),this.count--,i}shift(){return this.dequeue()}pop(){return this.dequeueBack()}fifoAdd(t){this.enqueue(t)}fifoRemove(){return this.dequeue()}filoAdd(t){this.enqueue(t)}filoRemove(){return this.dequeueBack()}lifoAdd(t){this.enqueueFront(t)}lifoRemove(){return this.dequeue()}liloAdd(t){this.enqueueFront(t)}liloRemove(){return this.dequeueBack()}get(t){if(t<0||t>=this.count)return;const e=(this.head+t)%this.capacity;return this.buffer[e]}set(t,e){if(t<0||t>=this.count)return!1;const i=(this.head+t)%this.capacity;return this.buffer[i]=e,!0}peek(){return this.count>0?this.buffer[this.head]:void 0}peekBack(){if(this.count===0)return;const t=(this.tail-1+this.capacity)%this.capacity;return this.buffer[t]}front(){return this.peek()}back(){return this.peekBack()}size(){return this.count}getCapacity(){return this.capacity}isEmpty(){return this.count===0}isFull(){return this.count===this.capacity}clear(){this.head=0,this.tail=0,this.count=0}toArray(){const t=[];for(let e=0;e<this.count;e++){const i=(this.head+e)%this.capacity;t.push(this.buffer[i])}return t}*[Symbol.iterator](){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*forward(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*reverse(){for(let t=this.count-1;t>=0;t--){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*entries(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield[t,this.buffer[e]]}}*keys(){for(let t=0;t<this.count;t++)yield t}*values(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}toString(){return`Queue(${this.toArray().join(", ")})`}resize(){const t=this.capacity*2,e=new Array(t);for(let i=0;i<this.count;i++){const n=(this.head+i)%this.capacity;e[i]=this.buffer[n]}this.buffer=e,this.capacity=t,this.head=0,this.tail=this.count}shiftLeft(t,e){this.head=(this.head-1+this.capacity)%this.capacity;for(let n=0;n<t;n++){const s=(this.head+1+n)%this.capacity,d=(this.head+n)%this.capacity;this.buffer[d]=this.buffer[s]}const i=(this.head+t)%this.capacity;this.buffer[i]=e}shiftRight(t,e){for(let n=this.count-1;n>=t;n--){const s=(this.head+n)%this.capacity,d=(this.head+n+1)%this.capacity;this.buffer[d]=this.buffer[s]}const i=(this.head+t)%this.capacity;this.buffer[i]=e,this.tail=(this.tail+1)%this.capacity}shiftRightForRemoval(t){for(let e=t;e>0;e--){const i=(this.head+e-1)%this.capacity,n=(this.head+e)%this.capacity;this.buffer[n]=this.buffer[i]}this.head=(this.head+1)%this.capacity}shiftLeftForRemoval(t){for(let e=t;e<this.count-1;e++){const i=(this.head+e+1)%this.capacity,n=(this.head+e)%this.capacity;this.buffer[n]=this.buffer[i]}this.tail=(this.tail-1+this.capacity)%this.capacity}shiftLeftArray(t,e){const i=e.length;this.head=(this.head-i+this.capacity)%this.capacity;for(let n=0;n<t;n++){const s=(this.head+i+n)%this.capacity,d=(this.head+n)%this.capacity;this.buffer[d]=this.buffer[s]}for(let n=0;n<i;n++){const s=(this.head+t+n)%this.capacity;this.buffer[s]=e[n]}}shiftRightArray(t,e){const i=e.length;for(let n=this.count-1;n>=t;n--){const s=(this.head+n)%this.capacity,d=(this.head+n+i)%this.capacity;this.buffer[d]=this.buffer[s]}for(let n=0;n<i;n++){const s=(this.head+t+n)%this.capacity;this.buffer[s]=e[n]}this.tail=(this.tail+i)%this.capacity}}function g(y,t=(e,i)=>e===i){let e=y;const i=new Set;let n=[];const s=()=>e,d=(f,l=!1)=>{if(l){e=f;return}t(e,f)||(e=f,i.forEach(m=>m(e)),n.forEach(m=>m(e)),n=[])},o=()=>{i.forEach(f=>f(e)),n.forEach(f=>f(e)),n=[]},h=f=>(i.add(f),()=>i.delete(f)),r=()=>new Promise(f=>{n.push(f)});return{get:s,set:d,onChange:h,nextChange:r,triggerChange:o,onChangePromise:f=>{let l=!0;return(async()=>{for(;l;){const p=await r();if(!l)break;f(p)}})(),()=>{l=!1}}}}function E(y,t){if(y.size!==t.size)return!1;for(const[e,i]of y.entries()){const n=t.get(e);if(!n||!T(i,n))return!1}return!0}function T(y,t){if(y.typNode!==t.typNode||y.nodName!==t.nodName||y.uidNode!==t.uidNode||y.nodPart!==t.nodPart)return!1;const e=y.nodDims,i=t.nodDims;return e.x===i.x&&e.y===i.y&&e.w===i.w&&e.h===i.h}class a{static cache={dimMins:new Map,mapDirs:new Map,tabCnts:new Map,mapElem:new Map,tabOpts:g(new Map,E),nodOpts:g(new Map,E),bndOpts:g(new Map,E)};kids=new w;dims={w:0,h:0,x:0,y:0};unId;next=null;prev=null;type="row";name="";part=0;host=null;open="";constructor(t={}){const e={type:"row",host:null,name:"",part:100,dims:{w:0,h:0,x:0,y:0},unId:crypto.randomUUID(),open:""};this.type=t.type??e.type,this.host=t.host??e.host,this.name=t.name??e.name,this.part=t.part??e.part,this.dims=t.dims??e.dims,this.open=t.open??e.open,this.unId=t.unId||e.unId}addBond(t,e=null){if(!e)return;const i=new O(t,this,e);a.cache.mapElem.set(i.unId,i)}getReqDimension(){const t=a.cache.dimMins.get(this.unId),e=a.cache.tabCnts.get(this.unId),i=Math.max(t.minWidth,e.horizontal*c._minW+Math.max(0,e.horizontal-1)*c._bond),n=Math.max(t.minHeight,e.vertical*c._minH+Math.max(0,e.vertical-1)*c._bond);return{width:i,height:n}}calcDimensions(){const t=a.cache.mapDirs.get(this.unId);if(!this.kids)return;let e=0;const i=a.cache.dimMins.get(this.unId)||{minWidth:0,minHeight:0};let n=0;for(const o of this.kids)e+=o.part;if(e===0)return;let s;t?s=this.dims.w-i.minWidth:s=this.dims.h-i.minHeight;let d=s;for(const o of this.kids){const h=a.cache.dimMins.get(o.unId)||{minWidth:0,minHeight:0};if(this.dims.w<i.minWidth)t?(o.dims.w=h.minWidth,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond);else{const r=o.part/e,u=Math.floor(s*r);if(o===this.kids.peekBack()){t?(o.dims.w=h.minWidth+d,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight+d,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond);break}t?(o.dims.w=h.minWidth+u,o.dims.h=this.dims.h,o.dims.x=this.dims.x+n,o.dims.y=this.dims.y,n+=o.dims.w+c._bond):(o.dims.h=h.minHeight+u,o.dims.w=this.dims.w,o.dims.y=this.dims.y+n,o.dims.x=this.dims.x,n+=o.dims.h+c._bond),d-=u}o.next&&(t?o.next.dims={w:c._bond,h:o.dims.h,x:o.dims.x+o.dims.w,y:o.dims.y}:o.next.dims={w:o.dims.w,h:c._bond,x:o.dims.x,y:o.dims.y+o.dims.h})}}toJSON(){const t=[];for(const i of this.kids)t.push(i.toJSON());const e={typNode:this.type,nodPart:this.part,nodName:this.name,uidNode:this.unId};return this.open&&(e.nodOpen=this.open),t.length>0&&(e.nodKids=t),e}}class c{static _root;static _tree;static _minW=40;static _minH=40;static _bond=10;static _inst=null;nodeOps;cntdown=null;tabsIds=new Map;constructor(t={}){const e={tabs:[],tree:null,minW:40,minH:40,bond:10,uqid:"dynamix-layout-root",tabsIds:new Map,...t};this.tabsIds=e.tabsIds,e.tree&&(c._tree=e.tree),c._root=new a({unId:e.uqid,name:e.uqid,type:"row"}),this.nodeOps=g(new Map,E),c._minW=e.minW,c._minH=e.minH,c._bond=e.bond;const i=new w(e.tabs.length,e.tabs);c._tree?this.createNodeLayout():this.createBinaryNodeTreeFromQueue(i),c._inst=this}*JSONLayoutIterator(t){const e=new w;for(e.enqueue(t);!e.isEmpty();){const i=e.dequeue();if(i&&(yield i,i.nodKids&&i.nodKids.length>0))for(const n of i.nodKids)e.enqueue(n)}}*NodeLayoutIterator(t){const e=new w;for(e.enqueue(t);!e.isEmpty();){const i=e.dequeue();if(i&&(a.cache.mapElem.set(i.unId,i),yield i,i.kids.size()>0))for(const n of i.kids)e.enqueue(n)}}*NodeLayoutRecursiveIterator(t){for(const e of t.kids)yield*this.NodeLayoutRecursiveIterator(e);yield t}updateChildDirections(t){const e=a.cache.mapDirs.get(t.unId);if(e===void 0){console.warn(`Cannot update child directions for node ${t.unId}; its own direction is not set.`);return}for(const i of t.kids)a.cache.mapDirs.set(i.unId,!e),i.kids.size()>0&&(i.host=t,this.updateChildDirections(i),i.next&&a.cache.mapDirs.set(i.next.unId,!e))}createNodeLayout(t=c._tree){const e=this.JSONLayoutIterator(t),i=this.NodeLayoutIterator(c._root);for(a.cache.mapDirs.set(c._root.unId,!0);;){const n=e.next(),s=i.next();if(n.done||s.done)break;const d=n.value,o=s.value;!d||!o||this.createNodeTreeFromJSONTree(d,o)}this.calcTabsetCountAndMinDim()}createNodeTreeFromJSONTree(t,e){const i=a.cache.mapDirs.get(e.unId);for(const n of t.nodKids||[]){const s=this.createNodeFromJSON(n),d=e.kids.peekBack();s.host=e,s.addBond(s.host,d),e.kids.enqueue(s),a.cache.mapDirs.set(s.unId,!i)}e.type==="tabset"&&a.cache.mapElem.set(e.unId,e),e.type==="tab"&&a.cache.mapElem.set(e.unId,e)}createBinaryNodeTreeFromQueue(t,e=c._root){const i=new w;for(i.enqueue(e),a.cache.mapDirs.set(c._root.unId,!0);!t.isEmpty();){const n=i.dequeue();if(!n)break;const s=a.cache.mapDirs.get(n.unId);if(t.size()==2){const u=t.dequeue(),f=t.dequeue(),l=new a({type:"tabset",host:n}),m=new a({type:"tabset",host:n}),p=new a({type:"tab",host:l,name:u,unId:this.tabsIds.get(u??"")??crypto.randomUUID()}),N=new a({type:"tab",host:m,name:f,unId:this.tabsIds.get(f??"")??crypto.randomUUID()});l.open=p.name,m.open=N.name,l.kids.enqueue(p),m.kids.enqueue(N),n.kids.enqueue(l),n.kids.enqueue(m),m.addBond(n,l),a.cache.mapDirs.set(l.unId,!s),a.cache.mapDirs.set(m.unId,!s),a.cache.mapElem.set(l.unId,l),a.cache.mapElem.set(m.unId,m),a.cache.mapDirs.set(p.unId,s),a.cache.mapDirs.set(N.unId,s),a.cache.mapElem.set(p.unId,p),a.cache.mapElem.set(N.unId,N),console.log(this.tabsIds);break}const d=t.dequeue(),o=new a({type:"tabset",host:n}),h=new a({type:"row",host:n}),r=new a({type:"tab",host:o,name:d,unId:this.tabsIds.get(d??"")??crypto.randomUUID()});o.open=r.name,o.kids.enqueue(r),n.kids.enqueue(o),n.kids.enqueue(h),h.addBond(n,o),a.cache.mapDirs.set(o.unId,!s),a.cache.mapDirs.set(h.unId,!s),a.cache.mapElem.set(o.unId,o),a.cache.mapDirs.set(r.unId,s),a.cache.mapElem.set(r.unId,r),i.enqueue(h)}this.calcTabsetCountAndMinDim()}createNodeFromJSON(t){const e=new a({type:t.typNode,name:t.nodName,unId:t.uidNode,part:t.nodPart,dims:{w:0,h:0,x:0,y:0},open:typeof t.nodOpen=="string"?t.nodOpen:""});return t.typNode==="tab"&&(e.unId=this.tabsIds.get(t.nodName)||t.uidNode),e}calcTabsetCountAndMinDim(t=c._root,e=!0){t===c._root&&e&&(a.cache.tabCnts.clear(),a.cache.dimMins.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear());for(const i of this.NodeLayoutRecursiveIterator(t)){const n=a.cache.tabCnts,s=a.cache.dimMins;a.cache.mapElem.set(i.unId,i);const d=n.set(i.unId,{horizontal:0,vertical:0}).get(i.unId),o=s.set(i.unId,{minWidth:0,minHeight:0}).get(i.unId),h=a.cache.mapDirs.get(i.unId);if(i.type==="tab"&&(a.cache.mapElem.set(i.unId,i),s.set(i.unId,{minWidth:0,minHeight:0})),i.next&&a.cache.mapElem.set(i.next.unId,i.next),i.type==="tabset"&&(a.cache.mapElem.set(i.unId,i),s.set(i.unId,{minWidth:c._minW,minHeight:c._minH}),h?n.set(i.unId,{horizontal:0,vertical:1}):n.set(i.unId,{horizontal:1,vertical:0})),i.type==="row"){for(const r of i.kids){const u=n.get(r.unId),f=s.get(r.unId);u&&(d.horizontal+=u.horizontal,d.vertical+=u.vertical,h?(o.minHeight=Math.max(o.minHeight,f.minHeight),o.minWidth+=f.minWidth):(o.minHeight+=f.minHeight,o.minWidth=Math.max(o.minWidth,f.minWidth)))}h?o.minWidth+=(i.kids.size()-1)*c._bond:o.minHeight+=(i.kids.size()-1)*c._bond}}}calculateRootAdjustment(){const t=c._root.getReqDimension();let e=!1,i=c._root.dims.w,n=c._root.dims.h;return c._root.dims.w<t.width&&(i=t.width,e=!0),c._root.dims.h<t.height&&(n=t.height,e=!0),e&&(c._root.dims.w=i,c._root.dims.h=n),{adjustedW:i,adjustedH:n,wasAdjusted:e}}calcDimensions(t=c._root,e=!1){const i=new Map,n=new Map,s=new Map;t===c._root&&this.calculateRootAdjustment();for(const d of this.NodeLayoutIterator(t)){d.calcDimensions();const o=a.cache.mapDirs.get(d.unId);if(d.type==="tabset"){const h={typNode:d.type,nodName:d.name,uidNode:d.unId,nodPart:d.part,nodOpen:d.open,nodeDir:o,nodKids:Array.from(d.kids).map(r=>{const u={typNode:r.type,nodName:r.name,uidNode:r.unId,nodPart:r.part,nodOpen:d.open===r.name,nodeDir:!o,nodDims:{...d.dims}};return s.set(r.unId,u),u}),nodDims:{...d.dims}};i.set(d.unId,h)}if(d.next&&d.type!=="tab"){const h={typNode:"bond",nodName:d.name,uidNode:d.next.unId,nodeDir:o,nodPart:0,nodDims:{...d.next.dims}};n.set(d.next.unId,h)}}a.cache.nodOpts.set(i,e),a.cache.bndOpts.set(n,e),a.cache.tabOpts.set(s,e)}updateDimension(t,e=!1,i=2){if(c._root.dims=t,e){this.calcDimensions(c._root);return}this.cntdown&&(clearTimeout(this.cntdown),this.cntdown=null),this.cntdown=setTimeout(()=>{this.cntdown=null,this.calcDimensions()},i)}updateSlider(t,e,i=!1,n=2){if(i){this.updateSliderDimension(t,e);return}this.cntdown&&(clearTimeout(this.cntdown),this.cntdown=null),this.cntdown=setTimeout(()=>{this.cntdown=null,this.updateSliderDimension(t,e)},n)}updateSliderDimension(t,e){const i=a.cache.mapElem.get(t);if(!i||!(i instanceof O)){console.warn(`Bond with id ${t} not found or is not a Bond instance`);return}const n=a.cache.mapDirs.get(i.host.unId),s=i.prev,d=i.next,o=i.host;if(!s||!d||!o){console.warn("Missing prev, next, or host node",s,d,o);return}const h=a.cache.dimMins.get(s.unId)||{minWidth:0,minHeight:0},r=a.cache.dimMins.get(d.unId)||{minWidth:0,minHeight:0},u=c._bond/2;if(n){const f=d.dims.x+d.dims.w,l=s.dims.x+h.minWidth+u,m=f-r.minWidth-u,p=Math.max(l,Math.min(m,e.x));i.dims.x=p-u,s.dims.w=i.dims.x-s.dims.x,d.dims.x=p+u,d.dims.w=f-d.dims.x;const N=Math.max(0,s.dims.w-h.minWidth),x=Math.max(0,d.dims.w-r.minWidth),k=N+x,b=s.part+d.part;k>0?(s.part=N/k*b,d.part=x/k*b):(s.part=b/2,d.part=b/2)}else{const f=d.dims.y+d.dims.h,l=s.dims.y+h.minHeight+u,m=f-r.minHeight-u,p=Math.max(l,Math.min(m,e.y));i.dims.y=p-u,s.dims.h=i.dims.y-s.dims.y,d.dims.y=p+u,d.dims.h=f-d.dims.y;const N=Math.max(0,s.dims.h-h.minHeight),x=Math.max(0,d.dims.h-r.minHeight),k=N+x,b=s.part+d.part;k>0?(s.part=N/k*b,d.part=x/k*b):(s.part=b/2,d.part=b/2)}this.calcDimensions(o)}updateTree(t,e,i){const n=a.cache.mapElem.get(t);let s=a.cache.mapElem.get(e);return!n||!(n instanceof a)||!s||!(s instanceof a)?(console.warn(`Source node ${t} not found or is not a Node instance`),!1):n?.type=="tab"&&n.host===s&&s.kids.size()<2?(console.warn("Cannot move to self as it has only one tab"),!1):n?.type=="tabset"&&s?.host===n?(console.warn("Cannot move tabset to self as it is already a child"),!1):!n||!s?(console.warn(`Source or destination node not found: ${t}, ${e}`),!1):n===s?(console.warn("Source and destination nodes are the same, no action taken."),!1):!n.host||!s.host&&s.type!=="row"?(console.warn(`Source node or destination node's host is null: ${n.unId}, ${s.unId}`),!1):s.type==="row"&&i==="contain"?(console.warn(`Cannot move to a row with 'contain' layout: ${s.unId}`),!1):n.type==="row"?!1:(s.type==="tabset"&&i==="contain"&&(s=s.kids.peekBack()||s),s.type==="tab"&&(i==="contain"||i==="left"||i==="right")?this.moveNodeAsTab(n,s,i):s.type==="row"&&i!=="contain"?this.moveRelativeToRoot(n,s,i):s.type==="tabset"&&i!=="contain"&&this.moveRelativeToTabset(n,s,i),this.calcTabsetCountAndMinDim(),this.calcDimensions(c._root,!0),!0)}moveNodeAsTab(t,e,i){if(!e||!e.host){console.warn(`Destination node ${e.unId} has no host, cannot move.`);return}this.removeNode(t);const n=e.host,s=n.kids.indexOf(e);if(s===void 0||s===-1)return;const d=i==="contain"||i==="left",o=d?s:s+1,h=n.kids.get(o+1),r=n.kids.get(o-1),u=e.next,f=e.prev;if(!d&&u?(a.cache.mapElem.delete(u.unId),a.cache.nodOpts.get().delete(u.unId)):d&&f&&(a.cache.mapElem.delete(f.unId),a.cache.nodOpts.get().delete(f.unId)),t.type=="tab")d?(r&&t.addBond(n,r),e.addBond(n,t)):(t.addBond(n,e),h&&h.addBond(n,t)),n.kids.insert(o,t),t.host=n,n.open=t.name;else if(t.type=="tabset"){const l=t.kids.peek(),m=t.kids.peekBack();d?(l&&r&&l.addBond(n,r),m&&e&&e.addBond(n,m)):(l&&e&&l.addBond(n,e),m&&h&&h.addBond(n,m)),n.kids.insertQueue(o,t.kids);for(const p of t.kids)p.host=n,p.next&&(p.next.host=n);n.open=m?m.name:""}this.updateChildDirections(n)}moveRelativeToRoot(t,e,i){this.removeNode(t);const n=a.cache.mapDirs.get(e.unId),s=i==="top"||i==="left";if(t.type==="tab"){const d=new a({type:"tabset",host:e.host});d.kids.enqueue(t),t.host=d,d.open=t.name,n==!1?i==="left"||i==="right"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s):i==="top"||i==="bottom"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s)}else t.type==="tabset"&&(n==!1?i==="left"||i==="right"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s):i==="top"||i==="bottom"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s))}moveRelativeToTabset(t,e,i){this.removeNode(t);const n=a.cache.mapDirs.get(e.unId),s=i==="top"||i==="left";if(t.type==="tab"){const d=new a({type:"tabset",host:e.host});d.kids.enqueue(t),t.host=d,d.open=t.name,n==!1?i==="top"||i==="bottom"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s):i==="left"||i==="right"?this.insertNodeWithNewParent(d,e,s):this.insertNode(e,d,s)}else t.type==="tabset"&&(n==!1?i==="top"||i==="bottom"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s):i==="left"||i==="right"?this.insertNodeWithNewParent(t,e,s):this.insertNode(e,t,s))}insertNode(t,e,i){const n=t.host;if(t==c._root){const f=c._root.kids.peek(),l=c._root.kids.peekBack();i?(c._root.kids.enqueueFront(e),f&&f.addBond(c._root,e)):(c._root.kids.enqueue(e),l&&e.addBond(c._root,l)),e.host=c._root,this.updateChildDirections(c._root);return}if(!n){console.warn(`Destination node ${t.unId} has no host, cannot insert.`);return}const s=n.kids.indexOf(t);if(s===-1){console.warn(`Destination node ${t.unId} not found in its host's kids.`);return}const d=a.cache.mapDirs.get(n.unId);d&&a.cache.mapDirs.set(e.unId,!d);const o=n.kids.get(s+1),h=n.kids.get(s-1),r=t.next,u=t.prev;e.host=n,i?(n.kids.insert(s,e),t.addBond(n,e),h&&e.addBond(n,h),u&&(a.cache.mapElem.delete(u.unId),a.cache.nodOpts.get().delete(u.unId))):(n.kids.insert(s+1,e),e.addBond(n,t),o&&o.addBond(n,e),r&&(a.cache.mapElem.delete(r.unId),a.cache.nodOpts.get().delete(r.unId))),this.updateChildDirections(n)}insertNodeWithNewParent(t,e,i){const n=new w,s=new a({type:"tabset",host:e.host});if(!e||!t){console.warn(`Destination node ${e.unId} has no host, cannot insert.`);return}if(e===c._root){const o=new a({type:"row",host:e});if(e.kids.size()==1&&e.kids.peek()?.type==="tabset"){const h=e.kids.dequeue();if(!h){console.warn(`No kid found in destination node ${e.unId}, cannot insert.`);return}i?(o.kids.enqueue(t),o.kids.enqueue(h),e.kids.enqueue(o),h.addBond(o,t)):(o.kids.enqueue(h),o.kids.enqueue(t),t.addBond(o,h),e.kids.enqueue(o)),t.host=o,h.host=o}else if(e.kids.size()==1&&e.kids.peek()?.type==="row"){const h=e.kids.peek(),r=h?.kids.peek(),u=h?.kids.peekBack();i&&h?(h.kids.enqueueFront(t),r&&r.addBond(h,t)):h&&(h.kids.enqueue(t),u&&t.addBond(h,u)),t.host=h}else if(e.kids.size()>1){const h=new a({type:"row",host:e}),r=new a({type:"row",host:h});for(const u of e.kids)r.kids.enqueue(u),u.host=r,u.next&&(u.next.host=r);t.host=h,e.kids.clear(),i?(h.kids.enqueueFront(t),h.kids.enqueue(r),r.addBond(h,t)):(h.kids.enqueue(r),h.kids.enqueue(t),t.addBond(h,r)),e.kids.enqueue(h)}this.updateChildDirections(e);return}t.host=e,s.host=e,s.kids=e.kids,s.open=e.open;const d=a.cache.mapDirs.get(e.unId);for(const o of s.kids)o.host=s,o.next&&(o.next.host=s),a.cache.mapDirs.set(o.unId,d);for(const o of t.kids)o.host=t,o.next&&(o.next.host=t),a.cache.mapDirs.set(o.unId,d);a.cache.mapDirs.set(s.unId,!d),a.cache.mapDirs.set(t.unId,!d),i?(n.enqueue(t),n.enqueue(s),e.kids=n,e.type="row",s.addBond(e,t)):(n.enqueue(s),n.enqueue(t),e.kids=n,e.type="row",t.addBond(e,s))}moveAdjacentNodeToGrandParent(t){if(!t.host||!t.host.host){console.warn(`Source node ${t.unId} has no host, cannot move.`);return}const e=t.host,i=t.host.host,n=i.kids.indexOf(e),s=i.kids.get(n-1),d=i.kids.get(n+1),o=t.kids.peek(),h=t.kids.peekBack();this.removeKid(e);let r=n;if(t.type=="row"&&e){s&&o&&o.addBond(i,s),d&&h&&d.addBond(i,h);for(const u of t.kids)u.host=i,u.next&&(u.next.host=i),i.kids.insert(r,u),a.cache.mapDirs.set(u.unId,!a.cache.mapDirs.get(i.unId)),a.cache.dimMins.delete(u.unId),r++}else if(t.type=="tabset"){s&&t.addBond(i,s),d&&d.addBond(i,t),i.kids.insert(r,t),t.host=i,a.cache.mapDirs.set(t.unId,!a.cache.mapDirs.get(i.unId));for(const u of t.kids)a.cache.mapDirs.set(u.unId,a.cache.mapDirs.get(i.unId)),a.cache.dimMins.delete(u.unId)}}removeRelation(t,e=!0){const i=t.host,n=t.prev,s=t.next;if(t.host=null,t.next=null,t.prev=null,n&&(n.next=null),s&&(s.prev=null),!e)return t;n&&s&&n.prev&&s.next?n.prev.addBond(i,s.next):n&&n.prev?n.prev.next=null:s&&s.next&&(s.next.prev=null)}removeNode(t){if(!t.host){console.warn("Kid node has no host, cannot remove.");return}const e=t?.host,i=e?.host;if(this.removeKid(t),t.type==="tabset"&&e.kids.size()===1){const n=e.kids.peek();n&&this.moveAdjacentNodeToGrandParent(n)}else if(t.type==="tab"&&e.kids.size()===0&&i.kids.size()===2){this.removeKid(e);const n=i?.kids.peek();n&&this.moveAdjacentNodeToGrandParent(n)}else if(t.type==="tab"&&e.kids.size()===0&&i.kids.size()>2)this.removeKid(e);else if(t.type==="tab"&&e.open===t.name&&e.kids.size()>0){const n=e.kids.peek();n&&(e.open=n.name)}}removeKid(t){if(!t.host){console.warn("Kid node has no host, cannot remove.");return}const e=t.host,i=e.kids.indexOf(t),n=e.kids.get(i+1),s=e.kids.get(i-1),d=t.next,o=t.prev;if(i===-1){console.warn("Kid node not found in its host's kids.");return}d&&(a.cache.mapElem.delete(d.unId),a.cache.nodOpts.get().delete(d.unId)),o&&(a.cache.mapElem.delete(o.unId),a.cache.nodOpts.get().delete(o.unId)),n&&s?n.addBond(e,s):n?n.prev=null:s&&(s.next=null),e.kids.removeAt(i),a.cache.mapElem.delete(t.unId),a.cache.dimMins.delete(t.unId),a.cache.mapDirs.delete(t.unId),a.cache.tabCnts.delete(t.unId),t.type==="tabset"&&a.cache.mapElem.delete(t.unId),t.type==="tab"&&a.cache.mapElem.delete(t.unId),t.host=null,t.next=null,t.prev=null}clearAllCache(){a.cache.dimMins.clear(),a.cache.mapDirs.clear(),a.cache.tabCnts.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear()}}class O{dims={w:0,h:0,x:0,y:0};unId=crypto.randomUUID();next=null;prev=null;host=null;constructor(t=null,e=null,i=null){this.host=t,this.next=e,this.prev=i,this.next&&(this.next.prev=this),this.prev&&(this.prev.next=this)}toJSON(){return{nodName:this.host?.name||"",typNode:"bond",uidNode:this.unId,nodPart:0,nodOpen:"",nodKids:[]}}}(()=>{if(typeof window>"u")return;const y="color: #03A9F4; font-weight: bold; line-height: 1.2;",t="color: #E0E0E0; font-size: 12px;",e="color: #42a5f5; font-size: 12px;",i="color: #9E9E9E; font-size: 10px;",n=`
2
+ ██████╗ ██╗ ██╗ ███╗ ██╗ █████╗ ███╗ ███╗ ██████╗ ██╗ ██╗
3
+ ██╔══██╗╚██╗ ██╔╝ ████╗ ██║ ██╔══██╗ ████╗ ████║ ╚═██╔═╝ ╚██╗██╔╝
4
+ ██║ ██║ ╚████╔╝ ██╔██╗ ██║ ███████║ ██╔████╔██║ ██║ ╚███╔╝
5
+ ██║ ██║ ╚██╔╝ ██║╚██╗██║ ██╔══██║ ██║╚██╔╝██║ ██║ ██╔██╗
6
+ ██████╔╝ ██║ ██║ ╚████║ ██║ ██║ ██║ ╚═╝ ██║ ██████╗ ██╔╝ ██╗
7
+ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
8
+ ██╗ █████╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗
9
+ ██║ ██╔══██╗ ╚██╗ ██╔╝ ██╔═══██╗ ██║ ██║╚══██╔══╝
10
+ ██║ ███████║ ╚████╔╝ ██║ ██║ ██║ ██║ ██║
11
+ ██║ ██╔══██║ ╚██╔╝ ██║ ██║ ██║ ██║ ██║
12
+ ███████╗ ██║ ██║ ██║ ╚██████╔╝ ╚█████╔╝ ██║
13
+ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚════╝ ╚═╝
14
+ `;console.groupCollapsed("%cDYNAMIX LAYOUT (click to expand)","color: #03A9F4; font-weight: bold; font-size: 14px;"),console.log(`%c${n}`,y),console.log("%c A powerful, dynamic layout system 🚀",t),console.log(`%c ⚡ For docs and more info,
15
+ ⚡ visit: https://github.com/akash-aman/dynamix-layout`,e),console.log(`%cMIT License
16
+
17
+ Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ of this software and associated documentation files (the "Software"), to deal
21
+ in the Software without restriction, including without limitation the rights
22
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ copies of the Software, and to permit persons to whom the Software is
24
+ furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all
27
+ copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ SOFTWARE.
36
+ `,i),console.groupEnd(),typeof window<"u"&&(window.__DYNAMIX_LAYOUT__={__LICENSE__:`MIT License
37
+
38
+ Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ of this software and associated documentation files (the "Software"), to deal
42
+ in the Software without restriction, including without limitation the rights
43
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ copies of the Software, and to permit persons to whom the Software is
45
+ furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all
48
+ copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56
+ SOFTWARE.
57
+ `,__LAYOUT__:c})})(),I.Bond=O,I.DynamixLayoutCore=c,I.Node=a,I.Queue=w,I.areNodeOptionsEqual=T,I.areNodeOptionsMapEqual=E,I.createReactiveState=g,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,3 @@
1
+ import { NodeOptions } from '../type';
2
+ export declare function areNodeOptionsMapEqual(mapA: Map<string, NodeOptions>, mapB: Map<string, NodeOptions>): boolean;
3
+ export declare function areNodeOptionsEqual(a: NodeOptions, b: NodeOptions): boolean;
@@ -0,0 +1,97 @@
1
+ import { Queue } from './queue';
2
+ import { Dimension, LayoutTree, NodeCache, NodeOptions, RootAdjustment, ReactiveValue, TabsIds } from '../type';
3
+ export declare class Node {
4
+ static cache: NodeCache;
5
+ kids: Queue<Node>;
6
+ dims: Dimension;
7
+ unId: string;
8
+ next: Bond | null;
9
+ prev: Bond | null;
10
+ type: 'row' | 'tabset' | 'tab' | 'bond';
11
+ name: string;
12
+ part: number;
13
+ host: Node | null;
14
+ open: string;
15
+ constructor(options?: {
16
+ type?: 'row' | 'tabset' | 'tab' | 'bond';
17
+ host?: Node | null;
18
+ name?: string;
19
+ part?: number;
20
+ dims?: Dimension;
21
+ unId?: string;
22
+ open?: string;
23
+ });
24
+ addBond(parent: Node | null, prev?: Node | null): void;
25
+ getReqDimension(): {
26
+ width: number;
27
+ height: number;
28
+ };
29
+ calcDimensions(): void;
30
+ toJSON(): LayoutTree;
31
+ }
32
+ declare class Layout {
33
+ static _root: Node;
34
+ static _tree: LayoutTree;
35
+ static _minW: number;
36
+ static _minH: number;
37
+ static _bond: number;
38
+ static _inst: Layout | null;
39
+ nodeOps: ReactiveValue<Map<string, NodeOptions>>;
40
+ cntdown: ReturnType<typeof setTimeout> | null;
41
+ tabsIds: TabsIds;
42
+ constructor(options?: {
43
+ tabs?: string[];
44
+ tree?: LayoutTree | null;
45
+ minW?: number;
46
+ minH?: number;
47
+ bond?: number;
48
+ uqid?: string;
49
+ tabsIds?: TabsIds;
50
+ });
51
+ JSONLayoutIterator(root: LayoutTree): IterableIterator<LayoutTree>;
52
+ NodeLayoutIterator(root: Node): IterableIterator<Node>;
53
+ NodeLayoutRecursiveIterator(root: Node): IterableIterator<Node>;
54
+ updateChildDirections(parent: Node): void;
55
+ createNodeLayout(root?: LayoutTree): void;
56
+ createNodeTreeFromJSONTree(json: LayoutTree, host: Node): void;
57
+ /**
58
+ * Create binary tree
59
+ * @param queue
60
+ * @param host
61
+ */
62
+ createBinaryNodeTreeFromQueue(queue: Queue<string>, host?: Node): void;
63
+ createNodeFromJSON(json: LayoutTree): Node;
64
+ calcTabsetCountAndMinDim(root?: Node, clear?: boolean): void;
65
+ calculateRootAdjustment(): RootAdjustment;
66
+ calcDimensions(root?: Node, supress?: boolean): void;
67
+ updateDimension(dim: Dimension, disableTimeout?: boolean, timeout?: number): void;
68
+ updateSlider(id: string, dim: {
69
+ x: number;
70
+ y: number;
71
+ }, disableTimeout?: boolean, timeout?: number): void;
72
+ updateSliderDimension(id: string, dim: {
73
+ x: number;
74
+ y: number;
75
+ }): void;
76
+ updateTree(src: string, des: string, layout: 'top' | 'bottom' | 'left' | 'right' | 'contain'): boolean;
77
+ moveNodeAsTab(src: Node, des: Node, layout: 'left' | 'right' | 'contain'): void;
78
+ moveRelativeToRoot(src: Node, des: Node, layout: 'top' | 'bottom' | 'left' | 'right'): void;
79
+ moveRelativeToTabset(src: Node, des: Node, layout: 'top' | 'bottom' | 'left' | 'right'): void;
80
+ insertNode(des: Node, src: Node, flag: boolean): void;
81
+ insertNodeWithNewParent(src: Node, des: Node, flag: boolean): void;
82
+ moveAdjacentNodeToGrandParent(src: Node): void;
83
+ removeRelation(src: Node, fix?: boolean): Node | undefined;
84
+ removeNode(src: Node): void;
85
+ removeKid(kid: Node): void;
86
+ clearAllCache(): void;
87
+ }
88
+ export declare class Bond {
89
+ dims: Dimension;
90
+ unId: string;
91
+ next: Node | null;
92
+ prev: Node | null;
93
+ host: Node | null;
94
+ constructor(parent?: Node | null, next?: Node | null, prev?: Node | null);
95
+ toJSON(): LayoutTree;
96
+ }
97
+ export { Layout as DynamixLayoutCore };
@@ -1,64 +1,4 @@
1
- import { ILayout, LayoutTree, AreaValue } from "../types";
2
- import { Node, Bond } from "../lib";
3
- export type LayoutOptions = {
4
- layout?: LayoutTree;
5
- range?: number;
6
- dimension?: [number, number];
7
- tabs?: string[];
8
- };
9
- export type Settings = {
10
- layout: LayoutTree;
11
- range: number;
12
- dimension: [number, number];
13
- coordinate: [number, number];
14
- tabs: string[];
15
- };
16
- export default class Layout implements ILayout<Node, Bond> {
17
- _root: Node;
18
- _tabs: Node[];
19
- _bond: Bond[];
20
- _settings: Settings;
21
- constructor(options?: LayoutOptions);
22
- shiftTree: (srcId: string, desId: string, area: AreaValue) => void;
23
- private createTree;
24
- updateTree: (width?: number, height?: number, hook?: Function) => {
25
- tabs: {
26
- type: any;
27
- dimension: any;
28
- coordinate: any;
29
- name: any;
30
- children: any;
31
- }[];
32
- bonds: {
33
- type: any;
34
- dimension: any;
35
- coordinate: any;
36
- name: any;
37
- children: any;
38
- }[];
39
- };
40
- calculate(node: Node, level?: number): void;
41
- getElements: () => {
42
- tabs: {
43
- type: any;
44
- dimension: any;
45
- coordinate: any;
46
- name: any;
47
- children: any;
48
- }[];
49
- bonds: {
50
- type: any;
51
- dimension: any;
52
- coordinate: any;
53
- name: any;
54
- children: any;
55
- }[];
56
- };
57
- jsonify: () => {
58
- type: any;
59
- dimension: any;
60
- coordinate: any;
61
- name: any;
62
- children: any;
63
- };
64
- }
1
+ export * from './dynamix';
2
+ export * from './comparator';
3
+ export * from './queue';
4
+ export * from './reactive-state';