UNPKG

@rpidanny/pdf2md

Version:
33 lines (30 loc) 887 B
const PageItem = require('./PageItem') const LineItem = require('./LineItem') // A block of LineItem[] within a Page module.exports = class LineItemBlock extends PageItem { constructor (options) { super(options) this.items = [] if (options.items) { options.items.forEach(item => this.addItem(item)) } } addItem (item /*: LineItem */) { if (this.type && item.type && this.type !== item.type) { throw new Error(`Adding item of type ${item.type} to block of type ${this.type}`) } if (!this.type) { this.type = item.type } if (item.parsedElements) { if (this.parsedElements) { this.parsedElements.add(item.parsedElements) } else { this.parsedElements = item.parsedElements } } const copiedItem = new LineItem({ ...item }) copiedItem.type = null this.items.push(copiedItem) } }