import*as Components from"../components/components.js";import*as UI from"../ui/ui.js";export class ImagePreviewPopover{constructor(e,t,o){this._getLinkElement=t,this._getDOMNode=o,this._popover=new UI.PopoverHelper.PopoverHelper(e,this._handleRequest.bind(this)),this._popover.setHasPadding(!0),this._popover.setTimeout(0,100)}_handleRequest(e){const t=this._getLinkElement(e);if(!t)return null;const o=elementToURLMap.get(t);return o?{box:t.boxInWindow(),hide:void 0,show:async e=>{const n=this._getDOMNode(t);if(!n)return!1;const i=await Components.ImagePreview.ImagePreview.loadDimensionsForNode(n),s=await Components.ImagePreview.ImagePreview.build(n.domModel().target(),o,!0,{imageAltText:void 0,precomputedFeatures:i});return s&&e.contentElement.appendChild(s),Boolean(s)}}:null}hide(){this._popover.hidePopover()}static setImageUrl(e,t){return elementToURLMap.set(e,t),e}static getImageURL(e){return elementToURLMap.get(e)}}const elementToURLMap=new WeakMap;