update nodejs_v18_compatibility (#62)

This commit is contained in:
laiso 2024-03-19 05:55:06 +07:00 committed by GitHub
parent ed59a3f24a
commit 12e5e9a383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 11980 additions and 10836 deletions

View File

@ -1,8 +1,8 @@
{ {
"env": { "env": {
"testing": { "testing": {
"presets": ["es2015"] "presets": ["@babel/preset-env", "@babel/preset-react"]
} }
}, },
"presets": [ ["es2015", { "loose": false, "modules": false}], "react", "stage-0", "stage-2"] "presets": ["@babel/preset-env", "@babel/preset-react"]
} }

22718
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@
"dependencies": { "dependencies": {
"bootstrap": "^3.3.7", "bootstrap": "^3.3.7",
"enumify": "^1.0.4", "enumify": "^1.0.4",
"mini-css-extract-plugin": "^2.7.6",
"pdfjs-dist": "^2.8.335", "pdfjs-dist": "^2.8.335",
"rc-progress": "^2.0.6", "rc-progress": "^2.0.6",
"react": "^15.4.2", "react": "^15.4.2",
@ -38,11 +39,12 @@
"remarkable": "^1.7.1" "remarkable": "^1.7.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"babel-core": "^6.22.1", "babel-core": "^6.22.1",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"babel-loader": "^7.1.1", "babel-loader": "^8.x",
"babel-plugin-transform-runtime": "^6.22.0", "babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0", "babel-preset-react": "^6.22.0",
"babel-preset-stage-0": "^6.22.0", "babel-preset-stage-0": "^6.22.0",
"babel-preset-stage-2": "^6.24.1", "babel-preset-stage-2": "^6.24.1",
@ -52,8 +54,7 @@
"esformatter-jsx": "^7.4.1", "esformatter-jsx": "^7.4.1",
"eslint": "^7.30.0", "eslint": "^7.30.0",
"eslint-plugin-jasmine": "^2.2.0", "eslint-plugin-jasmine": "^2.2.0",
"eslint-plugin-react": "^6.9.0", "eslint-plugin-react": "^7.x",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.2", "html-webpack-plugin": "^5.3.2",
"mocha": "^3.2.0", "mocha": "^3.2.0",

View File

@ -172,7 +172,7 @@ export default class DebugView extends React.Component {
</Checkbox> } </Checkbox> }
</ButtonGroup> </ButtonGroup>
<ButtonGroup> <ButtonGroup>
<Checkbox onClick={ ::this.showStatistics }> <Checkbox onClick={() => this.showStatistics()}>
Show Statistics Show Statistics
</Checkbox> </Checkbox>
</ButtonGroup> </ButtonGroup>

View File

@ -38,7 +38,7 @@ export default class AppState {
} }
// the uploaded pdf as file buffer // the uploaded pdf as file buffer
storeFileBuffer(fileBuffer:Uint8Array) { storeFileBuffer(fileBuffer) {
this.fileBuffer = fileBuffer; this.fileBuffer = fileBuffer;
this.mainView = View.LOADING; this.mainView = View.LOADING;
this.render() this.render()

View File

@ -17,7 +17,7 @@ export default class LineConverter {
} }
// returns a CombineResult // returns a CombineResult
compact(textItems: TextItem[]) { compact(textItems) {
// we can't trust order of occurence, esp. footnoteLinks like to come last // we can't trust order of occurence, esp. footnoteLinks like to come last
sortByX(textItems); sortByX(textItems);

View File

@ -12,7 +12,7 @@ export default class LineItemBlock extends PageItem {
} }
} }
addItem(item:LineItem) { addItem(item) {
if (this.type && item.type && this.type !== item.type) { if (this.type && item.type && this.type !== item.type) {
throw `Adding item of type ${item.type} to block of type ${this.type}` throw `Adding item of type ${item.type} to block of type ${this.type}`
} }

View File

@ -1,4 +1,3 @@
import TextItem from './TextItem.jsx';
import { sortByX } from '../pageItemFunctions.jsx' import { sortByX } from '../pageItemFunctions.jsx'
//Groups all text items which are on the same y line //Groups all text items which are on the same y line
@ -9,12 +8,12 @@ export default class TextItemLineGrouper {
} }
// returns a CombineResult // returns a CombineResult
group(textItems: TextItem[]) { group(textItems) {
return this.groupItemsByLine(textItems); return this.groupItemsByLine(textItems);
} }
groupItemsByLine(textItems:TextItem[]) { groupItemsByLine(textItems) {
const lines = []; const lines = [];
var currentLine = []; var currentLine = [];
textItems.forEach(item => { textItems.forEach(item => {

View File

@ -12,83 +12,83 @@ BlockType.initEnum({
H1: { H1: {
headline: true, headline: true,
headlineLevel: 1, headlineLevel: 1,
toText(block:LineItemBlock) { toText(block) {
return '# ' + linesToText(block.items, true); return '# ' + linesToText(block.items, true);
} }
}, },
H2: { H2: {
headline: true, headline: true,
headlineLevel: 2, headlineLevel: 2,
toText(block:LineItemBlock) { toText(block) {
return '## ' + linesToText(block.items, true); return '## ' + linesToText(block.items, true);
} }
}, },
H3: { H3: {
headline: true, headline: true,
headlineLevel: 3, headlineLevel: 3,
toText(block:LineItemBlock) { toText(block) {
return '### ' + linesToText(block.items, true); return '### ' + linesToText(block.items, true);
} }
}, },
H4: { H4: {
headline: true, headline: true,
headlineLevel: 4, headlineLevel: 4,
toText(block:LineItemBlock) { toText(block) {
return '#### ' + linesToText(block.items, true); return '#### ' + linesToText(block.items, true);
} }
}, },
H5: { H5: {
headline: true, headline: true,
headlineLevel: 5, headlineLevel: 5,
toText(block:LineItemBlock) { toText(block) {
return '##### ' + linesToText(block.items, true); return '##### ' + linesToText(block.items, true);
} }
}, },
H6: { H6: {
headline: true, headline: true,
headlineLevel: 6, headlineLevel: 6,
toText(block:LineItemBlock) { toText(block) {
return '###### ' + linesToText(block.items, true); return '###### ' + linesToText(block.items, true);
} }
}, },
TOC: { TOC: {
mergeToBlock: true, mergeToBlock: true,
toText(block:LineItemBlock) { toText(block) {
return linesToText(block.items, true); return linesToText(block.items, true);
} }
}, },
FOOTNOTES: { FOOTNOTES: {
mergeToBlock: true, mergeToBlock: true,
mergeFollowingNonTypedItems: true, mergeFollowingNonTypedItems: true,
toText(block:LineItemBlock) { toText(block) {
return linesToText(block.items, false); return linesToText(block.items, false);
} }
}, },
CODE: { CODE: {
mergeToBlock: true, mergeToBlock: true,
toText(block:LineItemBlock) { toText(block) {
return '```\n' + linesToText(block.items, true) + '```' return '```\n' + linesToText(block.items, true) + '```'
} }
}, },
LIST: { LIST: {
mergeToBlock: true, mergeToBlock: true,
mergeFollowingNonTypedItemsWithSmallDistance: true, mergeFollowingNonTypedItemsWithSmallDistance: true,
toText(block:LineItemBlock) { toText(block) {
return linesToText(block.items, false); return linesToText(block.items, false);
} }
}, },
PARAGRAPH: { PARAGRAPH: {
toText(block:LineItemBlock) { toText(block) {
return linesToText(block.items, false); return linesToText(block.items, false);
} }
} }
}); });
export function isHeadline(type: BlockType) { export function isHeadline(type) {
return type && type.name.length == 2 && type.name[0] === 'H' return type && type.name.length == 2 && type.name[0] === 'H'
} }
export function blockToText(block: LineItemBlock) { export function blockToText(block) {
if (!block.type) { if (!block.type) {
return linesToText(block.items, false); return linesToText(block.items, false);
} }

View File

@ -28,7 +28,7 @@ export default class ToLineItemBlockTransformation extends Transformation {
showWhitespaces={ this.showWhitespaces } />; showWhitespaces={ this.showWhitespaces } />;
} }
completeTransform(parseResult:ParseResult) { completeTransform(parseResult) {
// The usual cleanup // The usual cleanup
parseResult.messages = []; parseResult.messages = [];
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -28,7 +28,7 @@ export default class ToLineItemTransformation extends Transformation {
showWhitespaces={ this.showWhitespaces } />; showWhitespaces={ this.showWhitespaces } />;
} }
completeTransform(parseResult:ParseResult) { completeTransform(parseResult) {
// The usual cleanup // The usual cleanup
parseResult.messages = []; parseResult.messages = [];
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -13,7 +13,7 @@ export default class ToMarkdown extends Transformation {
return <MarkdownPageView key={ page.index } page={ page } />; return <MarkdownPageView key={ page.index } page={ page } />;
} }
transform(parseResult:ParseResult) { transform(parseResult) {
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {
var text = ''; var text = '';
page.items.forEach(block => { page.items.forEach(block => {

View File

@ -14,7 +14,7 @@ export default class ToTextBlocks extends Transformation {
return <TextPageView key={ page.index } page={ page } />; return <TextPageView key={ page.index } page={ page } />;
} }
transform(parseResult:ParseResult) { transform(parseResult) {
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {
const textItems = []; const textItems = [];
page.items.forEach(block => { page.items.forEach(block => {

View File

@ -28,7 +28,7 @@ export default class ToTextItemTransformation extends Transformation {
showWhitespaces={ this.showWhitespaces } />; showWhitespaces={ this.showWhitespaces } />;
} }
completeTransform(parseResult:ParseResult) { completeTransform(parseResult) {
// The usual cleanup // The usual cleanup
parseResult.messages = []; parseResult.messages = [];
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -23,12 +23,12 @@ export default class Transformation {
} }
// Transform an incoming ParseResult into an outgoing ParseResult // Transform an incoming ParseResult into an outgoing ParseResult
transform(parseResult: ParseResult) { // eslint-disable-line no-unused-vars transform(parseResult) { // eslint-disable-line no-unused-vars
throw new TypeError("Do not call abstract method foo from child."); throw new TypeError("Do not call abstract method foo from child.");
} }
// Sometimes the transform() does only visualize a change. This methods then does the actual change. // Sometimes the transform() does only visualize a change. This methods then does the actual change.
completeTransform(parseResult: ParseResult) { // eslint-disable-line no-unused-vars completeTransform(parseResult) { // eslint-disable-line no-unused-vars
parseResult.messages = []; parseResult.messages = [];
return parseResult; return parseResult;
} }

View File

@ -16,7 +16,7 @@ export default class CompactLines extends ToLineItemTransformation {
super("Compact To Lines"); super("Compact To Lines");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
const {mostUsedDistance, fontToFormats} = parseResult.globals; const {mostUsedDistance, fontToFormats} = parseResult.globals;
const foundFootnotes = []; const foundFootnotes = [];
const foundFootnoteLinks = []; const foundFootnoteLinks = [];

View File

@ -12,7 +12,7 @@ export default class DetectHeaders extends ToLineItemTransformation {
super("Detect Headers"); super("Detect Headers");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
const {tocPages, headlineTypeToHeightRange, mostUsedHeight, mostUsedDistance, mostUsedFont, maxHeight} = parseResult.globals; const {tocPages, headlineTypeToHeightRange, mostUsedHeight, mostUsedDistance, mostUsedFont, maxHeight} = parseResult.globals;
const hasToc = tocPages.length > 0; const hasToc = tocPages.length > 0;
var detectedHeaders = 0; var detectedHeaders = 0;

View File

@ -13,7 +13,7 @@ export default class DetectListItems extends ToLineItemTransformation {
super("Detect List Items"); super("Detect List Items");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
var foundListItems = 0; var foundListItems = 0;
var foundNumberedItems = 0; var foundNumberedItems = 0;
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -15,7 +15,7 @@ export default class DetectTOC extends ToLineItemTransformation {
super("Detect TOC"); super("Detect TOC");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
const tocPages = []; const tocPages = [];
const maxPagesToEvaluate = Math.min(20, parseResult.pages.length); const maxPagesToEvaluate = Math.min(20, parseResult.pages.length);
const linkLeveler = new LinkLeveler(); const linkLeveler = new LinkLeveler();
@ -289,7 +289,7 @@ class LinkLeveler {
this.uniqueFonts = []; this.uniqueFonts = [];
} }
levelPageItems(tocLinks:TocLink[]) { levelPageItems(tocLinks) {
if (!this.levelByMethod) { if (!this.levelByMethod) {
const uniqueX = this.calculateUniqueX(tocLinks); const uniqueX = this.calculateUniqueX(tocLinks);
if (uniqueX.length > 1) { if (uniqueX.length > 1) {

View File

@ -30,7 +30,7 @@ export default class RemoveRepetitiveElements extends ToLineItemTransformation {
// - For each page, collect all items of the first, and all items of the last line // - For each page, collect all items of the first, and all items of the last line
// - Calculate how often these items occur accros all pages (hash ignoring numbers, whitespace, upper/lowercase) // - Calculate how often these items occur accros all pages (hash ignoring numbers, whitespace, upper/lowercase)
// - Delete items occuring on more then 2/3 of all pages // - Delete items occuring on more then 2/3 of all pages
transform(parseResult:ParseResult) { transform(parseResult) {
// find first and last lines per page // find first and last lines per page
const pageStore = []; const pageStore = [];

View File

@ -11,7 +11,7 @@ export default class VerticalToHorizontal extends ToLineItemTransformation {
super("Vertical to Horizontal Text"); super("Vertical to Horizontal Text");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
var foundVerticals = 0; var foundVerticals = 0;
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {
const stream = new VerticalsStream(); const stream = new VerticalsStream();

View File

@ -9,7 +9,7 @@ export default class CalculateGlobalStats extends ToTextItemTransformation {
this.fontMap = fontMap; this.fontMap = fontMap;
} }
transform(parseResult:ParseResult) { transform(parseResult) {
// Parse heights // Parse heights
const heightToOccurrence = {}; const heightToOccurrence = {};
const fontToOccurrence = {}; const fontToOccurrence = {};

View File

@ -11,7 +11,7 @@ export default class DetectCodeQuoteBlocks extends ToLineItemBlockTransformation
super("Detect Code/Quote Blocks"); super("Detect Code/Quote Blocks");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
const {mostUsedHeight} = parseResult.globals; const {mostUsedHeight} = parseResult.globals;
var foundCodeItems = 0; var foundCodeItems = 0;
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -12,7 +12,7 @@ export default class DetectListLevels extends ToLineItemBlockTransformation {
this.showWhitespaces = true; this.showWhitespaces = true;
} }
transform(parseResult:ParseResult) { transform(parseResult) {
var listBlocks = 0; var listBlocks = 0;
var modifiedBlocks = 0; var modifiedBlocks = 0;
parseResult.pages.forEach(page => { parseResult.pages.forEach(page => {

View File

@ -11,7 +11,7 @@ export default class GatherBlocks extends ToLineItemBlockTransformation {
super("Gather Blocks"); super("Gather Blocks");
} }
transform(parseResult:ParseResult) { transform(parseResult) {
const {mostUsedDistance} = parseResult.globals; const {mostUsedDistance} = parseResult.globals;
var createdBlocks = 0; var createdBlocks = 0;
var lineItemCount = 0; var lineItemCount = 0;

View File

@ -1,7 +1,6 @@
import PageItem from './models/PageItem.jsx'; import PageItem from './models/PageItem.jsx';
import LineItemBlock from './models/LineItemBlock.jsx';
export function minXFromBlocks(blocks:LineItemBlock[]) { export function minXFromBlocks(blocks) {
var minX = 999; var minX = 999;
blocks.forEach(block => { blocks.forEach(block => {
block.items.forEach(item => { block.items.forEach(item => {
@ -14,7 +13,7 @@ export function minXFromBlocks(blocks:LineItemBlock[]) {
return minX; return minX;
} }
export function minXFromPageItems(items:PageItem) { export function minXFromPageItems(items) {
var minX = 999; var minX = 999;
items.forEach(item => { items.forEach(item => {
minX = Math.min(minX, item.x) minX = Math.min(minX, item.x)
@ -25,13 +24,13 @@ export function minXFromPageItems(items:PageItem) {
return minX; return minX;
} }
export function sortByX(items:PageItem) { export function sortByX(items) {
items.sort((a, b) => { items.sort((a, b) => {
return a.x - b.x; return a.x - b.x;
}); });
} }
export function sortCopyByX(items:PageItem) { export function sortCopyByX(items) {
const copy = items.concat(); const copy = items.concat();
sortByX(copy); sortByX(copy);
return copy; return copy;

View File

@ -9,6 +9,7 @@ var BUILD_DIR = path.resolve(__dirname, 'build');
var NODEMODULES_DIR = path.resolve(__dirname, 'node_modules'); var NODEMODULES_DIR = path.resolve(__dirname, 'node_modules');
module.exports = { module.exports = {
mode: 'development',
context: SOURCE_DIR, context: SOURCE_DIR,
resolve: { resolve: {
modules: [ modules: [