UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 3.06 kB
import*as Common from"../../core/common/common.js";import{elementDragStart}from"./UIUtils.js";export class ResizerWidget extends Common.ObjectWrapper.ObjectWrapper{isEnabledInternal;elementsInternal;installDragOnMouseDownBound;cursorInternal;startX;startY;constructor(){super(),this.isEnabledInternal=!0,this.elementsInternal=new Set,this.installDragOnMouseDownBound=this.installDragOnMouseDown.bind(this),this.cursorInternal="nwse-resize"}isEnabled(){return this.isEnabledInternal}setEnabled(t){this.isEnabledInternal=t,this.updateElementCursors()}elements(){return[...this.elementsInternal]}addElement(t){this.elementsInternal.has(t)||(this.elementsInternal.add(t),t.addEventListener("pointerdown",this.installDragOnMouseDownBound,!1),this.updateElementCursor(t))}removeElement(t){this.elementsInternal.has(t)&&(this.elementsInternal.delete(t),t.removeEventListener("pointerdown",this.installDragOnMouseDownBound,!1),t.style.removeProperty("cursor"))}updateElementCursors(){this.elementsInternal.forEach(this.updateElementCursor.bind(this))}updateElementCursor(t){this.isEnabledInternal?(t.style.setProperty("cursor",this.cursor()),t.style.setProperty("touch-action","none")):(t.style.removeProperty("cursor"),t.style.removeProperty("touch-action"))}cursor(){return this.cursorInternal}setCursor(t){this.cursorInternal=t,this.updateElementCursors()}installDragOnMouseDown(t){const e=t.target;if(!this.elementsInternal.has(e))return!1;elementDragStart(e,this.dragStart.bind(this),(t=>{this.drag(t)}),this.dragEnd.bind(this),this.cursor(),t)}dragStart(t){return!!this.isEnabledInternal&&(this.startX=t.pageX,this.startY=t.pageY,this.sendDragStart(this.startX,this.startY),!0)}sendDragStart(t,e){this.dispatchEventToListeners(Events.ResizeStart,{startX:t,currentX:t,startY:e,currentY:e})}drag(t){return this.isEnabledInternal?(this.sendDragMove(this.startX,t.pageX,this.startY,t.pageY,t.shiftKey),t.preventDefault(),!1):(this.dragEnd(t),!0)}sendDragMove(t,e,s,r,n){this.dispatchEventToListeners(Events.ResizeUpdateXY,{startX:t,currentX:e,startY:s,currentY:r,shiftKey:n})}dragEnd(t){this.dispatchEventToListeners(Events.ResizeEnd),delete this.startX,delete this.startY}}export var Events;!function(t){t.ResizeStart="ResizeStart",t.ResizeUpdateXY="ResizeUpdateXY",t.ResizeUpdatePosition="ResizeUpdatePosition",t.ResizeEnd="ResizeEnd"}(Events||(Events={}));export class SimpleResizerWidget extends ResizerWidget{isVerticalInternal;constructor(){super(),this.isVerticalInternal=!0}isVertical(){return this.isVerticalInternal}setVertical(t){this.isVerticalInternal=t,this.updateElementCursors()}cursor(){return this.isVerticalInternal?"ns-resize":"ew-resize"}sendDragStart(t,e){const s=this.isVerticalInternal?e:t;this.dispatchEventToListeners(Events.ResizeStart,{startPosition:s,currentPosition:s})}sendDragMove(t,e,s,r,n){this.isVerticalInternal?this.dispatchEventToListeners(Events.ResizeUpdatePosition,{startPosition:s,currentPosition:r,shiftKey:n}):this.dispatchEventToListeners(Events.ResizeUpdatePosition,{startPosition:t,currentPosition:e,shiftKey:n})}}