@readme/markdown 13.7.4 → 13.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -12070,13 +12070,91 @@ const Table = (props) => {
12070
12070
 
12071
12071
  ;// ./components/TableOfContents/index.tsx
12072
12072
 
12073
- function TableOfContents({ children, heading = 'Table of Contents' }) {
12074
- return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("nav", { "aria-label": "Table of contents", role: "navigation" },
12073
+ /**
12074
+ * Build link map and decode the hash to get the id and weird chars
12075
+ */
12076
+ function buildLinkMap(nav) {
12077
+ const map = new Map();
12078
+ Array.from(nav.querySelectorAll('a')).forEach(link => {
12079
+ const id = decodeURIComponent(link.hash.slice(1));
12080
+ if (!id)
12081
+ return;
12082
+ const list = map.get(id);
12083
+ if (list)
12084
+ list.push(link);
12085
+ else
12086
+ map.set(id, [link]);
12087
+ });
12088
+ return map;
12089
+ }
12090
+ /**
12091
+ * Watches headings in the viewport and toggles `active` on the
12092
+ * corresponding TOC links so the reader always knows where they are.
12093
+ */
12094
+ function useScrollHighlight(navRef) {
12095
+ const [linkCount, setLinkCount] = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useState)(0);
12096
+ (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useEffect)(() => {
12097
+ const nav = navRef.current;
12098
+ if (!nav)
12099
+ return;
12100
+ const count = nav.querySelectorAll('a[href^="#"]').length;
12101
+ setLinkCount(count);
12102
+ }, [navRef]);
12103
+ (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useEffect)(() => {
12104
+ const nav = navRef.current;
12105
+ if (!nav || typeof IntersectionObserver === 'undefined' || linkCount === 0)
12106
+ return undefined;
12107
+ const linkMap = buildLinkMap(nav);
12108
+ if (linkMap.size === 0)
12109
+ return undefined;
12110
+ const headings = [...linkMap.keys()]
12111
+ .map(id => document.getElementById(id))
12112
+ .filter((el) => el !== null);
12113
+ if (headings.length === 0)
12114
+ return undefined;
12115
+ let activeId = null;
12116
+ const visible = new Set();
12117
+ const activate = (id) => {
12118
+ if (id === activeId)
12119
+ return;
12120
+ if (activeId)
12121
+ linkMap.get(activeId)?.forEach(a => a.classList.remove('active'));
12122
+ activeId = id;
12123
+ // set active states + border pos/size
12124
+ if (id) {
12125
+ const links = linkMap.get(id);
12126
+ links?.forEach(a => a.classList.add('active'));
12127
+ const link = links?.[0];
12128
+ if (link) {
12129
+ const navRect = nav.getBoundingClientRect();
12130
+ const linkRect = link.getBoundingClientRect();
12131
+ nav.style.setProperty('--ToC-border-active-height', `${linkRect.height}px`);
12132
+ nav.style.setProperty('--ToC-border-active-top', `${linkRect.top - navRect.top}px`);
12133
+ }
12134
+ }
12135
+ };
12136
+ const observer = new IntersectionObserver(entries => {
12137
+ entries.forEach(e => {
12138
+ if (e.isIntersecting)
12139
+ visible.add(e.target.id);
12140
+ else
12141
+ visible.delete(e.target.id);
12142
+ });
12143
+ // Highlight the topmost visible heading; if none are visible,
12144
+ // keep the last active one so the user still has context.
12145
+ const topmost = headings.find(el => visible.has(el.id));
12146
+ if (topmost)
12147
+ activate(topmost.id);
12148
+ }, { rootMargin: '0px 0px -60% 0px', threshold: 0 });
12149
+ headings.forEach(el => { observer.observe(el); });
12150
+ return () => { observer.disconnect(); };
12151
+ }, [navRef, linkCount]);
12152
+ }
12153
+ function TableOfContents({ children }) {
12154
+ const navRef = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useRef)(null);
12155
+ useScrollHighlight(navRef);
12156
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("nav", { ref: navRef, "aria-label": "Table of contents", className: "rm-ToC" },
12075
12157
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("ul", { className: "toc-list" },
12076
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("li", null,
12077
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("a", { className: "tocHeader", href: "#" },
12078
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("i", { className: "icon icon-text-align-left" }),
12079
- heading)),
12080
12158
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("li", { className: "toc-children" }, children))));
12081
12159
  }
