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

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +155 -61
  3. package/{LICENSE → dist/LICENSE} +1 -1
  4. package/dist/core.cjs.js +57 -0
  5. package/dist/core.cjs.js.br +0 -0
  6. package/dist/core.cjs.js.gz +0 -0
  7. package/dist/core.cjs.js.map +1 -0
  8. package/dist/core.es.js +1025 -0
  9. package/dist/core.es.js.br +0 -0
  10. package/dist/core.es.js.gz +0 -0
  11. package/dist/core.es.js.map +1 -0
  12. package/dist/core.iife.js +57 -1
  13. package/dist/core.iife.js.br +0 -0
  14. package/dist/core.iife.js.gz +0 -0
  15. package/dist/core.iife.js.map +1 -0
  16. package/dist/core.umd.js +57 -1
  17. package/dist/core.umd.js.br +0 -0
  18. package/dist/core.umd.js.gz +0 -0
  19. package/dist/core.umd.js.map +1 -0
  20. package/dist/types/app/comparator.d.ts +3 -0
  21. package/dist/types/app/dynamix.d.ts +97 -0
  22. package/dist/types/app/index.d.ts +4 -64
  23. package/dist/types/app/queue.d.ts +217 -0
  24. package/dist/types/app/reactive-state.d.ts +3 -0
  25. package/dist/types/index.d.ts +2 -2
  26. package/dist/types/type/index.d.ts +54 -0
  27. package/package.json +58 -29
  28. package/dist/core.js +0 -1
  29. package/dist/core.mjs +0 -244
  30. package/dist/types/lib/Constant.d.ts +0 -14
  31. package/dist/types/lib/Element.d.ts +0 -22
  32. package/dist/types/lib/Helper.d.ts +0 -21
  33. package/dist/types/lib/Method.d.ts +0 -1
  34. package/dist/types/lib/index.d.ts +0 -4
  35. package/dist/types/types/Element.d.ts +0 -103
  36. package/dist/types/types/Method.d.ts +0 -5
  37. package/dist/types/types/index.d.ts +0 -2
  38. package/src/app/index.ts +0 -291
  39. package/src/index.ts +0 -3
  40. package/src/lib/Constant.ts +0 -17
  41. package/src/lib/Element.ts +0 -66
  42. package/src/lib/Helper.ts +0 -259
  43. package/src/lib/Method.ts +0 -12
  44. package/src/lib/index.ts +0 -4
  45. package/src/types/Element.ts +0 -116
  46. package/src/types/Method.ts +0 -4
  47. package/src/types/index.ts +0 -2
