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AS,CAsErB;AAtEY,8BAAS","sourcesContent":["import { Reflection, ReflectionKind, ProjectReflection, DeclarationReflection } from '../../models/reflections/index';\nimport { Component, RendererComponent } from '../components';\nimport { PageEvent } from '../events';\nimport { NavigationItem } from '../models/NavigationItem';\n\n/**\n * A plugin that generates a table of contents for the current page.\n *\n * The table of contents will start at the nearest module or dynamic module. This plugin\n * sets the [[PageEvent.toc]] property.\n */\n@Component({name: 'toc'})\nexport class TocPlugin extends RendererComponent {\n /**\n * Create a new TocPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [PageEvent.BEGIN]: this.onRendererBeginPage\n });\n }\n\n /**\n * Triggered before a document will be rendered.\n *\n * @param page An event object describing the current render operation.\n */\n private onRendererBeginPage(page: PageEvent) {\n let model = page.model;\n if (!(model instanceof Reflection)) {\n return;\n }\n\n const trail: Reflection[] = [];\n while (!(model instanceof ProjectReflection) && !model.kindOf(ReflectionKind.SomeModule)) {\n trail.unshift(model);\n model = model.parent;\n }\n\n const tocRestriction = this.owner.toc;\n page.toc = new NavigationItem();\n TocPlugin.buildToc(model, trail, page.toc, tocRestriction);\n }\n\n /**\n * Create a toc navigation item structure.\n *\n * @param model The models whose children should be written to the toc.\n * @param trail Defines the active trail of expanded toc entries.\n * @param parent The parent [[NavigationItem]] the toc should be appended to.\n * @param restriction The restricted table of contents.\n */\n static buildToc(model: Reflection, trail: Reflection[], parent: NavigationItem, restriction?: string[]) {\n const index = trail.indexOf(model);\n const children = model['children'] || [];\n\n if (index < trail.length - 1 && children.length > 40) {\n const child = trail[index + 1];\n const item = NavigationItem.create(child, parent, true);\n item.isInPath = true;\n item.isCurrent = false;\n TocPlugin.buildToc(child, trail, item);\n } else {\n children.forEach((child: DeclarationReflection) => {\n\n if (restriction && restriction.length > 0 && !restriction.includes(child.name)) {\n return;\n }\n\n if (child.kindOf(ReflectionKind.SomeModule)) {\n return;\n }\n\n const item = NavigationItem.create(child, parent, true);\n if (trail.includes(child)) {\n item.isInPath = true;\n item.isCurrent = (trail[trail.length - 1] === child);\n TocPlugin.buildToc(child, trail, item);\n }\n });\n }\n }\n}\n"]}
\No newline at end of file