|
|
|
|
@ -1,16 +1,23 @@
|
|
|
|
|
import { CURSOR_AGENT_HEIGHT } from '../../dataset/constant/Cursor'
|
|
|
|
|
import { EDITOR_PREFIX } from '../../dataset/constant/Editor'
|
|
|
|
|
import { DeepRequired } from '../../interface/Common'
|
|
|
|
|
import { ICursorOption } from '../../interface/Cursor'
|
|
|
|
|
import { IEditorOption } from '../../interface/Editor'
|
|
|
|
|
import { Draw } from '../draw/Draw'
|
|
|
|
|
import { CanvasEvent } from '../event/CanvasEvent'
|
|
|
|
|
import { Position } from '../position/Position'
|
|
|
|
|
import { CursorAgent } from './CursorAgent'
|
|
|
|
|
|
|
|
|
|
export type IDrawCursorOption = ICursorOption &
|
|
|
|
|
{
|
|
|
|
|
isBlink?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class Cursor {
|
|
|
|
|
|
|
|
|
|
private draw: Draw
|
|
|
|
|
private container: HTMLDivElement
|
|
|
|
|
private options: Required<IEditorOption>
|
|
|
|
|
private options: DeepRequired<IEditorOption>
|
|
|
|
|
private position: Position
|
|
|
|
|
private cursorDom: HTMLDivElement
|
|
|
|
|
private cursorAgent: CursorAgent
|
|
|
|
|
@ -43,12 +50,16 @@ export class Cursor {
|
|
|
|
|
return this.getAgentDom().value = ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public drawCursor() {
|
|
|
|
|
const isReadonly = this.draw.isReadonly()
|
|
|
|
|
public drawCursor(payload?: IDrawCursorOption) {
|
|
|
|
|
const cursorPosition = this.position.getCursorPosition()
|
|
|
|
|
if (!cursorPosition) return
|
|
|
|
|
const { scale, cursor } = this.options
|
|
|
|
|
const {
|
|
|
|
|
color,
|
|
|
|
|
width,
|
|
|
|
|
isBlink = true
|
|
|
|
|
} = { ...cursor, ...payload }
|
|
|
|
|
// 设置光标代理
|
|
|
|
|
const { scale } = this.options
|
|
|
|
|
const height = this.draw.getHeight()
|
|
|
|
|
const pageGap = this.draw.getPageGap()
|
|
|
|
|
const { metrics, coordinate: { leftTop, rightTop }, ascent, pageNo } = cursorPosition
|
|
|
|
|
@ -68,13 +79,21 @@ export class Cursor {
|
|
|
|
|
agentCursorDom.style.left = `${cursorLeft}px`
|
|
|
|
|
agentCursorDom.style.top = `${cursorTop + cursorHeight - CURSOR_AGENT_HEIGHT * scale}px`
|
|
|
|
|
// 模拟光标显示
|
|
|
|
|
const isReadonly = this.draw.isReadonly()
|
|
|
|
|
this.cursorDom.style.width = `${width}px`
|
|
|
|
|
this.cursorDom.style.backgroundColor = color
|
|
|
|
|
this.cursorDom.style.left = `${cursorLeft}px`
|
|
|
|
|
this.cursorDom.style.top = `${cursorTop}px`
|
|
|
|
|
this.cursorDom.style.display = isReadonly ? 'none' : 'block'
|
|
|
|
|
this.cursorDom.style.height = `${cursorHeight}px`
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.cursorDom.classList.add(`${EDITOR_PREFIX}-cursor--animation`)
|
|
|
|
|
}, 200)
|
|
|
|
|
const animationClassName = `${EDITOR_PREFIX}-cursor--animation`
|
|
|
|
|
if (isBlink) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.cursorDom.classList.add(animationClassName)
|
|
|
|
|
}, 200)
|
|
|
|
|
} else {
|
|
|
|
|
this.cursorDom.classList.remove(animationClassName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public recoveryCursor() {
|
|
|
|
|
|