UNPKG

devexpress-richedit

Version:

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

75 lines (74 loc) 2.72 kB
import { NumberMapUtils } from '@devexpress/utils/lib/utils/map/number'; import { ColorHelper } from '../model/color/color'; import { SearchUtils } from '@devexpress/utils/lib/utils/search'; import { MixedSize } from '../utils/mixed-size'; export class ModelPositionHolder { constructor(pos, posManager) { this.pos = posManager.registerPosition(pos); this.posManager = posManager; } get modelPosition() { return this.pos.value; } destructor() { this.posManager.unregisterPosition(this.pos); } } export class AnchorObjectsPositionInfo { constructor(model) { this.model = model; this.cache = {}; } add(obj, modelPosition) { this.delete(obj.objectId); this.cache[obj.objectId] = new ModelPositionHolder(modelPosition, this.model.subDocumentsCollection.collection[obj.belongsToSubDocId].positionManager); } delete(id) { const info = this.cache[id]; if (info) { info.destructor(); delete this.cache[id]; } } getPosition(objectId) { return this.cache[objectId].modelPosition; } clear() { NumberMapUtils.forEach(this.cache, (posInfo) => posInfo.destructor()); this.cache = {}; } } export class DocumentLayout { get grids() { return this.pages.reduce((res, page) => { page.grids.forEach((grid, table) => res.set(table, grid)); return res; }, new Map()); } constructor(anchorObjectsPositionInfo) { this.anchorObjectsPositionInfo = anchorObjectsPositionInfo; this.setEmptyLayout(ColorHelper.NO_COLOR); } setEmptyLayout(pageColor) { this.pages = []; this.validPageCount = 0; this.lastMaxNumPages = 0; this.isFullyFormatted = false; this.pageColor = pageColor; this.anchorObjectsPositionInfo.clear(); } getLastValidPage() { return this.pages[this.validPageCount - 1]; } isPageValid(pageIndex) { return pageIndex < this.validPageCount && this.pages[pageIndex].isValid; } getPageBySubDocumentId(subDocumentId) { return this.pages.find((page) => !!page.mainSubDocumentPageAreas[subDocumentId] || !!page.otherPageAreas[subDocumentId]); } findPageIndexByOffsetY(offsetY, sizeInfo) { const getPageOffsetY = (p) => MixedSize.fromLayout(sizeInfo.getPageOffsetY(p)).useScale(sizeInfo.zoomLevel).UISize; const normedInterpolationIndex = SearchUtils.normedInterpolationIndexOf(this.pages, getPageOffsetY, offsetY); return Math.max(0, normedInterpolationIndex); } }