UNPKG

@bixi/label

Version:
1,923 lines (1,916 loc) 58.8 kB
import { DragDropModule } from '@angular/cdk/drag-drop'; import { OverlayModule } from '@angular/cdk/overlay'; import { CommonModule } from '@angular/common'; import { EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, Input, ViewChild, ViewContainerRef, Output, NgModule } from '@angular/core'; import { NzIconModule } from 'ng-zorro-antd/icon'; import { NzPopoverModule } from 'ng-zorro-antd/popover'; import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; import { DomSanitizer } from '@angular/platform-browser'; import { BehaviorSubject, Subject, Subscription } from 'rxjs'; import { filter, delayWhen } from 'rxjs/operators'; import { __decorate, __metadata } from 'tslib'; import { POSITION_MAP, DEFAULT_TOOLTIP_POSITIONS } from 'ng-zorro-antd/core/overlay'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const PREFIX = 'BIXI'; /** @type {?} */ const EVENTS = { ready: `${PREFIX}_READY`, startLabeling: `${PREFIX}_START_LABELING`, deleteLabels: `${PREFIX}_DELETE_LABELS`, paginationChange: `${PREFIX}_PAGINATION_CHANGE`, zoomChange: `${PREFIX}_ZOOM_CHANGE`, searchResult: `${PREFIX}_SEARCH_RESULT`, clickLabels: `${PREFIX}_CLICK_LABELS`, hoverInLabel: `${PREFIX}_HOVER_IN_LABEL`, hoverOutLabel: `${PREFIX}_HOVER_OUT_LABEL`, pdfScrolling: `${PREFIX}_PDF_SCROLLING`, pdfLoadFailed: `${PREFIX}_PDF_LOAD_FAILED`, resize: `${PREFIX}_resize`, log: `${PREFIX}_LOG`, mergeTables: `${PREFIX}_MERGE_TABLES`, splitTable: `${PREFIX}_SPLIT_TABLE`, tblOperationRecords: `${PREFIX}_TABLE_OPERATION_RECORDS` }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function ILabel() { } if (false) { /** @type {?|undefined} */ ILabel.prototype.uuid; /** @type {?|undefined} */ ILabel.prototype.tagId; /** @type {?|undefined} */ ILabel.prototype.stroke; /** @type {?|undefined} */ ILabel.prototype.fill; /** @type {?} */ ILabel.prototype.index; /** @type {?} */ ILabel.prototype.word; /** @type {?|undefined} */ ILabel.prototype.selected; /** @type {?|undefined} */ ILabel.prototype.direction; } /** * @record */ function ILabelStyle() { } if (false) { /** @type {?} */ ILabelStyle.prototype.uuid; /** @type {?|undefined} */ ILabelStyle.prototype.fill; /** @type {?|undefined} */ ILabelStyle.prototype.stroke; } /** * @record */ function ISerarchParams() { } if (false) { /** @type {?} */ ISerarchParams.prototype.keyword; /** @type {?} */ ISerarchParams.prototype.caseSensitive; } /** * @record */ function ISearchResult() { } if (false) { /** @type {?|undefined} */ ISearchResult.prototype.result; } /** * @record */ function IClickMetadata() { } if (false) { /** @type {?} */ IClickMetadata.prototype.altKey; /** @type {?} */ IClickMetadata.prototype.ctrlKey; /** @type {?} */ IClickMetadata.prototype.metaKey; /** @type {?} */ IClickMetadata.prototype.shiftKey; /** @type {?} */ IClickMetadata.prototype.which; } /** * @record */ function ILabelsEvent() { } if (false) { /** @type {?} */ ILabelsEvent.prototype.data; /** @type {?} */ ILabelsEvent.prototype.position; } /** * @record */ function IClickLabelsEvent() { } if (false) { /** @type {?} */ IClickLabelsEvent.prototype.metadata; } /** * @record */ function IPagination() { } if (false) { /** @type {?} */ IPagination.prototype.pageNumber; /** @type {?} */ IPagination.prototype.pageCount; } /** * @record */ function IInitOptions() { } if (false) { /** @type {?} */ IInitOptions.prototype.id; /** @type {?} */ IInitOptions.prototype.pdfUrl; /** @type {?} */ IInitOptions.prototype.pdfInfoUrl; /** @type {?} */ IInitOptions.prototype.pdfCharsUrl; /** @type {?} */ IInitOptions.prototype.pdfMode; /** @type {?} */ IInitOptions.prototype.labelMode; /** @type {?|undefined} */ IInitOptions.prototype.pdfSize; /** @type {?|undefined} */ IInitOptions.prototype.labels; /** @type {?|undefined} */ IInitOptions.prototype.tables; } /** * @record */ function ISearchLabelByUuidParams() { } if (false) { /** @type {?} */ ISearchLabelByUuidParams.prototype.uuid; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.pageNumber; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.isHighlight; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.level; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.offsetTop; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.stroke; /** @type {?|undefined} */ ISearchLabelByUuidParams.prototype.fill; } /** * @record */ function ISearchLabelByIndexParams() { } if (false) { /** @type {?} */ ISearchLabelByIndexParams.prototype.index; /** @type {?|undefined} */ ISearchLabelByIndexParams.prototype.word; /** @type {?|undefined} */ ISearchLabelByIndexParams.prototype.isHighlight; /** @type {?|undefined} */ ISearchLabelByIndexParams.prototype.level; /** @type {?|undefined} */ ISearchLabelByIndexParams.prototype.offsetTop; } /** * @record */ function ISearchTableCellParams() { } if (false) { /** @type {?} */ ISearchTableCellParams.prototype.pageNumber; /** @type {?} */ ISearchTableCellParams.prototype.tableId; /** @type {?} */ ISearchTableCellParams.prototype.x; /** @type {?} */ ISearchTableCellParams.prototype.y; /** @type {?|undefined} */ ISearchTableCellParams.prototype.word; /** @type {?|undefined} */ ISearchTableCellParams.prototype.fontSize; /** @type {?|undefined} */ ISearchTableCellParams.prototype.scale; /** @type {?|undefined} */ ISearchTableCellParams.prototype.fill; } /** * @record */ function IViewPort() { } if (false) { /** @type {?} */ IViewPort.prototype.height; /** @type {?} */ IViewPort.prototype.left; /** @type {?} */ IViewPort.prototype.scale; /** @type {?} */ IViewPort.prototype.top; /** @type {?} */ IViewPort.prototype.width; /** @type {?} */ IViewPort.prototype.zoom; } /** * @record */ function ITableMatrix() { } if (false) { /** @type {?} */ ITableMatrix.prototype.tableId; /** @type {?} */ ITableMatrix.prototype.type; /** @type {?} */ ITableMatrix.prototype.pageNumber; /** @type {?} */ ITableMatrix.prototype.area; /** @type {?} */ ITableMatrix.prototype.lines; /** @type {?} */ ITableMatrix.prototype.detail; } /** @enum {string} */ const LabelTextMode = { /** * 禁止标注 */ non: 'non', /** * 划选 */ textSlip: 'textSlip', /** * 框选 */ textFrame: 'textFrame', /** * 组合 */ textGroup: 'textGroup', }; /** @enum {string} */ const LabelTableMode = { /** * 新增表格 */ tableAddTbl: 'tableAddTbl', /** * 调整表格 */ tableResizeTbl: 'tableResizeTbl', /** * 删除表格 */ tableDelTbl: 'tableDelTbl', /** * 横向拆分表格 */ tableHSplitTbl: 'tableHSplitTbl', /** * 纵向拆分表格 */ tableVSplitTbl: 'tableVSplitTbl', /** * 增加横线 */ tableAddHLine: 'tableAddHLine', /** * 增加竖线 */ tableAddVLine: 'tableAddVLine', /** * 增加表格线 (任意长度) */ tableAddLine: 'tableAddLine', /** * 调整线条 */ tableResizeCell: 'tableResizeCell', /** * 删除线 */ tableDelLine: 'tableDelLine', /** * 删除单元格线 */ tableDelCellLine: 'tableDelCellLine', /** * 合并单元格 */ tableMergeCell: 'tableMergeCell', /** * 拆分单元格 */ tableSplitCell: 'tableSplitCell', /** * 选择单元格 */ tableSelectCells: 'tableSelectCells', /** * 隐藏框线 */ tableHideTable: 'tableHideTable', /** * 显示框线 */ tableShowTable: 'tableShowTable', /** * 选择表格 */ selectTables: 'tableSelectTables', /** * 合并表格 */ mergeTables: 'tableMergeTables', /** * 拆分表格 */ splitTables: 'tableSplitTables', /** * 禁止表格操作 */ tableNon: 'tableNon', }; /** @enum {string} */ const PdfMode = { /** * 全部功能 */ full: 'full', /** * 只读 */ readonly: 'readonly', /** * 只删 */ deleteonly: 'deleteonly', /** * 预览(只能查看pdf文档) */ preview: 'preview', }; /** * @record */ function ISearchRectParams() { } if (false) { /** @type {?} */ ISearchRectParams.prototype.x1; /** @type {?} */ ISearchRectParams.prototype.y1; /** @type {?} */ ISearchRectParams.prototype.x2; /** @type {?} */ ISearchRectParams.prototype.y2; /** @type {?} */ ISearchRectParams.prototype.pageNumber; /** @type {?|undefined} */ ISearchRectParams.prototype.stroke; /** @type {?|undefined} */ ISearchRectParams.prototype.fill; } /** * @record */ function ITableSplit() { } if (false) { /** @type {?} */ ITableSplit.prototype.page_number; /** @type {?} */ ITableSplit.prototype.table_id; /** @type {?} */ ITableSplit.prototype.split_lines; } /** * @record */ function ITableOperationRecord() { } if (false) { /** @type {?} */ ITableOperationRecord.prototype.id; /** @type {?} */ ITableOperationRecord.prototype.type; } /** * @record */ function IModifiedTableLineMatrix() { } if (false) { /** @type {?} */ IModifiedTableLineMatrix.prototype.table_id; /** @type {?} */ IModifiedTableLineMatrix.prototype.page_number; /** @type {?} */ IModifiedTableLineMatrix.prototype.lines; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} origin * @return {?} */ function functionProxy(origin) { /** @type {?} */ const obj = [ 'init', 'setPage', 'setZoom', 'setLabelMode', 'setPdfMode', 'setLabels', 'restore', 'search', 'scrollToLabel', 'scrollToLabelByIdx', 'scrollToTableCell', 'setTables', 'getTableMatrix', 'getViewport', 'getSelectedLabels', 'resetLabelsStyle', 'resetSelectedLabels', 'getDocContent', 'enableMergeOrSplitTables', 'scrollToRect', 'getTableSplitLines', 'redirectToRecord', 'deleteTblRecords', 'ignoreTblOperations', 'getModifiedTableLinesMatrix', 'focusTableCells' ].reduce((/** * @param {?} pre * @param {?} key * @return {?} */ (pre, key) => { ((/** @type {?} */ (pre)))[key] = (/** * @return {?} */ function proxy() { /** @type {?} */ const timeTag = `Execution Time`; console.group(`[@bixi/label] Proxy ${key}`); console.log(...arguments); // tslint:disable-next-line: no-console console.time(timeTag); /** @type {?} */ let result; try { result = origin[key](...arguments); } catch (error) { console.error(`[@bixi/label] excute proxy.${key} failed`); console.error(error); } // tslint:disable-next-line: no-console console.timeEnd(timeTag); console.groupEnd(); return result; }); return pre; }), {}); return obj; } /** * @return {?} */ function Log() { return (/** * @param {?} _target * @param {?} _propKey * @param {?} desc * @return {?} */ (_target, _propKey, desc) => { return Object.assign(Object.assign({}, desc), { /** * @return {?} */ value() { if (((/** @type {?} */ (this))).dev === true) { console.group(`[@bixi/label] hub ${_propKey}`); console.log(...arguments); /** @type {?} */ let result; // tslint:disable-next-line: no-console console.time(_propKey); result = desc.value.bind(this)(...arguments); // tslint:disable-next-line: no-console console.timeEnd(_propKey); console.groupEnd(); return result; } return desc.value.bind(this)(...arguments); } }); }); } /** * @return {?} */ function Safe() { return (/** * @param {?} _target * @param {?} _propKey * @param {?} desc * @return {?} */ (_target, _propKey, desc) => { return Object.assign(Object.assign({}, desc), { /** * @return {?} */ value() { if (((/** @type {?} */ (this))).ready === false) { console.error('[@bixi/label] DANGEROUS!!! Call method before initialization:', _propKey); return void 0; } return desc.value.bind(this)(...arguments); } }); }); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function IOptions() { } if (false) { /** @type {?|undefined} */ IOptions.prototype.dev; /** @type {?|undefined} */ IOptions.prototype.logUnhandledEvents; /** @type {?|undefined} */ IOptions.prototype.logAllEvents; /** @type {?|undefined} */ IOptions.prototype.logIgnoreEvents; } class LabelHub { /** * @param {?=} options */ constructor(options) { this._hoverInLabelsEvent = null; this._labelingEvent = null; this._dev = false; this._logUnhandledEvents = false; this._logAllEvents = false; this._logIgnoreEvents = []; this._ready = false; this._loaded = false; this._zoom = 1; this._pagination = { pageCount: 1, pageNumber: 1 }; /** * 标注器是否加载完成 */ this.loaded$ = new BehaviorSubject(this._loaded); /** * 标注器是否准备完毕 */ this.ready$ = new BehaviorSubject(this._ready); /** * 初始化数据流 */ this.init$ = new BehaviorSubject(null); /** * 搜索结果 */ this.searchResult$ = new BehaviorSubject({ keyword: '', caseSensitive: false, result: [] }); /** * Tooltip 信息 */ this.hoverInLabelsEvent$ = new Subject(); /** * 分页信息 * 默认 * { * page: 1, * total: 1 * } */ this.pagination$ = new BehaviorSubject(this._pagination); /** * 缩放 */ this.zoom$ = new BehaviorSubject(this._zoom); /** * 标注列表 */ this.labels$ = new BehaviorSubject(null); /** * 表格列表 */ this.tables$ = new BehaviorSubject(null); /** * 删除标注 */ this.deleteLabelsEvent$ = new Subject(); /** * 当前正在标注的标注 */ this.labelingEvent$ = new Subject(); /** * 尺寸变化 */ this.resize$ = new Subject(); /** * 日志流 */ this.log$ = new Subject(); this._dev = (options === null || options === void 0 ? void 0 : options.dev) || false; this._logUnhandledEvents = (options === null || options === void 0 ? void 0 : options.logUnhandledEvents) || false; this._logAllEvents = (options === null || options === void 0 ? void 0 : options.logAllEvents) || false; this._logIgnoreEvents = (options === null || options === void 0 ? void 0 : options.logIgnoreEvents) || []; } /** * @return {?} */ get ready() { return this._ready; } /** * @return {?} */ get dev() { return this._dev; } /** * @return {?} */ get api() { return this._api; } /** * @return {?} */ get loaded() { return this._loaded; } /** * @return {?} */ get logUnhandledEvents() { return this._logUnhandledEvents; } /** * @return {?} */ get logAllEvents() { return this._logAllEvents; } /** * @return {?} */ get logIgnoreEvents() { return this._logIgnoreEvents; } /** * @return {?} */ get hoverInLabelsEvent() { return this._hoverInLabelsEvent; } /** * @return {?} */ get labelingEvent() { return this._labelingEvent; } /** * @return {?} */ get labeling() { return !!this._labelingEvent; } /** * 设置标注器是否准备完毕 * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} ready * @return {?} */ setReady(ready) { this._ready = ready; this.ready$.next(this._ready); } /** * 设置标注器是否加载完成 * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} loaded * @return {?} */ setLoaded(loaded) { this._loaded = loaded; this.loaded$.next(this._loaded); } /** * 初始化标注器 * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} options * @return {?} */ init(options) { this.id = options.id; // if ([LabelTextMode.textSlip, LabelTextMode.textFrame].includes(options.labelMode as LabelTextMode)) { if (options.labelMode in LabelTextMode) { if (options.labels) { this.setLabels(options.labels); } } else { if (options.tables) { this.setTables(options.tables); } } this.init$.next(options); } /** * 设置标注 * @param {?} labels * @return {?} */ setLabels(labels) { this.labels$.next(labels); } /** * 设置表格 * @param {?} tables * @return {?} */ setTables(tables) { this.tables$.next(tables); } /** * 获取表格标注数据 * @return {?} */ getTableMatrix() { return this._api.getTableMatrix(); } /** * 设置 Tooltip * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} event * @return {?} */ hoverInLabels(event) { this._hoverInLabelsEvent = event; this.hoverInLabelsEvent$.next(event); } /** * 设置分页 * @param {?} pagination * @return {?} */ setPagination(pagination) { /** @type {?} */ const p = Object.assign(Object.assign({}, this._pagination), pagination); if (p.pageCount < p.pageNumber || p.pageNumber < 1) return; this.pagination$.next(p); if (this._pagination.pageNumber !== pagination.pageNumber) { this._api.setPage(pagination.pageNumber); } this._pagination = p; } /** * 获取分页信息 * @return {?} */ getPagination() { return this._pagination; } /** * 设置分页(内部调用) * \@description 同外部调用区别是,它不需要通知标注器更新,最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} pagination * @return {?} */ innerSetPagination(pagination) { this._pagination = Object.assign(Object.assign({}, this._pagination), pagination); this.pagination$.next(this._pagination); } /** * 设置缩放 * @param {?} zoom * @return {?} */ setZoom(zoom) { if (this._zoom !== zoom) { this._zoom = zoom; this.zoom$.next(zoom); this._api.setZoom(zoom); } } /** * 获取缩放 * @return {?} */ getZoom() { return this._zoom; } /** * 设置标注模式 * @param {?} mode * @return {?} */ setLabelMode(mode) { this._api.setLabelMode(mode); } /** * 设置PDF模式 * @param {?} mode * @return {?} */ setPdfMode(mode) { this._api.setPdfMode(mode); } /** * 打印日志 * @param {?} log * @return {?} */ setLog(log) { const { level, content } = log; // tslint:disable-next-line: no-any /** @type {?} */ const logger = ((/** @type {?} */ (console)))[level]; if (logger) { logger(content); } else { console.error('[@bixi/label] 没有找到对应的日志等级', level, content); } this.log$.next({ level, content }); } /** * 开始标注 * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} labeling * @return {?} */ startLabeling(labeling) { this._labelingEvent = labeling; this.labelingEvent$.next(labeling); } /** * 清除当前标注 * @return {?} */ stopLabeling() { if (!this._labelingEvent) return; this._labelingEvent = null; this.labelingEvent$.next(null); } /** * 删除标注 * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @param {?} event * @return {?} */ deleteLabels(event) { this.deleteLabelsEvent$.next(event); } /** * 搜索 * @param {?} params * @return {?} */ search(params) { this._api.search(params); } /** * 设置搜索结果 * @param {?} result * @return {?} */ setSearchResult(result) { this.searchResult$.next(result); } /** * 强制标注器重新渲染 * @return {?} */ restore() { this._api.restore(); } /** * 跳转到某个标签 * @param {?} params * @return {?} */ scrollToLabelByUuid(params) { this._api.scrollToLabel(params); } /** * 通过索引跳转到某个标签 * @param {?} params * @return {?} */ scrollToLabelByIndex(params) { this._api.scrollToLabelByIdx(params); } /** * 通过坐标跳转到表格单元格 * @param {?=} params * @return {?} */ scrollToTableCell(params) { this._api.scrollToTableCell(params); } /** * 聚焦已高亮的单元格 * @param {?} params * @return {?} */ focusTableCells(params) { this._api.focusTableCells(params); } /** * 获取页面的显示相关信息 * @return {?} */ getViewport() { return this._api.getViewport(); } /** * 获取所有被选中的 Labels * @return {?} */ getSelectedLabels() { return this._api.getSelectedLabels(); } /** * @param {?} api * @return {?} */ setApi(api) { this._api = api; } /** * 重置已渲染标注填充色和边框 * @param {?} params * @return {?} */ resetLabelsStyle(params) { this._api.resetLabelsStyle(params); } /** * 重置选中的标注 * @param {?} params * @return {?} */ resetSelectedLabels(params) { this._api.resetSelectedLabels(params); } /** * 获取文档文本内容 * @return {?} */ getDocContent() { return this._api.getDocContent(); } /** * enable merge|split cross page tables * @param {?=} enable * @return {?} */ enableMergeOrSplitTables(enable = false) { this._api.enableMergeOrSplitTables(enable); } /** * scroll to rect * @param {?} params * @return {?} */ scrollToRect(params) { this._api.scrollToRect(params); } /** * get split line info * @return {?} */ getTableSplitLines() { return this._api.getTableSplitLines(); } /** * redirect to specific table status ( will reset table operation records ) * @param {?} recordId * @return {?} */ redirectToRecord(recordId) { this._api.redirectToRecord(recordId); } /** * delete table operation records * @param {?} recordIds * @return {?} */ deleteTblRecords(recordIds) { this._api.deleteTblRecords(recordIds); } /** * ignore table operations * @param {?} params * @return {?} */ ignoreTblOperations(params) { this._api.setIgnoreTblOperations(params); } /** * get modified table line matrix * @return {?} */ getModifiedTableLinesMatrix() { return this._api.getModifiedTableLinesMatrix(); } /** * 销毁 Hub * \@description 最好不要在外部调用,这可能会产生不可预期的效果 * @return {?} */ destory() { this.loaded$.complete(); this.ready$.complete(); this.init$.complete(); this.searchResult$.complete(); this.hoverInLabelsEvent$.complete(); this.pagination$.complete(); this.zoom$.complete(); this.labels$.complete(); this.tables$.complete(); this.deleteLabelsEvent$.complete(); this.labelingEvent$.complete(); this.log$.complete(); } } __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setReady", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setLoaded", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "init", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setLabels", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setTables", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LabelHub.prototype, "getTableMatrix", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "hoverInLabels", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setPagination", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Object) ], LabelHub.prototype, "getPagination", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "innerSetPagination", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setZoom", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Number) ], LabelHub.prototype, "getZoom", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setLabelMode", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setPdfMode", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setLog", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "startLabeling", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LabelHub.prototype, "stopLabeling", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "deleteLabels", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "search", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "setSearchResult", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LabelHub.prototype, "restore", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "scrollToLabelByUuid", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "scrollToLabelByIndex", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "scrollToTableCell", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "focusTableCells", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Array) ], LabelHub.prototype, "getViewport", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Array) ], LabelHub.prototype, "getSelectedLabels", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "resetLabelsStyle", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "resetSelectedLabels", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", String) ], LabelHub.prototype, "getDocContent", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "enableMergeOrSplitTables", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "scrollToRect", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Array) ], LabelHub.prototype, "getTableSplitLines", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "redirectToRecord", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "deleteTblRecords", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], LabelHub.prototype, "ignoreTblOperations", null); __decorate([ Log(), Safe(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Array) ], LabelHub.prototype, "getModifiedTableLinesMatrix", null); __decorate([ Log(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LabelHub.prototype, "destory", null); if (false) { /** @type {?} */ LabelHub.prototype.id; /** * @type {?} * @protected */ LabelHub.prototype._hoverInLabelsEvent; /** * @type {?} * @protected */ LabelHub.prototype._labelingEvent; /** * @type {?} * @protected */ LabelHub.prototype._dev; /** * @type {?} * @protected */ LabelHub.prototype._logUnhandledEvents; /** * @type {?} * @protected */ LabelHub.prototype._logAllEvents; /** * @type {?} * @protected */ LabelHub.prototype._logIgnoreEvents; /** * @type {?} * @protected */ LabelHub.prototype._api; /** * @type {?} * @protected */ LabelHub.prototype._ready; /** * @type {?} * @protected */ LabelHub.prototype._loaded; /** * @type {?} * @protected */ LabelHub.prototype._zoom; /** * @type {?} * @protected */ LabelHub.prototype._pagination; /** * 标注器是否加载完成 * @type {?} */ LabelHub.prototype.loaded$; /** * 标注器是否准备完毕 * @type {?} */ LabelHub.prototype.ready$; /** * 初始化数据流 * @type {?} */ LabelHub.prototype.init$; /** * 搜索结果 * @type {?} */ LabelHub.prototype.searchResult$; /** * Tooltip 信息 * @type {?} */ LabelHub.prototype.hoverInLabelsEvent$; /** * 分页信息 * 默认 * { * page: 1, * total: 1 * } * @type {?} */ LabelHub.prototype.pagination$; /** * 缩放 * @type {?} */ LabelHub.prototype.zoom$; /** * 标注列表 * @type {?} */ LabelHub.prototype.labels$; /** * 表格列表 * @type {?} */ LabelHub.prototype.tables$; /** * 删除标注 * @type {?} */ LabelHub.prototype.deleteLabelsEvent$; /** * 当前正在标注的标注 * @type {?} */ LabelHub.prototype.labelingEvent$; /** * 尺寸变化 * @type {?} */ LabelHub.prototype.resize$; /** * 日志流 * @type {?} */ LabelHub.prototype.log$; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BixiLabelCoreComponent { /** * @param {?} sanitizer * @param {?} cdr */ constructor(sanitizer, cdr) { this.sanitizer = sanitizer; this.cdr = cdr; this.subscription = new Subscription(); this.hoverInLabelsEvent = null; this.labelingEvent = null; this.labelTooltipDisabled = false; this.labelModalDisabled = false; this.startLabeling = new EventEmitter(); this.deleteLabels = new EventEmitter(); this.clickLabels = new EventEmitter(); this.pdfLoadFailed = new EventEmitter(); this.pdfScrolling = new EventEmitter(); this.mergeTables = new EventEmitter(); this.splitTable = new EventEmitter(); this.tblOperationRecords = new EventEmitter(); this.messageHandler = (/** * @param {?} e * @return {?} */ (e) => { const { id, event, data } = e.data; if (this.hub.id !== id) return; if (this.hub.logAllEvents) { if (!this.hub.logIgnoreEvents.includes(event)) { console.log(`[@bixi/label] Event(${this.hub.id})`, e.data); } } switch (event) { case EVENTS.ready: { // 初始化标注器 this.hub.setReady(true); this.hub.innerSetPagination({ pageCount: data.pageCount }); break; } case EVENTS.zoomChange: { this.hub.setZoom(data.zoom); break; } case EVENTS.startLabeling: { this.hub.startLabeling(data); this.startLabeling.emit(data); break; } case EVENTS.deleteLabels: { this.hub.deleteLabels(data); this.deleteLabels.emit(data); break; } case EVENTS.paginationChange: { this.hub.innerSetPagination({ pageNumber: data.pageNumber }); break; } case EVENTS.searchResult: { this.hub.setSearchResult(data); break; } case EVENTS.clickLabels: { this.clickLabels.emit(data); break; } case EVENTS.hoverInLabel: { this.hub.hoverInLabels(data); break; } case EVENTS.hoverOutLabel: { this.hub.hoverInLabels(null); break; } case EVENTS.pdfScrolling: { if (this.hub.hoverInLabelsEvent) { this.hub.hoverInLabels(null); } this.pdfScrolling.emit(true); break; } case EVENTS.pdfLoadFailed: { this.pdfLoadFailed.emit(); break; } case EVENTS.log: { this.hub.setLog(data); break; } case EVENTS.resize: { this.hub.resize$.next(); break; } case EVENTS.mergeTables: { this.mergeTables.emit(data); break; } case EVENTS.splitTable: { this.splitTable.emit(data); break; } case EVENTS.tblOperationRecords: { this.tblOperationRecords.emit(data); break; } default: { if (this.hub.logUnhandledEvents) { if (!this.hub.logIgnoreEvents.includes(event)) { console.warn(`[@bixi/label] Unhandled Event(${this.hub.id}) `, event, data); } } break; } } }); } /** * @param {?} val * @return {?} */ set engine(val) { this.url = this.sanitizer.bypassSecurityTrustResourceUrl(`${val || './bixi-label/index.html'}`); this._engine = val; } /** * @return {?} */ get engine() { return this._engine; } /** * @return {?} */ onLoad() { if (!this.hub) return; /** @type {?} */ const api = this.api; this.hub.setApi(api); this.hub.setLoaded(!!api); } /** * @return {?} */ get api() { if (!this.iframe) return; /** @type {?} */ const service = this.iframe.element.nativeElement.contentWindow.ProxyApiService2; if (this.hub.dev) { return functionProxy(service); } return service; } /** * @return {?} */ ngOnInit() { this.subscription.add(this.hub.init$ .pipe(filter((/** * @param {?} i * @return {?} */ i => !!i)), delayWhen((/** * @return {?} */ () => this.hub.loaded$.pipe(filter((/** * @param {?} r * @return {?} */ r => r === true)))))) .subscribe((/** * @param {?} options * @return {?} */ options => { if (!this.api) return; this.api.init(options); }))); this.subscription.add(this.hub.labels$ .pipe(filter((/** * @param {?} i * @return {?} */ i => !!i)), delayWhen((/** * @return {?} */ () => this.hub.ready$.pipe(filter((/** * @param {?} r * @return {?} */ r => r === true)))))) .subscribe((/** * @param {?} labels * @return {?} */ (labels) => { if (!this.api) return; this.api.setLabels(labels); }))); this.subscription.add(this.hub.tables$ .pipe(filter((/** * @param {?} i * @return {?} */ i => !!i)), delayWhen((/** * @return {?} */ () => this.hub.ready$.pipe(filter((/** * @param {?} r * @return {?} */ r => r === true)))))) .subscribe((/** * @param {?} tables * @return {?} */ (tables) => { if (!this.api) return; this.api.setTables(tables); }))); this.subscription.add(this.hub.hoverInLabelsEvent$ .subscribe((/** * @param {?} event * @return {?} */ event => { this.hoverInLabelsEvent = event; this.cdr.detectChanges(); }))); this.subscription.add(this.hub.labelingEvent$ .subscribe((/** * @param {?} event * @return {?} */ event => { this.labelingEvent = event; this.cdr.detectChanges(); }))); window.addEventListener('message', this.messageHandler); } /** * @return {?} */ onCloseLabelModal() { this.hub.stopLabeling(); this.hub.restore(); } /** * @return {?} */ ngOnDestroy() { this.subscription.unsubscribe(); this.hub.destory(); window.removeEventListener('message', this.messageHandler); } } BixiLabelCoreComponent.decorators = [ { type: Component, args: [{ selector: 'bixi-label-core', template: ` <div class="bixi-label-core"> <iframe #iframe [src]="url" (load)="onLoad()" [attr.id]="hub.id" [title]="hub.id"> </iframe> <bixi-label-tooltip *ngIf="hoverInLabelsEvent && !labelTooltipDisabled" [tooltip]="hoverInLabelsEvent" [content]="labelTooltipContent"> </bixi-label-tooltip> <bixi-label-modal *ngIf="labelModalContent && labelingEvent && !labelModalDisabled" [dragBoundary]="dragBoundary" (close)="onCloseLabelModal()" [labeling]="labelingEvent" [title]="labelModalTitle" [content]="labelModalContent"> </bixi-label-modal> </div> `, exportAs: 'bixiLabelText', encapsulation: ViewEncapsulation.None, preserveWhitespaces: true, changeDetection: ChangeDetectionStrategy.OnPush, styles: [".bixi-label-core{position:relative;width:100%;height:100%}.bixi-label-core iframe{width:100%;height:100%;vertical-align:top;border:none}.bixi-label-modal-backdrop{position:absolute;top:0;right:0;bottom:0;left:0;z-index:1000;background-color:rgba(0,0,0,.5);-webkit-tap-highlight-color:transparent;opacity:0;transition:opacity .4s cubic-bezier(.25,.8,.25,1);pointer-events:auto}.bixi-label-modal-backdrop.cdk-overlay-backdrop-showing{opacity:1}.bixi-label-modal,.bixi-label-tooltip{position:absolute;top:0;left:0}.bixi-label-tooltip{pointer-events:none}.bixi-label-modal{display:flex;flex-direction:column;background:#fff;border-radius:2px;box-shadow:0 3px 6px -4px rgba(0,0,0,.12),0 6px 16px 0 rgba(0,0,0,.08),0 9px 28px 8px rgba(0,0,0,.05)}.bixi-label-modal-header{height:32px;font-size:12px;border-bottom:1px solid #d9d9d9;cursor:move}.bixi-label-modal-header-inner{display:flex;justify-content:space-between;height:100%;line-height:32px}.bixi-label-modal-content{height:calc(100% - 32px);overflow:auto}.bixi-label-modal .bixi-label-modal-title{padding-left:8px;font-weight:500}.bixi-label-modal .bixi-label-modal-close-icon{width:36px;height:100%;text-align:center;cursor:pointer;-webkit-user-drag:none}"] }] } ]; /** @nocollapse */ BixiLabelCoreComponent.ctorParameters = () => [ { type: DomSanitizer }, { type: ChangeDetectorRef } ]; BixiLabelCoreComponent.propDecorators = { dragBoundary: [{ type: Input }], iframe: [{ type: ViewChild, args: ['iframe', { read: ViewContainerRef },] }], hub: [{ type: Input }], engine: [{ type: Input }], labelTooltipContent: [{ type: Input }], labelTooltipDisabled: [{ type: Input }], labelModalTitle: [{ type: Input }], labelModalDisabled: [{ type: Input }], labelModalContent: [{ type: Input }], startLabeling: [{ type: Output }], deleteLabels: [{ type: Output }], clickLabels: [{ type: Output }], pdfLoadFailed: [{ type: Output }], pdfScrolling: [{ type: Output }], mergeTables: [{ type: Output }], splitTable: [{ type: Output }], tblOperationRecords: [{ type: Output }] }; if (false) { /** @type {?} */ BixiLabelCoreComponent.prototype.subscription; /** @type {?} */ BixiLabelCoreComponent.prototype._engine; /** @type {?} */ BixiLabelCoreComponent.prototype.url; /** @type {?} */ BixiLabelCoreComponent.prototype.hoverInLabelsEvent; /** @type {?} */ BixiLabelCoreComponent.prototype.labelingEvent; /** @type {?} */ BixiLabelCoreComponent.prototype.dragBoundary; /** @type {?} */ BixiLabelCoreComponent.prototype.iframe; /** @type {?} */ BixiLabelCoreComponent.prototype.hub; /** @type {?} */ BixiLabelCoreComponent.prototype.labelTooltipContent; /** @type {?} */ BixiLabelCoreComponent.prototype.labelTooltipDisabled; /** @type {?} */ BixiLabelCoreComponent.prototype.labelModalTitle; /** @type {?} */ BixiLabelCoreComponent.prototype.labelModalDisabled; /** @type {?} */ BixiLabelCoreComponent.prototype.labelModalContent; /** @type {?} */ BixiLabelCoreComponent.prototype.startLabeling; /** @type {?} */ BixiLabelCoreComponent.prototype.deleteLabels; /** @type {?} */ BixiLabelCoreComponent.prototype.clickLabels; /** @type {?} */ BixiLabelCoreComponent.prototype.pdfLoadFailed; /** @type {?} */ BixiLabelCoreComponent.prototype.pdfScrolling; /** @type {?} */ BixiLabelCoreComponent.prototype.mergeTables; /** @type {?} */ BixiLabelCoreComponent.prototype.splitTable; /** @type {?} */ BixiLabelCoreComponent.prototype.tblOperationRecords; /** @type {?} */ BixiLabelCoreComponent.prototype.messageHandler; /** @type {?} */ BixiLabelCoreComponent.prototype.sanitizer; /** * @type {?} * @private */ BixiLabelCoreComponent.prototype.cdr; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const OVERLAY_WIDTH = 468; /** @type {?} */ const OVERLAY_HEIGHT = 288; class BixiLabelModalComponent { /** * @param {?} cdr */ constructor(cdr) { this.cdr = cdr; this.overlayWidth = OVERLAY_WIDTH; this.overlayHeight = OVERLAY_HEIGHT; this.placement = 'right'; this.isOpen = false; this._labeling = null; // tslint:disable-next-line: no-output-native this.close = new EventEmitter(); this.onClose = (/** * @return {?} */ () => { this.onHide(); this.close.emit(); }); } /** * @param {?} val * @return {?} */ set labeling(val) { this._labeling = val; if (val) { this.onShow(); } else { this.onHide(); } } /** * @return {?} */ get labeling() { return this._labeling; } /** * @return {?} */ get labels() { return this.labeling ? (this.labeling.data) || [] : []; } /** * @return {?} */ onShow() { if (this.isOpen && this.overlay) { // 如果是二次标注的话,只需要调整位置就可以了 Promise.resolve().then((/** * @return {?} */ () => { this.cdr.detectChanges(); this.overlay.overlayRef.updatePosition(); })); return; } this.isOpen = true; this.cdr.detectChanges(); } /** * @return {?}