12082
12160
  /* harmony default export */ const components_TableOfContents = (TableOfContents);
@@ -100940,7 +101018,7 @@ function createTocComponent(tocHast) {
100940
101018
  components: { p: (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default()).Fragment },
100941
101019
  });
100942
101020
  const tocReactElement = tocProcessor.stringify(tocHast);
100943
- const TocComponent = (props) => tocReactElement ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, { heading: props.heading }, tocReactElement)) : null;
101021
+ const TocComponent = () => tocReactElement ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, null, tocReactElement)) : null;
100944
101022
  TocComponent.displayName = 'Toc';
100945
101023
  return TocComponent;
100946
101024
  }
@@ -101106,7 +101184,7 @@ const run_run = (string, _opts = {}) => {
101106
101184
  default: (props) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, copyButtons: copyButtons, terms: terms, theme: theme, variables: variables },
101107
101185
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Content, { ...props }))),
101108
101186
  toc,
101109
- Toc: (props) => Toc ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, { heading: props.heading },
101187
+ Toc: () => Toc ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, null,
101110
101188
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Toc, null))) : null,
101111
101189
  stylesheet,
101112
101190
  ...exports,
package/dist/main.node.js CHANGED
@@ -24666,13 +24666,91 @@ const Table = (props) => {
24666
24666
 
24667
24667
  ;// ./components/TableOfContents/index.tsx
24668
24668
 
24669
- function TableOfContents({ children, heading = 'Table of Contents' }) {
24670
- return (external_react_default().createElement("nav", { "aria-label": "Table of contents", role: "navigation" },
24669
+ /**
24670
+ * Build link map and decode the hash to get the id and weird chars
24671
+ */
24672
+ function buildLinkMap(nav) {
24673
+ const map = new Map();
24674
+ Array.from(nav.querySelectorAll('a')).forEach(link => {
24675
+ const id = decodeURIComponent(link.hash.slice(1));
24676
+ if (!id)
24677
+ return;
24678
+ const list = map.get(id);
24679
+ if (list)
24680
+ list.push(link);
24681
+ else
24682
+ map.set(id, [link]);
24683
+ });
24684
+ return map;
24685
+ }
24686
+ /**
24687
+ * Watches headings in the viewport and toggles `active` on the
24688
+ * corresponding TOC links so the reader always knows where they are.
24689
+ */
24690
+ function useScrollHighlight(navRef) {
24691
+ const [linkCount, setLinkCount] = (0,external_react_.useState)(0);
24692
+ (0,external_react_.useEffect)(() => {
24693
+ const nav = navRef.current;
24694
+ if (!nav)
24695
+ return;
24696
+ const count = nav.querySelectorAll('a[href^="#"]').length;
24697
+ setLinkCount(count);
24698
+ }, [navRef]);
24699
+ (0,external_react_.useEffect)(() => {
24700
+ const nav = navRef.current;
24701
+ if (!nav || typeof IntersectionObserver === 'undefined' || linkCount === 0)
24702
+ return undefined;
24703
+ const linkMap = buildLinkMap(nav);
24704
+ if (linkMap.size === 0)
24705
+ return undefined;
24706
+ const headings = [...linkMap.keys()]
24707
+ .map(id => document.getElementById(id))
24708
+ .filter((el) => el !== null);
24709
+ if (headings.length === 0)
24710
+ return undefined;
24711
+ let activeId = null;
24712
+ const visible = new Set();
24713
+ const activate = (id) => {
24714
+ if (id === activeId)
24715
+ return;
24716
+ if (activeId)
24717
+ linkMap.get(activeId)?.forEach(a => a.classList.remove('active'));
24718
+ activeId = id;
24719
+ // set active states + border pos/size
24720
+ if (id) {
24721
+ const links = linkMap.get(id);
24722
+ links?.forEach(a => a.classList.add('active'));
24723
+ const link = links?.[0];
24724
+ if (link) {
24725
+ const navRect = nav.getBoundingClientRect();
24726
+ const linkRect = link.getBoundingClientRect();
24727
+ nav.style.setProperty('--ToC-border-active-height', `${linkRect.height}px`);
24728
+ nav.style.setProperty('--ToC-border-active-top', `${linkRect.top - navRect.top}px`);
24729
+ }
24730
+ }
24731
+ };
24732
+ const observer = new IntersectionObserver(entries => {
24733
+ entries.forEach(e => {
24734
+ if (e.isIntersecting)
24735
+ visible.add(e.target.id);
24736
+ else
24737
+ visible.delete(e.target.id);
24738
+ });
24739
+ // Highlight the topmost visible heading; if none are visible,
24740
+ // keep the last active one so the user still has context.
24741
+ const topmost = headings.find(el => visible.has(el.id));
24742
+ if (topmost)
24743
+ activate(topmost.id);
24744
+ }, { rootMargin: '0px 0px -60% 0px', threshold: 0 });
24745
+ headings.forEach(el => { observer.observe(el); });
24746
+ return () => { observer.disconnect(); };
24747
+ }, [navRef, linkCount]);
24748
+ }
24749
+ function TableOfContents({ children }) {
24750
+ const navRef = (0,external_react_.useRef)(null);
24751
+ useScrollHighlight(navRef);
24752
+ return (external_react_default().createElement("nav", { ref: navRef, "aria-label": "Table of contents", className: "rm-ToC" },
24671
24753
  external_react_default().createElement("ul", { className: "toc-list" },
24672
- external_react_default().createElement("li", null,
24673
- external_react_default().createElement("a", { className: "tocHeader", href: "#" },
24674
- external_react_default().createElement("i", { className: "icon icon-text-align-left" }),
24675
- heading)),
24676
24754
  external_react_default().createElement("li", { className: "toc-children" }, children))));
24677
24755
  }
24678
24756
  /* harmony default export */ const components_TableOfContents = (TableOfContents);
@@ -121134,7 +121212,7 @@ function createTocComponent(tocHast) {
121134
121212
  components: { p: (external_react_default()).Fragment },
121135
121213
  });
121136
121214
  const tocReactElement = tocProcessor.stringify(tocHast);
121137
- const TocComponent = (props) => tocReactElement ? (external_react_default().createElement(components_TableOfContents, { heading: props.heading }, tocReactElement)) : null;
121215
+ const TocComponent = () => tocReactElement ? (external_react_default().createElement(components_TableOfContents, null, tocReactElement)) : null;
121138
121216
  TocComponent.displayName = 'Toc';
121139
121217
  return TocComponent;
121140
121218
  }
@@ -121300,7 +121378,7 @@ const run_run = (string, _opts = {}) => {
121300
121378
  default: (props) => (external_react_default().createElement(contexts, { baseUrl: baseUrl, copyButtons: copyButtons, terms: terms, theme: theme, variables: variables },
121301
121379
  external_react_default().createElement(Content, { ...props }))),
121302
121380
  toc,
121303
- Toc: (props) => Toc ? (external_react_default().createElement(components_TableOfContents, { heading: props.heading },
121381
+ Toc: () => Toc ? (external_react_default().createElement(components_TableOfContents, null,
121304
121382
  external_react_default().createElement(Toc, null))) : null,
121305
121383
  stylesheet,
121306
121384
  ...exports,