Accessing the close tab and close button in the uxp plugin

is this what you’re looking for?

document.addEventListener('uxpcommand', (event) => {
   const { commandId } = event
   if (commandId === 'uxpshowpanel') {
     console.log("panel is showing");
   } else if (commandId === 'uxphidepanel') {
     console.log('panel is hiding');
   }
 })