UNPKG

nehan

Version:

Html layout engine for paged-media written in Typescript

39 lines 1.41 kB
export class LayoutOutlineEvaluator { constructor(createTitle) { this.createTitle = createTitle; } visitSectionRoot(section) { const root = document.createElement("ul"); return this.visitSectionChildren(section.children, root); } visitSectionNode(section) { const li = document.createElement("li"); const title = this.createTitle ? this.createTitle(section) : document.createTextNode(section.title); li.appendChild(title); const ul = this.visitSectionChildren(section.children); li.appendChild(ul); return li; } visitSectionLeaf(section) { const li = document.createElement("li"); const title = this.createTitle ? this.createTitle(section) : document.createTextNode(section.title); li.appendChild(title); return li; } visitSectionChildren(children, parent) { const ul = parent || document.createElement("ul"); children.forEach(child => { if (child.isRoot()) { ul.appendChild(this.visitSectionRoot(child)); } else if (child.isNode()) { ul.appendChild(this.visitSectionNode(child)); } else { ul.appendChild(this.visitSectionLeaf(child)); } }); return ul; } } //# sourceMappingURL=layout-outline-evaluator.js.map