tabby-paneworks 1.1.2 → 1.1.3
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/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Made for running several long-lived sessions side by side (coding agents, dev se
|
|
|
17
17
|
- **Label colours** per pane, so you recognise panes at a glance.
|
|
18
18
|
- **Open in VS Code** from the sidebar header: opens the workspace's project folder (set in the workspace menu; by default the first pane folder). WSL folders open in VS Code's WSL mode.
|
|
19
19
|
- **Copy the project folder path** from the sidebar header.
|
|
20
|
-
- **Edit a workspace's settings in VS Code** as a JSON file (workspace menu). Every save is checked and applied right away.
|
|
20
|
+
- **Edit a workspace's settings in VS Code** as a JSON file (workspace menu). Every save is checked and applied right away. **Copy settings file path** (same menu) copies the file's path, for editing it with any editor.
|
|
21
21
|
- **Duplicate a pane** from its editor: same settings, switched on in the same views.
|
|
22
22
|
- **Tab colour** per workspace, applied to the workspace tab every time it opens, also after a Tabby restart.
|
|
23
23
|
- **NEW marker** on hidden panes that printed something since you last looked.
|
|
@@ -47,7 +47,7 @@ When a workspace opens, you briefly see all of its panes: Tabby starts a termina
|
|
|
47
47
|
| Element | What it does |
|
|
48
48
|
|---|---|
|
|
49
49
|
| Workspace name (top) | Workspace menu: rename, tab colour, project folder, minimum pane size, open when Tabby starts, switch to or open another workspace, new workspace, delete this one |
|
|
50
|
-
| Copy icon | Copy the project folder path to the clipboard |
|
|
50
|
+
| Copy icon | Copy the project folder path to the clipboard (the settings file path is in the workspace menu) |
|
|
51
51
|
| `</>` | Open the project folder in VS Code (needs the `code` command, which VS Code's installer puts on PATH) |
|
|
52
52
|
| « / » | Collapse or expand the sidebar |
|
|
53
53
|
| **Views** **+** | Add a view, with all panes switched on |
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal"));else if("function"==typeof define&&define.amd)define(["@angular/common","@angular/core","fs","path","rxjs","rxjs/operators","tabby-core","tabby-terminal"],t);else{var n="object"==typeof exports?t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal")):t(e["@angular/common"],e["@angular/core"],e.fs,e.path,e.rxjs,e["rxjs/operators"],e["tabby-core"],e["tabby-terminal"]);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(global,(e,t,n,i,s,a,r,o)=>(()=>{"use strict";var p={358(t){t.exports=e},860(e){e.exports=t},947(e){e.exports=n},911(e){e.exports=i},961(e){e.exports=s},439(e){e.exports=a},650(e){e.exports=r},349(e){e.exports=o}};const d={};function c(e){const t=d[e];if(void 0!==t)return t.exports;const n=d[e]={exports:{}};return p[e](n,n.exports,c),n.exports}c.d=(e,t)=>{for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),c.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};let l={};c.r(l),c.d(l,{WorkspaceEditorService:()=>N,default:()=>Z});var h=c(860),w=c(358),f=c(650);const u="paneworks",m="Paneworks";const g=`${u}-open-menu`;let b=class extends f.HotkeyProvider{async provide(){return[{id:g,name:`${m}: open menu`}]}};b=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)()],b);let k=class extends f.ConfigProvider{constructor(){super(...arguments),this.defaults={[u]:{workspaces:[]},hotkeys:{[g]:["F1"]}}}};k=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)()],k);const v=require("child_process");var y=c(947);const x=require("os");var P=c(911),I=c(961);function S(e){return"children"in e}function C(e){return e.children.flatMap(e=>S(e)?C(e):[e.paneId])}function T(e,t,n,i,s){if(e<=0)return[];const a=Math.max(1,Math.floor(t/Math.max(1,i))),r=Math.max(1,Math.floor(n/Math.max(1,s))),o=Math.min(e,a*r);let p=null;for(let e=1;e<=Math.min(o,r);e++){const r=Math.ceil(o/e);if(r>a)continue;const d=Math.min(t/r/i,n/e/s);(!p||d>p.score+1e-9)&&(p={rows:e,score:d})}const d=p?.rows??1,c=Math.floor(o/d),l=o%d;return Array.from({length:d},(e,t)=>c+(t<l?1:0))}function W(e,t){let n=0;const i=t.map(t=>{const i=e.slice(n,n+t);return n+=t,1===i.length?{paneId:i[0]}:{orientation:"horizontal",ratios:i.map(()=>1/i.length),children:i.map(e=>({paneId:e}))}});return 1===i.length&&S(i[0])?i[0]:{orientation:"vertical",ratios:i.map(()=>1/i.length),children:i}}function $(e){if(Array.isArray(e.panes)||(e.panes=[]),e.panes=e.panes.filter(e=>e&&"object"==typeof e),Array.isArray(e.views)){e.views=e.views.filter(e=>e&&"object"==typeof e);for(const t of e.views){const e=t.hidden;"string"==typeof e?t.hidden=[e]:void 0===e||Array.isArray(e)||delete t.hidden}}if(Array.isArray(e.views)&&e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id),n=e.views[0];if(t.length){const e=Array.isArray(n.hidden)?n.hidden:[];n.hidden=[...e,...t.filter(t=>!e.includes(t))]}}if(!Array.isArray(e.views)||!e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id);e.views=[{id:`${e.id}-default`,name:"Default",...t.length?{hidden:t}:{}}]}for(const t of e.panes)"hidden"in t&&delete t.hidden;return e}function E(e){return e.views.find(t=>t.id===e.activeViewId)??e.views[0]}function O(e,t){return!e.hidden?.includes(t)}function A(e,t,n){const i=(e.hidden??[]).filter(e=>e!==t);n||i.push(t),i.length?e.hidden=i:delete e.hidden}function j(e="Default"){return{id:M(),name:e}}const V="paneworks:";function R(e){if("string"!=typeof e||!e.startsWith(V))return null;const[t,n]=e.slice(10).split(":");return t&&n?{workspaceId:t,paneId:n}:null}function F(e,t){const n=(e??"").trim(),i=(t??"").trim();return n?!i||i===n||i.startsWith(`${n} · `)?n:`${n} · ${i}`:i}function z(){return{id:M(),profileId:"",cwd:"",startupCommand:""}}const L=["columns","terminal","code","folder","home","briefcase","cog","database","server","cloud","rocket","flask","bug","wrench","cube","layer-group","sitemap","project-diagram"];function M(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function D(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>D(e));const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=D(e[n]));return t}let N=class{constructor(e,t,n,i){this.config=e,this.notifications=t,this.profilesService=n,this.platform=i,this.cachedProfiles=null,this.cacheTimestamp=0,this.CACHE_TTL=3e4,this.configFiles=new Map,this.workspaceEdited$=new I.Subject}async getCachedProfiles(){const e=Date.now();return(!this.cachedProfiles||e-this.cacheTimestamp>this.CACHE_TTL)&&(this.cachedProfiles=await this.profilesService.getProfiles(),this.cacheTimestamp=e),this.cachedProfiles}getWorkspaces(){const e=this.config.store?.[u]?.workspaces??[];for(const t of e)Array.isArray(t.panes)&&Array.isArray(t.views)&&t.views.length&&!t.panes.some(e=>!e||"hidden"in e)&&!t.views.some(e=>!e||"object"!=typeof e||void 0!==e.hidden&&!Array.isArray(e.hidden))||$(t);return e}async saveWorkspaceQuietly(e){const t=this.getWorkspaces(),n=t.findIndex(t=>t.id===e.id);-1!==n&&(t[n]=e,await this.saveWorkspaces(t),this.writeConfigFile(e))}minPaneSize(e){return{width:e.minPaneWidth||600,height:e.minPaneHeight||260}}planViewAll(e,t,n){const i=E(e),s=e.panes.filter(e=>O(i,e.id)).map(e=>e.id),a=this.minPaneSize(e),r=T(s.length,t,n,a.width,a.height),o=r.reduce((e,t)=>e+t,0),p=s.slice(0,o);return{tree:p.length?W(p,r):null,shown:p}}allPanesLayout(e,t,n){const i=e.panes.map(e=>e.id);if(!i.length)return null;const s=Math.max(1,t??window.innerWidth-210),a=Math.max(1,n??window.innerHeight-80);return W(i,T(i.length,s,a,1,1))}initialLayout(e){return this.allPanesLayout(e)}async saveWorkspaces(e){if(!this.config.store?.[u])throw new Error("Config store not initialized");this.config.store[u].workspaces=e,await this.saveConfig()}async addWorkspace(e){try{const t=this.getWorkspaces();t.push(e),await this.saveWorkspaces(t),this.notifications.info(`Workspace "${e.name}" created`)}catch(t){throw this.notifications.error(`Failed to create workspace "${e.name}"`),t}}async deleteWorkspace(e){const t=this.getWorkspaces(),n=t.find(t=>t.id===e);try{const i=t.filter(t=>t.id!==e);await this.saveWorkspaces(i),this.closeConfigFile(e),n&&this.notifications.info(`Workspace "${n.name}" deleted`)}catch(t){throw this.notifications.error(`Failed to delete workspace "${n?.name||e}"`),t}}async getAvailableProfiles(){return(await this.profilesService.getProfiles()).filter(e=>!e.id?.startsWith("split-layout:"))}cleanupOrphanedProfiles(){if(!this.config.store?.profiles)return;const e=this.config.store.profiles,t=`split-layout:${u}:`,n=e.filter(e=>!e.id?.startsWith(t));n.length!==e.length&&(this.config.store.profiles=n,this.config.save(),console.log(`[${m}] Cleaned up ${e.length-n.length} orphaned profiles`))}async generateTabbyProfile(e){await this.getCachedProfiles();const t=this.initialLayout(e);if(!t)return null;const n=this.sanitizeForProfileId(e.name);return{id:`split-layout:${u}:${n}:${e.id}`,type:"split-layout",name:e.name,group:m,icon:e.icon,color:e.color,isBuiltin:!1,options:{recoveryToken:this.generateRecoveryToken(t,e)}}}async createPaneToken(e,t){return await this.getCachedProfiles(),this.generatePaneToken(t,e.name,e.id)}generateRecoveryToken(e,t){return{type:"app:split-tab",orientation:"horizontal"===e.orientation?"h":"v",ratios:[...e.ratios],paneworksWorkspaceId:t.id,tabTitle:t.name,disableDynamicTitle:!0,children:e.children.map(e=>{if(S(e))return this.generateRecoveryToken(e,t);const n=t.panes.find(t=>t.id===e.paneId);return this.generatePaneToken(n,t.name,t.id)})}}generatePaneToken(e,t,n){const i=this.getProfileById(e.profileId),s=function(e,t){return`${V}${e}:${t}`}(n,e.id),a=F(e.name,"");if(!i)return{type:"app:local-tab",profile:{type:"local",name:"Shell",group:s},savedState:!1,tabTitle:e.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};if(!this.isLocalProfile(i))return{type:`app:${i.type}-tab`,profile:{...i,group:s,disableDynamicTitle:!1},savedState:!1,tabTitle:e.name||i.name,tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};const r=e.cwd||i.options?.cwd||"",o=this.isWslProfile(i),p=i.options?.args||[],d={restoreFromPTYID:!1,command:i.options?.command||"",args:o&&r?[...p,"--cd",r]:p,cwd:o?"":r,env:i.options?.env||{},width:null,height:null,pauseAfterExit:!1,runAsAdministrator:!1};return{type:"app:local-tab",profile:{id:i.id,type:"local",name:i.name||"Shell",group:s,options:d,icon:i.icon||"",color:i.color||"",disableDynamicTitle:!1,weight:0,isBuiltin:!1,isTemplate:!1,terminalColorScheme:null,behaviorOnSessionEnd:"auto"},savedState:!1,tabTitle:e.name||i.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1,cwd:o?"":r}}sanitizeForProfileId(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"workspace"}isLocalProfile(e){return"local"===e.type||e.type?.startsWith("local:")||!1}projectFolder(e){const t=e.panes.find(e=>e.cwd?.trim());let n=e.folder?.trim()||t?.cwd?.trim();if(!n)return null;const i="win32"===process.platform&&(n.startsWith("/")||"~"===n||n.startsWith("~/"));if(i||"~"!==n&&!n.startsWith("~/")||(n=x.homedir()+n.slice(1)),!i)return{path:n,wsl:i,distro:null};const s=t?[t,...e.panes]:e.panes;for(const e of s){const t=this.getProfileById(e.profileId);if(t&&this.isWslProfile(t))return{path:n,wsl:i,distro:this.wslDistro(t)}}return{path:n,wsl:i,distro:null}}async openInVsCode(e){await this.getCachedProfiles();const t=this.projectFolder(e);if(t)if(t.wsl){const e=t.path.startsWith("~/");this.spawnCode("wsl.exe",[...t.distro?["-d",t.distro]:[],"--cd",e?"~":t.path,"code",e?t.path.slice(2):"."])}else this.spawnCode("code",[t.path]);else this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}copyProjectFolder(e){const t=this.projectFolder(e);t?(this.platform.setClipboard({text:t.path}),this.notifications.info(`Copied ${t.path}`)):this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}openConfigInVsCode(e){const t=this.writeConfigFile(e,!0);t&&this.spawnCode("code",[t])}configFilePath(e){const t=this.platform.getConfigPath(),n=P.join(t?P.dirname(t):x.tmpdir(),"paneworks"),i=`-${e.id.replace(/[^A-Za-z0-9_-]/g,"_")}.json`;try{const e=y.readdirSync(n).find(e=>e.endsWith(i));if(e)return P.join(n,e)}catch{}const s=e.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"workspace";return P.join(n,s+i)}writeConfigFile(e,t=!1){let n=this.configFiles.get(e.id);if(!n&&!t)return null;const i=JSON.stringify(e,null,2)+"\n";try{if(!n){const t=this.configFilePath(e);y.mkdirSync(P.dirname(t),{recursive:!0}),n={file:t,written:""},this.configFiles.set(e.id,n);const i=n;y.watchFile(t,{interval:700},()=>this.configFileChanged(e.id,i))}if(t)n.invalid=!1;else{let t=null;try{t=y.readFileSync(n.file,"utf8")}catch{}if(null!==t&&t!==n.written&&t.trim())return this.configFileChanged(e.id,n),n.file}return i===n.written||n.invalid||(y.writeFileSync(n.file,i),n.written=i),n.file}catch(e){return console.error(`[${m}] Could not write the workspace file:`,e),this.notifications.error(`Could not write the workspace file: ${e}`),null}}closeConfigFile(e){const t=this.configFiles.get(e);t&&(y.unwatchFile(t.file),this.configFiles.delete(e))}async configFileChanged(e,t){let n;try{n=y.readFileSync(t.file,"utf8")}catch{return}if(n===t.written||!n.trim())return;t.written=n;const i=this.getWorkspaces(),s=i.findIndex(t=>t.id===e);if(-1===s)return void this.closeConfigFile(e);let a;try{a=this.parseWorkspace(n,i[s])}catch(e){return t.invalid?this.notifications.error(`${i[s].name}: not applied, ${e.message}`):this.notifications.error(`${i[s].name}: not applied, ${e.message}. Until the file is valid, sidebar changes are not written to it; "Edit settings in VS Code" starts it over.`),void(t.invalid=!0)}t.invalid=!1;const r=i[s],o=D(r);for(const e of Object.keys(r))delete r[e];Object.assign(r,a),await this.saveWorkspaces(i),this.writeConfigFile(r),this.notifications.info(`${r.name}: settings applied from the file`),this.workspaceEdited$.next({workspaceId:e,before:o})}parseWorkspace(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error(`invalid JSON (${e.message})`)}if(!n||"object"!=typeof n||Array.isArray(n))throw new Error("the file must hold one JSON object");if(!Array.isArray(n.panes)||!n.panes.length)throw new Error('"panes" must be a list with at least one pane');for(const e of n.panes){if(!e||"object"!=typeof e)throw new Error("every pane must be an object");if("string"==typeof e.id&&e.id||(e.id=M()),"string"!=typeof e.profileId)throw new Error(`pane ${e.name??e.id}: "profileId" must be a string`);for(const t of["name","cwd","startupCommand","color"])if(null===e[t]&&delete e[t],void 0!==e[t]&&"string"!=typeof e[t])throw new Error(`pane ${e.id}: "${t}" must be a string`)}for(const e of["name","folder","color","icon","activeViewId"])if(null===n[e]&&delete n[e],void 0!==n[e]&&"string"!=typeof n[e])throw new Error(`"${e}" must be a string`);for(const e of["minPaneWidth","minPaneHeight"])if(null===n[e]&&delete n[e],!(void 0===n[e]||"number"==typeof n[e]&&n[e]>0))throw new Error(`"${e}" must be a number above 0`);if(void 0!==n.launchOnStartup&&"boolean"!=typeof n.launchOnStartup)throw new Error('"launchOnStartup" must be true or false');const i=n.panes.map(e=>e.id);if(new Set(i).size!==i.length)throw new Error("two panes have the same id");if(void 0!==n.views){if(!Array.isArray(n.views))throw new Error('"views" must be a list');const e=new Set;for(const t of n.views){if(!t||"object"!=typeof t)throw new Error("every view must be an object");if("string"==typeof t.id&&t.id&&!e.has(t.id)||(t.id=M()),e.add(t.id),"string"!=typeof t.name||!t.name.trim())throw new Error('every view needs a "name"');if(void 0!==t.hidden&&!Array.isArray(t.hidden))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);if(t.hidden){if(t.hidden.some(e=>"string"!=typeof e))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);t.hidden=t.hidden.filter(e=>i.includes(e)),t.hidden.length||delete t.hidden}}}return n.id=t.id,"string"==typeof n.name&&n.name.trim()||(n.name=t.name),$(D(n))}spawnCode(e,t){let n=e,i=t,s={detached:!0,stdio:"ignore",windowsHide:!0};if("win32"===process.platform&&"code"===e){if(t.some(e=>/["%\r\n]/.test(e)))return void this.notifications.error('This path has characters that cannot be passed to VS Code safely: " or %');n=process.env.ComSpec||"cmd.exe",i=["/d","/v:off","/s","/c",`"code ${t.map(e=>`"${e.replace(/(\\+)$/,"$1$1")}"`).join(" ")}"`],s={...s,windowsVerbatimArguments:!0}}try{const a=(0,v.spawn)(n,i,s);a.on("error",n=>{if("ENOENT"===n.code&&"win32"!==process.platform&&"code"===e){const e=process.env.SHELL??"",n=/\/(ba|z|k|da)?sh$/.test(e)?e:"/bin/sh",i=(0,v.spawn)(n,["-lc",'exec code "$@"',"code",...t],s);return i.on("error",()=>this.vsCodeFailed()),i.on("exit",e=>{e&&this.vsCodeFailed()}),void i.unref()}this.vsCodeFailed()}),a.on("exit",e=>{e&&this.vsCodeFailed()}),a.unref()}catch{this.vsCodeFailed()}}vsCodeFailed(){this.notifications.error('Could not start VS Code. Is the "code" command on your PATH?')}wslDistro(e){const t=e.options?.args??[],n=t.findIndex(e=>"-d"===e||"--distribution"===e);return n>=0&&t[n+1]?t[n+1]:null}isWslProfile(e){if(e.id?.startsWith("local:wsl"))return!0;const t=(e.options?.command||"").toLowerCase();return"wsl.exe"===t||"wsl"===t||t.endsWith("\\wsl.exe")||t.endsWith("/wsl.exe")}getProfileById(e){return(this.config.store?.profiles??[]).find(t=>t.id===e)||this.cachedProfiles?.find(t=>t.id===e)}collectStartupCommands(e){return e.panes.filter(e=>e.startupCommand).map(e=>({paneId:e.id,command:e.startupCommand}))}getWorkspace(e){return this.getWorkspaces().find(t=>t.id===e)}async saveConfig(){try{await this.config.save()}catch(e){throw console.error(`[${m}] Save error:`,e),e}}};N=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)({providedIn:"root"}),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.ConfigService,f.NotificationsService,f.ProfilesService,f.PlatformService])],N);var H=c(349),q=c(439);const B=[0,300,1e3,3e3,8e3];let _=class{constructor(e,t){this.app=e,this.workspaces=t,this.workspaceSplitFound$=new I.Subject,this.pendingCommands=new Map,this.watchedSplits=new WeakSet,this.attachedPanes=new WeakSet,this.app.tabOpened$.subscribe(e=>this.onTabOpened(e))}registerCommands(e){for(const t of e)this.pendingCommands.set(t.paneId,t)}onTabOpened(e){e instanceof f.SplitTabComponent?this.watchSplit(e):e instanceof H.BaseTerminalTabComponent&&this.processPane(e,null)}watchSplit(e){if(this.watchedSplits.has(e))return;this.watchedSplits.add(e);const t=()=>this.scanSplit(e);e.initialized$?.subscribe({complete:t}),e.tabAdded$?.subscribe(()=>t());for(const e of B)setTimeout(t,e)}scanSplit(e){for(const t of e.getAllTabs())t instanceof H.BaseTerminalTabComponent&&this.processPane(t,e)}processPane(e,t){const n=R(e.profile?.group);n&&(t&&(this.pinSplitTitle(t,n.workspaceId),this.workspaceSplitFound$.next({split:t,workspaceId:n.workspaceId})),this.attachedPanes.has(e)||(this.attachedPanes.add(e),this.attachLabelSync(e,n.workspaceId,n.paneId),this.runPendingCommand(e,n.paneId)))}pinSplitTitle(e,t){const n=this.workspaces.getWorkspace(t)?.name;e.disableDynamicTitle=!0,n&&e.title!==n&&e.setTitle(n)}attachLabelSync(e,t,n){const i=e;i.disableDynamicTitle=!1;let s=e.customTitle,a=!0;const r=()=>{if(!a)return;if(e.customTitle!==s)return void(a=!1);const r=this.workspaces.getWorkspace(t),o=r?function(e,t){return e.panes.find(e=>e.id===t)}(r,n)?.name:void 0,p=F(o,e.title);p&&p!==e.customTitle&&(s=p,"function"==typeof i.setCustomTitle?i.setCustomTitle(p):e.customTitle=p)},o=e.setTitle.bind(e);e.setTitle=e=>{o(e),r()},r()}runPendingCommand(e,t,n=!1){const i=this.pendingCommands.get(t);if(!i?.command)return;this.pendingCommands.delete(t);const s=i.command,a=()=>{console.log(`[${m}] Sending startup command:`,s),e.sendInput(s+"\r"),this.clearProfileArgs(e)},r=e.sessionChanged$;if(!e.session&&r&&!n)return this.pendingCommands.set(t,i),void r.pipe((0,I.first)(e=>!!e),(0,I.timeout)(5e3),(0,q.catchError)(()=>(0,I.of)(null))).subscribe(()=>this.runPendingCommand(e,t,!0));e.session?.output$?e.session.output$.pipe((0,I.first)(),(0,I.timeout)(2e3),(0,q.catchError)(()=>(0,I.of)(null))).subscribe(()=>setTimeout(a,100)):setTimeout(a,500)}clearProfileArgs(e){const t=e.profile;t?.options?.args&&(t.options.args=[])}};_=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,N])],_);const Q=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"];function J(e){const t=e.trim().split(/[\\/]+/).filter(Boolean),n=t[t.length-1]??"";return/^[a-z]:$/i.test(n)||"~"===n?"":n}let G=class{constructor(e,t,n,i,s,a,r){this.app=e,this.profilesService=t,this.runtime=n,this.workspaces=i,this.tabsService=s,this.tabRecovery=a,this.platform=r,this.states=new WeakMap,this.active=new Set,this.resizeTimer=null,this.profiles=[],this.watchedSessions=new WeakSet,this.autofocus=!1,this.runtime.workspaceSplitFound$.subscribe(({split:e,workspaceId:t})=>this.attach(e,t)),this.workspaces.workspaceEdited$.subscribe(({workspaceId:e,before:t})=>this.syncEdited(e,t)),window.addEventListener("resize",()=>{this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>this.refreshAllGrids(),250)})}findOpenTab(e){for(const t of this.active)if(t.workspaceId===e)return t.split;for(const t of this.app.tabs)if(t instanceof f.SplitTabComponent&&t.getAllTabs().some(t=>R(t.profile?.group)?.workspaceId===e))return t;return null}async openWorkspace(e){const t=this.findOpenTab(e);if(t)return void this.app.selectTab(t);const n=this.workspaces.getWorkspace(e);if(!n)return;const i=this.workspaces.collectStartupCommands(n);i.length&&this.runtime.registerCommands(i);const s=await this.workspaces.generateTabbyProfile(n);s&&this.profilesService.openNewTabForProfile(s)}async createWorkspace(){await this.loadProfiles();const e=await this.askWorkspaceSetup();if(!e)return;const t=new Set(this.workspaces.getWorkspaces().map(e=>e.name));let n=J(e.folder);if(!n){let e=1;for(;t.has(`Workspace ${e}`);)e++;n=`Workspace ${e}`}let i=n;for(let e=2;t.has(i);e++)i=`${n} ${e}`;const s=function(e=""){return{id:M(),name:e,icon:L[Math.floor(Math.random()*L.length)],panes:[z(),z()],views:[j()],launchOnStartup:!1}}(i);s.panes=Array.from({length:e.panes},()=>({id:z().id,profileId:e.profileId,...e.folder?{cwd:e.folder}:{},...e.command?{startupCommand:e.command}:{}})),e.folder&&(s.folder=e.folder),await this.workspaces.addWorkspace(s),await this.openWorkspace(s.id)}askWorkspaceSetup(){return this.ensureStyles(),new Promise(e=>{const t=this.node("div","paneworks-overlay"),n=this.node("div","paneworks-sidebar pw-dialog"),i=this.node("div","pw-form"),s=document.createElement("select");s.className="pw-input";for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,s.append(t)}const a=this.profiles.find(e=>"local"===e.type||e.type?.startsWith("local:"))??this.profiles[0];s.value=a?.id??"";const r=this.input("text","","C:\\path or /home/user"),o=this.button("pw-btn","Browse…","Pick a folder",async()=>{try{const e=await this.platform.pickDirectory();e&&(r.value=e),h()}catch{}}),p=this.node("div","pw-folder-row");p.append(r,o);const d=this.input("text","","e.g. claude (optional)"),c=this.input("number","4","4");c.min="1",c.max="16",c.classList.add("pw-size");const l=this.node("div","pw-hint"),h=()=>{const e=J(r.value);l.textContent=e?`Workspace name: ${e}`:"The workspace is named after the folder."};r.addEventListener("input",h),h(),i.append(this.node("div","pw-dialog-title","New workspace"),this.field("Profile",s),this.field("Folder",p),l,this.field("Startup command",d),this.field("Panes",c),this.node("div","pw-hint","Every pane starts with this profile, folder and command. Change single panes later in the sidebar."));const w=n=>{t.remove(),e(n)},f=()=>w({profileId:s.value,folder:r.value.trim(),command:d.value.trim(),panes:Math.min(16,Math.max(1,Math.round(c.value.trim()&&Number.isFinite(Number(c.value))?Number(c.value):4)))});for(const e of[r,d,c])e.addEventListener("keydown",e=>{"Enter"===e.key&&f(),"Escape"===e.key&&w(null)});s.addEventListener("keydown",e=>{e.stopPropagation(),"Escape"===e.key&&w(null)});const u=this.node("div","pw-actions");u.append(this.button("pw-btn primary","Create","Create and open the workspace",f),this.button("pw-btn","Cancel","Close without creating",()=>w(null))),i.append(u),n.append(i),t.append(n),t.addEventListener("mousedown",e=>{e.target===t&&w(null)}),document.body.append(t),setTimeout(()=>r.focus(),0)})}async loadProfiles(){this.profiles.length||(this.profiles=await this.workspaces.getAvailableProfiles())}applyTabColor(e){const t=this.workspaces.getWorkspace(e.workspaceId)?.color||null;t?e.split.color=t:e.appliedColor&&(e.split.color=null),e.appliedColor=t}attach(e,t){const n=this.states.get(e);if(n)return void(n.sidebar?.isConnected||this.mountSidebar(n));const i={split:e,workspaceId:t,view:{kind:"all"},appliedPlan:null,parked:new Map,sidebar:null,collapsed:this.loadCollapsed(t),busy:!1,dragging:!1,editingPaneId:null,editingViewId:null,menuOpen:!1,timer:null,unseen:new Set,starting:!0,syncPending:!1,restartPending:new Set,drafts:new Map,draftOwner:null,appliedColor:null,leftAt:new Map};this.states.set(e,i),this.active.add(i),this.loadProfiles(),this.applyTabColor(i),e.destroyed$.subscribe(()=>{for(const e of i.parked.values())e.destroy();i.parked.clear(),i.timer&&clearInterval(i.timer),i.sidebar?.remove(),this.active.delete(i)}),e.visibility$?.subscribe(e=>{e&&setTimeout(()=>{i.syncPending?this.syncTab(i):this.refreshGrid(i)},50)}),this.mountSidebar(i),i.timer=setInterval(()=>this.render(i),1e3),this.startAllPanes(i)}async showAll(e,t=!1){const n=this.workspaces.getWorkspace(e.workspaceId),i=this.paneArea(e);if(!n||!i)return;const s=this.workspaces.planViewAll(n,i.width,i.height),a=JSON.stringify(s.tree);a!==e.appliedPlan&&console.log(`[${m}] View all:`,{area:i,shown:s.shown.length,min:this.workspaces.minPaneSize(n)});const r="all"===e.view.kind;if(e.view={kind:"all"},!s.tree&&n.panes.length&&(t||!r||"empty"!==e.appliedPlan)){const t=n.panes[0].id;await this.apply(e,n,{orientation:"horizontal",ratios:[1],children:[{paneId:t}]})&&(e.appliedPlan="empty")}!s.tree||!t&&r&&a===e.appliedPlan||await this.apply(e,n,s.tree)&&(e.appliedPlan=a),this.render(e,!0)}async showFocus(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(!n)return;const i={orientation:"horizontal",ratios:[1],children:[{paneId:t}]};await this.apply(e,n,i)&&(e.view={kind:"focus",paneId:t},e.appliedPlan=null),this.render(e,!0)}async reapplyView(e){"focus"===e.view.kind?await this.showFocus(e,e.view.paneId):await this.showAll(e,!0)}refreshGrid(e){"all"!==e.view.kind||e.busy||e.starting||this.showAll(e)}async startAllPanes(e){const t=e.view;e.starting=!0;try{const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=await this.waitFor(()=>this.paneArea(e),3e3),i=t.panes.some(t=>!this.livePanes(e).has(t.id)),s=this.workspaces.allPanesLayout(t,n?.width,n?.height);i&&s&&await this.apply(e,t,s),await this.waitFor(()=>{const t=[...this.livePanes(e).values()];return!(!t.length||!t.every(e=>e.session))||null},8e3)}finally{e.starting=!1}"focus"===t.kind?await this.showFocus(e,t.paneId):await this.showAll(e,!0)}async waitFor(e,t){const n=Date.now()+t;for(;;){const t=e();if(t)return t;if(Date.now()>n)return null;await new Promise(e=>setTimeout(e,100))}}refreshAllGrids(){for(const e of this.active)this.refreshGrid(e)}paneArea(e){const t=this.splitElement(e)?.getBoundingClientRect();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:null}async apply(e,t,n){if(e.busy)return!1;e.busy=!0;try{const i=e.split,s=new Map(t.panes.map(e=>[e.id,e])),a=this.livePanes(e),r=C(n).filter(e=>s.has(e));for(const e of r)if(!a.has(e)){const n=await this.createPane(t,s.get(e));n&&a.set(e,n)}const o=r.filter(e=>a.has(e));if(!o.length)return!1;for(const t of e.split.getAllTabs()){const n=this.paneIdOf(t);n&&o.includes(n)||(t.removeFromContainer(),i.viewRefs?.delete(t),t.parent=null,n?(e.parked.set(n,t),e.leftAt.set(n,Date.now())):t.destroy())}const p=this.buildContainer(n,a);if(!p)return!1;i.maximizedTab=null,i.root=p;for(const t of o){const n=a.get(t);e.unseen.delete(t),n.clearActivity(),i.viewRefs?.has(n)||(e.parked.delete(t),n.parent=e.split,n.emitVisibility?.(i.visibility?.value??!0),i.attachTabView(n),i.onAfterTabAdded(n))}return i.layout(),e.split.focus(a.get(o[0])),i.recoveryStateChangedHint?.next(),this.nudgeResize(),setTimeout(()=>this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),100),!0}catch(e){return console.error(`[${m}] Layout change failed:`,e),!1}finally{e.busy=!1}}buildContainer(e,t){const n=[],i=[];if(e.children.forEach((s,a)=>{const r=S(s)?this.buildContainer(s,t):t.get(s.paneId)??null;r&&(n.push(r),i.push(e.ratios[a]??1))}),!n.length)return null;const s=i.reduce((e,t)=>e+t,0)||1,a=new f.SplitContainer;return a.orientation="horizontal"===e.orientation?"h":"v",a.children=n,a.ratios=i.map(e=>e/s),a}async createPane(e,t){try{const n=await this.workspaces.createPaneToken(e,t),i=await this.tabRecovery.recoverTab(n);return i?(t.startupCommand&&this.runtime.registerCommands([{paneId:t.id,command:t.startupCommand}]),this.tabsService.create(i)):null}catch(e){return console.error(`[${m}] Could not create pane:`,t,e),null}}livePanes(e){const t=new Map;for(const n of e.split.getAllTabs()){const e=this.paneIdOf(n);e&&t.set(e,n)}for(const[n,i]of e.parked)t.set(n,i);return t}paneIdOf(e){return R(e.profile?.group)?.paneId??null}nudgeResize(){setTimeout(()=>window.dispatchEvent(new Event("resize")),50)}async toggleShown(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=E(n);A(s,t,!O(s,t)),await this.workspaces.saveWorkspaceQuietly(n),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async duplicatePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s={...i,id:z().id};i.name&&(s.name=`${i.name} copy`),n.panes.splice(n.panes.indexOf(i)+1,0,s);for(const e of n.views)A(e,s.id,O(e,i.id));await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=s.id,e.editingViewId=null,this.render(e,!0),await this.startAllPanes(e)}async syncEdited(e,t){const n=this.workspaces.getWorkspace(e),i=new Map(t.panes.map(e=>[e.id,e])),s=(n?.panes??[]).filter(e=>{const t=i.get(e.id);return!!t&&((t.startupCommand??"")!==(e.startupCommand??"")||(t.cwd??"")!==(e.cwd??"")||t.profileId!==e.profileId)}).map(e=>e.id);for(const t of[...this.active])if(t.workspaceId===e){for(const e of s)t.restartPending.add(e);await this.syncTab(t)}}async syncTab(e){await this.waitFor(()=>!e.busy&&!e.starting,1e4);const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!this.paneArea(e))return e.syncPending=!0,e.split.setTitle(t.name),void this.applyTabColor(e);e.syncPending=!1,e.split.setTitle(t.name),this.applyTabColor(e);const n=new Set(t.panes.map(e=>e.id));e.editingPaneId&&!n.has(e.editingPaneId)&&(e.editingPaneId=null),e.editingViewId&&!t.views.some(t=>t.id===e.editingViewId)&&(e.editingViewId=null),"focus"!==e.view.kind||n.has(e.view.paneId)||(e.view={kind:"all"}),await this.reapplyView(e);const i=()=>[...this.livePanes(e)].filter(([e])=>!n.has(e)),s=e.view;i().some(([,t])=>t.parent===e.split)&&await this.showFocus(e,t.panes[0].id);for(const[t,n]of i())n.parent!==e.split&&(e.parked.delete(t),n.destroy());"all"===s.kind&&"focus"===e.view.kind&&await this.showAll(e,!0);for(const t of[...e.restartPending])e.restartPending.delete(t),n.has(t)&&this.livePanes(e).has(t)&&await this.restartPane(e,t);this.render(e,!0),t.panes.some(t=>!this.livePanes(e).has(t.id))&&await this.startAllPanes(e)}async movePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId);if(!i)return;const s=i.panes.findIndex(e=>e.id===t);if(-1===s||t===n)return;const[a]=i.panes.splice(s,1),r=n?i.panes.findIndex(e=>e.id===n):-1;i.panes.splice(-1===r?i.panes.length:r,0,a),await this.workspaces.saveWorkspaceQuietly(i),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async addPane(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;await this.loadProfiles();const n=t.panes[t.panes.length-1],i={...z(),profileId:n?.profileId||this.profiles[0]?.id||"",cwd:n?.cwd||""};t.panes.push(i);const s=E(t);for(const e of t.views)e!==s&&A(e,i.id,!1);await this.workspaces.saveWorkspaceQuietly(t),e.editingPaneId=i.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)}async savePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.panes.find(e=>e.id===t);if(i&&s){Object.assign(s,n);for(const e of["name","color"])s[e]||delete s[e];await this.workspaces.saveWorkspaceQuietly(i),e.editingPaneId=null,this.render(e,!0),this.livePanes(e).has(t)||await this.startAllPanes(e)}}async restartPane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=this.livePanes(e).get(t),a=await this.createPane(n,i);a&&(s&&e.parked.get(t)===s?(e.parked.set(t,a),s.destroy()):s&&s.parent===e.split?(a.parent=e.split,e.split.replaceTab(s,a),e.split.viewRefs?.delete(s),s.destroy(),e.split.layout(),e.split.focus(a),this.nudgeResize()):e.parked.set(t,a),this.render(e,!0))}async removePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;if(n.panes.length<=1)return void window.alert("A workspace needs at least one pane. Delete the workspace from its menu instead.");const s=i.name||i.startupCommand||"this pane";if(!window.confirm(`Remove "${s}" from ${n.name}? Its terminal is closed.`))return;n.panes=n.panes.filter(e=>e.id!==t);for(const e of n.views)A(e,t,!0);await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=null;const a=this.livePanes(e).get(t);a&&a.parent===e.split&&("focus"===e.view.kind&&e.view.paneId===t&&(e.view={kind:"all"}),await this.reapplyView(e));const r=this.livePanes(e).get(t);if(r&&r.parent===e.split&&e.split.getAllTabs().length<=1){const t=n.panes[0];A(E(n),t.id,!0),await this.workspaces.saveWorkspaceQuietly(n),await this.showFocus(e,t.id)}e.parked.delete(t),this.livePanes(e).get(t)?.destroy(),a?.destroy(),this.render(e,!0)}async selectView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);n&&n.views.some(e=>e.id===t)&&(n.activeViewId!==t&&(n.activeViewId=t,await this.workspaces.saveWorkspaceQuietly(n)),await this.showAll(e,!0))}async addView(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=new Set(t.views.map(e=>e.name));let i=t.views.length+1;for(;n.has(`View ${i}`);)i++;const s=j(`View ${i}`);t.views.push(s),t.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(t),e.editingViewId=s.id,e.editingPaneId=null,e.menuOpen=!1,await this.showAll(e,!0)}async renameView(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.views.find(e=>e.id===t);i&&s&&(s.name=n.trim()||s.name,await this.workspaces.saveWorkspaceQuietly(i),e.editingViewId=null,this.render(e,!0))}async duplicateView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;const s={...j(`${i.name} copy`),...i.hidden?.length?{hidden:[...i.hidden]}:{}};n.views.splice(n.views.indexOf(i)+1,0,s),n.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=s.id,await this.showAll(e,!0)}async deleteView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;if(n.views.length<=1)return void window.alert("A workspace needs at least one view.");if(!window.confirm(`Delete the view "${i.name}"? Its panes keep running.`))return;const s=E(n)===i;n.views=n.views.filter(e=>e!==i),s&&(n.activeViewId=n.views[0].id),await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=null,s&&"all"===e.view.kind?await this.showAll(e,!0):this.render(e,!0)}async saveWorkspaceSettings(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(n){n.name=t.name.trim()||n.name;for(const e of["minPaneWidth","minPaneHeight"]){const i=t[e];i&&i>0?n[e]=Math.round(i):delete n[e]}t.launchOnStartup?n.launchOnStartup=!0:n.launchOnStartup=!1,t.color?n.color=t.color:delete n.color,t.folder.trim()?n.folder=t.folder.trim():delete n.folder,await this.workspaces.saveWorkspaceQuietly(n),e.split.setTitle(n.name),this.applyTabColor(e),e.menuOpen=!1,"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}}async deleteWorkspace(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!window.confirm(`Delete the workspace "${t.name}"? Its tab and all its panes are closed.`))return;await this.workspaces.deleteWorkspace(t.id);const n=this.app;"function"==typeof n.closeTab?n.closeTab(e.split,!1):e.split.destroy()}splitElement(e){const t=e.split;for(const e of[t.hostView,t.viewContainerEmbeddedRef]){const t=e?.rootNodes?.[0];if(t instanceof HTMLElement)return t}return null}mountSidebar(e){const t=this.splitElement(e),n=t?.parentElement;t&&n?(e.sidebar||(e.sidebar=document.createElement("div"),e.sidebar.className="paneworks-sidebar",this.ensureStyles()),n.insertBefore(e.sidebar,t),t.setAttribute("data-paneworks",""),this.render(e,!0),this.nudgeResize(),setTimeout(()=>this.refreshGrid(e),100)):setTimeout(()=>{!e.sidebar?.isConnected&&this.active.has(e)&&this.mountSidebar(e)},500)}applyLabelColors(e,t){const n=this.splitElement(e);if(!n||!t)return;const i=new Map(t.panes.map(e=>[e.id,e.color])),s=Array.from(n.querySelectorAll(":scope > split-tab-pane-label")),a=e.split.getAllTabs();s.forEach((e,t)=>{const n=e.querySelector(".custom-name");if(!n)return;const s=a[t]?this.paneIdOf(a[t]):null,r=s?i.get(s):void 0;r?(n.style.background=r,n.style.color=function(e){const t=e.replace("#","");if(!/^[0-9a-f]{6}$/i.test(t))return"#fff";const[n,i,s]=[0,2,4].map(e=>parseInt(t.slice(e,e+2),16)/255).map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n+.7152*i+.0722*s>.4?"#000":"#fff"}(r)):(n.style.removeProperty("background"),n.style.removeProperty("color"))})}watchOutput(e){for(const[t,n]of this.livePanes(e)){const i=n.session;i?.output$&&!this.watchedSessions.has(i)&&(this.watchedSessions.add(i),i.output$.subscribe(()=>{n.parent===e.split||e.unseen.has(t)||Date.now()-(e.leftAt.get(t)??0)<2500||e.unseen.add(t)}))}}render(e,t=!1){const n=e.sidebar;if(!n||!n.isConnected||e.dragging)return;if(this.watchOutput(e),this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),!t&&(e.editingPaneId||e.editingViewId||e.menuOpen))return;const i=this.workspaces.getWorkspace(e.workspaceId),s=this.livePanes(e),a=new Set(e.split.getAllTabs().map(e=>this.paneIdOf(e))),r=JSON.stringify([e.collapsed,e.view,e.editingPaneId,e.editingViewId,e.menuOpen,i,i?.panes.map(t=>{const n=s.get(t.id);return[n?.customTitle,n?.title,e.unseen.has(t.id),a.has(t.id)]})]);if(!t&&n.__pwSignature===r)return;n.__pwSignature=r;const o=e.editingPaneId?`p:${e.editingPaneId}`:e.editingViewId?`v:${e.editingViewId}`:e.menuOpen?"m":null,p=o!==e.draftOwner;p&&(e.drafts.clear(),e.draftOwner=o);const d=document.activeElement,c=d&&n.contains(d)?d.dataset?.draft??null:null,l=c&&"number"==typeof d.selectionStart?[d.selectionStart,d.selectionEnd]:null;this.autofocus=p,n.classList.toggle("collapsed",e.collapsed),n.style.flex=`0 0 ${e.collapsed?22:210}px`,n.textContent="";const h=this.button("pw-icon-btn pw-toggle",e.collapsed?"»":"«",e.collapsed?"Show sidebar":"Hide sidebar",()=>{e.collapsed=!e.collapsed,this.saveCollapsed(e.workspaceId,e.collapsed),this.render(e,!0),this.nudgeResize()});if(e.collapsed||!i)return void n.append(h);const w=this.node("div","pw-header"),f=this.button("pw-ws","","Workspace menu",()=>{e.menuOpen=!e.menuOpen,e.editingPaneId=null,e.editingViewId=null,this.render(e,!0)});f.append(this.node("span","pw-ws-name",i.name),this.node("span","pw-caret",e.menuOpen?"▴":"▾"));const u=this.workspaces.projectFolder(i),m=this.button("pw-icon-btn pw-code","",u?`Open ${u.path} in VS Code`:"Open in VS Code (no project folder yet: set one in the workspace menu)",()=>this.workspaces.openInVsCode(i));m.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>\n</svg>';const g=this.button("pw-icon-btn pw-code","",u?`Copy ${u.path}`:"Copy the project folder path (no project folder yet: set one in the workspace menu)",()=>this.workspaces.copyProjectFolder(i));g.innerHTML='<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>\n</svg>',w.append(f,g,m,h),n.append(w),e.menuOpen&&n.append(this.workspaceMenu(e,i));const b=E(i),k=this.node("div","pw-section");k.append(this.node("span","","Views"),this.button("pw-icon-btn pw-add","+","Add a view (all panes on)",()=>this.addView(e))),n.append(k);for(const t of i.views)n.append(this.viewRow(e,i,t,t===b,a)),e.editingViewId===t.id&&n.append(this.viewEditor(e,i,t));i.panes.some(e=>O(b,e.id))||n.append(this.node("div","pw-hint pw-empty-view",`Nothing is switched on in "${b.name}": switch panes on below.`));const v=this.node("div","pw-section");v.append(this.node("span","pw-section-title",`Panes · ${b.name}`),this.button("pw-icon-btn pw-add","+","Add a pane",()=>this.addPane(e))),n.append(v);const y="focus"===e.view.kind?e.view.paneId:null,x=this.node("div","pw-list");for(const t of i.panes)x.append(this.paneRow(e,t,s.get(t.id),a.has(t.id),y,O(b,t.id),b.name)),e.editingPaneId===t.id&&x.append(this.paneEditor(e,t));const P=this.node("div","pw-drop-end");if(this.makeDropTarget(e,P,null),x.append(P),n.append(x),c){const e=n.querySelector(`[data-draft="${c}"]`);if(e&&(e.focus(),l))try{e.setSelectionRange(l[0],l[1])}catch{}}}draft(e,t,n){n.dataset.draft=t;const i=n instanceof HTMLInputElement&&"checkbox"===n.type,s=e.drafts.get(t);void 0!==s&&(i?n.checked="1"===s:n.value=s);const a=()=>e.drafts.set(t,i?n.checked?"1":"0":n.value);return n.addEventListener("input",a),n.addEventListener("change",a),n}draftColor(e,t,n){return this.colorPicker(e.drafts.get(t)??n,n=>e.drafts.set(t,n))}paneRow(e,t,n,i,s,a,r){const o=(n?n.customTitle||n.title:"")||t.name||t.startupCommand||"New pane",p=[t.name,t.startupCommand].filter(Boolean).join(" · "),d=a&&!i&&"all"===e.view.kind,c=!i&&e.unseen.has(t.id),l=["pw-row","pw-pane"];i&&l.push("onscreen"),t.id===s&&l.push("focused"),a||l.push("off"),e.editingPaneId===t.id&&l.push("editing");const h=this.node("div",l.join(" "));h.title=[i?"On screen":n?"Running, not on screen":"Not running (shown again by a view or its title)",a?d?"switched on, but no room at the minimum pane size":"":`switched off in "${r}"`].filter(Boolean).join(" · "),h.draggable=!0,h.append(this.node("span","pw-handle","⋮⋮")),h.addEventListener("dragstart",n=>{e.dragging=!0,n.dataTransfer?.setData("text/plain",t.id),n.dataTransfer&&(n.dataTransfer.effectAllowed="move"),h.classList.add("dragging")}),h.addEventListener("dragend",()=>{e.dragging=!1,h.classList.remove("dragging"),this.render(e,!0)}),this.makeDropTarget(e,h,t.id);const w=this.node("span","pw-pane-color"+(t.color?"":" none"));t.color&&(w.style.background=t.color),w.title=t.color?`Label colour ${t.color}`:"No label colour",h.append(w);const f=this.node("span","pw-text"),u=this.node("span","pw-main");if(u.append(this.node("span","pw-name",o)),c){const e=this.node("span","pw-news","new");e.title="New output since it left the screen",u.append(e)}f.append(u),(p||d)&&f.append(this.node("span","pw-sub",[p,d?"no room":""].filter(Boolean).join(" · "))),f.onclick=()=>{t.id===s?this.showAll(e,!0):this.showFocus(e,t.id)},f.title=t.id===s?`Back to "${r}"`:"Show this pane alone";const m=this.node("label","pw-switch");m.title=a?`On: shown in "${r}"`:`Off: not in "${r}"`;const g=document.createElement("input");g.type="checkbox",g.checked=a,g.onchange=()=>this.toggleShown(e,t.id),m.append(g,this.node("span","pw-slider")),m.addEventListener("click",e=>e.stopPropagation());const b=this.button("pw-icon-btn pw-more","⋯","Edit pane",()=>{e.editingPaneId=e.editingPaneId===t.id?null:t.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)});return h.append(f,m,b),h}viewRow(e,t,n,i,s){const a=t.panes.filter(e=>O(n,e.id)),r=i&&"all"===e.view.kind,o=a.filter(e=>s.has(e.id)).length,p=["pw-row","pw-all","pw-view"];r?p.push("active"):i&&p.push("selected"),e.editingViewId===n.id&&p.push("editing");const d=this.node("div",p.join(" "));return d.append(this.node("span","pw-main",n.name),this.node("span","pw-count",r?`${o} / ${a.length}`:`${a.length} on`),this.button("pw-icon-btn pw-more","⋯","Edit view",()=>{e.editingViewId=e.editingViewId===n.id?null:n.id,e.editingPaneId=null,e.menuOpen=!1,this.render(e,!0)})),d.title=i?"Selected view: the pane switches below belong to it. Click to show its panes in a grid":"Select this view and show its switched-on panes in a grid",d.onclick=()=>this.selectView(e,n.id),d}viewEditor(e,t,n){const i=this.node("div","pw-form"),s=this.draft(e,"name",this.input("text",n.name,"View name"));i.append(this.field("Name",s),this.node("div","pw-hint","Select the view, then use the pane switches to choose what it shows."));const a=()=>this.renameView(e,n.id,s.value);s.addEventListener("keydown",t=>{"Enter"===t.key&&a(),"Escape"===t.key&&(e.editingViewId=null,this.render(e,!0))});const r=this.node("div","pw-actions");return r.append(this.button("pw-btn primary","Save","Save the view name",a),this.button("pw-btn","Duplicate","New view with the same switches",()=>this.duplicateView(e,n.id))),t.views.length>1&&r.append(this.button("pw-btn danger","Delete","Delete this view (panes keep running)",()=>this.deleteView(e,n.id))),i.append(r),this.autofocus&&setTimeout(()=>{s.focus(),s.select()},0),i}paneEditor(e,t){const n=this.node("div","pw-form"),i=this.draft(e,"name",this.input("text",t.name??"","optional")),s=this.draft(e,"command",this.input("text",t.startupCommand??"","e.g. c 1")),a=this.draft(e,"cwd",this.input("text",t.cwd??"","C:\\path or /home/user")),r=document.createElement("select");r.className="pw-input";const o=document.createElement("option");o.value="",o.textContent="-- profile --",r.append(o);for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,r.append(t)}r.value=t.profileId??"",this.draft(e,"profile",r);const p=this.draftColor(e,"color",t.color??"");n.append(this.field("Name",i),this.field("Label colour",p.element),this.field("Startup command",s),this.field("Folder",a),this.field("Profile",r),this.node("div","pw-hint","Command, folder and profile apply when the pane (re)starts."));const d=()=>this.savePane(e,t.id,{name:i.value.trim(),color:p.value(),startupCommand:s.value.trim(),cwd:a.value.trim(),profileId:r.value});for(const t of[i,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&d(),"Escape"===t.key&&(e.editingPaneId=null,this.render(e,!0))});const c=this.node("div","pw-actions");return c.append(this.button("pw-btn primary","Save","Save the pane settings",d),this.button("pw-btn","Restart","Save, then close and start the pane again",async()=>{await d(),await this.restartPane(e,t.id)}),this.button("pw-btn","Duplicate","Save, then add a copy of this pane (same settings and view switches)",async()=>{await d(),await this.duplicatePane(e,t.id)}),this.button("pw-btn danger","Remove","Remove the pane from the workspace",()=>this.removePane(e,t.id))),n.append(c),this.autofocus&&setTimeout(()=>i.focus(),0),n}colorPicker(e,t){let n=e;const i=this.node("div","pw-colors"),s=document.createElement("input");s.type="color",s.className="pw-color-custom",s.title="Custom colour";const a=()=>{i.querySelectorAll(".pw-swatch").forEach(e=>{e.classList.toggle("selected",e.dataset.color===n)}),s.classList.toggle("selected",!!n&&!Q.includes(n)),n&&(s.value=n)};for(const e of["",...Q]){const s=this.button("pw-swatch"+(e?"":" none"),"",e||"No colour",()=>{n=e,t?.(n),a()});s.dataset.color=e,e&&(s.style.background=e),i.append(s)}return s.addEventListener("input",()=>{n=s.value,t?.(n),a()}),i.append(s),a(),{element:i,value:()=>n}}workspaceMenu(e,t){const n=this.node("div","pw-form pw-menu"),i=this.draft(e,"name",this.input("text",t.name,"Workspace name")),s=this.draft(e,"minW",this.input("number",t.minPaneWidth?String(t.minPaneWidth):"",String(600))),a=this.draft(e,"minH",this.input("number",t.minPaneHeight?String(t.minPaneHeight):"",String(260)));s.classList.add("pw-size"),a.classList.add("pw-size");const r=this.node("div","pw-size-row");r.append(s,this.node("span","","×"),a,this.node("span","","px"));const o=document.createElement("input");o.type="checkbox",o.checked=!!t.launchOnStartup,this.draft(e,"startup",o);const p=this.node("label","pw-check");p.append(o,this.node("span","","Open when Tabby starts"));const d=this.draftColor(e,"color",t.color??""),c=t.panes.find(e=>e.cwd?.trim())?.cwd?.trim(),l=this.draft(e,"folder",this.input("text",t.folder??"",c||"C:\\path or /home/user"));n.append(this.field("Name",i),this.field("Tab colour",d.element),this.field("Project folder",l),this.node("div","pw-hint","Opened by the VS Code button. Empty: the first pane folder."),this.field("Minimum pane size",r),this.node("div","pw-hint","A view fits as many switched-on panes as this size allows."),p);const h=()=>this.saveWorkspaceSettings(e,{name:i.value,minPaneWidth:Number(s.value)||null,minPaneHeight:Number(a.value)||null,launchOnStartup:o.checked,color:d.value(),folder:l.value});for(const t of[i,l,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&h(),"Escape"===t.key&&(e.menuOpen=!1,this.render(e,!0))});const w=this.node("div","pw-actions");w.append(this.button("pw-btn primary","Save","Save the workspace settings",h),this.button("pw-btn","Close","Close the menu",()=>{e.menuOpen=!1,this.render(e,!0)})),n.append(w),n.append(this.button("pw-menu-item","Edit settings in VS Code","Open this workspace as a JSON file; every save there is applied right away",()=>{e.menuOpen=!1,this.render(e,!0),this.workspaces.openConfigInVsCode(t)})),n.append(this.node("div","pw-menu-title","Workspaces"));for(const i of this.workspaces.getWorkspaces()){const s=i.id===t.id,a=!s&&!!this.findOpenTab(i.id),r=this.button("pw-menu-item"+(s?" current":""),"",s?"This workspace":a?"Switch to its tab":"Open it",()=>{s||(e.menuOpen=!1,this.render(e,!0),this.openWorkspace(i.id))});r.append(this.node("span","pw-name",i.name),this.node("span","pw-count",s?"this":a?"open":"")),n.append(r)}return n.append(this.button("pw-menu-item","+ New workspace","Create a workspace from a profile, folder and command",()=>{e.menuOpen=!1,this.render(e,!0),this.createWorkspace()}),this.button("pw-menu-item danger","Delete this workspace…","Delete it and close its tab",()=>this.deleteWorkspace(e))),n}makeDropTarget(e,t,n){t.addEventListener("dragover",n=>{e.dragging&&(n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect="move"),t.classList.add("drop-before"))}),t.addEventListener("dragleave",()=>t.classList.remove("drop-before")),t.addEventListener("drop",i=>{i.preventDefault(),t.classList.remove("drop-before");const s=i.dataTransfer?.getData("text/plain");e.dragging=!1,s&&this.movePane(e,s,n)})}node(e,t,n){const i=document.createElement(e);return t&&(i.className=t),void 0!==n&&(i.textContent=n),i}button(e,t,n,i){const s=document.createElement("button");return s.type="button",s.className=e,s.textContent=t,s.title=n,s.addEventListener("click",e=>{e.stopPropagation(),i()}),s}input(e,t,n){const i=document.createElement("input");return i.type=e,i.className="pw-input",i.value=t,i.placeholder=n,i.addEventListener("keydown",e=>e.stopPropagation()),i}field(e,t){const n=this.node("label","pw-field");return n.append(this.node("span","pw-label",e),t),n}ensureStyles(){if(document.getElementById("paneworks-sidebar-styles"))return;const e=document.createElement("style");e.id="paneworks-sidebar-styles",e.textContent="\n /* Pane frames in Paneworks tabs: every pane gets a frame and a small gap,\n the pane with keyboard focus an accent frame. Tabby positions the panes\n (class \"child\") absolutely; border-box keeps them inside their slot. */\n [data-paneworks] > .child {\n box-sizing: border-box;\n border: 3px solid var(--theme-bg-more, rgba(0,0,0,.35));\n border-radius: 6px;\n overflow: hidden;\n transition: border-color .12s;\n }\n [data-paneworks] > .child.focused {\n border-color: var(--theme-primary, #4c9aff);\n }\n [data-paneworks] split-tab-pane-label .custom-name {\n font-weight: 600;\n }\n /* Split handles: Tabby's handle is a 10px band centred on the border between two\n panes. A bright 4px bar in its middle (inset 3px works for both orientations)\n stands out against the panes; brighter on hover, accent while dragging. */\n [data-paneworks] > split-tab-spanner::after {\n content: '';\n position: absolute;\n inset: 3px;\n border-radius: 2px;\n background: rgba(255, 255, 255, .30);\n background: color-mix(in srgb, var(--theme-fg, #fff) 32%, transparent);\n pointer-events: none;\n transition: background .12s;\n }\n [data-paneworks] > split-tab-spanner:hover::after {\n background: rgba(255, 255, 255, .55);\n background: color-mix(in srgb, var(--theme-fg, #fff) 60%, transparent);\n }\n [data-paneworks] > split-tab-spanner.active::after {\n background: var(--theme-primary, #4c9aff);\n }\n\n .paneworks-overlay {\n position: fixed; inset: 0; z-index: 10000; display: flex; align-items: flex-start; justify-content: center;\n padding-top: 12vh; background: rgba(0,0,0,.45);\n }\n .paneworks-sidebar.pw-dialog {\n width: 380px; max-width: calc(100vw - 32px); border: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.12));\n border-radius: 6px; background: var(--theme-bg, #1e1e1e); box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: visible;\n }\n .paneworks-sidebar.pw-dialog .pw-form { margin: 0; padding: 14px; gap: 8px; background: none; }\n .paneworks-sidebar .pw-dialog-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }\n .paneworks-sidebar .pw-folder-row { display: flex; gap: 4px; }\n .paneworks-sidebar .pw-folder-row .pw-input { flex: 1; min-width: 0; }\n .paneworks-sidebar .pw-folder-row .pw-btn { flex: none; }\n\n .paneworks-sidebar {\n --pw-accent: var(--theme-primary, #4c9aff);\n display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;\n background: var(--theme-bg-more, rgba(0,0,0,.25));\n border-right: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.08));\n color: var(--theme-fg, inherit); font-size: 12px; user-select: none;\n }\n .paneworks-sidebar.collapsed { align-items: center; }\n .paneworks-sidebar button { font: inherit; color: inherit; }\n .paneworks-sidebar .pw-icon-btn {\n background: none; border: none; opacity: .6; cursor: pointer; padding: 2px 6px; line-height: 1; font-size: 13px;\n }\n .paneworks-sidebar .pw-icon-btn:hover { opacity: 1; }\n .paneworks-sidebar .pw-code { display: flex; align-items: center; }\n .paneworks-sidebar.collapsed .pw-toggle { margin-top: 8px; }\n\n .paneworks-sidebar .pw-header { display: flex; align-items: center; padding: 6px 4px 4px 4px; }\n .paneworks-sidebar .pw-ws {\n flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: none; border: none;\n padding: 4px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; text-align: left;\n }\n .paneworks-sidebar .pw-ws:hover { background: rgba(127,127,127,.15); }\n .paneworks-sidebar .pw-ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-caret { opacity: .5; font-size: 10px; }\n\n .paneworks-sidebar .pw-section {\n display: flex; align-items: center; justify-content: space-between;\n padding: 10px 6px 2px 10px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6;\n }\n .paneworks-sidebar .pw-add { font-size: 15px; opacity: .9; }\n\n .paneworks-sidebar .pw-row {\n display: flex; align-items: center; gap: 6px; padding: 5px 4px 5px 4px;\n border-left: 3px solid transparent; border-top: 2px solid transparent;\n }\n .paneworks-sidebar .pw-row:hover { background: rgba(127,127,127,.10); }\n .paneworks-sidebar .pw-all { cursor: pointer; padding-left: 10px; }\n .paneworks-sidebar .pw-all .pw-main { flex: 1; font-weight: 600; }\n .paneworks-sidebar .pw-all.active { border-left-color: var(--pw-accent); background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-count { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-view { padding-right: 4px; }\n .paneworks-sidebar .pw-view .pw-main { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-view.active .pw-main, .paneworks-sidebar .pw-view.selected .pw-main { font-weight: 600; }\n .paneworks-sidebar .pw-view.selected { border-left-color: rgba(127,127,127,.5); }\n .paneworks-sidebar .pw-view.editing { background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-empty-view { padding: 4px 10px; }\n .paneworks-sidebar .pw-section-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n\n /* Pane states: on screen = accent bar + full brightness; running elsewhere = dimmed;\n switched off = dimmer; focus view = highlighted row. */\n .paneworks-sidebar .pw-pane .pw-text { opacity: .6; }\n .paneworks-sidebar .pw-pane.onscreen { border-left-color: var(--pw-accent); }\n .paneworks-sidebar .pw-pane.onscreen .pw-text { opacity: 1; }\n .paneworks-sidebar .pw-pane.off .pw-text { opacity: .38; }\n .paneworks-sidebar .pw-pane.focused { background: rgba(127,127,127,.20); }\n .paneworks-sidebar .pw-pane.focused .pw-name { font-weight: 600; }\n .paneworks-sidebar .pw-pane.editing { background: rgba(127,127,127,.14); }\n\n .paneworks-sidebar .pw-pane-color { flex: 0 0 8px; height: 8px; border-radius: 2px; }\n .paneworks-sidebar .pw-pane-color.none { border: 1px dashed rgba(127,127,127,.5); box-sizing: border-box; }\n .paneworks-sidebar .pw-colors { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }\n .paneworks-sidebar .pw-swatch {\n width: 16px; height: 16px; padding: 0; border-radius: 3px; cursor: pointer;\n border: 2px solid transparent; box-sizing: border-box;\n }\n .paneworks-sidebar .pw-swatch.none {\n background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(127,127,127,.5) 3px 4px);\n border-color: rgba(127,127,127,.4);\n }\n .paneworks-sidebar .pw-swatch.selected, .paneworks-sidebar .pw-color-custom.selected {\n border-color: var(--theme-fg, #fff);\n }\n .paneworks-sidebar .pw-color-custom {\n width: 22px; height: 18px; padding: 0; border: 2px solid transparent; border-radius: 3px;\n background: none; cursor: pointer;\n }\n .paneworks-sidebar .pw-handle { cursor: grab; opacity: .25; font-size: 10px; letter-spacing: -2px; }\n .paneworks-sidebar .pw-row:hover .pw-handle { opacity: .7; }\n .paneworks-sidebar .pw-row.dragging { opacity: .35; }\n .paneworks-sidebar .drop-before { border-top-color: var(--pw-accent); }\n .paneworks-sidebar .pw-drop-end { flex: 1; min-height: 24px; border-top: 2px solid transparent; }\n\n .paneworks-sidebar .pw-text { display: flex; flex-direction: column; min-width: 0; flex: 1; cursor: pointer; }\n .paneworks-sidebar .pw-main { display: flex; align-items: center; gap: 5px; min-width: 0; }\n .paneworks-sidebar .pw-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-sub { font-size: 10px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-news {\n flex: none; font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 3px;\n background: var(--pw-accent); color: var(--theme-bg, #000); font-weight: 600; text-transform: uppercase;\n }\n .paneworks-sidebar .pw-more { opacity: .35; font-size: 14px; }\n .paneworks-sidebar .pw-row:hover .pw-more, .paneworks-sidebar .pw-row.editing .pw-more { opacity: .9; }\n\n .paneworks-sidebar .pw-switch { position: relative; flex: 0 0 26px; height: 14px; cursor: pointer; }\n .paneworks-sidebar .pw-switch input { opacity: 0; width: 0; height: 0; position: absolute; }\n .paneworks-sidebar .pw-slider {\n position: absolute; inset: 0; border-radius: 7px; background: rgba(127,127,127,.35); transition: background .15s;\n }\n .paneworks-sidebar .pw-slider::before {\n content: ''; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px; border-radius: 50%;\n background: var(--theme-fg, #fff); transition: transform .15s;\n }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider { background: var(--pw-accent); }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider::before { transform: translateX(12px); }\n\n .paneworks-sidebar .pw-form {\n display: flex; flex-direction: column; gap: 6px; margin: 2px 6px 6px 7px; padding: 8px;\n border-radius: 4px; background: rgba(127,127,127,.10); user-select: text;\n }\n .paneworks-sidebar .pw-menu { margin-top: 0; }\n .paneworks-sidebar .pw-field { display: flex; flex-direction: column; gap: 2px; margin: 0; }\n .paneworks-sidebar .pw-label { font-size: 10px; opacity: .6; }\n .paneworks-sidebar .pw-input {\n width: 100%; box-sizing: border-box; padding: 3px 6px; font: inherit; color: inherit; border-radius: 3px;\n background: var(--theme-bg, rgba(0,0,0,.3)); border: 1px solid rgba(127,127,127,.35);\n }\n .paneworks-sidebar .pw-input:focus { outline: none; border-color: var(--pw-accent); }\n .paneworks-sidebar .pw-size-row { display: flex; align-items: center; gap: 4px; }\n .paneworks-sidebar .pw-size { width: 64px; }\n .paneworks-sidebar .pw-check { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }\n .paneworks-sidebar .pw-hint { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }\n .paneworks-sidebar .pw-btn {\n padding: 3px 8px; border-radius: 3px; cursor: pointer; background: rgba(127,127,127,.2);\n border: 1px solid transparent;\n }\n .paneworks-sidebar .pw-btn:hover { background: rgba(127,127,127,.3); }\n .paneworks-sidebar .pw-btn.primary { background: var(--pw-accent); color: var(--theme-bg, #000); }\n .paneworks-sidebar .pw-btn.danger:hover { background: #c0392b; color: #fff; }\n .paneworks-sidebar .pw-menu-title { margin-top: 8px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }\n .paneworks-sidebar .pw-menu-item {\n display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;\n background: none; border: none; padding: 4px 6px; border-radius: 3px; cursor: pointer; text-align: left;\n }\n .paneworks-sidebar .pw-menu-item:hover { background: rgba(127,127,127,.2); }\n .paneworks-sidebar .pw-menu-item.current { cursor: default; font-weight: 600; }\n .paneworks-sidebar .pw-menu-item.danger:hover { background: #c0392b; color: #fff; }\n ",document.head.appendChild(e)}loadCollapsed(e){try{return"1"===localStorage.getItem(`paneworks-sidebar-collapsed:${e}`)}catch{return!1}}saveCollapsed(e,t){try{localStorage.setItem(`paneworks-sidebar-collapsed:${e}`,t?"1":"0")}catch{}}};G=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,f.ProfilesService,_,N,f.TabsService,f.TabRecoveryService,f.PlatformService])],G);const U="__new__";let X=class extends f.ToolbarButtonProvider{constructor(e,t,n,i){super(),this.workspaceService=e,this.app=t,this.layout=n,i.hotkey$.subscribe(e=>{e===g&&this.showWorkspaceSelector()}),this.waitForTabbyReady().then(()=>{this.workspaceService.cleanupOrphanedProfiles(),this.launchStartupWorkspaces()})}waitForTabbyReady(){return new Promise(e=>{let t=-1;const n=()=>{const i=this.app.tabs.length;i===t?e():(t=i,setTimeout(n,300))};setTimeout(n,500)})}async launchStartupWorkspaces(){for(const e of this.workspaceService.getWorkspaces().filter(e=>e.launchOnStartup))this.layout.findOpenTab(e.id)?console.log(`[${m}] Workspace "${e.name}" already open, skipping`):await this.layout.openWorkspace(e.id)}provide(){return[{icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="7" height="7"/>\n <rect x="14" y="3" width="7" height="7"/>\n <rect x="14" y="14" width="7" height="7"/>\n <rect x="3" y="14" width="7" height="7"/>\n</svg>',title:m,weight:5,click:()=>this.showWorkspaceSelector()}]}async showWorkspaceSelector(){const e=this.workspaceService.getWorkspaces().map(e=>({name:e.name,description:`${e.panes.length} panes${this.layout.findOpenTab(e.id)?" · open":""}`,icon:e.icon||"columns",color:e.color,result:e.id}));e.push({name:"New workspace",description:"Pick a profile, folder, command and number of panes (default 4)",icon:"plus",color:void 0,result:U});const t=await this.app.showSelector(m,e);t===U?await this.layout.createWorkspace():t&&await this.layout.openWorkspace(t)}};X=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[N,f.AppService,G,f.HotkeysService])],X);let Y=class{};Y=function(e,t,n,i){var s,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(a<3?s(r):a>3?s(t,n,r):s(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([(0,h.NgModule)({imports:[w.CommonModule],providers:[{provide:f.ConfigProvider,useClass:k,multi:!0},{provide:f.ToolbarButtonProvider,useClass:X,multi:!0},{provide:f.HotkeyProvider,useClass:b,multi:!0},N,_,G]})],Y);const Z=Y;return l})());
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal"));else if("function"==typeof define&&define.amd)define(["@angular/common","@angular/core","fs","path","rxjs","rxjs/operators","tabby-core","tabby-terminal"],t);else{var n="object"==typeof exports?t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal")):t(e["@angular/common"],e["@angular/core"],e.fs,e.path,e.rxjs,e["rxjs/operators"],e["tabby-core"],e["tabby-terminal"]);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(global,(e,t,n,i,s,a,o,r)=>(()=>{"use strict";var p={358(t){t.exports=e},860(e){e.exports=t},947(e){e.exports=n},911(e){e.exports=i},961(e){e.exports=s},439(e){e.exports=a},650(e){e.exports=o},349(e){e.exports=r}};const d={};function c(e){const t=d[e];if(void 0!==t)return t.exports;const n=d[e]={exports:{}};return p[e](n,n.exports,c),n.exports}c.d=(e,t)=>{for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),c.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};let l={};c.r(l),c.d(l,{WorkspaceEditorService:()=>N,default:()=>Z});var h=c(860),w=c(358),f=c(650);const u="paneworks",m="Paneworks";const g=`${u}-open-menu`;let b=class extends f.HotkeyProvider{async provide(){return[{id:g,name:`${m}: open menu`}]}};b=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)()],b);let k=class extends f.ConfigProvider{constructor(){super(...arguments),this.defaults={[u]:{workspaces:[]},hotkeys:{[g]:["F1"]}}}};k=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)()],k);const v=require("child_process");var y=c(947);const x=require("os");var P=c(911),C=c(961);function S(e){return"children"in e}function I(e){return e.children.flatMap(e=>S(e)?I(e):[e.paneId])}function T(e,t,n,i,s){if(e<=0)return[];const a=Math.max(1,Math.floor(t/Math.max(1,i))),o=Math.max(1,Math.floor(n/Math.max(1,s))),r=Math.min(e,a*o);let p=null;for(let e=1;e<=Math.min(r,o);e++){const o=Math.ceil(r/e);if(o>a)continue;const d=Math.min(t/o/i,n/e/s);(!p||d>p.score+1e-9)&&(p={rows:e,score:d})}const d=p?.rows??1,c=Math.floor(r/d),l=r%d;return Array.from({length:d},(e,t)=>c+(t<l?1:0))}function W(e,t){let n=0;const i=t.map(t=>{const i=e.slice(n,n+t);return n+=t,1===i.length?{paneId:i[0]}:{orientation:"horizontal",ratios:i.map(()=>1/i.length),children:i.map(e=>({paneId:e}))}});return 1===i.length&&S(i[0])?i[0]:{orientation:"vertical",ratios:i.map(()=>1/i.length),children:i}}function $(e){if(Array.isArray(e.panes)||(e.panes=[]),e.panes=e.panes.filter(e=>e&&"object"==typeof e),Array.isArray(e.views)){e.views=e.views.filter(e=>e&&"object"==typeof e);for(const t of e.views){const e=t.hidden;"string"==typeof e?t.hidden=[e]:void 0===e||Array.isArray(e)||delete t.hidden}}if(Array.isArray(e.views)&&e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id),n=e.views[0];if(t.length){const e=Array.isArray(n.hidden)?n.hidden:[];n.hidden=[...e,...t.filter(t=>!e.includes(t))]}}if(!Array.isArray(e.views)||!e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id);e.views=[{id:`${e.id}-default`,name:"Default",...t.length?{hidden:t}:{}}]}for(const t of e.panes)"hidden"in t&&delete t.hidden;return e}function O(e){return e.views.find(t=>t.id===e.activeViewId)??e.views[0]}function E(e,t){return!e.hidden?.includes(t)}function A(e,t,n){const i=(e.hidden??[]).filter(e=>e!==t);n||i.push(t),i.length?e.hidden=i:delete e.hidden}function j(e="Default"){return{id:M(),name:e}}const V="paneworks:";function F(e){if("string"!=typeof e||!e.startsWith(V))return null;const[t,n]=e.slice(10).split(":");return t&&n?{workspaceId:t,paneId:n}:null}function R(e,t){const n=(e??"").trim(),i=(t??"").trim();return n?!i||i===n||i.startsWith(`${n} · `)?n:`${n} · ${i}`:i}function z(){return{id:M(),profileId:"",cwd:"",startupCommand:""}}const L=["columns","terminal","code","folder","home","briefcase","cog","database","server","cloud","rocket","flask","bug","wrench","cube","layer-group","sitemap","project-diagram"];function M(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function D(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>D(e));const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=D(e[n]));return t}let N=class{constructor(e,t,n,i){this.config=e,this.notifications=t,this.profilesService=n,this.platform=i,this.cachedProfiles=null,this.cacheTimestamp=0,this.CACHE_TTL=3e4,this.configFiles=new Map,this.workspaceEdited$=new C.Subject}async getCachedProfiles(){const e=Date.now();return(!this.cachedProfiles||e-this.cacheTimestamp>this.CACHE_TTL)&&(this.cachedProfiles=await this.profilesService.getProfiles(),this.cacheTimestamp=e),this.cachedProfiles}getWorkspaces(){const e=this.config.store?.[u]?.workspaces??[];for(const t of e)Array.isArray(t.panes)&&Array.isArray(t.views)&&t.views.length&&!t.panes.some(e=>!e||"hidden"in e)&&!t.views.some(e=>!e||"object"!=typeof e||void 0!==e.hidden&&!Array.isArray(e.hidden))||$(t);return e}async saveWorkspaceQuietly(e){const t=this.getWorkspaces(),n=t.findIndex(t=>t.id===e.id);-1!==n&&(t[n]=e,await this.saveWorkspaces(t),this.writeConfigFile(e))}minPaneSize(e){return{width:e.minPaneWidth||600,height:e.minPaneHeight||260}}planViewAll(e,t,n){const i=O(e),s=e.panes.filter(e=>E(i,e.id)).map(e=>e.id),a=this.minPaneSize(e),o=T(s.length,t,n,a.width,a.height),r=o.reduce((e,t)=>e+t,0),p=s.slice(0,r);return{tree:p.length?W(p,o):null,shown:p}}allPanesLayout(e,t,n){const i=e.panes.map(e=>e.id);if(!i.length)return null;const s=Math.max(1,t??window.innerWidth-210),a=Math.max(1,n??window.innerHeight-80);return W(i,T(i.length,s,a,1,1))}initialLayout(e){return this.allPanesLayout(e)}async saveWorkspaces(e){if(!this.config.store?.[u])throw new Error("Config store not initialized");this.config.store[u].workspaces=e,await this.saveConfig()}async addWorkspace(e){try{const t=this.getWorkspaces();t.push(e),await this.saveWorkspaces(t),this.notifications.info(`Workspace "${e.name}" created`)}catch(t){throw this.notifications.error(`Failed to create workspace "${e.name}"`),t}}async deleteWorkspace(e){const t=this.getWorkspaces(),n=t.find(t=>t.id===e);try{const i=t.filter(t=>t.id!==e);await this.saveWorkspaces(i),this.closeConfigFile(e),n&&this.notifications.info(`Workspace "${n.name}" deleted`)}catch(t){throw this.notifications.error(`Failed to delete workspace "${n?.name||e}"`),t}}async getAvailableProfiles(){return(await this.profilesService.getProfiles()).filter(e=>!e.id?.startsWith("split-layout:"))}cleanupOrphanedProfiles(){if(!this.config.store?.profiles)return;const e=this.config.store.profiles,t=`split-layout:${u}:`,n=e.filter(e=>!e.id?.startsWith(t));n.length!==e.length&&(this.config.store.profiles=n,this.config.save(),console.log(`[${m}] Cleaned up ${e.length-n.length} orphaned profiles`))}async generateTabbyProfile(e){await this.getCachedProfiles();const t=this.initialLayout(e);if(!t)return null;const n=this.sanitizeForProfileId(e.name);return{id:`split-layout:${u}:${n}:${e.id}`,type:"split-layout",name:e.name,group:m,icon:e.icon,color:e.color,isBuiltin:!1,options:{recoveryToken:this.generateRecoveryToken(t,e)}}}async createPaneToken(e,t){return await this.getCachedProfiles(),this.generatePaneToken(t,e.name,e.id)}generateRecoveryToken(e,t){return{type:"app:split-tab",orientation:"horizontal"===e.orientation?"h":"v",ratios:[...e.ratios],paneworksWorkspaceId:t.id,tabTitle:t.name,disableDynamicTitle:!0,children:e.children.map(e=>{if(S(e))return this.generateRecoveryToken(e,t);const n=t.panes.find(t=>t.id===e.paneId);return this.generatePaneToken(n,t.name,t.id)})}}generatePaneToken(e,t,n){const i=this.getProfileById(e.profileId),s=function(e,t){return`${V}${e}:${t}`}(n,e.id),a=R(e.name,"");if(!i)return{type:"app:local-tab",profile:{type:"local",name:"Shell",group:s},savedState:!1,tabTitle:e.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};if(!this.isLocalProfile(i))return{type:`app:${i.type}-tab`,profile:{...i,group:s,disableDynamicTitle:!1},savedState:!1,tabTitle:e.name||i.name,tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};const o=e.cwd||i.options?.cwd||"",r=this.isWslProfile(i),p=i.options?.args||[],d={restoreFromPTYID:!1,command:i.options?.command||"",args:r&&o?[...p,"--cd",o]:p,cwd:r?"":o,env:i.options?.env||{},width:null,height:null,pauseAfterExit:!1,runAsAdministrator:!1};return{type:"app:local-tab",profile:{id:i.id,type:"local",name:i.name||"Shell",group:s,options:d,icon:i.icon||"",color:i.color||"",disableDynamicTitle:!1,weight:0,isBuiltin:!1,isTemplate:!1,terminalColorScheme:null,behaviorOnSessionEnd:"auto"},savedState:!1,tabTitle:e.name||i.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1,cwd:r?"":o}}sanitizeForProfileId(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"workspace"}isLocalProfile(e){return"local"===e.type||e.type?.startsWith("local:")||!1}projectFolder(e){const t=e.panes.find(e=>e.cwd?.trim());let n=e.folder?.trim()||t?.cwd?.trim();if(!n)return null;const i="win32"===process.platform&&(n.startsWith("/")||"~"===n||n.startsWith("~/"));if(i||"~"!==n&&!n.startsWith("~/")||(n=x.homedir()+n.slice(1)),!i)return{path:n,wsl:i,distro:null};const s=t?[t,...e.panes]:e.panes;for(const e of s){const t=this.getProfileById(e.profileId);if(t&&this.isWslProfile(t))return{path:n,wsl:i,distro:this.wslDistro(t)}}return{path:n,wsl:i,distro:null}}async openInVsCode(e){await this.getCachedProfiles();const t=this.projectFolder(e);if(t)if(t.wsl){const e=t.path.startsWith("~/");this.spawnCode("wsl.exe",[...t.distro?["-d",t.distro]:[],"--cd",e?"~":t.path,"code",e?t.path.slice(2):"."])}else this.spawnCode("code",[t.path]);else this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}copyProjectFolder(e){const t=this.projectFolder(e);t?(this.platform.setClipboard({text:t.path}),this.notifications.info(`Copied ${t.path}`)):this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}openConfigInVsCode(e){const t=this.writeConfigFile(e,!0);t&&this.spawnCode("code",[t])}copyConfigFilePath(e){const t=this.writeConfigFile(e,!0);t&&(this.platform.setClipboard({text:t}),this.notifications.info(`Copied ${t}`))}configFilePath(e){const t=this.platform.getConfigPath(),n=P.join(t?P.dirname(t):x.tmpdir(),"paneworks"),i=`-${e.id.replace(/[^A-Za-z0-9_-]/g,"_")}.json`;try{const e=y.readdirSync(n).find(e=>e.endsWith(i));if(e)return P.join(n,e)}catch{}const s=e.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"workspace";return P.join(n,s+i)}writeConfigFile(e,t=!1){let n=this.configFiles.get(e.id);if(!n&&!t)return null;const i=JSON.stringify(e,null,2)+"\n";try{if(!n){const t=this.configFilePath(e);y.mkdirSync(P.dirname(t),{recursive:!0}),n={file:t,written:""},this.configFiles.set(e.id,n);const i=n;y.watchFile(t,{interval:700},()=>this.configFileChanged(e.id,i))}if(t)n.invalid=!1;else{let t=null;try{t=y.readFileSync(n.file,"utf8")}catch{}if(null!==t&&t!==n.written&&t.trim())return this.configFileChanged(e.id,n),n.file}return i===n.written||n.invalid||(y.writeFileSync(n.file,i),n.written=i),n.file}catch(e){return console.error(`[${m}] Could not write the workspace file:`,e),this.notifications.error(`Could not write the workspace file: ${e}`),null}}closeConfigFile(e){const t=this.configFiles.get(e);t&&(y.unwatchFile(t.file),this.configFiles.delete(e))}async configFileChanged(e,t){let n;try{n=y.readFileSync(t.file,"utf8")}catch{return}if(n===t.written||!n.trim())return;t.written=n;const i=this.getWorkspaces(),s=i.findIndex(t=>t.id===e);if(-1===s)return void this.closeConfigFile(e);let a;try{a=this.parseWorkspace(n,i[s])}catch(e){return t.invalid?this.notifications.error(`${i[s].name}: not applied, ${e.message}`):this.notifications.error(`${i[s].name}: not applied, ${e.message}. Until the file is valid, sidebar changes are not written to it; "Edit settings in VS Code" starts it over.`),void(t.invalid=!0)}t.invalid=!1;const o=i[s],r=D(o);for(const e of Object.keys(o))delete o[e];Object.assign(o,a),await this.saveWorkspaces(i),this.writeConfigFile(o),this.notifications.info(`${o.name}: settings applied from the file`),this.workspaceEdited$.next({workspaceId:e,before:r})}parseWorkspace(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error(`invalid JSON (${e.message})`)}if(!n||"object"!=typeof n||Array.isArray(n))throw new Error("the file must hold one JSON object");if(!Array.isArray(n.panes)||!n.panes.length)throw new Error('"panes" must be a list with at least one pane');for(const e of n.panes){if(!e||"object"!=typeof e)throw new Error("every pane must be an object");if("string"==typeof e.id&&e.id||(e.id=M()),"string"!=typeof e.profileId)throw new Error(`pane ${e.name??e.id}: "profileId" must be a string`);for(const t of["name","cwd","startupCommand","color"])if(null===e[t]&&delete e[t],void 0!==e[t]&&"string"!=typeof e[t])throw new Error(`pane ${e.id}: "${t}" must be a string`)}for(const e of["name","folder","color","icon","activeViewId"])if(null===n[e]&&delete n[e],void 0!==n[e]&&"string"!=typeof n[e])throw new Error(`"${e}" must be a string`);for(const e of["minPaneWidth","minPaneHeight"])if(null===n[e]&&delete n[e],!(void 0===n[e]||"number"==typeof n[e]&&n[e]>0))throw new Error(`"${e}" must be a number above 0`);if(void 0!==n.launchOnStartup&&"boolean"!=typeof n.launchOnStartup)throw new Error('"launchOnStartup" must be true or false');const i=n.panes.map(e=>e.id);if(new Set(i).size!==i.length)throw new Error("two panes have the same id");if(void 0!==n.views){if(!Array.isArray(n.views))throw new Error('"views" must be a list');const e=new Set;for(const t of n.views){if(!t||"object"!=typeof t)throw new Error("every view must be an object");if("string"==typeof t.id&&t.id&&!e.has(t.id)||(t.id=M()),e.add(t.id),"string"!=typeof t.name||!t.name.trim())throw new Error('every view needs a "name"');if(void 0!==t.hidden&&!Array.isArray(t.hidden))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);if(t.hidden){if(t.hidden.some(e=>"string"!=typeof e))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);t.hidden=t.hidden.filter(e=>i.includes(e)),t.hidden.length||delete t.hidden}}}return n.id=t.id,"string"==typeof n.name&&n.name.trim()||(n.name=t.name),$(D(n))}spawnCode(e,t){let n=e,i=t,s={detached:!0,stdio:"ignore",windowsHide:!0};if("win32"===process.platform&&"code"===e){if(t.some(e=>/["%\r\n]/.test(e)))return void this.notifications.error('This path has characters that cannot be passed to VS Code safely: " or %');n=process.env.ComSpec||"cmd.exe",i=["/d","/v:off","/s","/c",`"code ${t.map(e=>`"${e.replace(/(\\+)$/,"$1$1")}"`).join(" ")}"`],s={...s,windowsVerbatimArguments:!0}}try{const a=(0,v.spawn)(n,i,s);a.on("error",n=>{if("ENOENT"===n.code&&"win32"!==process.platform&&"code"===e){const e=process.env.SHELL??"",n=/\/(ba|z|k|da)?sh$/.test(e)?e:"/bin/sh",i=(0,v.spawn)(n,["-lc",'exec code "$@"',"code",...t],s);return i.on("error",()=>this.vsCodeFailed()),i.on("exit",e=>{e&&this.vsCodeFailed()}),void i.unref()}this.vsCodeFailed()}),a.on("exit",e=>{e&&this.vsCodeFailed()}),a.unref()}catch{this.vsCodeFailed()}}vsCodeFailed(){this.notifications.error('Could not start VS Code. Is the "code" command on your PATH?')}wslDistro(e){const t=e.options?.args??[],n=t.findIndex(e=>"-d"===e||"--distribution"===e);return n>=0&&t[n+1]?t[n+1]:null}isWslProfile(e){if(e.id?.startsWith("local:wsl"))return!0;const t=(e.options?.command||"").toLowerCase();return"wsl.exe"===t||"wsl"===t||t.endsWith("\\wsl.exe")||t.endsWith("/wsl.exe")}getProfileById(e){return(this.config.store?.profiles??[]).find(t=>t.id===e)||this.cachedProfiles?.find(t=>t.id===e)}collectStartupCommands(e){return e.panes.filter(e=>e.startupCommand).map(e=>({paneId:e.id,command:e.startupCommand}))}getWorkspace(e){return this.getWorkspaces().find(t=>t.id===e)}async saveConfig(){try{await this.config.save()}catch(e){throw console.error(`[${m}] Save error:`,e),e}}};N=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)({providedIn:"root"}),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.ConfigService,f.NotificationsService,f.ProfilesService,f.PlatformService])],N);var H=c(349),q=c(439);const B=[0,300,1e3,3e3,8e3];let _=class{constructor(e,t){this.app=e,this.workspaces=t,this.workspaceSplitFound$=new C.Subject,this.pendingCommands=new Map,this.watchedSplits=new WeakSet,this.attachedPanes=new WeakSet,this.app.tabOpened$.subscribe(e=>this.onTabOpened(e))}registerCommands(e){for(const t of e)this.pendingCommands.set(t.paneId,t)}onTabOpened(e){e instanceof f.SplitTabComponent?this.watchSplit(e):e instanceof H.BaseTerminalTabComponent&&this.processPane(e,null)}watchSplit(e){if(this.watchedSplits.has(e))return;this.watchedSplits.add(e);const t=()=>this.scanSplit(e);e.initialized$?.subscribe({complete:t}),e.tabAdded$?.subscribe(()=>t());for(const e of B)setTimeout(t,e)}scanSplit(e){for(const t of e.getAllTabs())t instanceof H.BaseTerminalTabComponent&&this.processPane(t,e)}processPane(e,t){const n=F(e.profile?.group);n&&(t&&(this.pinSplitTitle(t,n.workspaceId),this.workspaceSplitFound$.next({split:t,workspaceId:n.workspaceId})),this.attachedPanes.has(e)||(this.attachedPanes.add(e),this.attachLabelSync(e,n.workspaceId,n.paneId),this.runPendingCommand(e,n.paneId)))}pinSplitTitle(e,t){const n=this.workspaces.getWorkspace(t)?.name;e.disableDynamicTitle=!0,n&&e.title!==n&&e.setTitle(n)}attachLabelSync(e,t,n){const i=e;i.disableDynamicTitle=!1;let s=e.customTitle,a=!0;const o=()=>{if(!a)return;if(e.customTitle!==s)return void(a=!1);const o=this.workspaces.getWorkspace(t),r=o?function(e,t){return e.panes.find(e=>e.id===t)}(o,n)?.name:void 0,p=R(r,e.title);p&&p!==e.customTitle&&(s=p,"function"==typeof i.setCustomTitle?i.setCustomTitle(p):e.customTitle=p)},r=e.setTitle.bind(e);e.setTitle=e=>{r(e),o()},o()}runPendingCommand(e,t,n=!1){const i=this.pendingCommands.get(t);if(!i?.command)return;this.pendingCommands.delete(t);const s=i.command,a=()=>{console.log(`[${m}] Sending startup command:`,s),e.sendInput(s+"\r"),this.clearProfileArgs(e)},o=e.sessionChanged$;if(!e.session&&o&&!n)return this.pendingCommands.set(t,i),void o.pipe((0,C.first)(e=>!!e),(0,C.timeout)(5e3),(0,q.catchError)(()=>(0,C.of)(null))).subscribe(()=>this.runPendingCommand(e,t,!0));e.session?.output$?e.session.output$.pipe((0,C.first)(),(0,C.timeout)(2e3),(0,q.catchError)(()=>(0,C.of)(null))).subscribe(()=>setTimeout(a,100)):setTimeout(a,500)}clearProfileArgs(e){const t=e.profile;t?.options?.args&&(t.options.args=[])}};_=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,N])],_);const Q=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"];function J(e){const t=e.trim().split(/[\\/]+/).filter(Boolean),n=t[t.length-1]??"";return/^[a-z]:$/i.test(n)||"~"===n?"":n}let G=class{constructor(e,t,n,i,s,a,o){this.app=e,this.profilesService=t,this.runtime=n,this.workspaces=i,this.tabsService=s,this.tabRecovery=a,this.platform=o,this.states=new WeakMap,this.active=new Set,this.resizeTimer=null,this.profiles=[],this.watchedSessions=new WeakSet,this.autofocus=!1,this.runtime.workspaceSplitFound$.subscribe(({split:e,workspaceId:t})=>this.attach(e,t)),this.workspaces.workspaceEdited$.subscribe(({workspaceId:e,before:t})=>this.syncEdited(e,t)),window.addEventListener("resize",()=>{this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>this.refreshAllGrids(),250)})}findOpenTab(e){for(const t of this.active)if(t.workspaceId===e)return t.split;for(const t of this.app.tabs)if(t instanceof f.SplitTabComponent&&t.getAllTabs().some(t=>F(t.profile?.group)?.workspaceId===e))return t;return null}async openWorkspace(e){const t=this.findOpenTab(e);if(t)return void this.app.selectTab(t);const n=this.workspaces.getWorkspace(e);if(!n)return;const i=this.workspaces.collectStartupCommands(n);i.length&&this.runtime.registerCommands(i);const s=await this.workspaces.generateTabbyProfile(n);s&&this.profilesService.openNewTabForProfile(s)}async createWorkspace(){await this.loadProfiles();const e=await this.askWorkspaceSetup();if(!e)return;const t=new Set(this.workspaces.getWorkspaces().map(e=>e.name));let n=J(e.folder);if(!n){let e=1;for(;t.has(`Workspace ${e}`);)e++;n=`Workspace ${e}`}let i=n;for(let e=2;t.has(i);e++)i=`${n} ${e}`;const s=function(e=""){return{id:M(),name:e,icon:L[Math.floor(Math.random()*L.length)],panes:[z(),z()],views:[j()],launchOnStartup:!1}}(i);s.panes=Array.from({length:e.panes},()=>({id:z().id,profileId:e.profileId,...e.folder?{cwd:e.folder}:{},...e.command?{startupCommand:e.command}:{}})),e.folder&&(s.folder=e.folder),await this.workspaces.addWorkspace(s),await this.openWorkspace(s.id)}askWorkspaceSetup(){return this.ensureStyles(),new Promise(e=>{const t=this.node("div","paneworks-overlay"),n=this.node("div","paneworks-sidebar pw-dialog"),i=this.node("div","pw-form"),s=document.createElement("select");s.className="pw-input";for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,s.append(t)}const a=this.profiles.find(e=>"local"===e.type||e.type?.startsWith("local:"))??this.profiles[0];s.value=a?.id??"";const o=this.input("text","","C:\\path or /home/user"),r=this.button("pw-btn","Browse…","Pick a folder",async()=>{try{const e=await this.platform.pickDirectory();e&&(o.value=e),h()}catch{}}),p=this.node("div","pw-folder-row");p.append(o,r);const d=this.input("text","","e.g. claude (optional)"),c=this.input("number","4","4");c.min="1",c.max="16",c.classList.add("pw-size");const l=this.node("div","pw-hint"),h=()=>{const e=J(o.value);l.textContent=e?`Workspace name: ${e}`:"The workspace is named after the folder."};o.addEventListener("input",h),h(),i.append(this.node("div","pw-dialog-title","New workspace"),this.field("Profile",s),this.field("Folder",p),l,this.field("Startup command",d),this.field("Panes",c),this.node("div","pw-hint","Every pane starts with this profile, folder and command. Change single panes later in the sidebar."));const w=n=>{t.remove(),e(n)},f=()=>w({profileId:s.value,folder:o.value.trim(),command:d.value.trim(),panes:Math.min(16,Math.max(1,Math.round(c.value.trim()&&Number.isFinite(Number(c.value))?Number(c.value):4)))});for(const e of[o,d,c])e.addEventListener("keydown",e=>{"Enter"===e.key&&f(),"Escape"===e.key&&w(null)});s.addEventListener("keydown",e=>{e.stopPropagation(),"Escape"===e.key&&w(null)});const u=this.node("div","pw-actions");u.append(this.button("pw-btn primary","Create","Create and open the workspace",f),this.button("pw-btn","Cancel","Close without creating",()=>w(null))),i.append(u),n.append(i),t.append(n),t.addEventListener("mousedown",e=>{e.target===t&&w(null)}),document.body.append(t),setTimeout(()=>o.focus(),0)})}async loadProfiles(){this.profiles.length||(this.profiles=await this.workspaces.getAvailableProfiles())}applyTabColor(e){const t=this.workspaces.getWorkspace(e.workspaceId)?.color||null;t?e.split.color=t:e.appliedColor&&(e.split.color=null),e.appliedColor=t}attach(e,t){const n=this.states.get(e);if(n)return void(n.sidebar?.isConnected||this.mountSidebar(n));const i={split:e,workspaceId:t,view:{kind:"all"},appliedPlan:null,parked:new Map,sidebar:null,collapsed:this.loadCollapsed(t),busy:!1,dragging:!1,editingPaneId:null,editingViewId:null,menuOpen:!1,timer:null,unseen:new Set,starting:!0,syncPending:!1,restartPending:new Set,drafts:new Map,draftOwner:null,appliedColor:null,leftAt:new Map};this.states.set(e,i),this.active.add(i),this.loadProfiles(),this.applyTabColor(i),e.destroyed$.subscribe(()=>{for(const e of i.parked.values())e.destroy();i.parked.clear(),i.timer&&clearInterval(i.timer),i.sidebar?.remove(),this.active.delete(i)}),e.visibility$?.subscribe(e=>{e&&setTimeout(()=>{i.syncPending?this.syncTab(i):this.refreshGrid(i)},50)}),this.mountSidebar(i),i.timer=setInterval(()=>this.render(i),1e3),this.startAllPanes(i)}async showAll(e,t=!1){const n=this.workspaces.getWorkspace(e.workspaceId),i=this.paneArea(e);if(!n||!i)return;const s=this.workspaces.planViewAll(n,i.width,i.height),a=JSON.stringify(s.tree);a!==e.appliedPlan&&console.log(`[${m}] View all:`,{area:i,shown:s.shown.length,min:this.workspaces.minPaneSize(n)});const o="all"===e.view.kind;if(e.view={kind:"all"},!s.tree&&n.panes.length&&(t||!o||"empty"!==e.appliedPlan)){const t=n.panes[0].id;await this.apply(e,n,{orientation:"horizontal",ratios:[1],children:[{paneId:t}]})&&(e.appliedPlan="empty")}!s.tree||!t&&o&&a===e.appliedPlan||await this.apply(e,n,s.tree)&&(e.appliedPlan=a),this.render(e,!0)}async showFocus(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(!n)return;const i={orientation:"horizontal",ratios:[1],children:[{paneId:t}]};await this.apply(e,n,i)&&(e.view={kind:"focus",paneId:t},e.appliedPlan=null),this.render(e,!0)}async reapplyView(e){"focus"===e.view.kind?await this.showFocus(e,e.view.paneId):await this.showAll(e,!0)}refreshGrid(e){"all"!==e.view.kind||e.busy||e.starting||this.showAll(e)}async startAllPanes(e){const t=e.view;e.starting=!0;try{const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=await this.waitFor(()=>this.paneArea(e),3e3),i=t.panes.some(t=>!this.livePanes(e).has(t.id)),s=this.workspaces.allPanesLayout(t,n?.width,n?.height);i&&s&&await this.apply(e,t,s),await this.waitFor(()=>{const t=[...this.livePanes(e).values()];return!(!t.length||!t.every(e=>e.session))||null},8e3)}finally{e.starting=!1}"focus"===t.kind?await this.showFocus(e,t.paneId):await this.showAll(e,!0)}async waitFor(e,t){const n=Date.now()+t;for(;;){const t=e();if(t)return t;if(Date.now()>n)return null;await new Promise(e=>setTimeout(e,100))}}refreshAllGrids(){for(const e of this.active)this.refreshGrid(e)}paneArea(e){const t=this.splitElement(e)?.getBoundingClientRect();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:null}async apply(e,t,n){if(e.busy)return!1;e.busy=!0;try{const i=e.split,s=new Map(t.panes.map(e=>[e.id,e])),a=this.livePanes(e),o=I(n).filter(e=>s.has(e));for(const e of o)if(!a.has(e)){const n=await this.createPane(t,s.get(e));n&&a.set(e,n)}const r=o.filter(e=>a.has(e));if(!r.length)return!1;for(const t of e.split.getAllTabs()){const n=this.paneIdOf(t);n&&r.includes(n)||(t.removeFromContainer(),i.viewRefs?.delete(t),t.parent=null,n?(e.parked.set(n,t),e.leftAt.set(n,Date.now())):t.destroy())}const p=this.buildContainer(n,a);if(!p)return!1;i.maximizedTab=null,i.root=p;for(const t of r){const n=a.get(t);e.unseen.delete(t),n.clearActivity(),i.viewRefs?.has(n)||(e.parked.delete(t),n.parent=e.split,n.emitVisibility?.(i.visibility?.value??!0),i.attachTabView(n),i.onAfterTabAdded(n))}return i.layout(),e.split.focus(a.get(r[0])),i.recoveryStateChangedHint?.next(),this.nudgeResize(),setTimeout(()=>this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),100),!0}catch(e){return console.error(`[${m}] Layout change failed:`,e),!1}finally{e.busy=!1}}buildContainer(e,t){const n=[],i=[];if(e.children.forEach((s,a)=>{const o=S(s)?this.buildContainer(s,t):t.get(s.paneId)??null;o&&(n.push(o),i.push(e.ratios[a]??1))}),!n.length)return null;const s=i.reduce((e,t)=>e+t,0)||1,a=new f.SplitContainer;return a.orientation="horizontal"===e.orientation?"h":"v",a.children=n,a.ratios=i.map(e=>e/s),a}async createPane(e,t){try{const n=await this.workspaces.createPaneToken(e,t),i=await this.tabRecovery.recoverTab(n);return i?(t.startupCommand&&this.runtime.registerCommands([{paneId:t.id,command:t.startupCommand}]),this.tabsService.create(i)):null}catch(e){return console.error(`[${m}] Could not create pane:`,t,e),null}}livePanes(e){const t=new Map;for(const n of e.split.getAllTabs()){const e=this.paneIdOf(n);e&&t.set(e,n)}for(const[n,i]of e.parked)t.set(n,i);return t}paneIdOf(e){return F(e.profile?.group)?.paneId??null}nudgeResize(){setTimeout(()=>window.dispatchEvent(new Event("resize")),50)}async toggleShown(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=O(n);A(s,t,!E(s,t)),await this.workspaces.saveWorkspaceQuietly(n),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async duplicatePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s={...i,id:z().id};i.name&&(s.name=`${i.name} copy`),n.panes.splice(n.panes.indexOf(i)+1,0,s);for(const e of n.views)A(e,s.id,E(e,i.id));await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=s.id,e.editingViewId=null,this.render(e,!0),await this.startAllPanes(e)}async syncEdited(e,t){const n=this.workspaces.getWorkspace(e),i=new Map(t.panes.map(e=>[e.id,e])),s=(n?.panes??[]).filter(e=>{const t=i.get(e.id);return!!t&&((t.startupCommand??"")!==(e.startupCommand??"")||(t.cwd??"")!==(e.cwd??"")||t.profileId!==e.profileId)}).map(e=>e.id);for(const t of[...this.active])if(t.workspaceId===e){for(const e of s)t.restartPending.add(e);await this.syncTab(t)}}async syncTab(e){await this.waitFor(()=>!e.busy&&!e.starting,1e4);const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!this.paneArea(e))return e.syncPending=!0,e.split.setTitle(t.name),void this.applyTabColor(e);e.syncPending=!1,e.split.setTitle(t.name),this.applyTabColor(e);const n=new Set(t.panes.map(e=>e.id));e.editingPaneId&&!n.has(e.editingPaneId)&&(e.editingPaneId=null),e.editingViewId&&!t.views.some(t=>t.id===e.editingViewId)&&(e.editingViewId=null),"focus"!==e.view.kind||n.has(e.view.paneId)||(e.view={kind:"all"}),await this.reapplyView(e);const i=()=>[...this.livePanes(e)].filter(([e])=>!n.has(e)),s=e.view;i().some(([,t])=>t.parent===e.split)&&await this.showFocus(e,t.panes[0].id);for(const[t,n]of i())n.parent!==e.split&&(e.parked.delete(t),n.destroy());"all"===s.kind&&"focus"===e.view.kind&&await this.showAll(e,!0);for(const t of[...e.restartPending])e.restartPending.delete(t),n.has(t)&&this.livePanes(e).has(t)&&await this.restartPane(e,t);this.render(e,!0),t.panes.some(t=>!this.livePanes(e).has(t.id))&&await this.startAllPanes(e)}async movePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId);if(!i)return;const s=i.panes.findIndex(e=>e.id===t);if(-1===s||t===n)return;const[a]=i.panes.splice(s,1),o=n?i.panes.findIndex(e=>e.id===n):-1;i.panes.splice(-1===o?i.panes.length:o,0,a),await this.workspaces.saveWorkspaceQuietly(i),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async addPane(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;await this.loadProfiles();const n=t.panes[t.panes.length-1],i={...z(),profileId:n?.profileId||this.profiles[0]?.id||"",cwd:n?.cwd||""};t.panes.push(i);const s=O(t);for(const e of t.views)e!==s&&A(e,i.id,!1);await this.workspaces.saveWorkspaceQuietly(t),e.editingPaneId=i.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)}async savePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.panes.find(e=>e.id===t);if(i&&s){Object.assign(s,n);for(const e of["name","color"])s[e]||delete s[e];await this.workspaces.saveWorkspaceQuietly(i),e.editingPaneId=null,this.render(e,!0),this.livePanes(e).has(t)||await this.startAllPanes(e)}}async restartPane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=this.livePanes(e).get(t),a=await this.createPane(n,i);a&&(s&&e.parked.get(t)===s?(e.parked.set(t,a),s.destroy()):s&&s.parent===e.split?(a.parent=e.split,e.split.replaceTab(s,a),e.split.viewRefs?.delete(s),s.destroy(),e.split.layout(),e.split.focus(a),this.nudgeResize()):e.parked.set(t,a),this.render(e,!0))}async removePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;if(n.panes.length<=1)return void window.alert("A workspace needs at least one pane. Delete the workspace from its menu instead.");const s=i.name||i.startupCommand||"this pane";if(!window.confirm(`Remove "${s}" from ${n.name}? Its terminal is closed.`))return;n.panes=n.panes.filter(e=>e.id!==t);for(const e of n.views)A(e,t,!0);await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=null;const a=this.livePanes(e).get(t);a&&a.parent===e.split&&("focus"===e.view.kind&&e.view.paneId===t&&(e.view={kind:"all"}),await this.reapplyView(e));const o=this.livePanes(e).get(t);if(o&&o.parent===e.split&&e.split.getAllTabs().length<=1){const t=n.panes[0];A(O(n),t.id,!0),await this.workspaces.saveWorkspaceQuietly(n),await this.showFocus(e,t.id)}e.parked.delete(t),this.livePanes(e).get(t)?.destroy(),a?.destroy(),this.render(e,!0)}async selectView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);n&&n.views.some(e=>e.id===t)&&(n.activeViewId!==t&&(n.activeViewId=t,await this.workspaces.saveWorkspaceQuietly(n)),await this.showAll(e,!0))}async addView(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=new Set(t.views.map(e=>e.name));let i=t.views.length+1;for(;n.has(`View ${i}`);)i++;const s=j(`View ${i}`);t.views.push(s),t.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(t),e.editingViewId=s.id,e.editingPaneId=null,e.menuOpen=!1,await this.showAll(e,!0)}async renameView(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.views.find(e=>e.id===t);i&&s&&(s.name=n.trim()||s.name,await this.workspaces.saveWorkspaceQuietly(i),e.editingViewId=null,this.render(e,!0))}async duplicateView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;const s={...j(`${i.name} copy`),...i.hidden?.length?{hidden:[...i.hidden]}:{}};n.views.splice(n.views.indexOf(i)+1,0,s),n.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=s.id,await this.showAll(e,!0)}async deleteView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;if(n.views.length<=1)return void window.alert("A workspace needs at least one view.");if(!window.confirm(`Delete the view "${i.name}"? Its panes keep running.`))return;const s=O(n)===i;n.views=n.views.filter(e=>e!==i),s&&(n.activeViewId=n.views[0].id),await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=null,s&&"all"===e.view.kind?await this.showAll(e,!0):this.render(e,!0)}async saveWorkspaceSettings(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(n){n.name=t.name.trim()||n.name;for(const e of["minPaneWidth","minPaneHeight"]){const i=t[e];i&&i>0?n[e]=Math.round(i):delete n[e]}t.launchOnStartup?n.launchOnStartup=!0:n.launchOnStartup=!1,t.color?n.color=t.color:delete n.color,t.folder.trim()?n.folder=t.folder.trim():delete n.folder,await this.workspaces.saveWorkspaceQuietly(n),e.split.setTitle(n.name),this.applyTabColor(e),e.menuOpen=!1,"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}}async deleteWorkspace(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!window.confirm(`Delete the workspace "${t.name}"? Its tab and all its panes are closed.`))return;await this.workspaces.deleteWorkspace(t.id);const n=this.app;"function"==typeof n.closeTab?n.closeTab(e.split,!1):e.split.destroy()}splitElement(e){const t=e.split;for(const e of[t.hostView,t.viewContainerEmbeddedRef]){const t=e?.rootNodes?.[0];if(t instanceof HTMLElement)return t}return null}mountSidebar(e){const t=this.splitElement(e),n=t?.parentElement;t&&n?(e.sidebar||(e.sidebar=document.createElement("div"),e.sidebar.className="paneworks-sidebar",this.ensureStyles()),n.insertBefore(e.sidebar,t),t.setAttribute("data-paneworks",""),this.render(e,!0),this.nudgeResize(),setTimeout(()=>this.refreshGrid(e),100)):setTimeout(()=>{!e.sidebar?.isConnected&&this.active.has(e)&&this.mountSidebar(e)},500)}applyLabelColors(e,t){const n=this.splitElement(e);if(!n||!t)return;const i=new Map(t.panes.map(e=>[e.id,e.color])),s=Array.from(n.querySelectorAll(":scope > split-tab-pane-label")),a=e.split.getAllTabs();s.forEach((e,t)=>{const n=e.querySelector(".custom-name");if(!n)return;const s=a[t]?this.paneIdOf(a[t]):null,o=s?i.get(s):void 0;o?(n.style.background=o,n.style.color=function(e){const t=e.replace("#","");if(!/^[0-9a-f]{6}$/i.test(t))return"#fff";const[n,i,s]=[0,2,4].map(e=>parseInt(t.slice(e,e+2),16)/255).map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n+.7152*i+.0722*s>.4?"#000":"#fff"}(o)):(n.style.removeProperty("background"),n.style.removeProperty("color"))})}watchOutput(e){for(const[t,n]of this.livePanes(e)){const i=n.session;i?.output$&&!this.watchedSessions.has(i)&&(this.watchedSessions.add(i),i.output$.subscribe(()=>{n.parent===e.split||e.unseen.has(t)||Date.now()-(e.leftAt.get(t)??0)<2500||e.unseen.add(t)}))}}render(e,t=!1){const n=e.sidebar;if(!n||!n.isConnected||e.dragging)return;if(this.watchOutput(e),this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),!t&&(e.editingPaneId||e.editingViewId||e.menuOpen))return;const i=this.workspaces.getWorkspace(e.workspaceId),s=this.livePanes(e),a=new Set(e.split.getAllTabs().map(e=>this.paneIdOf(e))),o=JSON.stringify([e.collapsed,e.view,e.editingPaneId,e.editingViewId,e.menuOpen,i,i?.panes.map(t=>{const n=s.get(t.id);return[n?.customTitle,n?.title,e.unseen.has(t.id),a.has(t.id)]})]);if(!t&&n.__pwSignature===o)return;n.__pwSignature=o;const r=e.editingPaneId?`p:${e.editingPaneId}`:e.editingViewId?`v:${e.editingViewId}`:e.menuOpen?"m":null,p=r!==e.draftOwner;p&&(e.drafts.clear(),e.draftOwner=r);const d=document.activeElement,c=d&&n.contains(d)?d.dataset?.draft??null:null,l=c&&"number"==typeof d.selectionStart?[d.selectionStart,d.selectionEnd]:null;this.autofocus=p,n.classList.toggle("collapsed",e.collapsed),n.style.flex=`0 0 ${e.collapsed?22:210}px`,n.textContent="";const h=this.button("pw-icon-btn pw-toggle",e.collapsed?"»":"«",e.collapsed?"Show sidebar":"Hide sidebar",()=>{e.collapsed=!e.collapsed,this.saveCollapsed(e.workspaceId,e.collapsed),this.render(e,!0),this.nudgeResize()});if(e.collapsed||!i)return void n.append(h);const w=this.node("div","pw-header"),f=this.button("pw-ws","","Workspace menu",()=>{e.menuOpen=!e.menuOpen,e.editingPaneId=null,e.editingViewId=null,this.render(e,!0)});f.append(this.node("span","pw-ws-name",i.name),this.node("span","pw-caret",e.menuOpen?"▴":"▾"));const u=this.workspaces.projectFolder(i),m=this.button("pw-icon-btn pw-code","",u?`Open ${u.path} in VS Code`:"Open in VS Code (no project folder yet: set one in the workspace menu)",()=>this.workspaces.openInVsCode(i));m.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>\n</svg>';const g=this.button("pw-icon-btn pw-code","",u?`Copy ${u.path}`:"Copy the project folder path (no project folder yet: set one in the workspace menu)",()=>this.workspaces.copyProjectFolder(i));g.innerHTML='<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>\n</svg>',w.append(f,g,m,h),n.append(w),e.menuOpen&&n.append(this.workspaceMenu(e,i));const b=O(i),k=this.node("div","pw-section");k.append(this.node("span","","Views"),this.button("pw-icon-btn pw-add","+","Add a view (all panes on)",()=>this.addView(e))),n.append(k);for(const t of i.views)n.append(this.viewRow(e,i,t,t===b,a)),e.editingViewId===t.id&&n.append(this.viewEditor(e,i,t));i.panes.some(e=>E(b,e.id))||n.append(this.node("div","pw-hint pw-empty-view",`Nothing is switched on in "${b.name}": switch panes on below.`));const v=this.node("div","pw-section");v.append(this.node("span","pw-section-title",`Panes · ${b.name}`),this.button("pw-icon-btn pw-add","+","Add a pane",()=>this.addPane(e))),n.append(v);const y="focus"===e.view.kind?e.view.paneId:null,x=this.node("div","pw-list");for(const t of i.panes)x.append(this.paneRow(e,t,s.get(t.id),a.has(t.id),y,E(b,t.id),b.name)),e.editingPaneId===t.id&&x.append(this.paneEditor(e,t));const P=this.node("div","pw-drop-end");if(this.makeDropTarget(e,P,null),x.append(P),n.append(x),c){const e=n.querySelector(`[data-draft="${c}"]`);if(e&&(e.focus(),l))try{e.setSelectionRange(l[0],l[1])}catch{}}}draft(e,t,n){n.dataset.draft=t;const i=n instanceof HTMLInputElement&&"checkbox"===n.type,s=e.drafts.get(t);void 0!==s&&(i?n.checked="1"===s:n.value=s);const a=()=>e.drafts.set(t,i?n.checked?"1":"0":n.value);return n.addEventListener("input",a),n.addEventListener("change",a),n}draftColor(e,t,n){return this.colorPicker(e.drafts.get(t)??n,n=>e.drafts.set(t,n))}paneRow(e,t,n,i,s,a,o){const r=(n?n.customTitle||n.title:"")||t.name||t.startupCommand||"New pane",p=[t.name,t.startupCommand].filter(Boolean).join(" · "),d=a&&!i&&"all"===e.view.kind,c=!i&&e.unseen.has(t.id),l=["pw-row","pw-pane"];i&&l.push("onscreen"),t.id===s&&l.push("focused"),a||l.push("off"),e.editingPaneId===t.id&&l.push("editing");const h=this.node("div",l.join(" "));h.title=[i?"On screen":n?"Running, not on screen":"Not running (shown again by a view or its title)",a?d?"switched on, but no room at the minimum pane size":"":`switched off in "${o}"`].filter(Boolean).join(" · "),h.draggable=!0,h.append(this.node("span","pw-handle","⋮⋮")),h.addEventListener("dragstart",n=>{e.dragging=!0,n.dataTransfer?.setData("text/plain",t.id),n.dataTransfer&&(n.dataTransfer.effectAllowed="move"),h.classList.add("dragging")}),h.addEventListener("dragend",()=>{e.dragging=!1,h.classList.remove("dragging"),this.render(e,!0)}),this.makeDropTarget(e,h,t.id);const w=this.node("span","pw-pane-color"+(t.color?"":" none"));t.color&&(w.style.background=t.color),w.title=t.color?`Label colour ${t.color}`:"No label colour",h.append(w);const f=this.node("span","pw-text"),u=this.node("span","pw-main");if(u.append(this.node("span","pw-name",r)),c){const e=this.node("span","pw-news","new");e.title="New output since it left the screen",u.append(e)}f.append(u),(p||d)&&f.append(this.node("span","pw-sub",[p,d?"no room":""].filter(Boolean).join(" · "))),f.onclick=()=>{t.id===s?this.showAll(e,!0):this.showFocus(e,t.id)},f.title=t.id===s?`Back to "${o}"`:"Show this pane alone";const m=this.node("label","pw-switch");m.title=a?`On: shown in "${o}"`:`Off: not in "${o}"`;const g=document.createElement("input");g.type="checkbox",g.checked=a,g.onchange=()=>this.toggleShown(e,t.id),m.append(g,this.node("span","pw-slider")),m.addEventListener("click",e=>e.stopPropagation());const b=this.button("pw-icon-btn pw-more","⋯","Edit pane",()=>{e.editingPaneId=e.editingPaneId===t.id?null:t.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)});return h.append(f,m,b),h}viewRow(e,t,n,i,s){const a=t.panes.filter(e=>E(n,e.id)),o=i&&"all"===e.view.kind,r=a.filter(e=>s.has(e.id)).length,p=["pw-row","pw-all","pw-view"];o?p.push("active"):i&&p.push("selected"),e.editingViewId===n.id&&p.push("editing");const d=this.node("div",p.join(" "));return d.append(this.node("span","pw-main",n.name),this.node("span","pw-count",o?`${r} / ${a.length}`:`${a.length} on`),this.button("pw-icon-btn pw-more","⋯","Edit view",()=>{e.editingViewId=e.editingViewId===n.id?null:n.id,e.editingPaneId=null,e.menuOpen=!1,this.render(e,!0)})),d.title=i?"Selected view: the pane switches below belong to it. Click to show its panes in a grid":"Select this view and show its switched-on panes in a grid",d.onclick=()=>this.selectView(e,n.id),d}viewEditor(e,t,n){const i=this.node("div","pw-form"),s=this.draft(e,"name",this.input("text",n.name,"View name"));i.append(this.field("Name",s),this.node("div","pw-hint","Select the view, then use the pane switches to choose what it shows."));const a=()=>this.renameView(e,n.id,s.value);s.addEventListener("keydown",t=>{"Enter"===t.key&&a(),"Escape"===t.key&&(e.editingViewId=null,this.render(e,!0))});const o=this.node("div","pw-actions");return o.append(this.button("pw-btn primary","Save","Save the view name",a),this.button("pw-btn","Duplicate","New view with the same switches",()=>this.duplicateView(e,n.id))),t.views.length>1&&o.append(this.button("pw-btn danger","Delete","Delete this view (panes keep running)",()=>this.deleteView(e,n.id))),i.append(o),this.autofocus&&setTimeout(()=>{s.focus(),s.select()},0),i}paneEditor(e,t){const n=this.node("div","pw-form"),i=this.draft(e,"name",this.input("text",t.name??"","optional")),s=this.draft(e,"command",this.input("text",t.startupCommand??"","e.g. c 1")),a=this.draft(e,"cwd",this.input("text",t.cwd??"","C:\\path or /home/user")),o=document.createElement("select");o.className="pw-input";const r=document.createElement("option");r.value="",r.textContent="-- profile --",o.append(r);for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,o.append(t)}o.value=t.profileId??"",this.draft(e,"profile",o);const p=this.draftColor(e,"color",t.color??"");n.append(this.field("Name",i),this.field("Label colour",p.element),this.field("Startup command",s),this.field("Folder",a),this.field("Profile",o),this.node("div","pw-hint","Command, folder and profile apply when the pane (re)starts."));const d=()=>this.savePane(e,t.id,{name:i.value.trim(),color:p.value(),startupCommand:s.value.trim(),cwd:a.value.trim(),profileId:o.value});for(const t of[i,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&d(),"Escape"===t.key&&(e.editingPaneId=null,this.render(e,!0))});const c=this.node("div","pw-actions");return c.append(this.button("pw-btn primary","Save","Save the pane settings",d),this.button("pw-btn","Restart","Save, then close and start the pane again",async()=>{await d(),await this.restartPane(e,t.id)}),this.button("pw-btn","Duplicate","Save, then add a copy of this pane (same settings and view switches)",async()=>{await d(),await this.duplicatePane(e,t.id)}),this.button("pw-btn danger","Remove","Remove the pane from the workspace",()=>this.removePane(e,t.id))),n.append(c),this.autofocus&&setTimeout(()=>i.focus(),0),n}colorPicker(e,t){let n=e;const i=this.node("div","pw-colors"),s=document.createElement("input");s.type="color",s.className="pw-color-custom",s.title="Custom colour";const a=()=>{i.querySelectorAll(".pw-swatch").forEach(e=>{e.classList.toggle("selected",e.dataset.color===n)}),s.classList.toggle("selected",!!n&&!Q.includes(n)),n&&(s.value=n)};for(const e of["",...Q]){const s=this.button("pw-swatch"+(e?"":" none"),"",e||"No colour",()=>{n=e,t?.(n),a()});s.dataset.color=e,e&&(s.style.background=e),i.append(s)}return s.addEventListener("input",()=>{n=s.value,t?.(n),a()}),i.append(s),a(),{element:i,value:()=>n}}workspaceMenu(e,t){const n=this.node("div","pw-form pw-menu"),i=this.draft(e,"name",this.input("text",t.name,"Workspace name")),s=this.draft(e,"minW",this.input("number",t.minPaneWidth?String(t.minPaneWidth):"",String(600))),a=this.draft(e,"minH",this.input("number",t.minPaneHeight?String(t.minPaneHeight):"",String(260)));s.classList.add("pw-size"),a.classList.add("pw-size");const o=this.node("div","pw-size-row");o.append(s,this.node("span","","×"),a,this.node("span","","px"));const r=document.createElement("input");r.type="checkbox",r.checked=!!t.launchOnStartup,this.draft(e,"startup",r);const p=this.node("label","pw-check");p.append(r,this.node("span","","Open when Tabby starts"));const d=this.draftColor(e,"color",t.color??""),c=t.panes.find(e=>e.cwd?.trim())?.cwd?.trim(),l=this.draft(e,"folder",this.input("text",t.folder??"",c||"C:\\path or /home/user"));n.append(this.field("Name",i),this.field("Tab colour",d.element),this.field("Project folder",l),this.node("div","pw-hint","Opened by the VS Code button. Empty: the first pane folder."),this.field("Minimum pane size",o),this.node("div","pw-hint","A view fits as many switched-on panes as this size allows."),p);const h=()=>this.saveWorkspaceSettings(e,{name:i.value,minPaneWidth:Number(s.value)||null,minPaneHeight:Number(a.value)||null,launchOnStartup:r.checked,color:d.value(),folder:l.value});for(const t of[i,l,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&h(),"Escape"===t.key&&(e.menuOpen=!1,this.render(e,!0))});const w=this.node("div","pw-actions");w.append(this.button("pw-btn primary","Save","Save the workspace settings",h),this.button("pw-btn","Close","Close the menu",()=>{e.menuOpen=!1,this.render(e,!0)})),n.append(w),n.append(this.button("pw-menu-item","Edit settings in VS Code","Open this workspace as a JSON file; every save there is applied right away",()=>{e.menuOpen=!1,this.render(e,!0),this.workspaces.openConfigInVsCode(t)}),this.button("pw-menu-item","Copy settings file path","Copy the path of this workspace's JSON settings file; saves to it are applied right away",()=>{this.workspaces.copyConfigFilePath(t)})),n.append(this.node("div","pw-menu-title","Workspaces"));for(const i of this.workspaces.getWorkspaces()){const s=i.id===t.id,a=!s&&!!this.findOpenTab(i.id),o=this.button("pw-menu-item"+(s?" current":""),"",s?"This workspace":a?"Switch to its tab":"Open it",()=>{s||(e.menuOpen=!1,this.render(e,!0),this.openWorkspace(i.id))});o.append(this.node("span","pw-name",i.name),this.node("span","pw-count",s?"this":a?"open":"")),n.append(o)}return n.append(this.button("pw-menu-item","+ New workspace","Create a workspace from a profile, folder and command",()=>{e.menuOpen=!1,this.render(e,!0),this.createWorkspace()}),this.button("pw-menu-item danger","Delete this workspace…","Delete it and close its tab",()=>this.deleteWorkspace(e))),n}makeDropTarget(e,t,n){t.addEventListener("dragover",n=>{e.dragging&&(n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect="move"),t.classList.add("drop-before"))}),t.addEventListener("dragleave",()=>t.classList.remove("drop-before")),t.addEventListener("drop",i=>{i.preventDefault(),t.classList.remove("drop-before");const s=i.dataTransfer?.getData("text/plain");e.dragging=!1,s&&this.movePane(e,s,n)})}node(e,t,n){const i=document.createElement(e);return t&&(i.className=t),void 0!==n&&(i.textContent=n),i}button(e,t,n,i){const s=document.createElement("button");return s.type="button",s.className=e,s.textContent=t,s.title=n,s.addEventListener("click",e=>{e.stopPropagation(),i()}),s}input(e,t,n){const i=document.createElement("input");return i.type=e,i.className="pw-input",i.value=t,i.placeholder=n,i.addEventListener("keydown",e=>e.stopPropagation()),i}field(e,t){const n=this.node("label","pw-field");return n.append(this.node("span","pw-label",e),t),n}ensureStyles(){if(document.getElementById("paneworks-sidebar-styles"))return;const e=document.createElement("style");e.id="paneworks-sidebar-styles",e.textContent="\n /* Pane frames in Paneworks tabs: every pane gets a frame and a small gap,\n the pane with keyboard focus an accent frame. Tabby positions the panes\n (class \"child\") absolutely; border-box keeps them inside their slot. */\n [data-paneworks] > .child {\n box-sizing: border-box;\n border: 3px solid var(--theme-bg-more, rgba(0,0,0,.35));\n border-radius: 6px;\n overflow: hidden;\n transition: border-color .12s;\n }\n [data-paneworks] > .child.focused {\n border-color: var(--theme-primary, #4c9aff);\n }\n [data-paneworks] split-tab-pane-label .custom-name {\n font-weight: 600;\n }\n /* Split handles: Tabby's handle is a 10px band centred on the border between two\n panes. A bright 4px bar in its middle (inset 3px works for both orientations)\n stands out against the panes; brighter on hover, accent while dragging. */\n [data-paneworks] > split-tab-spanner::after {\n content: '';\n position: absolute;\n inset: 3px;\n border-radius: 2px;\n background: rgba(255, 255, 255, .30);\n background: color-mix(in srgb, var(--theme-fg, #fff) 32%, transparent);\n pointer-events: none;\n transition: background .12s;\n }\n [data-paneworks] > split-tab-spanner:hover::after {\n background: rgba(255, 255, 255, .55);\n background: color-mix(in srgb, var(--theme-fg, #fff) 60%, transparent);\n }\n [data-paneworks] > split-tab-spanner.active::after {\n background: var(--theme-primary, #4c9aff);\n }\n\n .paneworks-overlay {\n position: fixed; inset: 0; z-index: 10000; display: flex; align-items: flex-start; justify-content: center;\n padding-top: 12vh; background: rgba(0,0,0,.45);\n }\n .paneworks-sidebar.pw-dialog {\n width: 380px; max-width: calc(100vw - 32px); border: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.12));\n border-radius: 6px; background: var(--theme-bg, #1e1e1e); box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: visible;\n }\n .paneworks-sidebar.pw-dialog .pw-form { margin: 0; padding: 14px; gap: 8px; background: none; }\n .paneworks-sidebar .pw-dialog-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }\n .paneworks-sidebar .pw-folder-row { display: flex; gap: 4px; }\n .paneworks-sidebar .pw-folder-row .pw-input { flex: 1; min-width: 0; }\n .paneworks-sidebar .pw-folder-row .pw-btn { flex: none; }\n\n .paneworks-sidebar {\n --pw-accent: var(--theme-primary, #4c9aff);\n display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;\n background: var(--theme-bg-more, rgba(0,0,0,.25));\n border-right: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.08));\n color: var(--theme-fg, inherit); font-size: 12px; user-select: none;\n }\n .paneworks-sidebar.collapsed { align-items: center; }\n .paneworks-sidebar button { font: inherit; color: inherit; }\n .paneworks-sidebar .pw-icon-btn {\n background: none; border: none; opacity: .6; cursor: pointer; padding: 2px 6px; line-height: 1; font-size: 13px;\n }\n .paneworks-sidebar .pw-icon-btn:hover { opacity: 1; }\n .paneworks-sidebar .pw-code { display: flex; align-items: center; }\n .paneworks-sidebar.collapsed .pw-toggle { margin-top: 8px; }\n\n .paneworks-sidebar .pw-header { display: flex; align-items: center; padding: 6px 4px 4px 4px; }\n .paneworks-sidebar .pw-ws {\n flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: none; border: none;\n padding: 4px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; text-align: left;\n }\n .paneworks-sidebar .pw-ws:hover { background: rgba(127,127,127,.15); }\n .paneworks-sidebar .pw-ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-caret { opacity: .5; font-size: 10px; }\n\n .paneworks-sidebar .pw-section {\n display: flex; align-items: center; justify-content: space-between;\n padding: 10px 6px 2px 10px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6;\n }\n .paneworks-sidebar .pw-add { font-size: 15px; opacity: .9; }\n\n .paneworks-sidebar .pw-row {\n display: flex; align-items: center; gap: 6px; padding: 5px 4px 5px 4px;\n border-left: 3px solid transparent; border-top: 2px solid transparent;\n }\n .paneworks-sidebar .pw-row:hover { background: rgba(127,127,127,.10); }\n .paneworks-sidebar .pw-all { cursor: pointer; padding-left: 10px; }\n .paneworks-sidebar .pw-all .pw-main { flex: 1; font-weight: 600; }\n .paneworks-sidebar .pw-all.active { border-left-color: var(--pw-accent); background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-count { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-view { padding-right: 4px; }\n .paneworks-sidebar .pw-view .pw-main { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-view.active .pw-main, .paneworks-sidebar .pw-view.selected .pw-main { font-weight: 600; }\n .paneworks-sidebar .pw-view.selected { border-left-color: rgba(127,127,127,.5); }\n .paneworks-sidebar .pw-view.editing { background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-empty-view { padding: 4px 10px; }\n .paneworks-sidebar .pw-section-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n\n /* Pane states: on screen = accent bar + full brightness; running elsewhere = dimmed;\n switched off = dimmer; focus view = highlighted row. */\n .paneworks-sidebar .pw-pane .pw-text { opacity: .6; }\n .paneworks-sidebar .pw-pane.onscreen { border-left-color: var(--pw-accent); }\n .paneworks-sidebar .pw-pane.onscreen .pw-text { opacity: 1; }\n .paneworks-sidebar .pw-pane.off .pw-text { opacity: .38; }\n .paneworks-sidebar .pw-pane.focused { background: rgba(127,127,127,.20); }\n .paneworks-sidebar .pw-pane.focused .pw-name { font-weight: 600; }\n .paneworks-sidebar .pw-pane.editing { background: rgba(127,127,127,.14); }\n\n .paneworks-sidebar .pw-pane-color { flex: 0 0 8px; height: 8px; border-radius: 2px; }\n .paneworks-sidebar .pw-pane-color.none { border: 1px dashed rgba(127,127,127,.5); box-sizing: border-box; }\n .paneworks-sidebar .pw-colors { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }\n .paneworks-sidebar .pw-swatch {\n width: 16px; height: 16px; padding: 0; border-radius: 3px; cursor: pointer;\n border: 2px solid transparent; box-sizing: border-box;\n }\n .paneworks-sidebar .pw-swatch.none {\n background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(127,127,127,.5) 3px 4px);\n border-color: rgba(127,127,127,.4);\n }\n .paneworks-sidebar .pw-swatch.selected, .paneworks-sidebar .pw-color-custom.selected {\n border-color: var(--theme-fg, #fff);\n }\n .paneworks-sidebar .pw-color-custom {\n width: 22px; height: 18px; padding: 0; border: 2px solid transparent; border-radius: 3px;\n background: none; cursor: pointer;\n }\n .paneworks-sidebar .pw-handle { cursor: grab; opacity: .25; font-size: 10px; letter-spacing: -2px; }\n .paneworks-sidebar .pw-row:hover .pw-handle { opacity: .7; }\n .paneworks-sidebar .pw-row.dragging { opacity: .35; }\n .paneworks-sidebar .drop-before { border-top-color: var(--pw-accent); }\n .paneworks-sidebar .pw-drop-end { flex: 1; min-height: 24px; border-top: 2px solid transparent; }\n\n .paneworks-sidebar .pw-text { display: flex; flex-direction: column; min-width: 0; flex: 1; cursor: pointer; }\n .paneworks-sidebar .pw-main { display: flex; align-items: center; gap: 5px; min-width: 0; }\n .paneworks-sidebar .pw-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-sub { font-size: 10px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-news {\n flex: none; font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 3px;\n background: var(--pw-accent); color: var(--theme-bg, #000); font-weight: 600; text-transform: uppercase;\n }\n .paneworks-sidebar .pw-more { opacity: .35; font-size: 14px; }\n .paneworks-sidebar .pw-row:hover .pw-more, .paneworks-sidebar .pw-row.editing .pw-more { opacity: .9; }\n\n .paneworks-sidebar .pw-switch { position: relative; flex: 0 0 26px; height: 14px; cursor: pointer; }\n .paneworks-sidebar .pw-switch input { opacity: 0; width: 0; height: 0; position: absolute; }\n .paneworks-sidebar .pw-slider {\n position: absolute; inset: 0; border-radius: 7px; background: rgba(127,127,127,.35); transition: background .15s;\n }\n .paneworks-sidebar .pw-slider::before {\n content: ''; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px; border-radius: 50%;\n background: var(--theme-fg, #fff); transition: transform .15s;\n }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider { background: var(--pw-accent); }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider::before { transform: translateX(12px); }\n\n .paneworks-sidebar .pw-form {\n display: flex; flex-direction: column; gap: 6px; margin: 2px 6px 6px 7px; padding: 8px;\n border-radius: 4px; background: rgba(127,127,127,.10); user-select: text;\n }\n .paneworks-sidebar .pw-menu { margin-top: 0; }\n .paneworks-sidebar .pw-field { display: flex; flex-direction: column; gap: 2px; margin: 0; }\n .paneworks-sidebar .pw-label { font-size: 10px; opacity: .6; }\n .paneworks-sidebar .pw-input {\n width: 100%; box-sizing: border-box; padding: 3px 6px; font: inherit; color: inherit; border-radius: 3px;\n background: var(--theme-bg, rgba(0,0,0,.3)); border: 1px solid rgba(127,127,127,.35);\n }\n .paneworks-sidebar .pw-input:focus { outline: none; border-color: var(--pw-accent); }\n .paneworks-sidebar .pw-size-row { display: flex; align-items: center; gap: 4px; }\n .paneworks-sidebar .pw-size { width: 64px; }\n .paneworks-sidebar .pw-check { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }\n .paneworks-sidebar .pw-hint { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }\n .paneworks-sidebar .pw-btn {\n padding: 3px 8px; border-radius: 3px; cursor: pointer; background: rgba(127,127,127,.2);\n border: 1px solid transparent;\n }\n .paneworks-sidebar .pw-btn:hover { background: rgba(127,127,127,.3); }\n .paneworks-sidebar .pw-btn.primary { background: var(--pw-accent); color: var(--theme-bg, #000); }\n .paneworks-sidebar .pw-btn.danger:hover { background: #c0392b; color: #fff; }\n .paneworks-sidebar .pw-menu-title { margin-top: 8px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }\n .paneworks-sidebar .pw-menu-item {\n display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;\n background: none; border: none; padding: 4px 6px; border-radius: 3px; cursor: pointer; text-align: left;\n }\n .paneworks-sidebar .pw-menu-item:hover { background: rgba(127,127,127,.2); }\n .paneworks-sidebar .pw-menu-item.current { cursor: default; font-weight: 600; }\n .paneworks-sidebar .pw-menu-item.danger:hover { background: #c0392b; color: #fff; }\n ",document.head.appendChild(e)}loadCollapsed(e){try{return"1"===localStorage.getItem(`paneworks-sidebar-collapsed:${e}`)}catch{return!1}}saveCollapsed(e,t){try{localStorage.setItem(`paneworks-sidebar-collapsed:${e}`,t?"1":"0")}catch{}}};G=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,f.ProfilesService,_,N,f.TabsService,f.TabRecoveryService,f.PlatformService])],G);const U="__new__";let X=class extends f.ToolbarButtonProvider{constructor(e,t,n,i){super(),this.workspaceService=e,this.app=t,this.layout=n,i.hotkey$.subscribe(e=>{e===g&&this.showWorkspaceSelector()}),this.waitForTabbyReady().then(()=>{this.workspaceService.cleanupOrphanedProfiles(),this.launchStartupWorkspaces()})}waitForTabbyReady(){return new Promise(e=>{let t=-1;const n=()=>{const i=this.app.tabs.length;i===t?e():(t=i,setTimeout(n,300))};setTimeout(n,500)})}async launchStartupWorkspaces(){for(const e of this.workspaceService.getWorkspaces().filter(e=>e.launchOnStartup))this.layout.findOpenTab(e.id)?console.log(`[${m}] Workspace "${e.name}" already open, skipping`):await this.layout.openWorkspace(e.id)}provide(){return[{icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="7" height="7"/>\n <rect x="14" y="3" width="7" height="7"/>\n <rect x="14" y="14" width="7" height="7"/>\n <rect x="3" y="14" width="7" height="7"/>\n</svg>',title:m,weight:5,click:()=>this.showWorkspaceSelector()}]}async showWorkspaceSelector(){const e=this.workspaceService.getWorkspaces().map(e=>({name:e.name,description:`${e.panes.length} panes${this.layout.findOpenTab(e.id)?" · open":""}`,icon:e.icon||"columns",color:e.color,result:e.id}));e.push({name:"New workspace",description:"Pick a profile, folder, command and number of panes (default 4)",icon:"plus",color:void 0,result:U});const t=await this.app.showSelector(m,e);t===U?await this.layout.createWorkspace():t&&await this.layout.openWorkspace(t)}};X=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[N,f.AppService,G,f.HotkeysService])],X);let Y=class{};Y=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.NgModule)({imports:[w.CommonModule],providers:[{provide:f.ConfigProvider,useClass:k,multi:!0},{provide:f.ToolbarButtonProvider,useClass:X,multi:!0},{provide:f.HotkeyProvider,useClass:b,multi:!0},N,_,G]})],Y);const Z=Y;return l})());
|
|
3
3
|
//# sourceMappingURL=index.js.map
|