Comparing version 4.5.0 to 4.5.1
@@ -1,2 +0,2 @@ | ||
var g=(e,t)=>!e||!t?!1:t.contains(e),u=e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"),i=e=>document.createElement(e);var L=new Set,E=e=>e.replaceAll(/\s+/g,"_"),A=e=>encodeURIComponent(e).replaceAll(/%+/g,"."),T=(e,t="")=>{let n=t,o=1;for(;o<=e.length;){let r=o===1?n:`${n}_${o}`;if(!L.has(r)){n=r,L.add(n);break}o++;}return n},M=(e,t)=>{let n=E(e);return n=n.replaceAll(/&+/g,"").replaceAll(/&+/g,""),t&&(n=A(n)),n};var H="data-mokuji-anchor",N={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkPosition:"before",anchorLinkClassName:"",anchorContainerTagName:"ol"},k=e=>{let t=new Map;for(let n=0;n<e.length;n++){let o=e[n].hash.replace("#","");t.set(o,e[n]);}return t},x=(e,t,n)=>{let o=i("a");o.setAttribute(H,""),n.anchorLinkClassName&&o.classList.add(n.anchorLinkClassName);for(let r=0;r<e.length;r++){let s=e[r],c=t.get(encodeURIComponent(s.id));if(!c)continue;let a=o.cloneNode(!1);a.setAttribute("href",c.hash),n.anchorLinkSymbol&&(a.textContent=n.anchorLinkSymbol),n.anchorLinkPosition==="before"?s.insertBefore(a,s.firstChild):s.append(a);}},b=(e,t)=>{let n=new Map,o=new Map;for(let r of t){let s=r.hash.slice(1),c=o.get(s)||[];c.push(r),o.set(s,c);}for(let r of e){let s=r.id,c=n.get(s)||0;if(c>0){let a=`${s}-${c}`;r.id=a;let l=o.get(s)||[];for(let m of l)m.href=`#${a}`;}n.set(s,c+1);}},y=(e,t,n)=>{let o=0,r=i("li"),s=i("a");for(let c=0;c<e.length;c++){let a=e[c],l=Number(a.tagName[1]);if(o!==0&&o<l){let h=i("ol");t.lastChild.append(h),t=h;}else if(o!==0&&o>l)for(let h=0;h<o-l;h++)g(t,t.parentNode)&&(t=t.parentNode?.parentNode);let m=T(e,a.textContent||""),p=M(m,n);a.id=p;let d=s.cloneNode(!1);d.href=`#${p}`,d.textContent=a.textContent;let f=r.cloneNode(!1);f.append(d),t.append(f),o=l;}},j=(e,t)=>{if(!e)return;let n={...N,...t},o=[...u(e)];if(o.length===0)return;let r=i(n.anchorContainerTagName);y(o,r,n.anchorType);let s=[...r.querySelectorAll("a")];if(s.length!==0){if(b(o,s),n.anchorLink){let c=k(s);x(o,c,n);}return r}},U=()=>{let e=document.querySelectorAll(`[${H}]`);for(let t=e.length-1;t>=0;t--)e[t].remove();}; | ||
var g=(e,t)=>!e||!t?!1:t.contains(e),u=e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"),i=e=>document.createElement(e);var L=new Set,A=e=>e.replaceAll(/\s+/g,"_").replaceAll(":",""),E=e=>encodeURIComponent(e).replaceAll(/%+/g,"."),T=(e,t="")=>{let n=t,o=1;for(;o<=e.length;){let r=o===1?n:`${n}_${o}`;if(!L.has(r)){n=r,L.add(n);break}o++;}return n},M=(e,t)=>{let n=A(e);return n=n.replaceAll(/&+/g,"").replaceAll(/&+/g,""),t&&(n=E(n)),n};var H="data-mokuji-anchor",N={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkPosition:"before",anchorLinkClassName:"",anchorContainerTagName:"ol"},k=e=>{let t=new Map;for(let n=0;n<e.length;n++){let o=e[n].hash.replace("#","");t.set(o,e[n]);}return t},x=(e,t,n)=>{let o=i("a");o.setAttribute(H,""),n.anchorLinkClassName&&o.classList.add(n.anchorLinkClassName);for(let r=0;r<e.length;r++){let c=e[r],s=t.get(encodeURIComponent(c.id));if(!s)continue;let a=o.cloneNode(!1);a.setAttribute("href",s.hash),n.anchorLinkSymbol&&(a.textContent=n.anchorLinkSymbol),n.anchorLinkPosition==="before"?c.insertBefore(a,c.firstChild):c.append(a);}},b=(e,t)=>{let n=new Map,o=new Map;for(let r of t){let c=r.hash.slice(1),s=o.get(c)||[];s.push(r),o.set(c,s);}for(let r of e){let c=r.id,s=n.get(c)||0;if(s>0){let a=`${c}-${s}`;r.id=a;let l=o.get(c)||[];for(let m of l)m.href=`#${a}`;}n.set(c,s+1);}},y=(e,t,n)=>{let o=0,r=i("li"),c=i("a");for(let s=0;s<e.length;s++){let a=e[s],l=Number(a.tagName[1]);if(o!==0&&o<l){let h=i("ol");t.lastChild.append(h),t=h;}else if(o!==0&&o>l)for(let h=0;h<o-l;h++)g(t,t.parentNode)&&(t=t.parentNode?.parentNode);let m=T(e,a.textContent||""),p=M(m,n);a.id=p;let d=c.cloneNode(!1);d.href=`#${p}`,d.textContent=a.textContent;let f=r.cloneNode(!1);f.append(d),t.append(f),o=l;}},j=(e,t)=>{if(!e)return;let n={...N,...t},o=[...u(e)];if(o.length===0)return;let r=i(n.anchorContainerTagName);y(o,r,n.anchorType);let c=[...r.querySelectorAll("a")];if(c.length!==0){if(b(o,c),n.anchorLink){let s=k(c);x(o,s,n);}return r}},U=()=>{let e=document.querySelectorAll(`[${H}]`);for(let t=e.length-1;t>=0;t--)e[t].remove();}; | ||
@@ -3,0 +3,0 @@ export { U as Destroy, j as Mokuji }; |
{ | ||
"name": "mokuji.js", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "A table of content JavaScript Library", | ||
@@ -26,3 +26,3 @@ "scripts": { | ||
"package.json", | ||
"READNME.md" | ||
"README.md" | ||
], | ||
@@ -29,0 +29,0 @@ "lint-staged": { |
@@ -61,3 +61,3 @@ mokuji.js | ||
(default: `'before`) | ||
(default: `'before'`) | ||
@@ -64,0 +64,0 @@ set position (before/after) the anchor link in headings. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37792