import { ThemeData } from '@spectrum-web-components/theme' ; import { OverlayDisplayQueryDetail , OverlayOptions , TriggerInteractions , } from './overlay-types' ; import { OverlayStack } from './overlay-stack.js' ; /**
 * This class allows access to the overlay system which allows a client to
 * position an element in the overlay positioned relative to another node.
 */ export class Overlay { private static overlayStack = new OverlayStack ( ) ; private isOpen = false ; private overlayElement : HTMLElement ; private owner : HTMLElement ; private interaction : TriggerInteractions ; param owner param interaction param overlayElement constructor ( owner , interaction , overlayElement ) { this . owner = owner ; this . overlayElement = overlayElement ; this . interaction = interaction ; } param owner param interaction param overlayElement param options param options . delayed param options . offset param options . placement returns public static async open ( owner , interaction , overlayElement , options ) { const overlay = new Overlay ( owner , interaction , overlayElement ) ; await overlay . open ( options ) ; return ( ) : void => { overlay . close ( ) ; } ; } public static update ( ) { const overlayUpdateEvent = new CustomEvent ( 'sp-update-overlays' , { bubbles : true , composed : true , cancelable : true , } ) ; document . dispatchEvent ( overlayUpdateEvent ) ; } param options param options . delayed param options . offset param options . placement returns public async open ( { abortPromise , delayed , offset = 0 , placement = 'top' , receivesFocus , notImmediatelyClosable , virtualTrigger , } ) { if ( this . isOpen ) return true ; if ( delayed === undefined ) { delayed = this . overlayElement . hasAttribute ( 'delayed' ) ; } const queryThemeDetail = { color : undefined , scale : undefined , lang : undefined , } ; const queryThemeEvent = new CustomEvent < ThemeData > ( 'sp-query-theme' , { bubbles : true , composed : true , detail : queryThemeDetail , cancelable : true , } ) ; this . owner . dispatchEvent ( queryThemeEvent ) ; const overlayDetailQuery = { } ; const queryOverlayDetailEvent = new CustomEvent < OverlayDisplayQueryDetail > ( 'sp-overlay-query' , { bubbles : true , composed : true , detail : overlayDetailQuery , cancelable : true , } ) ; this . overlayElement . dispatchEvent ( queryOverlayDetailEvent ) ; await Overlay . overlayStack . openOverlay ( { abortPromise , content : this . overlayElement , contentTip : overlayDetailQuery . overlayContentTipElement , delayed , offset : offset , placement : placement , trigger : this . owner , interaction : this . interaction , theme : queryThemeDetail , receivesFocus , notImmediatelyClosable , virtualTrigger , ... overlayDetailQuery , } ) ; this . isOpen = true ; return true ; } /**
     * Close the overlay if it is open
     */ public close ( ) { Overlay . overlayStack . closeOverlay ( this . overlayElement ) ; } } event type { object } property event type { object } property