UNPKG

devexpress-richedit

Version:

DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.

23 lines (22 loc) 883 B
import { Errors } from '@devexpress/utils/lib/errors'; import { ListUtils } from '@devexpress/utils/lib/utils/list'; export class Columns { constructor(widths, positions) { this.width = widths; this.numColumns = widths.length; this.positions = positions; if (ListUtils.unsafeAnyOf(this.positions, (p) => isNaN(p) || p < 0)) throw new Error(Errors.InternalException); } static fromIntervals(intervalsInfo) { const widths = ListUtils.map(intervalsInfo, (curr) => curr.width); let pos = 0; const positions = [0, ...widths.map(w => (pos += w, pos))]; return new Columns(widths, positions); } static fromWidths(widths) { let pos = 0; const positions = [0, ...widths.map(w => (pos += w, pos))]; return new Columns([...widths], positions); } }