UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.06 kB
import*as Common from"../../core/common/common.js";let zoomManagerInstance;export class ZoomManager extends Common.ObjectWrapper.ObjectWrapper{frontendHost;zoomFactorInternal;constructor(o,n){super(),this.frontendHost=n,this.zoomFactorInternal=this.frontendHost.zoomFactor(),o.addEventListener("resize",this.onWindowResize.bind(this),!0)}static instance(o={forceNew:null,win:null,frontendHost:null}){const{forceNew:n,win:t,frontendHost:e}=o;if(!zoomManagerInstance||n){if(!t||!e)throw new Error(`Unable to create zoom manager: window and frontendHost must be provided: ${(new Error).stack}`);zoomManagerInstance=new ZoomManager(t,e)}return zoomManagerInstance}static removeInstance(){zoomManagerInstance=void 0}zoomFactor(){return this.zoomFactorInternal}cssToDIP(o){return o*this.zoomFactorInternal}dipToCSS(o){return o/this.zoomFactorInternal}onWindowResize(){const o=this.zoomFactorInternal;this.zoomFactorInternal=this.frontendHost.zoomFactor(),o!==this.zoomFactorInternal&&this.dispatchEventToListeners("ZoomChanged",{from:o,to:this.zoomFactorInternal})}}