UNPKG

delta-component

Version:

embeddable react component

43 lines (33 loc) 743 B
'use strict'; class Selection { constructor(lIndex, rIndex) { this.left = lIndex; this.right = rIndex; } set(lIndex, rIndex) { this.left = lIndex; this.right = rIndex; } move(rPosition) { /** * Параллельный сдвиг в сторону */ const delta = this.right - rPosition; this.set( Math.max(0, this.left - delta), Math.max(0, this.right - delta) ) } toNullWidth() { this.left = this.right; } getWidth() { return this.right - this.left; } toString() { return `Selection ${this.left}:${this.right}`; } } module.exports = { Selection, };