|
|
|
@ -1,4 +1,5 @@
|
|
|
|
import { EDITOR_COMPONENT } from "../../dataset/constant/Editor"
|
|
|
|
import { EDITOR_COMPONENT } from "../../dataset/constant/Editor"
|
|
|
|
|
|
|
|
import { IEditorOption } from "../../interface/Editor"
|
|
|
|
import { findParent } from "../../utils"
|
|
|
|
import { findParent } from "../../utils"
|
|
|
|
import { Cursor } from "../cursor/Cursor"
|
|
|
|
import { Cursor } from "../cursor/Cursor"
|
|
|
|
import { Draw } from "../draw/Draw"
|
|
|
|
import { Draw } from "../draw/Draw"
|
|
|
|
@ -10,6 +11,7 @@ export class GlobalEvent {
|
|
|
|
|
|
|
|
|
|
|
|
private draw: Draw
|
|
|
|
private draw: Draw
|
|
|
|
private canvas: HTMLCanvasElement
|
|
|
|
private canvas: HTMLCanvasElement
|
|
|
|
|
|
|
|
private options: Required<IEditorOption>
|
|
|
|
private cursor: Cursor | null
|
|
|
|
private cursor: Cursor | null
|
|
|
|
private canvasEvent: CanvasEvent
|
|
|
|
private canvasEvent: CanvasEvent
|
|
|
|
private range: RangeManager
|
|
|
|
private range: RangeManager
|
|
|
|
@ -18,6 +20,7 @@ export class GlobalEvent {
|
|
|
|
constructor(draw: Draw, canvasEvent: CanvasEvent) {
|
|
|
|
constructor(draw: Draw, canvasEvent: CanvasEvent) {
|
|
|
|
this.draw = draw
|
|
|
|
this.draw = draw
|
|
|
|
this.canvas = draw.getPage()
|
|
|
|
this.canvas = draw.getPage()
|
|
|
|
|
|
|
|
this.options = draw.getOptions()
|
|
|
|
this.canvasEvent = canvasEvent
|
|
|
|
this.canvasEvent = canvasEvent
|
|
|
|
this.cursor = null
|
|
|
|
this.cursor = null
|
|
|
|
this.range = draw.getRange()
|
|
|
|
this.range = draw.getRange()
|
|
|
|
@ -35,6 +38,9 @@ export class GlobalEvent {
|
|
|
|
document.addEventListener('mouseup', () => {
|
|
|
|
document.addEventListener('mouseup', () => {
|
|
|
|
this.setDragState()
|
|
|
|
this.setDragState()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
document.addEventListener('wheel', (evt: WheelEvent) => {
|
|
|
|
|
|
|
|
this.setPageScale(evt)
|
|
|
|
|
|
|
|
}, { passive: false })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public recoverEffect(evt: MouseEvent) {
|
|
|
|
public recoverEffect(evt: MouseEvent) {
|
|
|
|
@ -70,4 +76,23 @@ export class GlobalEvent {
|
|
|
|
this.range.setRangeStyle()
|
|
|
|
this.range.setRangeStyle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public setPageScale(evt: WheelEvent) {
|
|
|
|
|
|
|
|
if (!evt.ctrlKey) return
|
|
|
|
|
|
|
|
evt.preventDefault()
|
|
|
|
|
|
|
|
const { scale } = this.options
|
|
|
|
|
|
|
|
if (evt.deltaY < 0) {
|
|
|
|
|
|
|
|
// 放大
|
|
|
|
|
|
|
|
const nextScale = scale * 10 + 1
|
|
|
|
|
|
|
|
if (nextScale <= 30) {
|
|
|
|
|
|
|
|
this.draw.setPageScale(nextScale / 10)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 缩小
|
|
|
|
|
|
|
|
const nextScale = scale * 10 - 1
|
|
|
|
|
|
|
|
if (nextScale >= 5) {
|
|
|
|
|
|
|
|
this.draw.setPageScale(nextScale / 10)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|