const template = `
<style>
.tip {
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  color: #000000d9;
}
.close {
  position: absolute;
  right: 10px;
  padding: 10px;
  cursor: pointer;
}
</style>
<div class="tip">
  <span class="text"></span>
  <span class="close">X</span>
</div>
` ; export interface TipOptions { message : string ; style ? : Partial < CSSStyleDeclaration > ; } export const COMPONENT_ID = 'vite-plugin-tip' ; export class Tip extends HTMLElement { root : ShadowRoot ; constructor ( options ) { super ( ) ; this . root = this . attachShadow ( { mode : 'open' } ) ; this . root . innerHTML = template ; this . text ( options . message , options . style ) ; this . root . querySelector ( '.close' ) ?. addEventListener ( 'click' , ( ) => this . close ( ) ) ; } text ( message , style = { } ) { const container = this . root . querySelector ( '.tip' ) ! ; const textEl = this . root . querySelector ( '.text' ) ! ; Object . assign ( container . style , style ) ; textEl . innerText = message ; } close ( ) { this . parentNode ?. removeChild ( this ) ; } } export function createTip ( option ) { clearTips ( ) ; document . body . appendChild ( new Tip ( option ) ) ; } export function clearTips ( ) { document . querySelectorAll ( COMPONENT_ID ) . forEach ( n => ( n as Tip ) . close ( ) ) ; } customElements . define ( COMPONENT_ID , Tip ) ;