regular-layout 0.6.0 → 0.6.1
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/types.d.ts +14 -0
- package/dist/index.js +8 -8
- package/dist/index.js.map +3 -3
- package/dist/model/presize_queue.d.ts +12 -3
- package/dist/regular-layout.d.ts +14 -2
- package/package.json +1 -1
- package/src/core/types.ts +12 -0
- package/src/model/overlay_controller.ts +42 -29
- package/src/model/presize_queue.ts +33 -8
- package/src/regular-layout-frame.ts +1 -1
- package/src/regular-layout.ts +45 -11
package/dist/core/types.d.ts
CHANGED
|
@@ -80,6 +80,20 @@ export interface LayoutPath {
|
|
|
80
80
|
*/
|
|
81
81
|
export interface PresizeDetail {
|
|
82
82
|
calculatePresizePaths(): Record<string, LayoutPath>;
|
|
83
|
+
/**
|
|
84
|
+
* When the transition is a drag preview, the dragged panel's name and the
|
|
85
|
+
* {@link LayoutPath} of its preview box. The dragged panel is removed from
|
|
86
|
+
* the layout tree during a drag (so it is absent from
|
|
87
|
+
* {@link PresizeDetail.calculatePresizePaths}), but `path.view_window` here
|
|
88
|
+
* is exactly where the overlay renders it, letting consumers presize the
|
|
89
|
+
* dragged panel like any other. `null` when the pointer is outside every
|
|
90
|
+
* drop target (the dragged panel is hidden), `undefined` for non-drag
|
|
91
|
+
* transitions.
|
|
92
|
+
*/
|
|
93
|
+
overlay?: {
|
|
94
|
+
slot: string;
|
|
95
|
+
path: LayoutPath;
|
|
96
|
+
} | null;
|
|
83
97
|
}
|
|
84
98
|
/**
|
|
85
99
|
* An empty `Layout` with no panels.
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}let n=c=>c.slice(0,-1).map((d,p)=>c[p+1]-d).map(d=>`${e.SHOULD_ROUND?Math.round(d*100):d*100}fr`).join(" "),
|
|
3
|
-
`)}function
|
|
4
|
-
`)}var tt={row_start:0,row_end:1,col_start:0,col_end:1};function L(i,t,e,n=null){return
|
|
5
|
-
`))}});let
|
|
1
|
+
var S={type:"split-layout",orientation:"horizontal",sizes:[],children:[]};var _=Object.freeze({CUSTOM_EVENT_NAME_PREFIX:"regular-layout",CHILD_ATTRIBUTE_NAME:"name",MIN_DRAG_DISTANCE:10,SHOULD_ROUND:!1,OVERLAY_CLASSNAME:"overlay",MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD:.15,SPLIT_EDGE_TOLERANCE:.33,SPLIT_ROOT_EDGE_TOLERANCE:.03,GRID_TRACK_COLLAPSE_TOLERANCE:.001,OVERLAY_DEFAULT:"absolute",GRID_DIVIDER_SIZE:6,GRID_DIVIDER_CHECK_TARGET:!0});function Q(i,t,e){return(t.length===0||Math.abs(e-t[t.length-1])>i.GRID_TRACK_COLLAPSE_TOLERANCE)&&t.push(e),t}function J(i,t){return t.sort((n,r)=>n-r).reduce(Q.bind(void 0,i),[])}function D(i,t,e,n,r){if(i.type==="tab-layout")return[e,n];let o=[e,n];if(i.orientation===t){let s=e,a=n-e;for(let l=0;l<i.children.length;l++){let y=i.sizes[l],h=s+y*a;o.push(...D(i.children[l],t,s,h,r)),s=h}}else for(let s of i.children)o.push(...D(s,t,e,n,r));return J(r,o)}function R(i,t,e){let n=t.findIndex(r=>Math.abs(r-e)<i.GRID_TRACK_COLLAPSE_TOLERANCE);return n===-1?0:n}function G(i,t,e,n,r,o,s,a){if(i.type==="tab-layout"){let f=i.selected??0,m=R(a,t,n),g=R(a,t,r),T=R(a,e,o),H=R(a,e,s);return i.tabs.map((Z,j)=>({child:Z,colStart:m,colEnd:g,rowStart:T,rowEnd:H,zIndex:i.tabs.length>1&&j===f?1:void 0}))}let{children:l,sizes:y,orientation:h}=i,c=h==="horizontal",u=c?n:o,d=c?r-n:s-o,p=[];for(let f=0;f<l.length;f++){let m=u+y[f]*d;c?p.push(...G(l[f],t,e,u,m,o,s,a)):p.push(...G(l[f],t,e,n,r,u,m,a)),u=m}return p}var V=(i,t)=>`:host ::slotted(*){display:none}:host{display:grid;grid-template-rows:${i};grid-template-columns:${t}}`,w=(i,t,e,n,r)=>`:host ::slotted([${i.CHILD_ATTRIBUTE_NAME}="${t}"]){display:flex;grid-column:${n};grid-row:${e}${r===void 0?"":`;z-index:${r}`}}`;function E(i,t,e=_){if(i.type==="tab-layout"){let c=i.selected??0,u=i.tabs.length>1;return[V("100%","100%"),...i.tabs.map((d,p)=>w(e,d,"1","1",u&&p===c?1:void 0))].join(`
|
|
2
|
+
`)}let n=c=>c.slice(0,-1).map((d,p)=>c[p+1]-d).map(d=>`${e.SHOULD_ROUND?Math.round(d*100):d*100}fr`).join(" "),r=D(i,"horizontal",0,1,e),o=n(r),s=D(i,"vertical",0,1,e),a=n(s),l=(c,u)=>u-c===1?`${c+1}`:`${c+1} / ${u+1}`,y=G(i,r,s,0,1,0,1,e),h=[V(a,o)];for(let c of y){let u=l(c.colStart,c.colEnd),d=l(c.rowStart,c.rowEnd);h.push(w(e,c.child,d,u,c.zIndex)),c.child===t?.[1]&&(h.push(w(e,t[0],d,u)),h.push(`:host ::slotted([${e.CHILD_ATTRIBUTE_NAME}=${t[0]}]){z-index:2}`))}return h.join(`
|
|
3
|
+
`)}function Y(i,t=_){return[V("100%","100%"),w(t,i,"1","1")].join(`
|
|
4
|
+
`)}var tt={row_start:0,row_end:1,col_start:0,col_end:1};function L(i,t,e,n=null){return B(i,t,e,n)}function B(i,t,e,n,r=null,o=structuredClone(tt),s=[]){if(i<0||t<0||i>1||t>1)return null;if(e.type==="tab-layout"){let p=e.selected??0,f=o.col_end-o.col_start,m=o.row_end-o.row_start;return{type:"layout-path",layout:e,slot:e.tabs[p],path:s,view_window:o,is_edge:!1,column:i,row:t,column_offset:(i-o.col_start)/f,row_offset:(t-o.row_start)/m,orientation:r||"horizontal"}}let a=e.orientation==="vertical",l=a?t:i,y=a?"row_start":"col_start",h=a?"row_end":"col_end",c=a?n?.rect?.height:n?.rect?.width,u=o[y],d=o[h]-o[y];for(let p=0;p<e.children.length;p++){let f=u+d*e.sizes[p];if(n&&c){let m=n.size/c;if(Math.abs(l-f)<m)return{path:[...s,p],type:e.orientation,view_window:{...o,[y]:u,[h]:f}}}if(l>=u&&(l<f||p===e.children.length-1))return B(i,t,e.children[p],n,e.orientation,{...o,[y]:u,[h]:f},[...s,p]);u=f}return null}function b(i,t){if(i.type==="tab-layout"){if(i.tabs.includes(t)){let s=i.tabs.filter(a=>a!==t);return s.length===0?structuredClone(S):{type:"tab-layout",tabs:s}}return structuredClone(i)}let e=structuredClone(i),n=e.children.findIndex(s=>s.type==="tab-layout"?s.tabs.includes(t):!1);if(n!==-1){let s=e.children[n];if(s.tabs.length===1){let a=e.children.filter((y,h)=>h!==n),l=et(e.sizes,n);if(a.length===1)return a[0];e.children=a,e.sizes=l}else s.tabs.splice(s.tabs.indexOf(t),1),s.selected&&s.selected>=s.tabs.length&&s.selected--;return e}let r=!1,o=e.children.map(s=>{if(s.type==="split-layout"){let a=b(s,t);return a!==s&&(r=!0),a}return s});return r&&(e.children=o),e}function et(i,t){let e=[],n=i[t],r=0;for(let o=0;o<i.length;o++)o!==t&&(r+=i[o]);for(let o=0;o<i.length;o++)if(o!==t){let s=i[o]/r;e.push(i[o]+n*s)}return e}function v(i,t,e,n){let r=c=>({type:"tab-layout",tabs:[c]});if(e.length===0){if(i.type==="tab-layout")return{type:"tab-layout",tabs:[t,...i.tabs]};if(n)return{type:"split-layout",orientation:n,children:[r(t),i],sizes:[.5,.5]};{let c=[...i.children,r(t)],u=[...i.sizes,1/(c.length-1)];return{...i,children:c,sizes:I(u)}}}let[o,...s]=e;if(n&&s.length===0){if(i.type==="split-layout"&&i.orientation===n){let u=[...i.children];u.splice(o,0,r(t));let d=[...i.sizes];return d.splice(o,0,1/(u.length-1)),{...i,children:u,sizes:I(d)}}let c=o===0?[r(t),i]:[i,r(t)];return{type:"split-layout",orientation:n,children:c,sizes:[.5,.5]}}if(i.type==="tab-layout"){if(s.length===0&&n===void 0&&o>=0&&o<=i.tabs.length){let u=[...i.tabs];return u.splice(o,0,t),{...i,tabs:u}}return v({type:"split-layout",orientation:n||"horizontal",children:[i],sizes:[1]},t,e,n)}if(s.length===0||o===i.children.length){if(n&&i.children[o]){let d={type:"split-layout",orientation:n,children:[r(t),i.children[o]],sizes:[.5,.5]},p=[...i.children];return p[o]=d,{...i,children:p,sizes:I(i.sizes)}}let c=[...i.children];c.splice(o,0,r(t));let u=[...i.sizes];return u.splice(o,0,1/(c.length-1)),{...i,children:c,sizes:I(u)}}let a=i.children[o],l=a.type==="tab-layout"&&s.length>0&&n!==void 0?i.orientation==="horizontal"?"vertical":"horizontal":n,y=v(a,t,s,l),h=[...i.children];return h[o]=y,{...i,children:h}}function I(i){let t=i.reduce((e,n)=>e+n,0);return i.map(e=>e/t)}function O(i,t,e,n=_){let r=structuredClone(i),o=r,s={horizontal:e||0,vertical:e||0};for(let a=0;a<t.length-1;a++)o.type==="split-layout"&&(s[o.orientation]/=o.sizes[t[a]],o=o.children[t[a]]);if(o.type==="split-layout")if(e===void 0)o.sizes=o.sizes.map(a=>1/o.sizes.length);else{let a=s[o.orientation],l=t[t.length-1];l<o.sizes.length-1&&(o.sizes=nt(n,o.sizes,l,a))}return r}function nt(i,t,e,n){let r=[...t],o=0;for(let a=0;a<=e;a++)o+=t[a];let s=0;for(let a=e+1;a<t.length;a++)s+=t[a];n=Math.sign(n)*Math.min(Math.abs(n),(1-i.MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD)*(n>0?o:s));for(let a=0;a<=e;a++){let l=t[a]/o;r[a]=t[a]-n*l}for(let a=e+1;a<t.length;a++){let l=t[a]/s;r[a]=t[a]+n*l}return r}function $(i,t,e,n){let r=parseFloat(e.paddingLeft),o=parseFloat(e.paddingTop),s=t.width-r-parseFloat(e.paddingRight),a=t.height-o-parseFloat(e.paddingBottom),l=r+i.col_start*s,y=o+i.row_start*a,h=(i.col_end-i.col_start)*s,c=(i.row_end-i.row_start)*a;if(n){let u=parseFloat(n.marginTop),d=parseFloat(n.marginRight),p=parseFloat(n.marginBottom),f=parseFloat(n.marginLeft);h-=f+d,c-=u+p}return{x:l,y,width:h,height:c}}function k(i,t,e,n,r=_,o){if(!n)return`:host ::slotted([${r.CHILD_ATTRIBUTE_NAME}="${i}"]){display:none;}`;let s=$(n.view_window,t,e,o),a=`display:flex;position:absolute!important;z-index:2;top:${s.y}px;left:${s.x}px;height:${s.height}px;width:${s.width}px;`;return`::slotted([${r.CHILD_ATTRIBUTE_NAME}="${i}"]){${a}}`}function z(i){if(i.type==="tab-layout")return i.selected=i.selected||0,i;let t=[],e=[];for(let n=0;n<i.children.length;n++){let r=i.children[n],o=i.sizes[n],s=z(r);if(s.type==="split-layout"&&s.orientation===i.orientation)for(let a=0;a<s.children.length;a++)t.push(s.children[a]),e.push(s.sizes[a]*o);else t.push(s),e.push(o)}return t.length===1?t[0]:{type:"split-layout",orientation:i.orientation,children:t,sizes:e}}function W(i,t){return q(i,t,[])}function q(i,t,e){if(t.type==="tab-layout")return t.tabs.includes(i)?e:null;for(let n=0;n<t.children.length;n++){let r=q(i,t.children[n],[...e,n]);if(r)return r}return null}function X(i){let t={};return K(i,t,[],null,{row_start:0,row_end:1,col_start:0,col_end:1}),t}function K(i,t,e,n,r){if(i.type==="tab-layout"){let h=i.selected??0,c=i.tabs[h],u=(r.col_start+r.col_end)/2,d=(r.row_start+r.row_end)/2;t[c]={type:"layout-path",layout:i,slot:c,path:e,view_window:r,is_edge:!1,column:u,row:d,column_offset:.5,row_offset:.5,orientation:n||"horizontal"};return}let o=i.orientation==="vertical",s=o?"row_start":"col_start",a=o?"row_end":"col_end",l=r[s],y=r[a]-r[s];for(let h=0;h<i.children.length;h++){let c=l+y*i.sizes[h],u={...r,[s]:l,[a]:c};K(i.children[h],t,[...e,h],i.orientation,u),l=c}}var A=class{constructor(t,e,n){this.S=t;this.T=e;this.g=n}#n=!1;#t=null;#e=null;async run(t,e,n){if(this.#n){this.#t={layout:t,fn:e,overlay:n};return}this.#n=!0;try{for(await this.#o(t,e,n);this.#t;){let{layout:r,fn:o,overlay:s}=this.#t;this.#t=null,await this.#o(r,o,s)}}finally{this.#n=!1}}resume(){if(this.#e){let t=this.#e;this.#e=null,t()}}async#o(t,e,n){this.g?.();let r={calculatePresizePaths:()=>X(t),overlay:n},o=new CustomEvent(this.T,{cancelable:!0,detail:r});this.S.dispatchEvent(o)||await new Promise(a=>{this.#e=a}),e()}};function F(i,t,e,n,r,o,s=_){if(i<s.SPLIT_ROOT_EDGE_TOLERANCE)return M(e,n,r,[0],!0,"horizontal");if(i>1-s.SPLIT_ROOT_EDGE_TOLERANCE)return M(e,n,r,r.path.length>0?r.path:[1],!1,"horizontal");if(t<s.SPLIT_ROOT_EDGE_TOLERANCE)return M(e,n,r,[0],!0,"vertical");if(t>1-s.SPLIT_ROOT_EDGE_TOLERANCE)return M(e,n,r,r.path.length>0?r.path:[1],!1,"vertical");let a=r.column_offset<s.SPLIT_EDGE_TOLERANCE||r.column_offset>1-s.SPLIT_EDGE_TOLERANCE,l=r.row_offset<s.SPLIT_EDGE_TOLERANCE||r.row_offset>1-s.SPLIT_EDGE_TOLERANCE;if(a&&l){let y=Math.abs(r.column_offset-.5),h=Math.abs(r.row_offset-.5),c=(o?.width||1)*(r.view_window.col_end-r.view_window.col_start),u=(o?.height||1)*(r.view_window.row_end-r.view_window.row_start),d=c/2-y*c<u/2-h*u;return x(e,n,r,d?r.column_offset<s.SPLIT_EDGE_TOLERANCE:r.row_offset<s.SPLIT_EDGE_TOLERANCE,d?"horizontal":"vertical")}return a?x(e,n,r,r.column_offset<s.SPLIT_EDGE_TOLERANCE,"horizontal"):l?x(e,n,r,r.row_offset<s.SPLIT_EDGE_TOLERANCE,"vertical"):{...r,path:[...r.path,0]}}function M(i,t,e,n,r,o){return x(i,t,{...e,path:n,orientation:o},r,o)}function x(i,t,e,n,r){let o;if(e.orientation===r)if(e.path.length===0)o=[n?0:1];else{let l=e.path[e.path.length-1];o=[...e.path.slice(0,-1),n?l:l+1]}else o=[...e.path,n?0:1];let s=v(i,t,o,r),a=ot(s,o);return{...e,path:o,slot:e.slot,is_edge:!0,orientation:r,view_window:a}}function ot(i,t){let e={row_start:0,row_end:1,col_start:0,col_end:1},n=i;for(let r of t){if(n.type==="tab-layout")break;let o=Math.min(r,n.children.length-1),s=n.orientation==="vertical",a=s?"row_start":"col_start",l=s?"row_end":"col_end",y=e[l]-e[a],h=n.sizes.slice(0,o).reduce((c,u)=>c+u*y,e[a]);e={...e,[a]:h,[l]:h+y*n.sizes[o]},n=n.children[o]}return e}var N=class{constructor(t){this.d=t}async set(t,{slot:e},n=this.d.physics.OVERLAY_CLASSNAME,r=this.d.physics.OVERLAY_DEFAULT){let o=this.d,s=b(o.panel,e),a=`:scope > [${o.physics.CHILD_ATTRIBUTE_NAME}="${e}"]`,l=o.querySelector(a);l&&l.classList.add(n);let[y,h,c,u]=o.relativeCoordinates(t,!0),d=L(y,h,s);d&&(d=F(y,h,s,e,d,c,o.physics));let p=d?{slot:e,path:d}:null;await o.presizeQueue.run(s,()=>{if(r==="grid"&&d){let g=[e,d?.slot],T=E(s,g,o.physics);o.stylesheet.replaceSync(T)}else if(r==="absolute"){let g=E(s,void 0,o.physics);for(;l?.tagName==="SLOT"&&l;)l=l.assignedElements()[0];let T=l?getComputedStyle(l):void 0,H=k(e,c,u,d,o.physics,T);o.stylesheet.replaceSync([g,H].join(`
|
|
5
|
+
`))}},p);let f=`${o.physics.CUSTOM_EVENT_NAME_PREFIX}-before-update`,m=new CustomEvent(f,{detail:s});o.dispatchEvent(m)}async clear(t,{slot:e,layout:n},r=this.d.physics.OVERLAY_CLASSNAME){let o=this.d,s=b(o.panel,e),a=`:scope > [${o.physics.CHILD_ATTRIBUTE_NAME}="${e}"]`,l=o.querySelector(a);if(t===null){await o.restore(n);return}let[y,h,c]=o.relativeCoordinates(t,!1),u=L(y,h,s);if(u&&(u=F(y,h,s,e,u,c,o.physics)),u){let d=u?.is_edge?u.orientation:void 0,p=v(s,e,u.path,d);await o.restore(p)}else await o.restore(n);l&&l.classList.remove(r)}};var P=class extends HTMLElement{i;t;s;u;h;l;r;e;c;_;p;E;constructor(){super(),this.e=_,this.t=structuredClone(S),this.i=this.attachShadow({mode:"open"}),this.i.innerHTML="<slot></slot>",this.s=new CSSStyleSheet,this.u=new CSSStyleSheet,this.l=!1;let t=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-before-resize`;this.c=new A(this,t,()=>{this.r=void 0}),this._=new N(this.create_overlay_host()),this.i.adoptedStyleSheets=[this.s,this.u]}connectedCallback(){this.E??=new ResizeObserver(()=>{this.r=void 0}),this.E.observe(this),this.addEventListener("dblclick",this.onDblClick),this.addEventListener("pointerdown",this.onPointerDown),this.addEventListener("pointerup",this.onPointerUp),this.addEventListener("pointermove",this.onPointerMove)}disconnectedCallback(){this.E?.disconnect(),this.removeEventListener("dblclick",this.onDblClick),this.removeEventListener("pointerdown",this.onPointerDown),this.removeEventListener("pointerup",this.onPointerUp),this.removeEventListener("pointermove",this.onPointerMove)}calculateIntersect=t=>{let[e,n,r]=this.relativeCoordinates(t,!1);return L(e,n,this.t)};calculatePath=t=>W(t,this.t);setOverlayState=async(t,e,n,r)=>{await this._.set(t,e,n,r)};clearOverlayState=async(t,e,n)=>{await this._.clear(t,e,n)};insertPanel=async(t,e=[],n)=>{let r;typeof n=="boolean"&&n?r="horizontal":typeof n=="string"&&(r=n),await this.restore(v(this.t,t,e,r))};removePanel=async t=>{await this.restore(b(this.t,t))};select=async t=>{let e=this.save(),n=this.getPanel(t,e);if(!n)return;let r=n.tabs.indexOf(t);r!==-1&&n.selected!==r&&(n.selected=r,await this.restore(e));let o=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-select`;this.dispatchEvent(new CustomEvent(o,{detail:{name:t}}))};getPanel=(t,e=this.t)=>{if(e.type==="tab-layout")return e.tabs.includes(t)?e:null;for(let n of e.children){let r=this.getPanel(t,n);if(r)return r}return null};clear=async()=>{await this.restore(S)};maximize=async t=>{if(!this.getPanel(t))return;let e={type:"tab-layout",tabs:[t],selected:0};await this.c.run(e,()=>{this.p=t,this.s.replaceSync(Y(t,this.e))})};minimize=async()=>{this.p!==void 0&&await this.c.run(this.t,()=>{this.p=void 0,this.s.replaceSync(E(this.t,void 0,this.e))})};restoreSync=(t,e=!1)=>{this.r=void 0,this.p=void 0,this.t=e?t:z(t);let n=E(this.t,void 0,this.e);this.s.replaceSync(n);let r=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-update`,o=new CustomEvent(r,{detail:this.t});this.dispatchEvent(o)};restore=async(t,e=!1)=>{let n=e?t:z(t);await this.c.run(n,()=>{this.p=void 0,this.t=n;let r=E(this.t,void 0,this.e);this.s.replaceSync(r);let o=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-update`,s=new CustomEvent(o,{detail:this.t});this.dispatchEvent(s)})};resumeResize=()=>{this.c.resume()};save=()=>structuredClone(this.t);restorePhysics(t){this.e=Object.freeze({...this.e,...t})}savePhysics(){return this.e}relativeCoordinates=(t,e=!0)=>{(e||!this.r)&&(this.r={box:this.getBoundingClientRect(),style:getComputedStyle(this)});let n=this.r.box,r=this.r.style,o=parseFloat(r.paddingLeft),s=parseFloat(r.paddingTop),a=n.width-o-parseFloat(r.paddingRight),l=n.height-s-parseFloat(r.paddingBottom),y=t.clientX-n.left-o,h=t.clientY-n.top-s,c=Math.max(0,Math.min(1,y/a)),u=Math.max(0,Math.min(1,h/l));return[c,u,n,r]};realCoordinates=(t,e)=>{this.r||(this.r={box:this.getBoundingClientRect(),style:getComputedStyle(this)});let n=this.r.box,r=this.r.style,o;e&&(o=getComputedStyle(e));let s=$(t,n,r,o);return new DOMRect(n.left+s.x,n.top+s.y,s.width,s.height)};diffCoordinates=(t,e)=>{let[n,r,o]=this.relativeCoordinates(t,!1),s=(n-e.column)*o.width,a=(r-e.row)*o.height;return Math.sqrt(s**2+a**2)};create_overlay_host(){let t=this;return{get panel(){return t.t},get physics(){return t.e},get stylesheet(){return t.s},get presizeQueue(){return t.c},relativeCoordinates:(e,n)=>t.relativeCoordinates(e,n),restore:(e,n)=>t.restore(e,n),querySelector:e=>t.querySelector(e),dispatchEvent:e=>t.dispatchEvent(e)}}onDblClick=async t=>{let[e,n,r]=this.relativeCoordinates(t,!1),o=L(e,n,this.t,{rect:r,size:this.e.GRID_DIVIDER_SIZE});if(o?.type==="horizontal"||o?.type==="vertical"){let s=O(this.t,o.path,void 0);await this.restore(s,!0)}};onPointerDown=t=>{if(t.button===0&&(!this.e.GRID_DIVIDER_CHECK_TARGET||t.target===this)){let[e,n,r]=this.relativeCoordinates(t),o=this.e.GRID_DIVIDER_SIZE,s=L(e,n,this.t,{rect:r,size:o});s&&s.type!=="layout-path"&&(this.h=[s,e,n],this.setPointerCapture(t.pointerId),t.preventDefault())}};onPointerMove=async t=>{if(this.h){let[s,a]=this.relativeCoordinates(t,!1),[{path:l,type:y},h,c]=this.h,u=y==="horizontal"?h-s:c-a,d=O(this.t,l,u);await this.c.run(d,()=>{this.s.replaceSync(E(d,void 0,this.e))})}if(this.e.GRID_DIVIDER_CHECK_TARGET&&t.target!==this){this.l&&(this.l=!1,this.u.replaceSync(""));return}let[e,n,r]=this.relativeCoordinates(t,!1),o=L(e,n,this.t,{rect:r,size:this.e.GRID_DIVIDER_SIZE});o?.type==="vertical"?(this.u.replaceSync(":host{cursor:row-resize"),this.l=!0):o?.type==="horizontal"?(this.u.replaceSync(":host{cursor:col-resize"),this.l=!0):this.l&&(this.l=!1,this.u.replaceSync(""))};onPointerUp=async t=>{if(this.h){this.releasePointerCapture(t.pointerId);let[e,n]=this.relativeCoordinates(t,!1),[{path:r,type:o},s,a]=this.h,l=o==="horizontal"?s-e:a-n,y=O(this.t,r,l);await this.restore(y,!0),this.h=void 0}}};var rt=`
|
|
6
6
|
:host{box-sizing:border-box;flex-direction:column;pointer-events:none}
|
|
7
7
|
[part~="titlebar"]{height:24px;user-select:none;overflow:hidden}
|
|
8
8
|
[part~="container"]{flex:1 1 auto;pointer-events:auto}
|
|
@@ -13,9 +13,9 @@ var T={type:"split-layout",orientation:"horizontal",sizes:[],children:[]};var _=
|
|
|
13
13
|
.tabs slot[name="tab"]{display:grid;grid-row:1;pointer-events:auto}
|
|
14
14
|
.tabs regular-layout-tab{display:flex;overflow:hidden}
|
|
15
15
|
`,it=`
|
|
16
|
-
<div part="titlebar"><div class="tabs"><slot name="tab"><regular-layout-tab></regular-layout-tab></slot></div></div>
|
|
16
|
+
<div part="titlebar"><div class="tabs" part="titlebar-track"><slot name="tab"><regular-layout-tab></regular-layout-tab></slot></div></div>
|
|
17
17
|
<div part="container"><slot></slot></div>
|
|
18
18
|
`,st=i=>`"${i.replace(/[\\"\n]/g,t=>t===`
|
|
19
|
-
`?"\\A ":`\\${t}`)}"`,at=i=>`--regular-layout-${globalThis.CSS.escape(i)}--title`,
|
|
20
|
-
`))}};var
|
|
19
|
+
`?"\\A ":`\\${t}`)}"`,at=i=>`--regular-layout-${globalThis.CSS.escape(i)}--title`,C=class extends HTMLElement{i;L;v;n;m;b;o=null;connectedCallback(){this.L??=new CSSStyleSheet,this.L.replaceSync(rt),this.v??=new CSSStyleSheet,this.i??=this.attachShadow({mode:"open"}),this.i.adoptedStyleSheets=[this.L,this.v],this.i.innerHTML=it,this.n=this.parentElement,this.m=this.i.children[0],this.b=this.m.querySelector("regular-layout-tab"),this.m.addEventListener("pointerdown",this.onPointerDown),this.addEventListener("pointermove",this.onPointerMove),this.addEventListener("pointerup",this.onPointerUp),this.addEventListener("pointercancel",this.onPointerCancel),this.addEventListener("lostpointercapture",this.onPointerLost),this.n.addEventListener("regular-layout-update",this.drawTabs),this.n.addEventListener("regular-layout-before-update",this.drawTabs)}disconnectedCallback(){this.m.removeEventListener("pointerdown",this.onPointerDown),this.removeEventListener("pointermove",this.onPointerMove),this.removeEventListener("pointerup",this.onPointerUp),this.removeEventListener("pointercancel",this.onPointerUp),this.removeEventListener("lostpointercapture",this.onPointerLost),this.n.removeEventListener("regular-layout-update",this.drawTabs),this.n.removeEventListener("regular-layout-before-update",this.drawTabs)}onPointerDown=t=>{if(t.button!==0)return;if(t.target.part.contains("tab")){let n=this.getAttribute(this.n.savePhysics().CHILD_ATTRIBUTE_NAME),r=this.n.calculateIntersect(t);r&&n?(this.o={path:{...r,slot:n}},this.setPointerCapture(t.pointerId),t.preventDefault()):this.o=null}};onPointerMove=t=>{if(this.o){let e=this.n.savePhysics();if(!this.o.moved&&this.n.diffCoordinates(t,this.o.path)<=e.MIN_DRAG_DISTANCE)return;this.o.moved=!0,this.n.setOverlayState(t,this.o.path)}};onPointerUp=t=>{this.o?.moved&&this.n.clearOverlayState(t,this.o.path)};onPointerCancel=t=>{this.o?.moved&&this.n.clearOverlayState(null,this.o.path)};onPointerLost=t=>{this.releasePointerCapture(t.pointerId),this.o=null};drawTabs=t=>{let e=this.n.savePhysics().CHILD_ATTRIBUTE_NAME,n=this.getAttribute(e);if(!n)return;let r=this.n.getPanel(n,t.detail);r||(r={type:"tab-layout",tabs:[n],selected:0});let o=r.tabs.indexOf(n),s=(r.selected??0)===o;this.toggleAttribute("inactive",!s),this.b.populate(this.n,r,o),this.drawTab(n,o,r.tabs.length)};drawTab=(t,e,n)=>{this.v.replaceSync([`.tabs{grid-template-columns:repeat(${n},var(--rl-tab-width,1fr))}`,`.tabs slot[name="tab"]{grid-column:${e+1}}`,`[part~="title"]::before{content:var(${at(t)}, ${st(t)})}`].join(`
|
|
20
|
+
`))}};var U=class extends HTMLElement{n;a;f;populate=(t,e,n)=>{if(this.setAttribute(t.savePhysics().CHILD_ATTRIBUTE_NAME,e.tabs[n]),this.a)(n===e.selected!=(n===this.a?.selected)||this.a?.tabs[n]!==e.tabs[n])&&(e.selected===n?(this.children[1].part.add("active-close"),this.part.add("active-tab")):(this.children[1].part.remove("active-close"),this.part.remove("active-tab")));else{let r=e.selected===n,o=r?"active-close close":"close";this.innerHTML=`<div part="title"></div><button part="${o}"></button>`,r?this.part.add("tab","active-tab"):this.part.add("tab"),this.addEventListener("pointerdown",this.onTabClick),this.children[1].addEventListener("pointerdown",this.onTabClose)}this.a=e,this.n=t,this.f=n};onTabClose=t=>{t instanceof PointerEvent&&t?.button!==0||this.a!==void 0&&this.f!==void 0&&this.n?.removePanel(this.a.tabs[this.f])};onTabClick=t=>{t.button===0&&this.a!==void 0&&this.f!==void 0&&this.n?.select(this.a.tabs[this.f])}};customElements.define("regular-layout",P);customElements.define("regular-layout-frame",C);customElements.define("regular-layout-tab",U);export{P as RegularLayout,C as RegularLayoutFrame};
|
|
21
21
|
//# sourceMappingURL=index.js.map
|