index.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. export = tocbot;
  2. export as namespace tocbot;
  3. declare namespace tocbot {
  4. /**
  5. * @see https://github.com/tscanlin/tocbot#options
  6. */
  7. interface IStaticOptions {
  8. // Where to render the table of contents.
  9. tocSelector?: string
  10. // Where to grab the headings to build the table of contents.
  11. contentSelector?: string
  12. // Which headings to grab inside of the contentSelector element.
  13. headingSelector?: string
  14. // Headings that match the ignoreSelector will be skipped.
  15. ignoreSelector?: string
  16. // For headings inside relative or absolute positioned containers within content.
  17. hasInnerContainers?: boolean
  18. // Main class to add to links.
  19. linkClass?: string
  20. // Extra classes to add to links.
  21. extraLinkClasses?: string
  22. // Class to add to active links // the link corresponding to the top most heading on the page.
  23. activeLinkClass?: string
  24. // Main class to add to lists.
  25. listClass?: string
  26. // Extra classes to add to lists.
  27. extraListClasses?: string
  28. // Class that gets added when a list should be collapsed.
  29. isCollapsedClass?: string
  30. // Class that gets added when a list should be able
  31. // to be collapsed but isn't necessarily collapsed.
  32. collapsibleClass?: string
  33. // Class to add to list items.
  34. listItemClass?: string
  35. // Class to add to active list items.
  36. activeListItemClass?: string
  37. // How many heading levels should not be collapsed.
  38. // For example; number 6 will show everything since
  39. // there are only 6 heading levels and number 0 will collapse them all.
  40. // The sections that are hidden will open
  41. // and close as you scroll to headings within them.
  42. collapseDepth?: number
  43. // Smooth scrolling enabled.
  44. scrollSmooth?: boolean
  45. // Smooth scroll duration.
  46. scrollSmoothDuration?: number
  47. // Smooth scroll offset.
  48. scrollSmoothOffset?: number
  49. // Callback for scroll end.
  50. scrollEndCallback?(e: WheelEvent): void
  51. // Headings offset between the headings and the top of the document (this is meant for minor adjustments).
  52. headingsOffset?: number
  53. // Timeout between events firing to make sure it's
  54. // not too rapid (for performance reasons).
  55. throttleTimeout?: number
  56. // Element to add the positionFixedClass to.
  57. positionFixedSelector?: string | null
  58. // Fixed position class to add to make sidebar fixed after scrolling
  59. // down past the fixedSidebarOffset.
  60. positionFixedClass?: string
  61. // fixedSidebarOffset can be any number but by default is set
  62. // to auto which sets the fixedSidebarOffset to the sidebar
  63. // element's offsetTop from the top of the document on init.
  64. fixedSidebarOffset?: 'auto' | number
  65. // includeHtml can be set to true to include the HTML markup from the
  66. // heading node instead of just including the innerText.
  67. includeHtml?: boolean
  68. // includeTitleTags automatically sets the html title tag of the link
  69. // to match the title. This can be useful for SEO purposes or
  70. // when truncating titles.
  71. includeTitleTags?: boolean
  72. // onclick function to apply to all links in toc. will be called with
  73. // the event as the first parameter; and this can be used to stop // propagation; prevent default or perform action
  74. onClick?: (e: MouseEvent) => void
  75. // orderedList can be set to false to generate unordered lists (ul)
  76. // instead of ordered lists (ol)
  77. orderedList?: boolean
  78. // If there is a fixed article scroll container; set to calculate titles' offset
  79. scrollContainer?: string | null
  80. // prevent ToC DOM rendering if it's already rendered by an external system
  81. skipRendering?: boolean
  82. // Optional callback to change heading labels.
  83. // For example it can be used to cut down and put ellipses on multiline headings you deem too long.
  84. // Called each time a heading is parsed. Expects a string in return, the modified label to display.
  85. headingLabelCallback?: (headingLabel: string) => string
  86. // ignore headings that are hidden in DOM
  87. ignoreHiddenElements?: boolean
  88. // Optional callback to modify properties of parsed headings.
  89. // The heading element is passed in node parameter and information parsed by default parser is provided in obj parameter.
  90. // Function has to return the same or modified obj.
  91. // The heading will be excluded from TOC if nothing is returned.
  92. headingObjectCallback?: (obj: object, node: HTMLElement) => object | void
  93. // Set the base path, useful if you use a `base` tag in `head`.
  94. basePath?: string
  95. // Only takes affect when `tocSelector` is scrolling,
  96. // keep the toc scroll position in sync with the content.
  97. disableTocScrollSync?: boolean
  98. // Offset for the toc scroll (top) position when scrolling the page.
  99. // Only effective if `disableTocScrollSync` is false.
  100. tocScrollOffset?: number
  101. }
  102. /**
  103. * Initialize tocbot with an options object.
  104. * @see https://github.com/tscanlin/tocbot#init
  105. */
  106. function init(options?: IStaticOptions): void
  107. /**
  108. * Destroy tocbot and remove event listeners.
  109. * @see https://github.com/tscanlin/tocbot#destroy
  110. */
  111. function destroy(): void
  112. /**
  113. * Refresh tocbot if the document changes and it needs to be rebuilt.
  114. * @see https://github.com/tscanlin/tocbot#refresh
  115. */
  116. function refresh(options?: IStaticOptions): void
  117. }