2017-01-06 20:49:37 +01:00
|
|
|
import { Enum } from 'enumify';
|
|
|
|
|
2017-03-15 06:09:18 +01:00
|
|
|
import CalculateGlobalStats from './transformations/textitem/CalculateGlobalStats.jsx';
|
|
|
|
import CompactLines from './transformations/textitem/CompactLines.jsx';
|
|
|
|
import RemoveRepetitiveElements from './transformations/textitem/RemoveRepetitiveElements.jsx'
|
|
|
|
import VerticalToHorizontal from './transformations/textitem/VerticalToHorizontal.jsx';
|
2017-03-18 08:56:08 +01:00
|
|
|
import PostprocessLines from './transformations/textitem/PostprocessLines.jsx';
|
2017-03-15 06:09:18 +01:00
|
|
|
import DetectTOC from './transformations/textitem/DetectTOC.jsx'
|
|
|
|
import DetectListItems from './transformations/textitem/DetectListItems.jsx'
|
2017-03-15 08:42:46 +01:00
|
|
|
import DetectHeaders from './transformations/textitem/DetectHeaders.jsx'
|
2017-03-24 12:30:35 +01:00
|
|
|
import CompleteFormats from './transformations/textitem/CompleteFormats.jsx'
|
2017-03-10 08:49:40 +01:00
|
|
|
|
2017-03-15 06:09:18 +01:00
|
|
|
import GatherBlocks from './transformations/textitemblock/GatherBlocks.jsx'
|
|
|
|
import DetectCodeQuoteBlocks from './transformations/textitemblock/DetectCodeQuoteBlocks.jsx'
|
|
|
|
import DetectListLevels from './transformations/textitemblock/DetectListLevels.jsx'
|
2017-02-17 20:17:04 +01:00
|
|
|
import ToTextBlocks from './transformations/ToTextBlocks.jsx';
|
2017-02-06 19:13:43 +01:00
|
|
|
import ToMarkdown from './transformations/ToMarkdown.jsx'
|
2017-01-07 11:38:06 +01:00
|
|
|
|
2017-01-06 20:49:37 +01:00
|
|
|
// Holds the state of the Application
|
|
|
|
export default class AppState {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
this.renderFunction = options.renderFunction;
|
|
|
|
this.mainView = View.UPLOAD;
|
2017-01-09 20:08:32 +01:00
|
|
|
this.fileBuffer;
|
2017-03-22 07:19:21 +01:00
|
|
|
this.metadata;
|
|
|
|
this.pages = [];
|
2017-03-22 20:08:34 +01:00
|
|
|
this.transformations ;
|
2017-01-06 20:49:37 +01:00
|
|
|
|
|
|
|
//bind functions
|
|
|
|
this.render = this.render.bind(this);
|
2017-01-09 20:08:32 +01:00
|
|
|
this.storeFileBuffer = this.storeFileBuffer.bind(this);
|
|
|
|
this.storePdfPages = this.storePdfPages.bind(this);
|
2017-02-06 19:13:43 +01:00
|
|
|
this.switchMainView = this.switchMainView.bind(this);
|
2017-01-06 20:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.renderFunction(this)
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:08:32 +01:00
|
|
|
// the uploaded pdf as file buffer
|
|
|
|
storeFileBuffer(fileBuffer:ArrayBuffer) {
|
|
|
|
this.fileBuffer = fileBuffer;
|
2017-01-06 20:49:37 +01:00
|
|
|
this.mainView = View.LOADING;
|
|
|
|
this.render()
|
|
|
|
}
|
|
|
|
|
2017-03-22 07:19:21 +01:00
|
|
|
storePdfPages(metadata, fontMap, pages) {
|
|
|
|
this.metadata = metadata;
|
|
|
|
this.pages = pages;
|
2017-01-09 20:08:32 +01:00
|
|
|
this.fileBuffer = null;
|
2017-02-06 19:13:43 +01:00
|
|
|
this.mainView = View.RESULT;
|
2017-03-22 20:08:34 +01:00
|
|
|
|
|
|
|
this.transformations = [
|
|
|
|
new CalculateGlobalStats(fontMap),
|
|
|
|
new CompactLines(),
|
|
|
|
new RemoveRepetitiveElements(),
|
|
|
|
new VerticalToHorizontal(),
|
|
|
|
new PostprocessLines(),
|
|
|
|
new DetectTOC(),
|
|
|
|
new DetectHeaders(),
|
2017-03-24 12:30:35 +01:00
|
|
|
new CompleteFormats(),
|
|
|
|
new DetectListItems(),
|
2017-03-22 20:08:34 +01:00
|
|
|
|
|
|
|
new GatherBlocks(),
|
|
|
|
new DetectCodeQuoteBlocks(),
|
|
|
|
new DetectListLevels(),
|
|
|
|
|
|
|
|
new ToTextBlocks(),
|
|
|
|
new ToMarkdown()];
|
|
|
|
|
2017-02-06 19:13:43 +01:00
|
|
|
this.render();
|
2017-03-22 20:08:34 +01:00
|
|
|
|
2017-02-06 19:13:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switchMainView(view) {
|
|
|
|
this.mainView = view;
|
2017-01-09 20:08:32 +01:00
|
|
|
this.render();
|
2017-01-06 20:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class View extends Enum {
|
|
|
|
}
|
2017-02-06 19:13:43 +01:00
|
|
|
View.initEnum(['UPLOAD', 'LOADING', 'RESULT', 'DEBUG'])
|