import*as UI from"../ui/ui.js";let inspectedPagePlaceholderInstance;export class InspectedPagePlaceholder extends UI.Widget.Widget{constructor(){super(!0),this.registerRequiredCSS("emulation/inspectedPagePlaceholder.css",{enableLegacyPatching:!0}),UI.ZoomManager.ZoomManager.instance().addEventListener(UI.ZoomManager.Events.ZoomChanged,this.onResize,this),this.restoreMinimumSize()}static instance(e={forceNew:null}){const{forceNew:t}=e;return inspectedPagePlaceholderInstance&&!t||(inspectedPagePlaceholderInstance=new InspectedPagePlaceholder),inspectedPagePlaceholderInstance}onResize(){this._updateId&&this.element.window().cancelAnimationFrame(this._updateId),this._updateId=this.element.window().requestAnimationFrame(this.update.bind(this,!1))}restoreMinimumSize(){this.setMinimumSize(150,150)}clearMinimumSize(){this.setMinimumSize(1,1)}_dipPageRect(){const e=UI.ZoomManager.ZoomManager.instance().zoomFactor(),t=this.element.getBoundingClientRect(),i=this.element.ownerDocument.body.getBoundingClientRect(),n=Math.max(t.left*e,i.left*e),a=Math.max(t.top*e,i.top*e),s=Math.min(t.bottom*e,i.bottom*e);return{x:n,y:a,width:Math.min(t.right*e,i.right*e)-n,height:s-a}}update(e){delete this._updateId;const t=this._dipPageRect(),i={x:Math.round(t.x),y:Math.round(t.y),height:Math.max(1,Math.round(t.height)),width:Math.max(1,Math.round(t.width))};e&&(--i.height,this.dispatchEventToListeners(Events.Update,i),++i.height),this.dispatchEventToListeners(Events.Update,i)}}export const Events={Update:Symbol("Update")};