UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.59 kB
import*as Common from"../../core/common/common.js";import*as UI from"../../ui/legacy/legacy.js";import inspectedPagePlaceholderStyles from"./inspectedPagePlaceholder.css.legacy.js";let inspectedPagePlaceholderInstance;export class InspectedPagePlaceholder extends(Common.ObjectWrapper.eventMixin(UI.Widget.Widget)){updateId;constructor(){super(!0),this.registerRequiredCSS(inspectedPagePlaceholderStyles),UI.ZoomManager.ZoomManager.instance().addEventListener("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),o=Math.min(t.bottom*e,i.bottom*e);return{x:n,y:a,width:Math.min(t.right*e,i.right*e)-n,height:o-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("Update",i),++i.height),this.dispatchEventToListeners("Update",i)}}