@valaxyjs/utils 0.22.12 → 0.22.14

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},y=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!g.call(n,r)&&r!==t&&u(n,r,{get:()=>e[r],enumerable:!(o=f(e,r))||o.enumerable});return n};var v=n=>y(u({},"__esModule",{value:!0}),n);var M={};b(M,{addToParent:()=>H,buildTree:()=>d,getHeaders:()=>x,resolveHeaders:()=>c,resolvedHeaders:()=>m,serializeHeader:()=>h});module.exports=v(M);var m=[];function d(n,e,t){m.length=0;let o=[],r=[];return n.forEach(l=>{let s={...l,children:[]},i=r[r.length-1];for(;i&&i.level>=s.level;)r.pop(),i=r[r.length-1];if(s.element.classList.contains("ignore-header")||i&&"shouldIgnore"in i){r.push({level:s.level,shouldIgnore:!0});return}s.level>t||s.level<e||(m.push({element:s.element,link:s.link}),i?i.children.push(s):o.push(s),r.push(s))}),o}function H(n,e,t){if(n===0)return!0;let o=e[n];for(let r=n-1;r>=0;r--){let l=e[r];if(l.level<o.level&&l.level>=t[0]&&l.level<=t[1])return l.children==null&&(l.children=[]),l.children.push(o),!1}return!0}function c(n,e=[2,4]){let t=(typeof e=="object"&&!Array.isArray(e)?e.level:e)||2,[o,r]=typeof t=="number"?[t,t]:t==="deep"?[2,6]:t;return d(n,o,r)}function h(n){let e="";for(let t of Array.from(n.childNodes))if(t.nodeType===1){if(t.classList.contains("VABadge")||t.classList.contains("header-anchor"))continue;e+=t.textContent}else t.nodeType===3&&(e+=t.textContent);return e.trim()}function x(n={range:[2,4],selector:".markdown-body"}){let e=n.selector||".markdown-body",t=document.querySelectorAll(e),o=t[t.length-1],r=Array.from(o.querySelectorAll(`${e} :where(h1,h2,h3,h4,h5,h6)`)).filter(l=>n.filter?n.filter(l):!0).map(l=>{let s=Number(l.tagName[1]);return{element:l,title:h(l),link:`#${l.id}`,level:s,lang:l.lang}});return c(r,n.range)}0&&(module.exports={addToParent,buildTree,getHeaders,resolveHeaders,resolvedHeaders,serializeHeader});
1
+ "use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},y=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!g.call(n,r)&&r!==t&&u(n,r,{get:()=>e[r],enumerable:!(o=f(e,r))||o.enumerable});return n};var v=n=>y(u({},"__esModule",{value:!0}),n);var M={};b(M,{addToParent:()=>H,buildTree:()=>d,getHeaders:()=>x,resolveHeaders:()=>c,resolvedHeaders:()=>m,serializeHeader:()=>h});module.exports=v(M);var m=[];function d(n,e,t){m.length=0;let o=[],r=[];return n.forEach(l=>{let s={...l,children:[]},i=r[r.length-1];for(;i&&i.level>=s.level;)r.pop(),i=r[r.length-1];if(s.element.classList.contains("ignore-header")||i&&"shouldIgnore"in i){r.push({level:s.level,shouldIgnore:!0});return}s.level>t||s.level<e||(m.push({element:s.element,link:s.link}),i?i.children.push(s):o.push(s),r.push(s))}),o}function H(n,e,t){if(n===0)return!0;let o=e[n];for(let r=n-1;r>=0;r--){let l=e[r];if(l.level<o.level&&l.level>=t[0]&&l.level<=t[1])return l.children==null&&(l.children=[]),l.children.push(o),!1}return!0}function c(n,e=[2,4]){let t=(typeof e=="object"&&!Array.isArray(e)?e.level:e)||2,[o,r]=typeof t=="number"?[t,t]:t==="deep"?[2,6]:t;return d(n,o,r)}function h(n){let e="";for(let t of Array.from(n.childNodes))if(t.nodeType===1){if(t.classList.contains("VABadge")||t.classList.contains("header-anchor"))continue;e+=t.textContent}else t.nodeType===3&&(e+=t.textContent);return e.trim()}function x(n={range:[2,4],selector:".markdown-body"}){let e=n.selector||".markdown-body",t=document.querySelectorAll(e),o=t[t.length-1],r=Array.from(o?.querySelectorAll(`${e} :where(h1,h2,h3,h4,h5,h6)`)||[]).filter(l=>n.filter?n.filter(l):!0).map(l=>{let s=Number(l.tagName[1]);return{element:l,title:h(l),link:`#${l.id}`,level:s,lang:l.lang}});return c(r,n.range)}0&&(module.exports={addToParent,buildTree,getHeaders,resolveHeaders,resolvedHeaders,serializeHeader});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var a=[];function d(l,t,e){a.length=0;let s=[],r=[];return l.forEach(n=>{let o={...n,children:[]},i=r[r.length-1];for(;i&&i.level>=o.level;)r.pop(),i=r[r.length-1];if(o.element.classList.contains("ignore-header")||i&&"shouldIgnore"in i){r.push({level:o.level,shouldIgnore:!0});return}o.level>e||o.level<t||(a.push({element:o.element,link:o.link}),i?i.children.push(o):s.push(o),r.push(o))}),s}function f(l,t,e){if(l===0)return!0;let s=t[l];for(let r=l-1;r>=0;r--){let n=t[r];if(n.level<s.level&&n.level>=e[0]&&n.level<=e[1])return n.children==null&&(n.children=[]),n.children.push(s),!1}return!0}function c(l,t=[2,4]){let e=(typeof t=="object"&&!Array.isArray(t)?t.level:t)||2,[s,r]=typeof e=="number"?[e,e]:e==="deep"?[2,6]:e;return d(l,s,r)}function h(l){let t="";for(let e of Array.from(l.childNodes))if(e.nodeType===1){if(e.classList.contains("VABadge")||e.classList.contains("header-anchor"))continue;t+=e.textContent}else e.nodeType===3&&(t+=e.textContent);return t.trim()}function p(l={range:[2,4],selector:".markdown-body"}){let t=l.selector||".markdown-body",e=document.querySelectorAll(t),s=e[e.length-1],r=Array.from(s.querySelectorAll(`${t} :where(h1,h2,h3,h4,h5,h6)`)).filter(n=>l.filter?l.filter(n):!0).map(n=>{let o=Number(n.tagName[1]);return{element:n,title:h(n),link:`#${n.id}`,level:o,lang:n.lang}});return c(r,l.range)}export{f as addToParent,d as buildTree,p as getHeaders,c as resolveHeaders,a as resolvedHeaders,h as serializeHeader};
1
+ var a=[];function d(l,t,e){a.length=0;let s=[],r=[];return l.forEach(n=>{let o={...n,children:[]},i=r[r.length-1];for(;i&&i.level>=o.level;)r.pop(),i=r[r.length-1];if(o.element.classList.contains("ignore-header")||i&&"shouldIgnore"in i){r.push({level:o.level,shouldIgnore:!0});return}o.level>e||o.level<t||(a.push({element:o.element,link:o.link}),i?i.children.push(o):s.push(o),r.push(o))}),s}function f(l,t,e){if(l===0)return!0;let s=t[l];for(let r=l-1;r>=0;r--){let n=t[r];if(n.level<s.level&&n.level>=e[0]&&n.level<=e[1])return n.children==null&&(n.children=[]),n.children.push(s),!1}return!0}function c(l,t=[2,4]){let e=(typeof t=="object"&&!Array.isArray(t)?t.level:t)||2,[s,r]=typeof e=="number"?[e,e]:e==="deep"?[2,6]:e;return d(l,s,r)}function h(l){let t="";for(let e of Array.from(l.childNodes))if(e.nodeType===1){if(e.classList.contains("VABadge")||e.classList.contains("header-anchor"))continue;t+=e.textContent}else e.nodeType===3&&(t+=e.textContent);return t.trim()}function p(l={range:[2,4],selector:".markdown-body"}){let t=l.selector||".markdown-body",e=document.querySelectorAll(t),s=e[e.length-1],r=Array.from(s?.querySelectorAll(`${t} :where(h1,h2,h3,h4,h5,h6)`)||[]).filter(n=>l.filter?l.filter(n):!0).map(n=>{let o=Number(n.tagName[1]);return{element:n,title:h(n),link:`#${n.id}`,level:o,lang:n.lang}});return c(r,l.range)}export{f as addToParent,d as buildTree,p as getHeaders,c as resolveHeaders,a as resolvedHeaders,h as serializeHeader};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@valaxyjs/utils",
3
3
  "type": "module",
4
- "version": "0.22.12",
4
+ "version": "0.22.14",
5
5
  "description": "A utility library for Valaxy",
6
6
  "author": {
7
7
  "name": "Valaxy",
@@ -128,7 +128,7 @@ export function getHeaders(options: GetHeadersOptions = {
128
128
  // the first is the old one, the last is the new one
129
129
  const markdownBodyElements = document.querySelectorAll(mdBodySelector) as NodeListOf<HTMLElement>
130
130
  const markdownBody = markdownBodyElements[markdownBodyElements.length - 1]
131
- const headers = Array.from(markdownBody.querySelectorAll(`${mdBodySelector} :where(h1,h2,h3,h4,h5,h6)`))
131
+ const headers = Array.from(markdownBody?.querySelectorAll(`${mdBodySelector} :where(h1,h2,h3,h4,h5,h6)`) || [])
132
132
  .filter(el => options.filter ? options.filter(el) : true)
133
133
  .map((el) => {
134
134
  const level = Number(el.tagName[1])