Files
openclaw-config/cache/control-ui-assets/d08fd045b9cb86d13f0b4aa403c8a06ddcd32e533058ae463245169e5cff5e85/assets/browser-panel-BNW001UL.js
T

424 lines
45 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{fs as n,ml as r,ms as i,pl as a}from"./control-ui-core-pH6nakZ-.js";import{G as o,J as s,W as c,X as l,Z as ee,at as u,lt as te}from"./lit-runtime-BEtFSUCp.js";import{Ht as d,Lt as f,Rt as ne,g as p,qt as m,w as re}from"./control-ui-core-Br5DB0Zj.js";import{$a as h,Aa as ie,Ba as ae,Da as oe,Ea as g,Fa as se,Ga as ce,Ha as le,Ia as ue,Ja as _,Ka as v,La as de,Ma as y,Oa as b,Pa as fe,Qa as pe,Ra as me,Ta as he,Ua as ge,Va as _e,Wa as ve,Xa as x,Ya as S,Za as ye,eo as be,fo as xe,ja as C,ka as w,no as Se,oo as Ce,po as we,qa as Te,ro as Ee,to as De,za as Oe}from"./control-ui-boot-Cdpgu1Gm.js";import{n as ke,t as Ae}from"./scrollbar-styles-BYLTmsP_.js";import{n as je,r as Me,t as Ne}from"./dock-layout-controller-uvZhgHTs.js";import{a as Pe,i as Fe,n as Ie,r as T,t as Le}from"./dock-destination-controls-qvkD_2gG.js";function Re(e){return new Promise((t,n)=>{let r=new Image;r.addEventListener(`load`,()=>t(r)),r.addEventListener(`error`,()=>n(Error(m(`browser.errors.screenshotDecodeFailed`)))),r.src=e})}function ze(e){return D.has(e)||e.length===1}function E(e,t){if(!e)return null;let n=e.getBoundingClientRect();return n.width<=0||n.height<=0?null:{x:(t.clientX-n.left)/n.width,y:(t.clientY-n.top)/n.height}}function Be(e,t,n){let r=E(e,t);if(!r||!n)return null;let i=n.metrics?.cssWidth??n.image.naturalWidth,a=n.metrics?.cssHeight??n.image.naturalHeight;return{x:r.x*i,y:r.y*a}}function Ve(e,t){if(!e||!t)return null;let n=e.metrics?.cssWidth??e.image.naturalWidth,r=e.metrics?.cssHeight??e.image.naturalHeight;return n<=0||r<=0?null:{x:t.rect.x/n,y:t.rect.y/r,width:t.rect.width/n,height:t.rect.height/r}}function He(e,t,n,r){if(!e||!t)return;let i=Math.max(1,Math.round(t.clientWidth)),a=Math.max(1,Math.round(t.clientHeight));(e.width!==i||e.height!==a)&&(e.width=i,e.height=a);let o=e.getContext(`2d`);o&&(o.clearRect(0,0,i,a),me(o,{width:i,height:a,strokes:n,highlight:r}))}function Ue(e,t,n,r,i){let a=e.metrics?.url||e.url||t?.url||``,o=e.metrics?.title||t?.title||``,s=fe({url:a,title:o,strokes:n,element:r,browserTab:e.browserTab}),c=se({image:e.image,width:e.image.naturalWidth,height:e.image.naturalHeight,strokes:n,highlight:i});return ue({...s,dataUrl:c,fileName:`annotated-page.png`})}var D;function O(){return(O=e((()=>{d(),de(),D=new Set([`Enter`,`Backspace`,`Delete`,`Tab`,`Escape`,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`])})))()}var k,A;function j(){return(j=e((()=>{d(),v(),O(),k=120,A=class{constructor(e){this.host=e,this.drawingGesture=null,this.suppressStageClick=!1,this.inspectionError=null}resetCaptureState(){this.host.pendingInput.clearInput(),this.cancelOverlayPointerGesture()}stageElement(){return this.host.host.renderRoot.querySelector(`.bp-stage`)}remotePoint(e){return Be(this.stageElement(),e,this.host.view)}inspectHighlightRegion(){return Ve(this.host.view,this.host.inspected)}handleStageClick(e){if(this.suppressStageClick){this.suppressStageClick=!1;return}if(this.host.mode!==`interact`)return;this.host.host.renderRoot.querySelector(`.bp-viewport`)?.focus({preventScroll:!0});let t=this.remotePoint(e),n=this.host.activeTargetId;!t||!n||this.host.runAction(e=>_e(e,{targetId:n,x:t.x,y:t.y}))}handleWheel(e){if(this.host.mode!==`interact`||!this.host.view)return;let t=this.host.operations.captureClient(),n=this.host.activeTargetId;if(!t||!n)return;e.preventDefault();let r=this.host.operations.epoch;this.host.pendingInput.queueWheel(e.deltaX,e.deltaY,150,(e,i)=>{!this.host.operations.isLive(r,t)||this.host.activeTargetId!==n||this.host.mode!==`interact`||this.host.runAction(async t=>{if(this.host.evaluateUnavailable){await h(t,{targetId:n,key:i>=0?`PageDown`:`PageUp`});return}await Se(t,{targetId:n,deltaX:e,deltaY:i})})})}handleViewportKeydown(e){if(this.host.mode!==`interact`||!this.host.view||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key,n=this.host.activeTargetId;!ze(t)||!n||(e.preventDefault(),this.host.runAction(e=>h(e,{targetId:n,key:t})))}handleOverlayPointerDown(e){if(this.host.mode===`inspect`){this.suppressStageClick=!0,this.sendAnnotation({element:this.host.inspected});return}if(this.host.mode!==`annotate`||e.button!==0||this.drawingGesture)return;let t=E(this.stageElement(),e);if(!t)return;let n=e.currentTarget instanceof HTMLElement?e.currentTarget:e.target instanceof HTMLElement?e.target:null;if(!n)return;e.preventDefault();try{n.setPointerCapture(e.pointerId)}catch{}let r={pointerId:e.pointerId,captureTarget:n,stroke:{points:[t]}};this.drawingGesture=r,this.host.setState(`strokes`,[...this.host.strokes,r.stroke]),this.paintOverlay()}handleOverlayPointerMove(e){if(this.host.mode===`annotate`){let t=this.drawingGesture;if(!t||e.pointerId!==t.pointerId)return;let n=E(this.stageElement(),e);n&&(t.stroke.points.push(n),this.paintOverlay());return}this.host.mode===`inspect`&&this.queueInspect(e)}handleOverlayPointerUp(e){e.pointerId===this.drawingGesture?.pointerId&&(this.drawingGesture=null)}cancelOverlayPointerGesture(){let e=this.drawingGesture;if(this.drawingGesture=null,e)try{e.captureTarget.hasPointerCapture(e.pointerId)&&e.captureTarget.releasePointerCapture(e.pointerId)}catch{}}queueInspect(e){let t=this.host.operations.captureClient(),n=this.remotePoint(e),r=E(this.stageElement(),e),i=this.host.activeTargetId;if(!t||!n||!r||!i||this.host.evaluateUnavailable)return;let a=this.host.operations.beginInspection(t,()=>this.host.activeTargetId===i&&this.host.view?.targetId===i&&this.host.mode===`inspect`);this.host.setState(`inspected`,null),this.host.setState(`inspectPointer`,r),this.paintOverlay(),this.host.pendingInput.queueInspection(k,a,()=>{Te(t,{targetId:i,x:n.x,y:n.y}).then(e=>{a()&&(this.inspectionError!==null&&this.host.errorText===this.inspectionError&&this.host.setState(`errorText`,null),this.inspectionError=null,this.host.setState(`inspected`,e),this.paintOverlay())}).catch(e=>{if(a()){if(_(e)){this.host.setState(`evaluateUnavailable`,!0),this.host.setState(`errorText`,m(`browser.inspectUnavailable`)),this.host.setState(`mode`,`interact`);return}this.host.reportError(e),this.inspectionError=this.host.errorText}})})}undoStroke(){this.cancelOverlayPointerGesture(),this.host.setState(`strokes`,this.host.strokes.slice(0,-1)),this.paintOverlay()}clearStrokes(){this.cancelOverlayPointerGesture(),this.host.setState(`strokes`,[]),this.paintOverlay()}async sendAnnotation(e){this.cancelOverlayPointerGesture();let t=this.host.view,n=this.host.tabs.find(e=>e.id===this.host.activeTargetId),r=e.element??null;if(!t||this.host.strokes.length===0&&!r)return;let i=r?this.inspectHighlightRegion():null,a;try{a=Ue(t,n,this.host.strokes,r,i)}catch(e){this.host.reportError(e);return}if(a===`unhandled`){this.host.setState(`noticeText`,null),this.host.setState(`errorText`,m(`browser.noChatTarget`));return}if(a===`rejected`){this.host.setState(`noticeText`,null),this.host.setState(`errorText`,m(`browser.annotationLimitReached`));return}this.host.setState(`errorText`,null),this.host.setState(`noticeText`,m(`browser.annotationSent`)),this.host.exitCaptureModes()}paintOverlay(){He(this.host.host.renderRoot.querySelector(`.bp-overlay`),this.stageElement(),this.host.strokes,this.host.mode===`inspect`?this.inspectHighlightRegion():null)}}})))()}async function We(e,t,n,r,i){if(n||!r())return null;try{return await be(e,t)}catch(e){if(r()&&S(e))throw e;return r()&&_(e)&&i(),null}}var M;function N(){return(N=e((()=>{v(),M=class{constructor(e){this.host=e,this.lifecycleEpoch=0,this.requestedMutation=0,this.requestedSnapshot=0,this.acceptedSnapshot=0,this.requestedCapture=0,this.requestedInspection=0,this.capturePending=!1,this.navigationQueues=new WeakMap,this.navigationCommits=new WeakMap}get epoch(){return this.lifecycleEpoch}get hasPendingCapture(){return this.capturePending}captureClient(){let e=this.host.client;if(!this.host.available||!e||!this.host.isConnected||!this.host.browserPanelIsOpen())return null;if(this.scope?.gateway!==e){let t=Oe(e,this.route,()=>this.scope?.client===t&&this.scope.gateway===this.host.client&&this.host.available&&this.host.isConnected&&this.host.browserPanelIsOpen());this.scope={gateway:e,client:t}}return this.scope.client}resetRoute(e){this.invalidate(),this.route=e,this.scope=void 0}isLive(e,t){return this.host.isConnected&&this.host.available&&this.host.browserPanelIsOpen()&&this.lifecycleEpoch===e&&(t===void 0||this.scope?.gateway===this.host.client&&this.scope.client===t)}invalidate(){this.lifecycleEpoch+=1,this.capturePending=!1,this.invalidateInspection()}invalidateInspection(){this.requestedInspection+=1}beginMutation(e){this.requestedCapture+=1,this.capturePending=!1;let t={client:e,epoch:this.lifecycleEpoch,id:++this.requestedMutation,mutationId:this.requestedMutation,isCurrent:()=>this.isLive(t.epoch,e)&&t.id===this.requestedMutation};return t}hasQueuedNavigation(e,t){return this.navigationQueues.get(e)?.has(t)??!1}hasUnreconciledNavigation(e,t){return!e||!t?!1:this.navigationCommits.get(e)?.has(t)??!1}hasPendingNavigation(e,t){return!!(e&&t&&(this.hasQueuedNavigation(e,t)||this.hasUnreconciledNavigation(e,t)))}markNavigationCommitted(e,t){let n=this.navigationCommits.get(e);n||(n=new Set,this.navigationCommits.set(e,n)),n.add(t)}markNavigationReconciled(e,t){this.forgetNavigation(e,t)}forgetNavigation(e,t){let n=this.navigationCommits.get(e);n?.delete(t),n?.size===0&&this.navigationCommits.delete(e)}retainTabSnapshot(e,t){let n=this.navigationCommits.get(e);if(!n)return t;let r=new Set(t.map(e=>e.id));for(let e of n.keys())r.has(e)||n.delete(e);return n.size===0&&this.navigationCommits.delete(e),t}capturedTabs(e,t,n,r){let i=e.find(e=>e.id===t);if(!i)return e;let a=n?.title??i.title,o=n?.url||r||i.url;return a===i.title&&o===i.url&&!i.urlUnavailableReason?e:e.map(e=>e.id===t?{...e,title:a,url:o,urlUnavailableReason:void 0}:e)}async queueNavigation(e,t,n){let r=this.navigationQueues.get(e);r||(r=new Map,this.navigationQueues.set(e,r));let i=r.get(t),a=i?i.then(n,n):n();r.set(t,a);try{return await a}finally{r.get(t)===a&&(r.delete(t),r.size===0&&this.navigationQueues.delete(e))}}beginSnapshot(e){let t=this.requestedMutation,n={client:e,epoch:this.lifecycleEpoch,id:++this.requestedSnapshot,mutationId:t,isCurrent:()=>this.isLive(n.epoch,e)&&n.id===this.requestedSnapshot&&t===this.requestedMutation};return n}acceptSnapshot(e,t,n){return!this.isLive(e.epoch,e.client)||e.id<this.acceptedSnapshot||!e.isCurrent()&&n!==t?!1:(this.acceptedSnapshot=e.id,!0)}canCaptureSnapshot(e){return this.isLive(e.epoch,e.client)&&e.mutationId===this.requestedMutation}survivingInvocation(e,t){let n=this.lifecycleEpoch,r=this.requestedMutation;return()=>this.isLive(n,t)&&r===this.requestedMutation&&(r!==e.id||n!==e.epoch)}beginCapture(e,t,n,r=this.lifecycleEpoch){if(!this.isLive(r,e)||n()!==t)return null;let i=++this.requestedCapture;return this.capturePending=!0,()=>this.isLive(r,e)&&n()===t&&i===this.requestedCapture}completeCapture(){this.capturePending=!1}beginInspection(e,t){let n=this.lifecycleEpoch,r=++this.requestedInspection;return()=>this.isLive(n,e)&&r===this.requestedInspection&&t()}}})))()}var P;function F(){return(F=e((()=>{P=class{constructor(){this.refreshTimer=null,this.viewportResizeTimer=null,this.wheelTimer=null,this.inspectTimer=null,this.wheelDeltaX=0,this.wheelDeltaY=0,this.lastInspectAt=0}clear(){this.refreshTimer!==null&&(clearTimeout(this.refreshTimer),this.refreshTimer=null),this.viewportResizeTimer!==null&&(clearTimeout(this.viewportResizeTimer),this.viewportResizeTimer=null),this.clearInput()}clearInput(){this.wheelTimer!==null&&(clearTimeout(this.wheelTimer),this.wheelTimer=null),this.inspectTimer!==null&&(clearTimeout(this.inspectTimer),this.inspectTimer=null),this.wheelDeltaX=0,this.wheelDeltaY=0,this.lastInspectAt=0}scheduleRefresh(e,t){this.refreshTimer!==null&&clearTimeout(this.refreshTimer),this.refreshTimer=window.setTimeout(()=>{this.refreshTimer=null,t()},e)}scheduleViewportResize(e,t){this.viewportResizeTimer!==null&&clearTimeout(this.viewportResizeTimer),this.viewportResizeTimer=window.setTimeout(()=>{this.viewportResizeTimer=null,t()},e)}queueWheel(e,t,n,r){this.wheelDeltaX+=e,this.wheelDeltaY+=t,this.wheelTimer===null&&(this.wheelTimer=window.setTimeout(()=>{this.wheelTimer=null;let e=this.wheelDeltaX,t=this.wheelDeltaY;this.wheelDeltaX=0,this.wheelDeltaY=0,(e!==0||t!==0)&&r(e,t)},n))}queueInspection(e,t,n){let r=()=>{t()&&(this.lastInspectAt=Date.now(),n())};if(Date.now()-this.lastInspectAt>=e){r();return}this.inspectTimer!==null&&clearTimeout(this.inspectTimer),this.inspectTimer=window.setTimeout(()=>{this.inspectTimer=null,r()},e)}}})))()}function I(e){let t=e.trim();if(!t)return null;let n=/^[a-z][a-z0-9+.-]*:(?![0-9])/i.test(t);if(n&&!/^https?:\/\//i.test(t))return null;let r=n?t:`https://${t}`;try{let e=new URL(r);return e.protocol===`http:`||e.protocol===`https:`?e.toString():null}catch{return null}}var L,R,z,B,V;function H(){return(H=e((()=>{d(),i(),v(),j(),N(),F(),O(),C(),L=350,R=300,z=100,B=8192,V=class{constructor(e){this.host=e,this.running=null,this.tabs=[],this.activeTargetId=null,this.view=null,this.loading=!1,this.errorText=null,this.noticeText=null,this.mode=`interact`,this.strokes=[],this.inspected=null,this.inspectPointer=null,this.evaluateUnavailable=!1,this.urlDraft=``,this.pendingNewTab=!1,this.pendingInput=new P,this.activeClient=null,this.urlDraftEditing=!1,this.observedViewportSize=null,this.lastRequestedViewport=null,this.operations=new M(e),this.input=new A(this),e.addController(this)}hostDisconnected(){this.input.cancelOverlayPointerGesture(),this.invalidateViewOperations(),this.setState(`loading`,!1)}setState(e,t){Object.is(this[e],t)||(Object.assign(this,{[e]:t}),this.host.requestUpdate())}synchronizeClient(){return this.host.client!==this.activeClient&&(this.activeClient=this.host.client,this.operations.resetRoute(),this.resetBrowserState(),!0)}get unavailableTabText(){let e=this.tabs.find(e=>e.id===this.activeTargetId)?.urlUnavailableReason;return e?m(e===`navigation_blocked`?`browser.navigationBlocked`:`browser.navigationCheckFailed`):null}clearUnavailableView(){return this.unavailableTabText?(this.invalidateViewOperations(),this.setState(`view`,null),this.setState(`loading`,!1),this.setState(`urlDraft`,``),this.setState(`errorText`,null),this.exitCaptureModes(),!0):!1}invalidateViewOperations(){this.operations.invalidate(),this.pendingInput.clear(),this.lastRequestedViewport=null}resetBrowserState(){this.invalidateViewOperations(),this.setState(`running`,null),this.setState(`tabs`,[]),this.setState(`activeTargetId`,null),this.setState(`view`,null),this.setState(`loading`,!1),this.setState(`errorText`,null),this.setState(`noticeText`,null),this.setState(`mode`,`interact`),this.setState(`strokes`,[]),this.input.resetCaptureState(),this.setState(`inspected`,null),this.setState(`inspectPointer`,null),this.urlDraftEditing=!1,this.setState(`urlDraft`,``),this.setState(`pendingNewTab`,!1),this.setState(`evaluateUnavailable`,!1)}reportError(e){let t=S(e)?m(`browser.navigationBlocked`):n(e);this.setState(`errorText`,m(`browser.errors.requestFailed`,{error:t}))}async refreshAll(){let e=this.operations.captureClient();if(!e)return;let t=this.operations.beginSnapshot(e);this.setState(`errorText`,null),this.setState(`loading`,!0);try{let n=await x(e),r=n.tabs.find(e=>e.id===this.activeTargetId||e.targetId===this.activeTargetId),i=r??n.tabs.find(e=>!e.urlUnavailableReason)??n.tabs[0];if(!this.operations.acceptSnapshot(t,this.activeTargetId,i?.id??null)||(this.setState(`running`,n.running),this.setState(`tabs`,this.operations.retainTabSnapshot(e,n.tabs)),!this.operations.canCaptureSnapshot(t)))return;n.running||this.setState(`view`,null),this.activeTargetId!==null&&!r&&(this.invalidateViewOperations(),t.epoch=this.operations.epoch,this.setState(`view`,null),this.exitCaptureModes()),this.setState(`activeTargetId`,i?.id??null),this.urlDraftEditing||this.setState(`urlDraft`,i?.url??``),i?await this.refreshView(i.id,t.epoch):this.setState(`view`,null)}catch(e){t.isCurrent()&&this.reportError(e)}finally{t.isCurrent()&&this.setState(`loading`,!1)}}async refreshView(e,t=this.operations.epoch){let n=this.operations.captureClient();if(!n||!this.operations.isLive(t,n)||this.activeTargetId!==e||this.clearUnavailableView())return;let r=this.operations.beginCapture(n,e,()=>this.activeTargetId,t);if(r){this.setState(`loading`,!0);try{let t=await ae(n,e);if(!r())return;let i=await ge({resourceBasePath:this.host.resourceBasePath,authToken:this.host.authToken,path:t.path});if(!r())return;let a=await Re(i),o=await We(n,e,this.evaluateUnavailable,r,()=>this.setState(`evaluateUnavailable`,!0));if(!r())return;let s=t.url&&o?.url&&t.url!==o.url?null:o;this.setState(`tabs`,this.operations.capturedTabs(this.tabs,e,s,t.url)),this.setState(`view`,{targetId:e,dataUrl:i,image:a,url:t.url,metrics:s,...this.operations.route?{browserTab:{...this.operations.route,targetId:e}}:{}}),s&&this.observedViewportSize&&(Math.abs(s.cssWidth-this.observedViewportSize.width)>1||Math.abs(s.cssHeight-this.observedViewportSize.height)>1)&&this.scheduleViewportSync(),!this.urlDraftEditing&&t.url&&this.setState(`urlDraft`,t.url)}catch(t){r()&&(S(t)?(this.setState(`tabs`,this.tabs.map(t=>t.id===e?{...t,url:``,urlUnavailableReason:`navigation_blocked`}:t)),this.clearUnavailableView()||this.reportError(t)):this.reportError(t))}finally{r()&&(this.operations.completeCapture(),this.setState(`loading`,!1))}}}async runAction(e,t=!0){let n=this.operations.captureClient();if(!n)return!1;let r=this.operations.epoch,i=()=>this.operations.isLive(r,n);try{return this.setState(`errorText`,null),await e(n),i()&&t&&this.pendingInput.scheduleRefresh(L,()=>{i()&&this.activeTargetId&&this.refreshView(this.activeTargetId,r)}),i()}catch(e){return i()?(_(e)&&this.setState(`evaluateUnavailable`,!0),this.reportError(e),this.operations.hasPendingCapture||this.setState(`loading`,!1),!1):!1}}handleViewportResize(e,t){this.observedViewportSize={width:e,height:t},this.scheduleViewportSync()}scheduleViewportSync(){this.pendingInput.scheduleViewportResize(R,()=>this.syncViewport())}syncViewport(){let e=this.activeTargetId,t=this.observedViewportSize;if(!this.host.browserPanelIsOpen()||!this.operations.captureClient()||!e||!t)return;let n=Math.min(B,Math.max(z,Math.round(t.width))),r=Math.min(B,Math.max(z,Math.round(t.height))),i=this.view?.targetId===e?this.view:null;if(!i)return;let a=i.metrics;a&&Math.abs(a.cssWidth-n)<=1&&Math.abs(a.cssHeight-r)<=1||(this.lastRequestedViewport?.targetId!==e||this.lastRequestedViewport.width!==n||this.lastRequestedViewport.height!==r)&&(this.lastRequestedViewport={targetId:e,width:n,height:r},this.runAction(t=>De(t,{targetId:e,width:n,height:r})))}async startBrowserNow(){if(!this.operations.captureClient())return;let e=this.operations.epoch;this.setState(`loading`,!0),await this.runAction(async t=>{await Ee(t),this.operations.isLive(e,t)&&await this.refreshAll()},!1)}async openUrl(e,t){let n=this.operations.captureClient();if(!n)return;let r=this.operations.beginMutation(n);this.setState(`loading`,!0),this.setState(`errorText`,null),this.setState(`pendingNewTab`,!1);let i=!1;try{if(t.newTab||!this.activeTargetId){let t=await pe(n,e);if(!r.isCurrent()){await this.refreshTabsOnly(n,this.operations.survivingInvocation(r,n));return}let i=t?.id??this.activeTargetId;i!==this.activeTargetId&&(this.invalidateViewOperations(),r.epoch=this.operations.epoch,this.setState(`view`,null),this.exitCaptureModes()),this.setState(`activeTargetId`,i)}else{this.invalidateViewOperations(),r.epoch=this.operations.epoch,this.exitCaptureModes();let t=this.activeTargetId;if(i=this.operations.hasQueuedNavigation(n,t)||this.operations.hasUnreconciledNavigation(n,t),await this.operations.queueNavigation(n,t,async()=>{r.isCurrent()&&(await ye(n,{url:e,targetId:t}),this.operations.markNavigationCommitted(n,t))}),!r.isCurrent())return;this.setState(`view`,null)}if(await this.refreshTabsOnly(n,()=>r.isCurrent())!==`rejected`&&r.isCurrent()&&this.activeTargetId){let e=this.activeTargetId;await this.refreshView(e,r.epoch),!t.newTab&&r.isCurrent()&&this.view?.targetId===e&&this.operations.markNavigationReconciled(n,e)}}catch(e){if(r.isCurrent()){if(i&&this.activeTargetId){let e=this.activeTargetId,t=await this.refreshTabsOnly(n,()=>r.isCurrent()),i=this.tabs.find(t=>t.id===e);t===`accepted`&&r.isCurrent()&&i&&(this.setState(`view`,null),await this.refreshView(e,r.epoch),r.isCurrent()&&this.view?.targetId===e&&this.operations.markNavigationReconciled(n,e)),r.isCurrent()&&this.operations.hasUnreconciledNavigation(n,e)&&(this.setState(`activeTargetId`,null),this.setState(`view`,null),this.urlDraftEditing||this.setState(`urlDraft`,``))}this.reportError(e)}}finally{r.isCurrent()&&this.setState(`loading`,!1)}}async refreshTabsOnly(e,t){let n=this.operations.beginSnapshot(e);try{let r=await x(e);return t()&&this.operations.acceptSnapshot(n,this.activeTargetId,this.activeTargetId)?(this.setState(`running`,r.running),this.setState(`tabs`,this.operations.retainTabSnapshot(e,r.tabs)),this.clearUnavailableView(),`accepted`):`rejected`}catch{return t()&&n.isCurrent()?`failed`:`rejected`}}async selectTab(e,t){if(t&&w(this.operations.route)!==w(t))this.operations.resetRoute(t),this.resetBrowserState();else if(e===this.activeTargetId&&!t)return;let n=this.operations.captureClient(),r={targetId:this.activeTargetId,view:this.view};this.invalidateViewOperations();let i=this.operations.epoch;if(this.setState(`activeTargetId`,e),this.setState(`view`,null),this.exitCaptureModes(),!(!t&&this.clearUnavailableView())&&!await this.runAction(async n=>{if(t){if(await this.refreshTabsOnly(n,()=>this.operations.isLive(i,n)),!this.operations.isLive(i,n))return;let t=this.tabs.find(t=>t.id===e||t.targetId===e);if(this.setState(`activeTargetId`,t?.id??e),this.clearUnavailableView())return}let r=this.activeTargetId;r&&(await ve(n,r),this.operations.isLive(i,n)&&(await this.refreshView(r,i),this.operations.isLive(i,n)&&this.activeTargetId===r&&this.view?.targetId===r&&this.operations.markNavigationReconciled(n,r)))},!1)&&this.operations.isLive(i)&&this.activeTargetId===e){if(this.operations.hasPendingNavigation(n,r.targetId)){this.setState(`activeTargetId`,null),this.urlDraftEditing||this.setState(`urlDraft`,``);return}this.setState(`activeTargetId`,r.targetId),this.setState(`view`,r.view)}}async closeTab(e){await this.runAction(async t=>{let n=this.operations.epoch;if(await le(t,e),this.operations.forgetNavigation(t,e),!this.operations.isLive(n,t)){this.operations.isLive(this.operations.epoch,t)&&await this.refreshAll();return}this.setState(`tabs`,this.tabs.filter(t=>t.id!==e));let r=await this.refreshTabsOnly(t,()=>this.operations.isLive(n,t));if(!this.operations.isLive(n,t))return;if(this.activeTargetId!==e){r!==`rejected`&&!this.operations.hasPendingCapture&&this.setState(`loading`,!1);return}let i=this.tabs.find(e=>!e.urlUnavailableReason)??this.tabs[0]??null;this.invalidateViewOperations(),this.setState(`activeTargetId`,i?.id??null),this.setState(`view`,null),this.exitCaptureModes(),i?await this.refreshView(i.id):this.setState(`loading`,!1)},!1),await this.host.updateComplete}reloadPage(){if(this.unavailableTabText){this.refreshAll();return}let e=I(this.view?.metrics?.url||this.view?.url||this.urlDraft);if(this.activeTargetId){if(!e){this.refreshView(this.activeTargetId);return}this.openUrl(e,{newTab:!1})}}goHistory(e){let t=this.activeTargetId;!t||!this.view||this.runAction(n=>ce(n,{targetId:t,delta:e}))}commitUrlDraft(){let e=I(this.urlDraft);e&&this.openUrl(e,{newTab:this.pendingNewTab||this.tabs.length===0})}beginNewTab(){this.setState(`pendingNewTab`,!0),this.setState(`urlDraft`,``);let e=this.operations.epoch;this.host.updateComplete.then(()=>{this.operations.isLive(e)&&this.host.renderRoot.querySelector(`.bp-url`)?.focus()})}setUrlDraft(e){this.setState(`urlDraft`,e)}setUrlDraftEditing(e){this.urlDraftEditing=e}resetUrlDraftFromView(){this.setState(`urlDraft`,this.view?.metrics?.url||this.view?.url||``)}exitCaptureModes(){this.operations.invalidateInspection(),this.input.resetCaptureState(),this.setState(`mode`,`interact`),this.setState(`strokes`,[]),this.setState(`inspected`,null),this.setState(`inspectPointer`,null)}setMode(e){if(this.mode===e){this.exitCaptureModes();return}this.exitCaptureModes(),this.setState(`mode`,e),this.setState(`noticeText`,null),e===`inspect`&&this.evaluateUnavailable&&(this.setState(`errorText`,m(`browser.inspectUnavailable`)),this.setState(`mode`,`interact`))}inspectHighlightRegion(){return this.input.inspectHighlightRegion()}handleStageClick(e){this.input.handleStageClick(e)}handleWheel(e){this.input.handleWheel(e)}handleViewportKeydown(e){this.input.handleViewportKeydown(e)}handleOverlayPointerDown(e){this.input.handleOverlayPointerDown(e)}handleOverlayPointerMove(e){this.input.handleOverlayPointerMove(e)}handleOverlayPointerUp(e){this.input.handleOverlayPointerUp(e)}cancelOverlayPointerGesture(){this.input.cancelOverlayPointerGesture()}undoStroke(){this.input.undoStroke()}clearStrokes(){this.input.clearStrokes()}async sendAnnotation(e){await this.input.sendAnnotation(e)}paintOverlay(){this.input.paintOverlay()}}})))()}function Ge(e){if(e.title.trim())return e.title.trim();try{return new URL(e.url).host||m(`browser.untitledTab`)}catch{return e.url||m(`browser.untitledTab`)}}function Ke(e){let t=e.tabs.map(e=>{let t=Ge(e);return{id:e.id,domId:`browser-tab-${e.id}`,label:t,title:e.url,closeLabel:`${m(`browser.closeTab`)}: ${t}`}});return Pe({tabs:t,activeId:e.activeTargetId,ariaControls:`browser-tab-panel`,onSelect:e.onSelect,onClose:e.onClose,onNew:e.onNew,newLabel:m(`browser.newTab`),newTabAction:!0,...e.hideNewControl?{newControl:o}:{}})}function U(){return(U=e((()=>{c(),d(),T()})))()}function qe(e,t){return Ke({tabs:e.tabs,activeTargetId:e.activeTargetId,onSelect:t=>void e.selectTab(t),onClose:t=>e.closeTab(t),onNew:()=>e.beginNewTab(),hideNewControl:t})}function Je(e,t,n,r){let i=e.view?.metrics?.url||e.view?.url||e.urlDraft;return s`
<div class="rail-header__actions bp-actions">
${Ie({current:t,groupClass:`bp-dock-modes`,groupLabel:m(`browser.title`),destinations:[{dock:`bottom`,label:m(`browser.dockBottom`),icon:f.panelBottomOpen,className:`bp-icon`},{dock:`right`,label:m(`browser.dockRight`),icon:f.panelRightOpen,className:`bp-icon`}],onSelect:n})}
<button
class="rail-header__action bp-icon"
type="button"
data-new-tab-action
title=${m(`browser.openExternal`)}
aria-label=${m(`browser.openExternal`)}
?disabled=${!i}
@click=${()=>{i&&we(i)}}
>
${f.externalLink}
</button>
<button
class="rail-header__action bp-icon"
type="button"
title=${m(`browser.close`)}
aria-label=${m(`browser.close`)}
@click=${r}
>
${f.x}
</button>
</div>
`}function Ye(e,t){let n=!!e.view;return s`
<div class="bp-toolbar">
${e.operations.route?s`<span
class="bp-profile"
title=${m(`browser.profile`,{profile:e.operations.route.profile})}
>${e.operations.route.profile}</span
>`:o}
${t?s`<button
class="bp-icon"
type="button"
data-new-tab-action
title=${m(`browser.newTab`)}
aria-label=${m(`browser.newTab`)}
@click=${()=>e.beginNewTab()}
>
${f.plus}
</button>`:o}
<button
class="bp-icon"
type="button"
title=${m(`browser.back`)}
aria-label=${m(`browser.back`)}
?disabled=${!n||e.evaluateUnavailable}
@click=${()=>e.goHistory(-1)}
>
${G}
</button>
<button
class="bp-icon"
type="button"
title=${m(`browser.forward`)}
aria-label=${m(`browser.forward`)}
?disabled=${!n||e.evaluateUnavailable}
@click=${()=>e.goHistory(1)}
>
${K}
</button>
<button
class="bp-icon"
type="button"
title=${m(`browser.reload`)}
aria-label=${m(`browser.reload`)}
?disabled=${!e.activeTargetId}
@click=${()=>e.reloadPage()}
>
${q}
</button>
<input
class="bp-url"
type="text"
spellcheck="false"
autocomplete="off"
placeholder=${m(`browser.urlPlaceholder`)}
.value=${e.urlDraft}
@focus=${t=>{e.setUrlDraftEditing(!0),t.target.select()}}
@blur=${()=>e.setUrlDraftEditing(!1)}
@input=${t=>e.setUrlDraft(t.target.value)}
@keydown=${t=>{t.key===`Enter`?(t.preventDefault(),e.commitUrlDraft(),t.target.blur()):t.key===`Escape`&&(e.resetUrlDraftFromView(),t.target.blur())}}
/>
<button
class="bp-icon ${e.mode===`annotate`?`is-active`:``}"
type="button"
title=${m(`browser.annotate`)}
aria-label=${m(`browser.annotate`)}
?disabled=${!n}
@click=${()=>e.setMode(`annotate`)}
>
${J}
</button>
<button
class="bp-icon ${e.mode===`inspect`?`is-active`:``}"
type="button"
title=${e.evaluateUnavailable?m(`browser.inspectUnavailable`):m(`browser.inspect`)}
aria-label=${m(`browser.inspect`)}
?disabled=${!n||e.evaluateUnavailable}
@click=${()=>e.setMode(`inspect`)}
>
${Y}
</button>
</div>
`}function Xe(e){return e.mode===`annotate`?s`
<div class="bp-annotatebar">
<span class="bp-annotatebar__hint">${m(`browser.annotateHint`)}</span>
<button
class="bp-btn"
type="button"
?disabled=${e.strokes.length===0}
@click=${()=>e.undoStroke()}
>
${m(`browser.annotateUndo`)}
</button>
<button
class="bp-btn"
type="button"
?disabled=${e.strokes.length===0}
@click=${()=>e.clearStrokes()}
>
${m(`browser.annotateClear`)}
</button>
<button
class="bp-btn"
type="button"
title=${m(`browser.annotateDone`)}
@click=${()=>e.exitCaptureModes()}
>
${W}
</button>
<button
class="bp-btn bp-btn--primary"
type="button"
?disabled=${e.strokes.length===0}
@click=${()=>void e.sendAnnotation({})}
>
${m(`browser.annotateSend`)}
</button>
</div>
`:o}function Ze(e){let t=e.inspected,n=e.inspectPointer;if(e.mode!==`inspect`||!t||!n)return o;let r=`${Math.min(92,Math.max(0,n.x*100))}%`,i=`${Math.min(92,Math.max(0,n.y*100+2))}%`,a=t.classes.map(e=>`.${e}`).join(``);return s`
<div class="bp-tooltip" style="left:${r};top:${i}">
<div class="bp-tooltip__title">
<span class="bp-tooltip__selector"
>${t.tag}${t.id?`#${t.id}`:``}${a}</span
>
<span class="bp-tooltip__size"
>${Math.round(t.rect.width)} × ${Math.round(t.rect.height)}</span
>
</div>
${t.name?s`<div class="bp-tooltip__row">
<span>${m(`browser.inspectName`)}</span><span>${t.name}</span>
</div>`:o}
${t.role?s`<div class="bp-tooltip__row">
<span>${m(`browser.inspectRole`)}</span><span>${t.role}</span>
</div>`:o}
<div class="bp-tooltip__row">
<span>${m(`browser.inspectFocusable`)}</span><span>${t.focusable?`✓`:``}</span>
</div>
</div>
`}function Qe(e){if(e.running===!1)return b({icon:f.globe,heading:m(`chat.sidePanel.browser`),description:m(`browser.notRunning`),action:s`
<button class="bp-btn" type="button" @click=${()=>void e.startBrowserNow()}>
${m(`browser.start`)}
</button>
`});if(!e.view&&e.unavailableTabText)return s`<div class="bp-status" role="status">${e.unavailableTabText}</div>`;if(!e.view)return e.loading?g(`browser`,m(`browser.loading`)):b({icon:f.globe,heading:m(`chat.sidePanel.browser`),description:m(`chat.sidePanel.browserEmpty`)});let t=e.mode===`annotate`?`bp-overlay--annotate`:e.mode===`inspect`?`bp-overlay--inspect`:``;return s`
<div class="bp-stage">
<img
class="bp-shot"
src=${e.view.dataUrl}
alt=${e.view.metrics?.title||``}
/>
<canvas
class="bp-overlay ${t}"
@click=${t=>e.handleStageClick(t)}
@pointerdown=${t=>e.handleOverlayPointerDown(t)}
@pointermove=${t=>e.handleOverlayPointerMove(t)}
@pointerup=${t=>e.handleOverlayPointerUp(t)}
@pointercancel=${t=>e.handleOverlayPointerUp(t)}
@lostpointercapture=${t=>e.handleOverlayPointerUp(t)}
></canvas>
${Ze(e)}
</div>
`}function $e(e){return s`
<wa-tab-panel
id="browser-tab-panel"
class="bp-viewport"
name=${e.activeTargetId??`browser`}
active
aria-labelledby=${e.activeTargetId?`browser-tab-${e.activeTargetId}`:o}
tabindex="0"
@wheel=${t=>e.handleWheel(t)}
@keydown=${t=>e.handleViewportKeydown(t)}
aria-busy=${e.loading?`true`:`false`}
>
${Qe(e)}
${e.loading&&e.view?g(`browser`,m(`browser.loading`),!1,!0):o}
</wa-tab-panel>
`}function et(e,t,n,r,i,a,c,l=!1){let ee=l?o:t===`bottom`?`height:${n}px`:`width:${r}px`;return s`
<section
class="bp bp--${l?`embedded`:t}"
style=${ee}
aria-label=${m(`browser.title`)}
>
${l?o:c}
${l&&e.tabs.length===0?o:s`<header class="rail-header bp-header">
${qe(e,l)}
${l?o:Je(e,t,i,a)}
</header>`}
${Ye(e,l)} ${Xe(e)}
${e.errorText?s`<div class="bp-note bp-note--error" role="alert">${e.errorText}</div>`:e.noticeText?s`<div class="bp-note" role="status">${e.noticeText}</div>`:o}
${$e(e)}
</section>
`}var W,G,K,q,J,Y;function X(){return(X=e((()=>{c(),d(),xe(),Le(),ne(),oe(),he(),U(),W=l`<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M4 4l8 8M12 4l-8 8" /></svg>`,G=l`<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L5 8l5 5" /></svg>`,K=l`<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3l5 5-5 5" /></svg>`,q=l`<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M13 8a5 5 0 1 1-1.5-3.6M13 2.5V5h-2.5" /></svg>`,J=l`<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M11.3 2.7l2 2L5 13H3v-2z" /></svg>`,Y=l`<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l5.5 10 1.2-4.3L14 7.5z" /></svg>`})))()}var Z;function Q(){return(Q=e((()=>{c(),Z=te`
/* Docked panels get a single hairline separator on the inner edge so they
read as layout, not as a floating card. The browser dock yields to the
terminal dock's reserved edges so the two panels tile instead of
overlapping when both are open. */
.bp--bottom {
left: var(--shell-nav-width, 0);
right: var(--oc-terminal-reserve-right, 0px);
bottom: var(--oc-terminal-reserve-bottom, 0px);
}
.bp--right {
top: var(--shell-topbar-height, 0);
right: var(--oc-terminal-reserve-right, 0px);
bottom: var(--oc-terminal-reserve-bottom, 0px);
}
.bp--embedded {
position: relative;
width: 100%;
height: 100%;
}
.bp-actions {
flex: none;
}
.bp-profile {
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--muted);
font-size: 11px;
}
.bp-toolbar {
display: flex;
align-items: center;
gap: 4px;
padding: 5px 8px;
border-bottom: 1px solid var(--border, #262b34);
}
.bp-toolbar .bp-icon {
display: inline-flex;
width: 28px;
height: 28px;
align-items: center;
justify-content: center;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--muted, #8a919e);
}
.bp-toolbar .bp-icon:hover,
.bp-toolbar .bp-icon:focus-visible {
background: color-mix(in srgb, var(--text, #d7dae0) 10%, transparent);
color: var(--text, #d7dae0);
}
.bp-url {
flex: 1;
min-width: 0;
height: 28px;
padding: 0 12px;
border: 1px solid transparent;
border-radius: 14px;
background: color-mix(in srgb, var(--text, #d7dae0) 8%, transparent);
color: var(--text, #d7dae0);
font-size: 12.5px;
font-family: inherit;
outline: none;
text-overflow: ellipsis;
}
.bp-url:focus {
border-color: var(--accent, #ff5c5c);
background: var(--bg, #0e1015);
}
.bp-annotatebar {
display: flex;
align-items: center;
gap: 8px;
padding: 5px 10px;
font-size: 12px;
color: var(--muted, #8a919e);
border-bottom: 1px solid var(--border, #262b34);
background: color-mix(in srgb, var(--accent, #ff5c5c) 7%, transparent);
}
.bp-annotatebar__hint {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bp-btn {
border: 1px solid var(--border, #262b34);
background: transparent;
color: var(--text, #d7dae0);
font-size: 12px;
font-family: inherit;
border-radius: 6px;
padding: 3px 10px;
}
.bp-btn:hover {
background: color-mix(in srgb, var(--text, #d7dae0) 10%, transparent);
}
.bp-btn--primary {
border-color: var(--accent, #ff5c5c);
color: var(--accent, #ff5c5c);
}
.bp-viewport {
position: relative;
display: flex;
flex: 1;
min-height: 0;
flex-direction: column;
overflow: auto;
background: var(--bg, #0e1015);
outline: none;
}
/* The tab panel's own body must stretch, otherwise an empty state sizes to its
content and sits in the upper third instead of centring in the viewport. */
.bp-viewport::part(base) {
display: flex;
flex: 1 1 auto;
min-height: 0;
flex-direction: column;
}
.bp-stage {
position: relative;
width: 100%;
}
.bp-shot {
display: block;
width: 100%;
height: auto;
user-select: none;
-webkit-user-drag: none;
}
.bp-overlay {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
touch-action: none;
}
.bp-overlay--annotate {
cursor: crosshair;
}
.bp-overlay--inspect {
cursor: default;
}
.bp-tooltip {
position: absolute;
z-index: 3;
max-width: 320px;
padding: 8px 10px;
border-radius: 8px;
border: 1px solid var(--border, #262b34);
background: var(--bg, #0e1015);
box-shadow: var(--shadow-md, 0 4px 16px rgba(0, 0, 0, 0.3));
font-size: 12px;
pointer-events: none;
}
.bp-tooltip__title {
display: flex;
align-items: baseline;
gap: 8px;
justify-content: space-between;
}
.bp-tooltip__selector {
color: var(--accent, #6ea8fe);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
word-break: break-all;
}
.bp-tooltip__size {
color: var(--muted, #8a919e);
white-space: nowrap;
}
.bp-tooltip__row {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 4px;
color: var(--muted, #8a919e);
}
.bp-tooltip__row span:last-child {
color: var(--text, #d7dae0);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bp-status {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
height: 100%;
padding: 20px;
font-size: 12.5px;
color: var(--muted, #8a919e);
text-align: center;
}
.bp-note {
padding: 6px 12px;
font-size: 12px;
color: var(--muted, #8a919e);
border-bottom: 1px solid var(--border, #262b34);
}
.bp-note--error {
color: var(--danger, #ff6b6b);
}
`})))()}var tt,$;function nt(){return(nt=e((()=>{c(),ee(),d(),r(),Ae(),Me(),T(),re(),H(),X(),Q(),C(),tt=Ce({storageKey:`openclaw.browser.panel.v1`,minHeight:240,minWidth:380,defaultDock:`right`,supportedDocks:[`bottom`,`right`],defaultHeight:420,defaultWidth:560}),$=class extends a{constructor(...e){super(...e),this.client=null,this.available=!1,this.suppressed=!1,this.resourceBasePath=``,this.authToken=null,this.embedded=!1,this.presented=!1,this.refreshOnPresentation=!0,this.sessionKey=``,this.activeSessionKey=``,this.browserPanelController=new V(this),this.dockLayout=new Ne(this,{layout:tt,reservationPrefix:`browser`,isAvailable:()=>this.available}),this.onToggleRequest=e=>this.handleToggleRequest(e),this.viewportResizeObserver=null,this.observedViewportElement=null}static{this.styles=[Fe,je,Z,ke]}connectedCallback(){super.connectedCallback(),this.embedded||window.addEventListener(p,this.onToggleRequest),this.dockLayout.setSuppressed(this.suppressed),!this.embedded&&this.dockLayout.open&&this.browserPanelController.refreshAll()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(p,this.onToggleRequest),this.viewportResizeObserver?.disconnect(),this.viewportResizeObserver=null,this.observedViewportElement=null}updated(e){if(e.has(`embedded`)&&(this.embedded?window.removeEventListener(p,this.onToggleRequest):window.addEventListener(p,this.onToggleRequest)),e.has(`suppressed`)){let e=this.dockLayout.setSuppressed(this.suppressed);this.suppressed?this.browserPanelController.cancelOverlayPointerGesture():e&&this.browserPanelIsOpen()&&this.browserPanelController.refreshAll()}let t=e.has(`client`)||e.has(`available`),n=this.embedded&&(e.has(`embedded`)||e.has(`presented`)),r=this.synchronizeBrowserContext(),i=this.refreshOnPresentation&&this.followPreferredTab();this.embedded?!this.presented||!this.available||!this.client?(n||t)&&this.browserPanelController.hostDisconnected():this.refreshOnPresentation&&!i&&(r||n||t)&&this.browserPanelController.refreshAll():t&&(!this.available&&this.dockLayout.open?(this.dockLayout.hideWithoutPersisting(),this.browserPanelController.resetBrowserState()):this.available&&(this.dockLayout.restoreOpenState()||r&&this.browserPanelIsOpen())&&!i&&this.browserPanelController.refreshAll()),this.dockLayout.syncReservation(),this.browserPanelController.paintOverlay();let a=this.renderRoot.querySelector(`.bp-viewport`);a!==this.observedViewportElement&&(this.viewportResizeObserver?.disconnect(),this.observedViewportElement=a,a&&typeof ResizeObserver==`function`&&(this.viewportResizeObserver??=new ResizeObserver(e=>{let t=e[0];t&&this.browserPanelController.handleViewportResize(t.contentRect.width,t.contentRect.height)}),this.viewportResizeObserver.observe(a)))}synchronizeBrowserContext(){let e=this.browserPanelController.synchronizeClient(),t=this.activeSessionKey!==this.sessionKey;return t&&(this.activeSessionKey=this.sessionKey,this.browserPanelController.operations.resetRoute(),this.browserPanelController.resetBrowserState()),(e||t)&&(this.consumedPreferredRevision=void 0),e||t}preferredRevision(){let e=this.preferredTab;return e&&y(e.tab)?JSON.stringify([ie(e.tab),e.revision]):void 0}followPreferredTab(){let e=this.preferredRevision();if(!this.browserPanelIsOpen()||!this.available||!this.client||!this.preferredTab||!e||e===this.consumedPreferredRevision)return!1;this.consumedPreferredRevision=e;let t=y(this.preferredTab.tab);return t&&this.browserPanelController.selectTab(t.targetId,t),!0}browserPanelIsOpen(){return this.embedded?this.presented&&!this.suppressed:this.dockLayout.open}toggle(){this.available&&(this.dockLayout.open?this.closePanel():(this.dockLayout.setOpen(!0),this.browserPanelController.refreshAll()))}handleToggleRequest(e){let t=e instanceof CustomEvent&&typeof e.detail==`object`&&e.detail!==null?e.detail:null;this.synchronizeBrowserContext();let n=y(t?.browserTab);if(t?.browserTab!==void 0&&!n)return;if(this.embedded){if(!this.browserPanelIsOpen()||t?.open===!1||!this.available)return;let e=typeof t?.url==`string`?I(t.url):null;e?this.browserPanelController.openUrl(e,{newTab:!0}):n?(this.consumedPreferredRevision=this.preferredRevision(),this.browserPanelController.selectTab(n.targetId,n)):t?.newTab===!0?this.browserPanelController.beginNewTab():this.followPreferredTab()||this.browserPanelController.refreshAll();return}if((t?.dock===`right`||t?.dock===`bottom`)&&this.dockLayout.setDock(t.dock,!1),t?.open===!1){this.closePanel();return}let r=typeof t?.url==`string`?I(t.url):null;if(r||t?.open===!0){if(!this.available)return;let e=this.dockLayout.open;this.dockLayout.setOpen(!0),r?this.browserPanelController.openUrl(r,{newTab:!0}):n?(this.consumedPreferredRevision=this.preferredRevision(),this.browserPanelController.selectTab(n.targetId,n)):t?.newTab===!0?this.browserPanelController.beginNewTab():!e&&!this.followPreferredTab()&&this.browserPanelController.refreshAll();return}this.toggle()}closePanel(){this.browserPanelController.cancelOverlayPointerGesture(),this.dockLayout.setOpen(!1)}setDock(e){this.dockLayout.setDock(e)}render(){return!this.available||!this.embedded&&!this.dockLayout.open?o:et(this.browserPanelController,this.dockLayout.dock,this.dockLayout.height,this.dockLayout.width,e=>this.setDock(e),()=>this.closePanel(),this.dockLayout.renderResizer(`bp`,m(`browser.resize`)),this.embedded)}},t([u({attribute:!1})],$.prototype,`client`,void 0),t([u({type:Boolean})],$.prototype,`available`,void 0),t([u({type:Boolean})],$.prototype,`suppressed`,void 0),t([u({attribute:!1})],$.prototype,`resourceBasePath`,void 0),t([u({attribute:!1})],$.prototype,`authToken`,void 0),t([u({type:Boolean})],$.prototype,`embedded`,void 0),t([u({type:Boolean})],$.prototype,`presented`,void 0),t([u({type:Boolean})],$.prototype,`refreshOnPresentation`,void 0),t([u({attribute:!1})],$.prototype,`sessionKey`,void 0),t([u({attribute:!1})],$.prototype,`preferredTab`,void 0),customElements.get(`openclaw-browser-panel`)||customElements.define(`openclaw-browser-panel`,$)})))()}nt();
//# sourceMappingURL=browser-panel-BNW001UL.js.map