@@ -0,0 +1,54 @@
1
+ import { Node, Bond } from '../app/dynamix';
2
+ export type Dimension = {
3
+ w: number;
4
+ h: number;
5
+ x: number;
6
+ y: number;
7
+ };
8
+ export interface NodeCache {
9
+ dimMins: Map<string, {
10
+ minWidth: number;
11
+ minHeight: number;
12
+ }>;
13
+ mapDirs: Map<string, boolean>;
14
+ tabCnts: Map<string, {
15
+ horizontal: number;
16
+ vertical: number;
17
+ }>;
18
+ mapElem: Map<string, Node | Bond>;
19
+ nodOpts: ReactiveValue<Map<string, NodeOptions>>;
20
+ bndOpts: ReactiveValue<Map<string, NodeOptions>>;
21
+ tabOpts: ReactiveValue<Map<string, NodeOptions>>;
22
+ }
23
+ export type NodeType = 'row' | 'tabset' | 'tab';
24
+ export type NodeTypeWithBond = NodeType | 'bond';
25
+ export type TabsIds = Map<string, string>;
26
+ export interface BaseNode {
27
+ typNode: NodeTypeWithBond;
28
+ nodName: string;
29
+ uidNode: string;
30
+ nodPart: number;
31
+ nodeDir: boolean;
32
+ nodDims: Dimension;
33
+ nodOpen?: string | boolean;
34
+ }
35
+ export type LayoutTree = Omit<BaseNode, 'nodeDir' | 'nodDims'> & {
36
+ nodKids?: LayoutTree[];
37
+ };
38
+ export interface NodeOptions extends BaseNode {
39
+ nodKids?: BaseNode[];
40
+ }
41
+ export interface RootAdjustment {
42
+ adjustedW: number;
43
+ adjustedH: number;
44
+ wasAdjusted: boolean;
45
+ }
46
+ export type ChangeListener<T> = (newValue: T) => void;
47
+ export interface ReactiveValue<T> {
48
+ get: () => T;
49
+ set: (newValue: T, flag?: boolean) => void;
50
+ onChange: (listener: ChangeListener<T>) => () => void;
51
+ nextChange: () => Promise<T>;
52
+ onChangePromise: (listener: ChangeListener<T>) => () => void;
53
+ triggerChange: () => void;
54
+ }
package/package.json CHANGED
@@ -1,45 +1,74 @@
1
1
  {
2
2
  "name": "@dynamix-layout/core",
3
- "version": "0.0.2-beta.0",
3
+ "version": "0.0.5",
4
4
  "description": "Dynamix Layout/Core is a JavaScript package for creating dynamic layouts with ease.",
5
- "main": "dist/core.js",
6
- "module": "dist/core.mjs",
7
- "browser": "dist/core.iife.js",
8
- "types": "dist/types/index.d.ts",
9
- "typings": "dist/types/index.d.ts",
10
- "funding": {
11
- "type": "patreon",
12
- "url": "https://www.patreon.com/Akash960"
5
+ "keywords": [
6
+ "dynamix-layout",
7
+ "ui",
8
+ "ux"
9
+ ],
10
+ "author": "Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)",
11
+ "license": "MIT",
12
+ "funding": [
13
+ {
14
+ "type": "patreon",
15
+ "url": "https://www.patreon.com/akashaman"
16
+ },
17
+ {
18
+ "type": "buymeacoffee",
19
+ "url": "https://www.buymeacoffee.com/akashaman"
20
+ }
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/akash-aman/dynamix-layout.git",
25
+ "directory": "packages/core"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/akash-aman/dynamix-layout/issues"
29
+ },
30
+ "homepage": "https://github.com/akash-aman/dynamix-layout#readme",
31
+ "main": "./dist/core.cjs.js",
32
+ "module": "./dist/core.es.js",
33
+ "browser": "./dist/core.iife.js",
34
+ "types": "./dist/types/index.d.ts",
35
+ "typings": "./dist/types/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/types/index.d.ts",
39
+ "import": "./dist/core.es.js",
40
+ "require": "./dist/core.cjs.js"
41
+ }
13
42
  },
14
43
  "files": [
15
- "src",
16
44
  "dist",
17
45
  "LICENSE",
18
46
  "CHANGELOG.md",
19
47
  "README.md"
20
48
  ],
