import { Layer } from './layer'; import { EditorState, EditorStateConfigEntity, PlaygroundConfigEntity, SnaplineConfigEntity } from './config'; import { able, ables, entity, Entity, TransformData } from '../../common'; import { DOMCache, domUtils } from '@gedit/utils/lib/browser'; import { Selectable, SelectState } from '../able/selectable'; import { Align, AlignInfo, AlignType } from '../utils/align'; import { Rectangle } from '@gedit/math'; import { Adsorber } from '../utils/adsorber'; import { Adsorbable, Dragable, Resizable, Rotatable } from '../able'; /** * 对齐线相关绘制 */ export class AlignLayer extends Layer { @entity(PlaygroundConfigEntity) protected playgroundConfigEntity: PlaygroundConfigEntity; @entity(EditorStateConfigEntity) protected editorStateConfig: EditorStateConfigEntity; @able(Selectable) protected selectableNodes: Entity[]; @entity(SnaplineConfigEntity) protected snaplineEntity: SnaplineConfigEntity; @ables([Selectable], [Dragable, Resizable, Rotatable]) protected movingNodes: Entity[]; @ables([Adsorbable]) protected adsorbableNodes: Entity[]; readonly node = domUtils.createDivWithClass('gedit-alignment'); readonly lineNodes = this.createDOMCache('gedit-align-line'); drawLine(node: DOMCache, info: AlignInfo): void { const isHorizantal = Adsorber.isHorizantal(info.direction); const scale = this.playgroundConfigEntity.finalScale; if (isHorizantal) { // 水平 node.setStyle({ left: info.startPos.x * scale, top: info.startPos.y * scale - 1, width: (info.endPos.x - info.startPos.x) * scale, height: 0, }); } else { // 垂直 node.setStyle({ left: info.startPos.x * scale - 1, top: (info.startPos.y) * scale, height: (info.endPos.y - info.startPos.y) * scale, width: 0, }); } if (info.type === AlignType.LINE_BETWEEN) { node.className = `gedit-align-line gedit-align-line-between ${isHorizantal ? 'horizantal' : 'vertical'}`; node.innerHTML = `