regular-layout 0.4.0 → 0.6.0
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/extensions.d.ts +7 -0
- package/dist/index.js +19 -14
- package/dist/index.js.map +3 -3
- package/dist/layout/generate_grid.d.ts +9 -0
- package/dist/regular-layout-frame.d.ts +24 -1
- package/dist/regular-layout.d.ts +39 -0
- package/package.json +1 -1
- package/src/extensions.ts +12 -0
- package/src/layout/generate_grid.ts +57 -13
- package/src/layout/generate_overlay.ts +1 -1
- package/src/model/overlay_controller.ts +0 -1
- package/src/regular-layout-frame.ts +92 -35
- package/src/regular-layout-tab.ts +19 -21
- package/src/regular-layout.ts +86 -1
- package/themes/borland.css +6 -4
- package/themes/chicago.css +12 -4
- package/themes/fluxbox.css +6 -3
- package/themes/gibson.css +8 -22
- package/themes/hotdog.css +13 -4
- package/themes/lorax.css +40 -43
package/dist/extensions.d.ts
CHANGED
|
@@ -26,10 +26,17 @@ declare global {
|
|
|
26
26
|
addEventListener(name: "regular-layout-before-resize", cb: (e: RegularLayoutPresizeEvent) => void, options?: {
|
|
27
27
|
signal: AbortSignal;
|
|
28
28
|
}): void;
|
|
29
|
+
addEventListener(name: "regular-layout-select", cb: (e: RegularLayoutSelectEvent) => void, options?: {
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}): void;
|
|
29
32
|
removeEventListener(name: "regular-layout-update", cb: (e: RegularLayoutEvent) => void): void;
|
|
30
33
|
removeEventListener(name: "regular-layout-before-update", cb: (e: RegularLayoutEvent) => void): void;
|
|
31
34
|
removeEventListener(name: "regular-layout-before-resize", cb: (e: RegularLayoutPresizeEvent) => void): void;
|
|
35
|
+
removeEventListener(name: "regular-layout-select", cb: (e: RegularLayoutSelectEvent) => void): void;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
export type RegularLayoutEvent = CustomEvent<Layout>;
|
|
35
39
|
export type RegularLayoutPresizeEvent = CustomEvent<PresizeDetail>;
|
|
40
|
+
export type RegularLayoutSelectEvent = CustomEvent<{
|
|
41
|
+
name: string;
|
|
42
|
+
}>;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}let
|
|
3
|
-
`)}
|
|
4
|
-
`)
|
|
5
|
-
:
|
|
6
|
-
:host
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
:host
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var T={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,o)=>n-o).reduce(Q.bind(void 0,i),[])}function w(i,t,e,n,o){if(i.type==="tab-layout")return[e,n];let r=[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;r.push(...w(i.children[l],t,s,h,o)),s=h}}else for(let s of i.children)r.push(...w(s,t,e,n,o));return J(o,r)}function C(i,t,e){let n=t.findIndex(o=>Math.abs(o-e)<i.GRID_TRACK_COLLAPSE_TOLERANCE);return n===-1?0:n}function H(i,t,e,n,o,r,s,a){if(i.type==="tab-layout"){let f=i.selected??0,m=C(a,t,n),g=C(a,t,o),U=C(a,e,r),K=C(a,e,s);return i.tabs.map((Z,j)=>({child:Z,colStart:m,colEnd:g,rowStart:U,rowEnd:K,zIndex:i.tabs.length>1&&j===f?1:void 0}))}let{children:l,sizes:y,orientation:h}=i,c=h==="horizontal",u=c?n:r,d=c?o-n:s-r,p=[];for(let f=0;f<l.length;f++){let m=u+y[f]*d;c?p.push(...H(l[f],t,e,u,m,r,s,a)):p.push(...H(l[f],t,e,n,o,u,m,a)),u=m}return p}var G=(i,t)=>`:host ::slotted(*){display:none}:host{display:grid;grid-template-rows:${i};grid-template-columns:${t}}`,R=(i,t,e,n,o)=>`:host ::slotted([${i.CHILD_ATTRIBUTE_NAME}="${t}"]){display:flex;grid-column:${n};grid-row:${e}${o===void 0?"":`;z-index:${o}`}}`;function E(i,t,e=_){if(i.type==="tab-layout"){let c=i.selected??0,u=i.tabs.length>1;return[G("100%","100%"),...i.tabs.map((d,p)=>R(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(" "),o=w(i,"horizontal",0,1,e),r=n(o),s=w(i,"vertical",0,1,e),a=n(s),l=(c,u)=>u-c===1?`${c+1}`:`${c+1} / ${u+1}`,y=H(i,o,s,0,1,0,1,e),h=[G(a,r)];for(let c of y){let u=l(c.colStart,c.colEnd),d=l(c.rowStart,c.rowEnd);h.push(R(e,c.child,d,u,c.zIndex)),c.child===t?.[1]&&(h.push(R(e,t[0],d,u)),h.push(`:host ::slotted([${e.CHILD_ATTRIBUTE_NAME}=${t[0]}]){z-index:2}`))}return h.join(`
|
|
3
|
+
`)}function F(i,t=_){return[G("100%","100%"),R(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 Y(i,t,e,n)}function Y(i,t,e,n,o=null,r=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=r.col_end-r.col_start,m=r.row_end-r.row_start;return{type:"layout-path",layout:e,slot:e.tabs[p],path:s,view_window:r,is_edge:!1,column:i,row:t,column_offset:(i-r.col_start)/f,row_offset:(t-r.row_start)/m,orientation:o||"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=r[y],d=r[h]-r[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:{...r,[y]:u,[h]:f}}}if(l>=u&&(l<f||p===e.children.length-1))return Y(i,t,e.children[p],n,e.orientation,{...r,[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(T):{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 o=!1,r=e.children.map(s=>{if(s.type==="split-layout"){let a=b(s,t);return a!==s&&(o=!0),a}return s});return o&&(e.children=r),e}function et(i,t){let e=[],n=i[t],o=0;for(let r=0;r<i.length;r++)r!==t&&(o+=i[r]);for(let r=0;r<i.length;r++)if(r!==t){let s=i[r]/o;e.push(i[r]+n*s)}return e}function v(i,t,e,n){let o=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:[o(t),i],sizes:[.5,.5]};{let c=[...i.children,o(t)],u=[...i.sizes,1/(c.length-1)];return{...i,children:c,sizes:D(u)}}}let[r,...s]=e;if(n&&s.length===0){if(i.type==="split-layout"&&i.orientation===n){let u=[...i.children];u.splice(r,0,o(t));let d=[...i.sizes];return d.splice(r,0,1/(u.length-1)),{...i,children:u,sizes:D(d)}}let c=r===0?[o(t),i]:[i,o(t)];return{type:"split-layout",orientation:n,children:c,sizes:[.5,.5]}}if(i.type==="tab-layout"){if(s.length===0&&n===void 0&&r>=0&&r<=i.tabs.length){let u=[...i.tabs];return u.splice(r,0,t),{...i,tabs:u}}return v({type:"split-layout",orientation:n||"horizontal",children:[i],sizes:[1]},t,e,n)}if(s.length===0||r===i.children.length){if(n&&i.children[r]){let d={type:"split-layout",orientation:n,children:[o(t),i.children[r]],sizes:[.5,.5]},p=[...i.children];return p[r]=d,{...i,children:p,sizes:D(i.sizes)}}let c=[...i.children];c.splice(r,0,o(t));let u=[...i.sizes];return u.splice(r,0,1/(c.length-1)),{...i,children:c,sizes:D(u)}}let a=i.children[r],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[r]=y,{...i,children:h}}function D(i){let t=i.reduce((e,n)=>e+n,0);return i.map(e=>e/t)}function I(i,t,e,n=_){let o=structuredClone(i),r=o,s={horizontal:e||0,vertical:e||0};for(let a=0;a<t.length-1;a++)r.type==="split-layout"&&(s[r.orientation]/=r.sizes[t[a]],r=r.children[t[a]]);if(r.type==="split-layout")if(e===void 0)r.sizes=r.sizes.map(a=>1/r.sizes.length);else{let a=s[r.orientation],l=t[t.length-1];l<r.sizes.length-1&&(r.sizes=nt(n,r.sizes,l,a))}return o}function nt(i,t,e,n){let o=[...t],r=0;for(let a=0;a<=e;a++)r+=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?r:s));for(let a=0;a<=e;a++){let l=t[a]/r;o[a]=t[a]-n*l}for(let a=e+1;a<t.length;a++){let l=t[a]/s;o[a]=t[a]+n*l}return o}function V(i,t,e,n){let o=parseFloat(e.paddingLeft),r=parseFloat(e.paddingTop),s=t.width-o-parseFloat(e.paddingRight),a=t.height-r-parseFloat(e.paddingBottom),l=o+i.col_start*s,y=r+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 B(i,t,e,n,o=_,r){if(!n)return`:host ::slotted([${o.CHILD_ATTRIBUTE_NAME}="${i}"]){display:none;}`;let s=V(n.view_window,t,e,r),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([${o.CHILD_ATTRIBUTE_NAME}="${i}"]){${a}}`}function O(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 o=i.children[n],r=i.sizes[n],s=O(o);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]*r);else t.push(s),e.push(r)}return t.length===1?t[0]:{type:"split-layout",orientation:i.orientation,children:t,sizes:e}}function k(i,t){return W(i,t,[])}function W(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 o=W(i,t.children[n],[...e,n]);if(o)return o}return null}function q(i){let t={};return X(i,t,[],null,{row_start:0,row_end:1,col_start:0,col_end:1}),t}function X(i,t,e,n,o){if(i.type==="tab-layout"){let h=i.selected??0,c=i.tabs[h],u=(o.col_start+o.col_end)/2,d=(o.row_start+o.row_end)/2;t[c]={type:"layout-path",layout:i,slot:c,path:e,view_window:o,is_edge:!1,column:u,row:d,column_offset:.5,row_offset:.5,orientation:n||"horizontal"};return}let r=i.orientation==="vertical",s=r?"row_start":"col_start",a=r?"row_end":"col_end",l=o[s],y=o[a]-o[s];for(let h=0;h<i.children.length;h++){let c=l+y*i.sizes[h],u={...o,[s]:l,[a]:c};X(i.children[h],t,[...e,h],i.orientation,u),l=c}}var A=class{constructor(t,e){this.g=t;this.b=e}#n=!1;#t=null;#e=null;async run(t,e){if(this.#n){this.#t={layout:t,fn:e};return}this.#n=!0;try{for(await this.#o(t,e);this.#t;){let{layout:n,fn:o}=this.#t;this.#t=null,await this.#o(n,o)}}finally{this.#n=!1}}resume(){if(this.#e){let t=this.#e;this.#e=null,t()}}async#o(t,e){let n={calculatePresizePaths:()=>q(t)},o=new CustomEvent(this.b,{cancelable:!0,detail:n});this.g.dispatchEvent(o)||await new Promise(s=>{this.#e=s}),e()}};function $(i,t,e,n,o,r,s=_){if(i<s.SPLIT_ROOT_EDGE_TOLERANCE)return z(e,n,o,[0],!0,"horizontal");if(i>1-s.SPLIT_ROOT_EDGE_TOLERANCE)return z(e,n,o,o.path.length>0?o.path:[1],!1,"horizontal");if(t<s.SPLIT_ROOT_EDGE_TOLERANCE)return z(e,n,o,[0],!0,"vertical");if(t>1-s.SPLIT_ROOT_EDGE_TOLERANCE)return z(e,n,o,o.path.length>0?o.path:[1],!1,"vertical");let a=o.column_offset<s.SPLIT_EDGE_TOLERANCE||o.column_offset>1-s.SPLIT_EDGE_TOLERANCE,l=o.row_offset<s.SPLIT_EDGE_TOLERANCE||o.row_offset>1-s.SPLIT_EDGE_TOLERANCE;if(a&&l){let y=Math.abs(o.column_offset-.5),h=Math.abs(o.row_offset-.5),c=(r?.width||1)*(o.view_window.col_end-o.view_window.col_start),u=(r?.height||1)*(o.view_window.row_end-o.view_window.row_start),d=c/2-y*c<u/2-h*u;return M(e,n,o,d?o.column_offset<s.SPLIT_EDGE_TOLERANCE:o.row_offset<s.SPLIT_EDGE_TOLERANCE,d?"horizontal":"vertical")}return a?M(e,n,o,o.column_offset<s.SPLIT_EDGE_TOLERANCE,"horizontal"):l?M(e,n,o,o.row_offset<s.SPLIT_EDGE_TOLERANCE,"vertical"):{...o,path:[...o.path,0]}}function z(i,t,e,n,o,r){return M(i,t,{...e,path:n,orientation:r},o,r)}function M(i,t,e,n,o){let r;if(e.orientation===o)if(e.path.length===0)r=[n?0:1];else{let l=e.path[e.path.length-1];r=[...e.path.slice(0,-1),n?l:l+1]}else r=[...e.path,n?0:1];let s=v(i,t,r,o),a=ot(s,r);return{...e,path:r,slot:e.slot,is_edge:!0,orientation:o,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 o of t){if(n.type==="tab-layout")break;let r=Math.min(o,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,r).reduce((c,u)=>c+u*y,e[a]);e={...e,[a]:h,[l]:h+y*n.sizes[r]},n=n.children[r]}return e}var x=class{constructor(t){this.h=t}async set(t,{slot:e},n=this.h.physics.OVERLAY_CLASSNAME,o=this.h.physics.OVERLAY_DEFAULT){let r=this.h,s=b(r.panel,e),a=`:scope > [${r.physics.CHILD_ATTRIBUTE_NAME}="${e}"]`,l=r.querySelector(a);l&&l.classList.add(n);let[y,h,c,u]=r.relativeCoordinates(t,!0),d=L(y,h,s);d&&(d=$(y,h,s,e,d,c,r.physics)),await r.presizeQueue.run(s,()=>{if(o==="grid"&&d){let m=[e,d?.slot],g=E(s,m,r.physics);r.stylesheet.replaceSync(g)}else if(o==="absolute"){let m=E(s,void 0,r.physics);for(;l?.tagName==="SLOT"&&l;)l=l.assignedElements()[0];let g=l?getComputedStyle(l):void 0,U=B(e,c,u,d,r.physics,g);r.stylesheet.replaceSync([m,U].join(`
|
|
5
|
+
`))}});let p=`${r.physics.CUSTOM_EVENT_NAME_PREFIX}-before-update`,f=new CustomEvent(p,{detail:s});r.dispatchEvent(f)}async clear(t,{slot:e,layout:n},o=this.h.physics.OVERLAY_CLASSNAME){let r=this.h,s=b(r.panel,e),a=`:scope > [${r.physics.CHILD_ATTRIBUTE_NAME}="${e}"]`,l=r.querySelector(a);if(t===null){await r.restore(n);return}let[y,h,c]=r.relativeCoordinates(t,!1),u=L(y,h,s);if(u&&(u=$(y,h,s,e,u,c,r.physics)),u){let d=u?.is_edge?u.orientation:void 0,p=v(s,e,u.path,d);await r.restore(p)}else await r.restore(n);l&&l.classList.remove(o)}};var S=class extends HTMLElement{r;t;i;c;u;l;s;e;d;_;p;constructor(){super(),this.e=_,this.t=structuredClone(T),this.r=this.attachShadow({mode:"open"}),this.r.innerHTML="<slot></slot>",this.i=new CSSStyleSheet,this.c=new CSSStyleSheet,this.l=!1;let t=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-before-resize`;this.d=new A(this,t),this._=new x(this.create_overlay_host()),this.r.adoptedStyleSheets=[this.i,this.c]}connectedCallback(){this.addEventListener("dblclick",this.onDblClick),this.addEventListener("pointerdown",this.onPointerDown),this.addEventListener("pointerup",this.onPointerUp),this.addEventListener("pointermove",this.onPointerMove)}disconnectedCallback(){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,o]=this.relativeCoordinates(t,!1);return L(e,n,this.t)};calculatePath=t=>k(t,this.t);setOverlayState=async(t,e,n,o)=>{await this._.set(t,e,n,o)};clearOverlayState=async(t,e,n)=>{await this._.clear(t,e,n)};insertPanel=async(t,e=[],n)=>{let o;typeof n=="boolean"&&n?o="horizontal":typeof n=="string"&&(o=n),await this.restore(v(this.t,t,e,o))};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 o=n.tabs.indexOf(t);o!==-1&&n.selected!==o&&(n.selected=o,await this.restore(e));let r=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-select`;this.dispatchEvent(new CustomEvent(r,{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 o=this.getPanel(t,n);if(o)return o}return null};clear=async()=>{await this.restore(T)};maximize=t=>{this.getPanel(t)&&(this.p=t,this.i.replaceSync(F(t,this.e)))};minimize=()=>{this.p!==void 0&&(this.p=void 0,this.i.replaceSync(E(this.t,void 0,this.e)))};restoreSync=(t,e=!1)=>{this.p=void 0,this.t=e?t:O(t);let n=E(this.t,void 0,this.e);this.i.replaceSync(n);let o=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-update`,r=new CustomEvent(o,{detail:this.t});this.dispatchEvent(r)};restore=async(t,e=!1)=>{let n=e?t:O(t);await this.d.run(n,()=>{this.p=void 0,this.t=n;let o=E(this.t,void 0,this.e);this.i.replaceSync(o);let r=`${this.e.CUSTOM_EVENT_NAME_PREFIX}-update`,s=new CustomEvent(r,{detail:this.t});this.dispatchEvent(s)})};resumeResize=()=>{this.d.resume()};save=()=>structuredClone(this.t);restorePhysics(t){this.e=Object.freeze({...this.e,...t})}savePhysics(){return this.e}relativeCoordinates=(t,e=!0)=>{(e||!this.s)&&(this.s={box:this.getBoundingClientRect(),style:getComputedStyle(this)});let n=this.s.box,o=this.s.style,r=parseFloat(o.paddingLeft),s=parseFloat(o.paddingTop),a=n.width-r-parseFloat(o.paddingRight),l=n.height-s-parseFloat(o.paddingBottom),y=t.clientX-n.left-r,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,o]};realCoordinates=(t,e)=>{this.s||(this.s={box:this.getBoundingClientRect(),style:getComputedStyle(this)});let n=this.s.box,o=this.s.style,r;e&&(r=getComputedStyle(e));let s=V(t,n,o,r);return new DOMRect(n.left+s.x,n.top+s.y,s.width,s.height)};diffCoordinates=(t,e)=>{let[n,o,r]=this.relativeCoordinates(t,!1),s=(n-e.column)*r.width,a=(o-e.row)*r.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.i},get presizeQueue(){return t.d},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,o]=this.relativeCoordinates(t,!1),r=L(e,n,this.t,{rect:o,size:this.e.GRID_DIVIDER_SIZE});if(r?.type==="horizontal"||r?.type==="vertical"){let s=I(this.t,r.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,o]=this.relativeCoordinates(t),r=this.e.GRID_DIVIDER_SIZE,s=L(e,n,this.t,{rect:o,size:r});s&&s.type!=="layout-path"&&(this.u=[s,e,n],this.setPointerCapture(t.pointerId),t.preventDefault())}};onPointerMove=async t=>{if(this.u){let[s,a]=this.relativeCoordinates(t,!1),[{path:l,type:y},h,c]=this.u,u=y==="horizontal"?h-s:c-a,d=I(this.t,l,u);await this.d.run(d,()=>{this.i.replaceSync(E(d,void 0,this.e))})}if(this.e.GRID_DIVIDER_CHECK_TARGET&&t.target!==this){this.l&&(this.l=!1,this.c.replaceSync(""));return}let[e,n,o]=this.relativeCoordinates(t,!1),r=L(e,n,this.t,{rect:o,size:this.e.GRID_DIVIDER_SIZE});r?.type==="vertical"?(this.c.replaceSync(":host{cursor:row-resize"),this.l=!0):r?.type==="horizontal"?(this.c.replaceSync(":host{cursor:col-resize"),this.l=!0):this.l&&(this.l=!1,this.c.replaceSync(""))};onPointerUp=async t=>{if(this.u){this.releasePointerCapture(t.pointerId);let[e,n]=this.relativeCoordinates(t,!1),[{path:o,type:r},s,a]=this.u,l=r==="horizontal"?s-e:a-n,y=I(this.t,o,l);await this.restore(y,!0),this.u=void 0}}};var rt=`
|
|
6
|
+
:host{box-sizing:border-box;flex-direction:column;pointer-events:none}
|
|
7
|
+
[part~="titlebar"]{height:24px;user-select:none;overflow:hidden}
|
|
8
|
+
[part~="container"]{flex:1 1 auto;pointer-events:auto}
|
|
9
|
+
[part~="title"]{flex:1 1 auto;pointer-events:none}
|
|
10
|
+
[part~="close"]{align-self:stretch}
|
|
11
|
+
:host([inactive]) [part~="container"]{display:none}
|
|
12
|
+
.tabs{display:grid;width:100%;height:100%}
|
|
13
|
+
.tabs slot[name="tab"]{display:grid;grid-row:1;pointer-events:auto}
|
|
14
|
+
.tabs regular-layout-tab{display:flex;overflow:hidden}
|
|
15
|
+
`,it=`
|
|
16
|
+
<div part="titlebar"><div class="tabs"><slot name="tab"><regular-layout-tab></regular-layout-tab></slot></div></div>
|
|
14
17
|
<div part="container"><slot></slot></div>
|
|
15
|
-
`,
|
|
18
|
+
`,st=i=>`"${i.replace(/[\\"\n]/g,t=>t===`
|
|
19
|
+
`?"\\A ":`\\${t}`)}"`,at=i=>`--regular-layout-${globalThis.CSS.escape(i)}--title`,P=class extends HTMLElement{r;E;L;n;m;v;o=null;connectedCallback(){this.E??=new CSSStyleSheet,this.E.replaceSync(rt),this.L??=new CSSStyleSheet,this.r??=this.attachShadow({mode:"open"}),this.r.adoptedStyleSheets=[this.E,this.L],this.r.innerHTML=it,this.n=this.parentElement,this.m=this.r.children[0],this.v=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),o=this.n.calculateIntersect(t);o&&n?(this.o={path:{...o,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 o=this.n.getPanel(n,t.detail);o||(o={type:"tab-layout",tabs:[n],selected:0});let r=o.tabs.indexOf(n),s=(o.selected??0)===r;this.toggleAttribute("inactive",!s),this.v.populate(this.n,o,r),this.drawTab(n,r,o.tabs.length)};drawTab=(t,e,n)=>{this.L.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 N=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 o=e.selected===n,r=o?"active-close close":"close";this.innerHTML=`<div part="title"></div><button part="${r}"></button>`,o?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",S);customElements.define("regular-layout-frame",P);customElements.define("regular-layout-tab",N);export{S as RegularLayout,P as RegularLayoutFrame};
|
|
16
21
|
//# sourceMappingURL=index.js.map
|