21
- "repository": {
22
- "type": "git",
23
- "url": "https://github.com/akash-aman/dynamix-layout.git"
49
+ "sideEffects": false,
50
+ "publishConfig": {
51
+ "access": "public"
24
52
  },
25
- "keywords": [
26
- "dynamix-layout",
27
- "ui",
28
- "ux"
29
- ],
30
- "author": "Akash Aman",
31
- "license": "MIT",
32
- "devDependencies": {
33
- "@changesets/cli": "^2.26.2",
34
- "typescript": "^5.2.2",
35
- "vite": "^4.4.9"
53
+ "type": "module",
54
+ "engines": {
55
+ "node": ">=22.16.0",
56
+ "pnpm": ">=10.13.1"
36
57
  },
37
- "dependencies": {
38
- "@rollup/plugin-typescript": "^11.1.3",
39
- "tslib": "^2.6.2"
58
+ "devDependencies": {
59
+ "@changesets/cli": "^2.29.5",
60
+ "typescript": "^5.8.3",
61
+ "vite": "^7.0.4",
62
+ "@repo/eslint-config": "0.0.0"
40
63
  },
41
64
  "scripts": {
42
- "build": "vite build",
43
- "dev": "vite"
65
+ "dev": "vite build --watch",
66
+ "debug": "vite --debug",
67
+ "clean": "rm -rf dist",
68
+ "build": "pnpm run clean && vite build && cp ../../LICENSE dist/LICENSE",
69
+ "dev:local": "vite",
70
+ "preview": "vite preview",
71
+ "test": "vitest",
72
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
44
73
  }
45
74
  }
package/dist/core.js DELETED
@@ -1 +0,0 @@
1
- "use strict";const g={Row:0,Column:1,Tabset:2,Tab:3};class b{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 w{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 $={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 w(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($[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 b(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 b(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 m=0;m<u;m++){const d=n.shift(),T=((c=d.parent)==null?void 0:c.children.indexOf(d))??0;if(d.name=`r${o.length}/c${m}/tb${T}`,d&&(i.push(d),h<s&&(d.children[0]=new b(a,50,d),n.push(d.children[0])),h<s)){d.children[1]=new b(a,50,d),n.push(d.children[1]),h++;const y=new w(a,d.children[0],d.children[1]);y.name=`r${o.length}/c${m}/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 w(e,s.children[t-1],s.children[t]),new w(e,s.children[t],s.children[t+1])),t===n-1&&(new w(e,s.children[t-1],s.children[t]),s.children[t].next=null),t===0&&(new w(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 b(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 j{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 b(i.type,i.weight,c??null)),c==null||c.children.push(o[o.length-1]),u!=0&&new w(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),m=l.getTotalWeight(i);let d=0,T=0,y=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,E)=>{if(a.push(p),p.dimension=[...x],p.coordinate=[..._],p.weight=p.weight/m*100,E===i.children.length-1)p.dimension[i.type]=u-T,p.weight=100-d;else{p.weight=p.weight/m*100;const B=u*(p.weight/100);p.dimension[i.type]=B,d+=p.weight,T+=p.dimension[i.type]}p.dimension[i.type]=p.dimension[i.type],p.prev&&(p.coordinate[i.type]=y.coordinate[i.type]+y.dimension[i.type]+8,p.prev.dimension=[...x],p.prev.coordinate=[..._],p.prev.dimension[i.type]=8,p.prev.coordinate[i.type]=y.coordinate[i.type]+y.dimension[i.type],p.prev.type=1-i.type,y=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 b(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)})}}module.exports=j;
package/dist/core.mjs DELETED
@@ -1,244 +0,0 @@
1
- const g = {
2
- Row: 0,
3
- Column: 1,
4
- Tabset: 2,
5
- Tab: 3
6
- };
7
- class b {
8
- constructor(e, s, t) {
9
- 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;
10
- }
11
- }
12
- class w {
13
- constructor(e, s, t) {
14
- 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;
15
- }
16
- }
17
- const $ = {
18
- top: g.Row,
19
- left: g.Column,
20
- right: g.Column,
21
- bottom: g.Row,
22
- cover: g.Tab
23
- }, v = {
24
- top: 0,
25
- left: 0,
26
- right: 1,
27
- bottom: 1,
28
- cover: 0
29
- };
30
- class l {
31
- static detach(e, s) {
32
- var h;
33
- const t = e.parent;
34
- if (!t)
35
- return;
36
- 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];
37
- if (!s)
38
- return l.fixSrc(e);
39
- if (n > 0 && n < o - 1) {
40
- const r = (e.weight + a) / 2, c = t.children[n + 1], i = t.children[n - 1];
41
- c.weight += r, i.weight += r, new w(e.type, i, c);
42
- }
43
- if (n === o - 1) {
44
- const r = t.children[n - 1];
45
- r.weight += e.weight + a, r.next = null;
46
- }
47
- if (n === 0) {
48
- const r = t.children[n + 1];
49
- r.weight += e.weight + a, r.prev = null;
50
- }
51
- t.children.splice(n, 1);
52
- }
53
- static attach(e, s, t) {
54
- const n = e.parent;
55
- if (!n)
56
- return;
57
- const o = n.children.indexOf(e);
58
- switch ($[t]) {
59
- case 1 - n.type:
60
- const a = o + v[t], h = 8 * 100 / n.dimension[n.type];
61
- s.weight = e.weight = (e.weight - h) / 2, s.parent = n, n.children.splice(a, 0, s), l.fixBond(s, n.type);
62
- break;
63
- case n.type:
64
- const r = e.weight / 2, c = v[t] == 0 ? [s, e] : [e, s], i = new b(1 - n.type, e.weight, n);
65
- i.children = c, n.children[o] = i, c.forEach((u) => {
66
- u.weight = r, u.parent = i;
67
- }), this.fixBond(i, n.type), this.fixBond(s, n.type), this.fixBond(e, n.type);
68
- break;
69
- case g.Tab:
70
- e.children.push(...s.children), s.children.forEach((u) => {
71
- u.parent = e;
72
- });
73
- break;
74
- }
75
- }
76
- static getTotalWeight(e) {
77
- return e.children.reduce((s, t) => s + t.weight, 0) ?? 100;
78
- }
79
- static getTotalNodes(e) {
80
- return e.children.length;
81
- }
82
- static getSize(e) {
83
- return e.dimension[e.type] - (this.getTotalNodes(e) - 1) * 8;
84
- }
85
- }
86
- l.createBinaryTree = (f, e) => {
87
- var c;
88
- const { range: s } = e, t = [...e.tabs];
89
- if (s == 1) {
90
- const i = new b(g.Column, 100, f);
91
- f.children = [i], l.addTab(i, t);
92
- return;
93
- }
94
- const n = [f], o = [];
95
- let a = 1, h = 1;
96
- for (; h < s || n.length; ) {
97
- const i = [], u = n.length;
98
- for (let m = 0; m < u; m++) {
99
- const d = n.shift(), T = ((c = d.parent) == null ? void 0 : c.children.indexOf(d)) ?? 0;
100
- if (d.name = `r${o.length}/c${m}/tb${T}`, d && (i.push(d), h < s && (d.children[0] = new b(a, 50, d), n.push(d.children[0])), h < s)) {
101
- d.children[1] = new b(a, 50, d), n.push(d.children[1]), h++;
102
- const y = new w(a, d.children[0], d.children[1]);
103
- y.name = `r${o.length}/c${m}/b${T}-${T + 1}`;
104
- }
105
- }
106
- o.push(i), a = 1 - a;
107
- }
108
- [
109
- ...o[o.length - 1],
110
- ...o[o.length - 2]
111
- ].forEach((i) => {
112
- l.addTab(i, t);
113
- });
114
- };
115
- l.fixSrc = (f) => {
116
- const e = f.parent;
117
- if (!e)
118
- return;
119
- const s = e.children.indexOf(f), t = e.children[1 - s], n = e.parent, o = n == null ? void 0 : n.children.indexOf(e);
120
- switch (t.type) {
121
- case g.Tabset:
122
- const a = e.weight;
123
- 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);
124
- break;
125
- default:
126
- if (!n) {
127
- e.children.splice(s, 1);
128
- break;
129
- }
130
- const h = t.children.length, r = 8 * (h - 1) * 100 / n.dimension[t.type];
131
- t.children.forEach((u) => {
132
- u.weight = (e.weight - r) * u.weight / 100;
133
- });
134
- const c = t.children[0], i = t.children[h - 1];
135
- n.children = [
136
- ...n.children.slice(0, o),
137
- ...t.children,
138
- ...n.children.slice(o + 1)
139
- ], t.children.forEach((u) => {
140
- u.parent = n;
141
- }), l.fixBond(c, t.type), l.fixBond(i, t.type);
142
- break;
143
- }
144
- };
145
- l.fixBond = (f, e) => {
146
- const s = f.parent;
147
- if (!s)
148
- return;
149
- const t = s.children.indexOf(f), n = s.children.length;
150
- t > 0 && t < n - 1 && (new w(e, s.children[t - 1], s.children[t]), new w(e, s.children[t], s.children[t + 1])), t === n - 1 && (new w(e, s.children[t - 1], s.children[t]), s.children[t].next = null), t === 0 && (new w(e, s.children[t], s.children[t + 1]), s.children[t].prev = null);
151
- };
152
- l.addTab = (f, e) => {
153
- if (f.children.length !== 0)
154
- return;
155
- f.type = g.Tabset;
156
- const s = new b(g.Tab, 100, f), t = e.shift();
157
- s.name = t, f.children = [s];
158
- };
159
- l.json = (f) => {
160
- var e;
161
- return {
162
- type: f.type,
163
- dimension: f.dimension,
164
- coordinate: f.coordinate,
165
- name: f.name,
166
- children: (e = f.children) == null ? void 0 : e.map((s) => l.json(s))
167
- };
168
- };
169
- class j {
170
- constructor(e = {}) {
171
- this.shiftTree = (t, n, o) => {
172
- let a, h;
173
- if (this._tabs.forEach((c) => {
174
- c.name == n && (a = c), c.name == t && (h = c), c.children.forEach((i) => {
175
- i.name == n && (a = i), i.name == t && (h = i);
176
- });
177
- }), h == null || a == null || h.parent === null)
178
- return;
179
- const r = h.parent.children.length;
180
- 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);
181
- }, this.createTree = () => {
182
- const { layout: t } = this._settings;
183
- if (!t)
184
- return l.createBinaryTree(this._root, this._settings), console.log("create tree", JSON.stringify(this.jsonify())), this.updateTree();
185
- const n = [t], o = [this._root];
186
- for (; n.length; ) {
187
- const a = n.length;
188
- for (let h = 0; h < a; h++) {
189
- const r = n.shift(), c = o.shift();
190
- r && r.children.forEach((i, u) => {
191
- n.push(i), o.push(new b(i.type, i.weight, c ?? null)), c == null || c.children.push(o[o.length - 1]), u != 0 && new w(i.type, o[o.length - 2], o[o.length - 1]);
192
- });
193
- }
194
- }
195
- return this.updateTree(), this;
196
- }, this.updateTree = (t, n, o) => {
197
- t && n && (this._root.dimension = [t, n]);
198
- const a = [this._root];
199
- for (this._bond = [], this._tabs = []; a.length; ) {
200
- const h = [], r = a.length;
201
- for (let c = 0; c < r; c++) {
202
- const i = a.shift(), u = l.getSize(i), m = l.getTotalWeight(i);
203
- let d = 0, T = 0, y = i.children[0];
204
- const x = i.dimension, _ = i.coordinate;
205
- i && (h.push(i.coordinate), i.type == g.Tabset && this._tabs.push(i), i.children.forEach((p, E) => {
206
- if (a.push(p), p.dimension = [...x], p.coordinate = [..._], p.weight = p.weight / m * 100, E === i.children.length - 1)
207
- p.dimension[i.type] = u - T, p.weight = 100 - d;
208
- else {
209
- p.weight = p.weight / m * 100;
210
- const B = u * (p.weight / 100);
211
- p.dimension[i.type] = B, d += p.weight, T += p.dimension[i.type];
212
- }
213
- p.dimension[i.type] = p.dimension[i.type], p.prev && (p.coordinate[i.type] = y.coordinate[i.type] + y.dimension[i.type] + 8, p.prev.dimension = [...x], p.prev.coordinate = [..._], p.prev.dimension[i.type] = 8, p.prev.coordinate[i.type] = y.coordinate[i.type] + y.dimension[i.type], p.prev.type = 1 - i.type, y = p, this._bond.push(p.prev));
214
- }));
215
- }
216
- }
217
- return o && o(), this.getElements();
218
- }, this.getElements = () => ({
219
- tabs: this._tabs.map((t) => l.json(t)),
220
- bonds: this._bond.map((t) => l.json(t))
221
- }), this.jsonify = () => l.json(this._root);
222
- let s = Object.assign({
223
- layout: null,
224
- range: 1,
225
- dimension: [0, 0],
226
- coordinate: [0, 0],
227
- tabs: Array.from({ length: e.range ?? 1 }, (t, n) => `tab-${n + 1}`)
228
- }, e);
229
- this._tabs = [], this._bond = [], this._settings = s, this._root = new b(g.Row, 100, null), this._root.coordinate = this._settings.coordinate, this._root.dimension = this._settings.dimension, this.createTree();
230
- }
231
- calculate(e, s = 0) {
232
- s == 0 && (this._bond = [], this._tabs = []);
233
- const t = l.getSize(e), n = l.getTotalWeight(e);
234
- let o = e.children[0], a = 0, h = 0;
235
- e.type == g.Tabset && this._tabs.push(e), e.children.forEach((r, c) => {
236
- 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);
237
- }), e.type == g.Tabset && this._tabs.push(e), e.children.forEach((r) => {
238
- r.children.length && this.calculate(r, s + 1);
239
- });
240
- }
241
- }
242
- export {
243
- j as default
244
- };
@@ -1,14 +0,0 @@
1
- export declare const AreaType: {
2
- top: number;
3
- left: number;
4
- right: number;
5
- bottom: number;
6
- cover: number;
7
- };
8
- export declare const AreaIndex: {
9
- top: number;
10
- left: number;
11
- right: number;
12
- bottom: number;
13
- cover: number;
14
- };
@@ -1,22 +0,0 @@
1
- import { INode, IBond, TypeValue } from '../types';
2
- export declare class Node implements INode<Node, Bond> {
3
- type: TypeValue;
4
- name: string | null;
5
- weight: number;
6
- parent: Node | null;
7
- children: Node[];
8
- dimension: [number, number];
9
- coordinate: [number, number];
10
- prev: Bond | null;
11
- next: Bond | null;
12
- constructor(type: TypeValue, weight: number, parent: Node | null);
13
- }
14
- export declare class Bond implements IBond<Node> {
15
- type: TypeValue;
16
- name: string | null;
17
- prev: Node;
18
- next: Node;
19
- dimension: [number, number];
20
- coordinate: [number, number];
21
- constructor(type: TypeValue, prev: Node, next: Node);
22
- }
@@ -1,21 +0,0 @@
1
- import { IMethods, AreaValue, TypeValue } from "../types";
2
- import { Node } from "./Element";
3
- import { Settings } from "../app";
4
- export declare class Helper implements IMethods {
5
- static createBinaryTree: (root: Node, settings: Settings) => void;
6
- static fixSrc: (src: Node) => void;
7
- static detach(src: Node, flag: Boolean): void;
8
- static attach(des: Node, src: Node, area: AreaValue): void;
9
- static fixBond: (node: Node, type: TypeValue) => void;
10
- static getTotalWeight(node: Node): number;
11
- static getTotalNodes(node: Node): number;
12
- static getSize(node: Node): number;
13
- static addTab: (child: Node, names: string[]) => void;
14
- static json: (node: any) => {
15
- type: any;
16
- dimension: any;
17
- coordinate: any;
18
- name: any;
19
- children: any;
20
- };
21
- }
@@ -1 +0,0 @@
1
- export declare function emitEvent(type: string, detail?: {}, elem?: Document): boolean | undefined;
@@ -1,4 +0,0 @@
1
- export * from './Element';
2
- export * from './Helper';
3
- export * from './Constant';
4
- export * from './Method';
@@ -1,103 +0,0 @@
1
- /**
2
- * @file Element.ts
3
- * @description Interface to create concrete class.
4
- */
5
- /**
6
- * @interface INode
7
- * @description Interface for Node.
8
- * @property {Type} type : Type of Node (Row, Column, Tabset, Tab).
9
- * @property {number} weight : Weight of Node.
10
- * @property {[number,number]} dimension : Dimension of Node.
11
- * @property {[number,number]} coordinate : Coordinate of Node.
12
- * @property {Node | null} parent : Parent Node ( Node | null ).
13
- * @property {Node[]} children : Children Node ( Node[] ).
14
- * @property {Bond | null} prev : Previous Bond ( Bond | null ).
15
- * @property {Bond | null} next : Next Bond ( Bond | null ).
16
- *
17
- */
18
- export interface INode<T, K> {
19
- type: TypeValue;
20
- weight: number;
21
- dimension: [number, number];
22
- coordinate: [number, number];
23
- parent: T | null;
24
- children: T[];
25
- prev: K | null;
26
- next: K | null;
27
- }
28
- /**
29
- * @interface IBond
30
- * @description Interface for Bond.
31
- * @property {Type} type : Type of Bond (Row, Column, Tabset, Tab).
32
- * @property {Node} prev : Previous Node ( Node | null ).
33
- * @property {Node} next : Next Node ( Node | null ).
34
- * @property {[number,number]} dimension : Dimension of Bond.
35
- * @property {[number,number]} coordinate : Coordinate of Bond.
36
- *
37
- */
38
- export interface IBond<T> {
39
- type: TypeValue;
40
- prev: T;
41
- next: T;
42
- dimension: [number, number];
43
- coordinate: [number, number];
44
- }
45
- /**
46
- * @interface ILayout
47
- * @description Interface for Layout.
48
- * @property {Node} root : Root Node.
49
- * @property {Node[]} tabs : Tabs Node.
50
- * @property {Bond[]} bond : Bond between two components.
51
- *
52
- */
53
- export interface ILayout<T, K> {
54
- _root: T;
55
- _tabs: T[];
56
- _bond: K[];
57
- }
58
- /**
59
- * @enum Type
60
- * @description Enum for Type.
61
- * @property {Row} Row : Row Type.
62
- * @property {Column} Column : Column Type.
63
- * @property {Tabset} Tabset : Tabset Type.
64
- * @property {Tab} Tab : Tab Type.
65
- */
66
- export declare const Type: {
67
- Row: number;
68
- Column: number;
69
- Tabset: number;
70
- Tab: number;
71
- };
72
- /**
73
- * @enum TypeValue : Value of Type.
74
- */
75
- export type TypeValue = number;
76
- /**
77
- * @enum Area
78
- * @description Enum for Area.
79
- * @property {Left} Left : Left Area.
80
- * @property {Right} Right : Right Area.
81
- * @property {Top} Top : Top Area.
82
- * @property {Bottom} Bottom : Bottom Area.
83
- * @property {Cover} Cover : Cover Area.
84
- */
85
- export declare const Area: {
86
- Left: "left";
87
- Right: "right";
88
- Top: "top";
89
- Bottom: "bottom";
90
- Cover: "cover";
91
- };
92
- export type Left = "left";
93
- export type Right = "right";
94
- export type Top = "top";
95
- export type Bottom = "bottom";
96
- export type Cover = "cover";
97
- export type AreaValue = typeof Area[keyof typeof Area];
98
- export type LayoutTree = {
99
- type: TypeValue;
100
- weight: number;
101
- children: LayoutTree[];
102
- name: string;
103
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * Methods
3
- */
4
- export interface IMethods {
5
- }
@@ -1,2 +0,0 @@
1
- export * from './Element';
2
- export * from './Method';