UNPKG

devexpress-richedit

Version:

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

92 lines (91 loc) 2.65 kB
import { isDefined } from "@devexpress/utils/lib/utils/common"; export class MixedSize { static fromLayout(value) { return new MixedSize().addLayoutSize(value); } static fromUI(value) { return new MixedSize().addUISize(value); } _UISizePart = 0; _UISize; _layoutSizePart = 0; _layoutSize; _scale = 1; _scaleIsSpecified = false; get UISize() { this.checkScaleIsSpecified(); if (!isDefined(this._UISize)) this._UISize = this._layoutSizePart * this._scale + this._UISizePart; return this._UISize; } get LayoutSize() { this.checkScaleIsSpecified(); if (!isDefined(this._layoutSize)) this._layoutSize = this._layoutSizePart + this._UISizePart / this._scale; return this._layoutSize; } get UISizePart() { return this._UISizePart; } set UISizePart(value) { this._UISizePart = value; this.onSizeChanged(); } get LayoutSizePart() { return this._layoutSizePart; } set LayoutSizePart(value) { this._layoutSizePart = value; this.onSizeChanged(); } onSizeChanged() { this._UISize = null; this._layoutSize = null; } addUISize(value) { this.UISizePart += value; return this; } addLayoutSize(value) { this.LayoutSizePart += value; return this; } addSize(value) { this.checkSizeHasSameScale(value); this.addLayoutSize(value._layoutSizePart); this.addUISize(value._UISizePart); return this; } subtractUISize(value) { this.UISizePart -= value; return this; } subtractLayoutSize(value) { this.LayoutSizePart -= value; return this; } subtractSize(value) { this.checkSizeHasSameScale(value); this.subtractLayoutSize(value._layoutSizePart); this.subtractUISize(value._UISizePart); return this; } checkSizeHasSameScale(size) { if (size._scaleIsSpecified && size._scale !== this._scale) throw new Error("The size has a different scale and cannot be added."); } checkScaleIsSpecified() { if (!this._scaleIsSpecified) console.warn("MixedSize is used without specifying the scale."); } useScale(value) { this._scale = value; this._scaleIsSpecified = true; return this; } clear() { this.UISizePart = 0; this.LayoutSizePart = 0; return this; } }