@cryptlex/web-components 6.6.6-alpha16 → 6.6.6-alpha17
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as
|
|
1
|
+
"use client";import{jsxs as m,jsx as a}from"react/jsx-runtime";import{useMemo as p,useRef as u,useEffect as d,useState as h}from"react";import{classNames as g}from"../utilities/theme.js";import"clsx";function v(r){const[c,i]=h("");return d(()=>{const s=new IntersectionObserver(o=>{const t=o.filter(n=>n.isIntersecting);if(t.length===0)return;const e=t.map(n=>n.target.id)[0];i(e)});for(const o of r??[]){const t=document.getElementById(o);t&&s.observe(t)}return()=>{for(const o of r??[]){const t=document.getElementById(o);t&&s.unobserve(t)}}},[r]),c}function y({toc:r,className:c}){const i=p(()=>r.map(e=>e.url.replace("#","")),[r]),s=v(i),o=u({}),t=u(null);return d(()=>{if(s){const e=o.current[`#${s}`],n=t.current;if(e&&n){const l=e.offsetTop,f=n.clientHeight;n.scrollTo({top:l-f/2,behavior:"smooth"})}}},[s]),r.length?m("nav",{ref:t,className:g(c),children:[a("p",{className:"text-muted opacity-70 mb-1 body-sm select-none",children:"On This Page"}),a("div",{className:"flex flex-col gap-1",children:r.map(e=>{const n=e.url.replace(/^#/,"");return a("a",{href:e.url,ref:l=>{o.current[e.url]=l},className:"text-muted-foreground hover:text-foreground data-[active=true]:text-foreground body-sm no-underline transition-colors data-[depth=3]:pl-4 data-[depth=4]:pl-6","data-active":s===n,"data-depth":e.depth,children:e.title},e.url)})})]}):null}export{y as TableOfContents};
|
|
2
2
|
//# sourceMappingURL=table-of-contents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-of-contents.js","sources":["../../lib/components/table-of-contents.tsx"],"sourcesContent":["'use client';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { classNames } from '../utilities/theme';\n\nfunction useActiveItem(itemIds: string[]) {\n const [
|
|
1
|
+
{"version":3,"file":"table-of-contents.js","sources":["../../lib/components/table-of-contents.tsx"],"sourcesContent":["'use client';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { classNames } from '../utilities/theme';\n\nfunction useActiveItem(itemIds: string[]) {\n const [activeId, setActiveId] = useState<string>('');\n\n useEffect(() => {\n const observer = new IntersectionObserver(entries => {\n const intersectingEntries = entries.filter(entry => entry.isIntersecting);\n\n // Last-active entry remains highlighted\n if (intersectingEntries.length === 0) {\n return;\n }\n\n const topIntersectingId = intersectingEntries.map(e => e.target.id)[0];\n setActiveId(topIntersectingId);\n });\n\n for (const id of itemIds ?? []) {\n const element = document.getElementById(id);\n if (element) {\n observer.observe(element);\n }\n }\n\n return () => {\n for (const id of itemIds ?? []) {\n const element = document.getElementById(id);\n if (element) {\n observer.unobserve(element);\n }\n }\n };\n }, [itemIds]);\n\n return activeId;\n}\n\nexport type TableOfContentsHeading = {\n title?: React.ReactNode;\n url: string;\n depth: number;\n};\n\nexport function TableOfContents({ toc, className }: { toc: TableOfContentsHeading[]; className?: string }) {\n const itemIds = useMemo(() => toc.map(item => item.url.replace('#', '')), [toc]);\n const activeId = useActiveItem(itemIds);\n const linkRefs = useRef<Record<string, HTMLAnchorElement | null>>({});\n const containerRef = useRef<HTMLDivElement | null>(null);\n\n // Scroll to first active item\n useEffect(() => {\n if (activeId) {\n const activeEl = linkRefs.current[`#${activeId}`];\n const containerEl = containerRef.current;\n\n if (activeEl && containerEl) {\n const linkTop = activeEl.offsetTop;\n const containerHeight = containerEl.clientHeight;\n containerEl.scrollTo({\n top: linkTop - containerHeight / 2,\n behavior: 'smooth',\n });\n }\n }\n }, [activeId]);\n\n if (!toc.length) {\n return null;\n }\n\n return (\n <nav ref={containerRef} className={classNames(className)}>\n <p className=\"text-muted opacity-70 mb-1 body-sm select-none\">On This Page</p>\n <div className=\"flex flex-col gap-1\">\n {toc.map(item => {\n const id = item.url.replace(/^#/, '');\n\n return (\n // It is okay to use plain <a hrefs> here because the links all point to IDs on the same page and does not impact any routers.\n <a\n key={item.url}\n href={item.url}\n ref={el => {\n linkRefs.current[item.url] = el;\n }}\n className=\"text-muted-foreground hover:text-foreground data-[active=true]:text-foreground body-sm no-underline transition-colors data-[depth=3]:pl-4 data-[depth=4]:pl-6\"\n data-active={activeId === id}\n data-depth={item.depth}\n >\n {item.title}\n </a>\n );\n })}\n </div>\n </nav>\n );\n}\n"],"names":["useActiveItem","itemIds","activeId","setActiveId","useState","useEffect","observer","entries","intersectingEntries","entry","topIntersectingId","e","id","element","TableOfContents","toc","className","useMemo","item","linkRefs","useRef","containerRef","activeEl","containerEl","linkTop","containerHeight","classNames","jsx","el"],"mappings":"wMAIA,SAASA,EAAcC,EAAmB,CACtC,KAAM,CAACC,EAAUC,CAAW,EAAIC,EAAiB,EAAE,EAEnD,OAAAC,EAAU,IAAM,CACZ,MAAMC,EAAW,IAAI,qBAAqBC,GAAW,CACjD,MAAMC,EAAsBD,EAAQ,OAAOE,GAASA,EAAM,cAAc,EAGxE,GAAID,EAAoB,SAAW,EAC/B,OAGJ,MAAME,EAAoBF,EAAoB,IAAIG,GAAKA,EAAE,OAAO,EAAE,EAAE,CAAC,EACrER,EAAYO,CAAiB,CACjC,CAAC,EAED,UAAWE,KAAMX,GAAW,GAAI,CAC5B,MAAMY,EAAU,SAAS,eAAeD,CAAE,EACtCC,GACAP,EAAS,QAAQO,CAAO,CAEhC,CAEA,MAAO,IAAM,CACT,UAAWD,KAAMX,GAAW,GAAI,CAC5B,MAAMY,EAAU,SAAS,eAAeD,CAAE,EACtCC,GACAP,EAAS,UAAUO,CAAO,CAElC,CACJ,CACJ,EAAG,CAACZ,CAAO,CAAC,EAELC,CACX,CAQO,SAASY,EAAgB,CAAE,IAAAC,EAAK,UAAAC,GAAoE,CACvG,MAAMf,EAAUgB,EAAQ,IAAMF,EAAI,IAAIG,GAAQA,EAAK,IAAI,QAAQ,IAAK,EAAE,CAAC,EAAG,CAACH,CAAG,CAAC,EACzEb,EAA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