mark-deco 0.7.0 → 0.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.
Files changed (48) hide show
  1. package/dist/cache/filesystem.d.ts +2 -2
  2. package/dist/cache/index.d.ts +2 -2
  3. package/dist/cache/localstorage.d.ts +2 -2
  4. package/dist/cache/memory.d.ts +2 -2
  5. package/dist/fetcher.d.ts +2 -2
  6. package/dist/frontmatter.d.ts +2 -2
  7. package/dist/index.cjs +11 -11
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +534 -531
  11. package/dist/index.js.map +1 -1
  12. package/dist/internal-B7OqH3Vn.cjs +2 -2
  13. package/dist/internal-BLcZHfk2.js +2 -2
  14. package/dist/internal.cjs +2 -2
  15. package/dist/internal.d.ts +2 -2
  16. package/dist/internal.js +2 -2
  17. package/dist/logger.d.ts +2 -2
  18. package/dist/plugins/card/amazon-rules.d.ts +2 -2
  19. package/dist/plugins/card/fetcher.d.ts +2 -2
  20. package/dist/plugins/card/html-generator.d.ts +2 -2
  21. package/dist/plugins/card/index.d.ts +2 -2
  22. package/dist/plugins/card/ogp-rules.d.ts +2 -2
  23. package/dist/plugins/card/rule-engine.d.ts +2 -2
  24. package/dist/plugins/card/types.d.ts +2 -2
  25. package/dist/plugins/card/utils.d.ts +2 -2
  26. package/dist/plugins/card-plugin.d.ts +2 -2
  27. package/dist/plugins/mermaid/index.d.ts +2 -2
  28. package/dist/plugins/mermaid/types.d.ts +2 -2
  29. package/dist/plugins/mermaid-plugin.d.ts +2 -2
  30. package/dist/plugins/oembed/fetcher.d.ts +2 -2
  31. package/dist/plugins/oembed/html-generator.d.ts +2 -2
  32. package/dist/plugins/oembed/index.d.ts +2 -2
  33. package/dist/plugins/oembed/providers.d.ts +2 -2
  34. package/dist/plugins/oembed/providers.json.d.ts +2 -2
  35. package/dist/plugins/oembed/redirect-resolver.d.ts +2 -2
  36. package/dist/plugins/oembed/types.d.ts +2 -2
  37. package/dist/plugins/oembed/utils.d.ts +2 -2
  38. package/dist/plugins/oembed-plugin.d.ts +2 -2
  39. package/dist/plugins/remark-attr.d.ts +2 -2
  40. package/dist/plugins/responsive-images.d.ts +2 -2
  41. package/dist/plugins/shared/error-formatter.d.ts +2 -2
  42. package/dist/processor.d.ts +2 -2
  43. package/dist/processor.d.ts.map +1 -1
  44. package/dist/types.d.ts +19 -7
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/utils/responsive-image.d.ts +2 -2
  47. package/dist/utils.d.ts +2 -2
  48. package/package.json +6 -6
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  /**
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './index.js';
package/dist/fetcher.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './cache/index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
10
 
11
11
  import { FrontmatterData } from './types.js';
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.7.0
3
+ * version: 0.8.0
4
4
  * description: Flexible Markdown to HTML conversion library
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/mark-deco.git
8
- * git.commit.hash: 2b8fc59fb30d614d1c529a3d2c9ec721a49c9115
8
+ * git.commit.hash: cc985acbf6dd451ba9668a6c148f9e041c1032c5
9
9
  */
10
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("js-beautify"),et=require("rehype-stringify"),rt=require("remark-gfm"),nt=require("remark-parse"),at=require("remark-rehype"),st=require("unified"),A=require("unist-util-visit"),M=require("js-yaml"),k=require("./internal-B7OqH3Vn.cjs");function ot(e){const t=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,r=e.match(t);if(!r)return{data:{},content:e};const s=r[1]||"",n=e.slice(r[0].length);try{const a=M.load(s,{schema:M.JSON_SCHEMA});return{data:a&&typeof a=="object"&&!Array.isArray(a)?a:{},content:n}}catch(a){const h=a instanceof Error?a.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${h}`)}}function ct(e){if(!e||Object.keys(e).length===0)return"";const t=M.dump(e,{lineWidth:0});return typeof t!="string"||t.length===0?"":t.endsWith(`
10
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("js-beautify"),et=require("rehype-stringify"),rt=require("remark-gfm"),nt=require("remark-parse"),at=require("remark-rehype"),st=require("unified"),q=require("unist-util-visit"),M=require("js-yaml"),v=require("./internal-B7OqH3Vn.cjs");function B(e){const t=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,n=e.match(t);if(!n)return{data:{},content:e};const o=n[1]||"",r=e.slice(n[0].length);try{const a=M.load(o,{schema:M.JSON_SCHEMA});return{data:a&&typeof a=="object"&&!Array.isArray(a)?a:{},content:r}}catch(a){const h=a instanceof Error?a.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${h}`)}}function ot(e){if(!e||Object.keys(e).length===0)return"";const t=M.dump(e,{lineWidth:0});return typeof t!="string"||t.length===0?"":t.endsWith(`
11
11
  `)?t:`${t}
12
- `}function it(e,t){const r=t??"";return`${`---
13
- ${ct(e)}---
14
- `}${r}`}const T=()=>{},lt={debug:T,info:T,warn:T,error:T},ht={debug:console.debug,info:console.info,warn:console.warn,error:console.error},V=()=>lt,ut=()=>ht,x=e=>{const t={},r=e.slice(1,-1).trim(),s=r.match(/\.([a-zA-Z0-9_-]+)/g);if(s){const h=s.map(p=>p.slice(1));t.class=h.join(" ")}const n=r.match(/#([a-zA-Z0-9_-]+)/);n&&n[1]&&(t.id=n[1]);const a=r.match(/([a-zA-Z0-9_-]+)=["']?([^"'\s]*)["']?/g);if(a)for(const h of a){const[p,d]=h.split("=");p&&d&&p!=="class"&&p!=="id"&&(t[p]=d.replace(/["']/g,""))}return t},ft=e=>{const t=e.lang?` class="language-${e.lang}"`:"",r=e.value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return`<pre><code${t}>${r}</code></pre>`},H=(e,t)=>{e.data||(e.data={}),e.data.hProperties||(e.data.hProperties={}),Object.entries(t).forEach(([r,s])=>{if(r==="class"){const n=e.data.hProperties.class;n?typeof n=="string"&&n.startsWith("language-")?e.data.hProperties.class=`${n} ${s}`:e.data.hProperties.class=`${n} ${s}`:e.data.hProperties.class=s}else e.data.hProperties[r]=s})},dt=()=>e=>{A.visit(e,(t,r,s)=>{if(t.type==="heading"&&t.children?.length>0){const n=t.children[t.children.length-1];if(n?.type==="text"&&n.value){const a=n.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(a){const h=a[1].trim(),p=a[2],d=x(p);n.value=h,H(t,d)}}}if(t.type==="paragraph"&&t.children?.length>0){const n=t.children[t.children.length-1];if(n?.type==="text"&&n.value){const a=n.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(a){const h=a[1].trim(),p=a[2],d=x(p);n.value=h,H(t,d)}}}if(t.type==="link"&&s&&typeof r=="number"){const n=s.children[r+1];if(n?.type==="text"&&n.value){const a=n.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],p=x(h);H(t,p),n.value=n.value.replace(a[0],"")}}}if(t.type==="image"&&s&&typeof r=="number"){const n=s.children[r+1];if(n?.type==="text"&&n.value){const a=n.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],p=x(h);H(t,p),n.value=n.value.replace(a[0],"")}}}if(t.type==="listItem"&&t.children?.length>0){const n=t.children[t.children.length-1];if(n?.type==="paragraph"&&n.children?.length>0){const a=n.children[n.children.length-1];if(a?.type==="text"&&a.value){const h=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(h){const p=h[1].trim(),d=h[2],o=x(d);a.value=p,H(t,o)}}}}if(t.type==="list"&&s&&typeof r=="number"){const n=s.children[r+1];if(n?.type==="paragraph"&&n.children?.length===1){const a=n.children[0];if(a?.type==="text"&&a.value){const h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const p=h[1],d=x(p);H(t,d),s.children.splice(r+1,1)}}}}if(t.type==="blockquote"&&t.children?.length>0){const n=t.children[t.children.length-1];if(n?.type==="paragraph"&&n.children?.length>0){const a=n.children[n.children.length-1];if(a?.type==="text"&&a.value){const h=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(h){const p=h[1].trim(),d=h[2],o=x(d);a.value=p,H(t,o)}}}}if(t.type==="blockquote"&&s&&typeof r=="number"){const n=s.children[r+1];if(n?.type==="paragraph"&&n.children?.length===1){const a=n.children[0];if(a?.type==="text"&&a.value){const h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const p=h[1],d=x(p);H(t,d),s.children.splice(r+1,1)}}}}if(t.type==="inlineCode"&&s&&typeof r=="number"){const n=s.children[r+1];if(n?.type==="text"&&n.value){const a=n.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],p=x(h);H(t,p),n.value=n.value.replace(a[0],"")}}}if(t.type==="code"&&t.meta){const n=t.meta.match(/\{([^}]+)\}/);if(n){const a=`{${n[1]}}`,h=x(a),p={type:"html",value:`<div class="${h.class||""}" ${Object.entries(h).filter(([d])=>d!=="class").map(([d,o])=>`${d}="${o}"`).join(" ")}>${ft(t)}</div>`};s&&typeof r=="number"&&(s.children[r]=p),t.meta=t.meta.replace(n[0],"").trim()||null}}})},pt=()=>e=>{A.visit(e,"element",t=>{if(t.tagName==="img"){const r=k.generateResponsiveImageStyles();t.properties||(t.properties={});const s=t.properties.style||"",n=s?`${s}; ${r}`:r;t.properties.style=n}})},{html:mt}=tt,Q={indent_size:2,indent_char:" ",max_preserve_newlines:2,preserve_newlines:!0,end_with_newline:!1,wrap_line_length:0,indent_inner_html:!0,indent_empty_lines:!1,unformatted:["code","pre","textarea"],content_unformatted:["pre","code","textarea"],extra_liners:[]},yt=e=>{const t=r=>{if(r instanceof Date)return new Date(r.getTime());if(Array.isArray(r))return r.map(t);if(r&&typeof r=="object"){const s={};for(const[n,a]of Object.entries(r))s[n]=t(a);return s}return r};return t(e??{})},U=e=>{if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(U);if(e&&typeof e=="object"){const t=Object.entries(e).filter(([,s])=>s!==void 0).sort(([s],[n])=>s<n?-1:s>n?1:0),r={};for(const[s,n]of t)r[s]=U(n);return r}return e},B=e=>JSON.stringify(U(e??{})),z=e=>e.type==="text"||e.type==="inlineCode"?e.value||"":e.children&&Array.isArray(e.children)?e.children.map(z).join(""):"",gt=(e,t)=>`${e}-${t.join("-")}`,wt=e=>{const t=[],r=[];for(const s of e){const n=s.level;for(;r.length>n;)r.pop();for(;r.length<n;)r.push(0);const a=n-1;r[a]=(r[a]||0)+1;const h=r.slice(0,n);t.push({level:s.level,text:s.text,numbers:h})}return t},K=(e,t,r)=>{const s=k.generateHeadingId(t);return s!==void 0?`${e}-${s}`:r()},vt=e=>{const t=[],r=[];for(const s of e){const n={level:s.level,text:s.text,id:s.id,children:[]};for(;r.length>0;){const a=r[r.length-1];if(a&&a.level>=s.level)r.pop();else break}if(r.length===0)t.push(n);else{const a=r[r.length-1];a&&a.children.push(n)}r.push(n)}return t},kt=e=>{const{plugins:t=[],logger:r=V(),fetcher:s}=e,n=new Map;for(const o of t){if(n.has(o.name))throw new Error(`Plugin with name '${o.name}' is already registered`);n.set(o.name,o)}const a=async(o,c,i)=>{const l=n.get(o);return l?await l.processBlock(c,i):`<pre><code class="language-${o}">${k.escapeHtml(c)}</code></pre>`},h=(o,c,i)=>{const l={logger:r,signal:c,frontmatter:o,getUniqueId:i,fetcher:s};return()=>async u=>{const f=[];A.visit(u,"code",(m,y,w)=>{if(!m.lang||!n.has(m.lang))return;const g=(async()=>{const v={type:"html",value:await a(m.lang,m.value,l)};w&&typeof y=="number"&&(w.children[y]=v)})();f.push(g)}),await Promise.all(f)}},p=(o,c,i=!1,l=!1,u="")=>()=>f=>{const m=[],y=[];A.visit(f,"heading",v=>{v.depth>=1&&v.depth<=6&&y.push(v)});let w=[];if(i){const v=y.map($=>({level:$.depth,text:z($)}));w=wt(v)}const g=[];y.forEach((v,$)=>{const F=z(v),O=v.data?.hProperties?.id;let S;if(O)S=O;else if(i&&l){const C=K(u,F,()=>c(F)).replace(`${u}-`,"");for(;g.length>0;){const L=g[g.length-1];if(L&&L.level>=v.depth)g.pop();else break}const I=g.map(L=>L.contentId);S=I.length>0?`${u}-${I.join("-")}-${C}`:`${u}-${C}`,g.push({level:v.depth,contentId:C})}else if(i&&$<w.length){const C=w[$];C?S=gt(u,C.numbers):S=c(F)}else S=c(F);v.data||(v.data={}),v.data.hProperties||(v.data.hProperties={}),O||(v.data.hProperties.id=S),m.push({level:v.depth,text:F,id:S})});const b=vt(m);o.push(...b)};return{process:async(o,c,{signal:i,useContentStringHeaderId:l=!1,useHierarchicalHeadingId:u=!0,advancedOptions:f,frontmatterTransform:m}={})=>{const{allowDangerousHtml:y=!0,htmlOptions:w=Q,gfmOptions:g={},remarkPlugins:b=[],rehypePlugins:v=[]}=f||{};try{const $=o,{data:F,content:O}=ot(o);let S=F;const C=B(F);let I=!1;if(m){const E={originalFrontmatter:yt(F),markdownContent:O},j=m(E);j!==void 0&&(S=j,I=B(j)!==C)}const R=[];let L=0;const D=()=>`${c}-${++L}`;let N=st.unified().use(nt);if(b)for(const E of b)Array.isArray(E)?N=N.use(E[0],E[1]):N=N.use(E);let P=N.use(rt,g).use(dt).use(p(R,l?E=>K(c,E,D):D,u,l,c)).use(h(S,i,D)).use(at,{allowDangerousHtml:y}).use(pt).use(et,{allowDangerousHtml:y});if(v)for(const E of v)Array.isArray(E)?P=P.use(E[0],E[1]):P=P.use(E);const Z=await P.process(O),X=String(Z);return{html:mt(X,w),frontmatter:S,changed:I,headingTree:R,composeMarkdown:()=>I?it(S,O):$}}catch($){throw r.error(`Failed to process markdown: ${$ instanceof Error?$.message:"Unknown error"}`),new Error(`Failed to process markdown: ${$ instanceof Error?$.message:"Unknown error"}`)}}}},Et=(e,t={})=>{const{maxRedirects:r=5,timeoutEachRedirect:s=1e4}=t;return{name:"oembed",processBlock:async(a,h)=>{const p=a.trim();if(!k.isValidUrl(p))throw new Error(`Invalid URL: ${p}`);try{const d=await k.fetchOEmbedData(p,r,s,h,e);return k.generateHtml(d,p,t)}catch(d){h.logger.warn("oEmbed fetch failed for URL:",p,d);const o=k.formatErrorInfo(d);return k.generateFallbackHtml(p,o)}}}},bt=(e={})=>({name:"card",processBlock:async(r,s)=>{const n=r.trim();if(!k.isValidUrl$1(n))throw new Error(`Invalid URL: ${n}`);try{const a=await k.fetchMetadata(n,e,s);return k.generateCardHtml(a,n,e)}catch(a){s.logger.warn("Card plugin fetch failed for URL:",n,a);const h=k.formatErrorInfo(a);return k.generateFallbackHtml$1(n,h)}}}),$t=(e={})=>{const{className:t="mermaid",includeId:r=!0}=e;return{name:"mermaid",processBlock:async(n,a)=>{const h=n.trim();if(!h){a.logger.warn("Mermaid plugin received empty content");const c=r?` id="${a.getUniqueId()}"`:"";return`<div class="${t}-wrapper">
12
+ `}function ct(e,t){const n=t??"";return`${`---
13
+ ${ot(e)}---
14
+ `}${n}`}const R=()=>{},it={debug:R,info:R,warn:R,error:R},lt={debug:console.debug,info:console.info,warn:console.warn,error:console.error},V=()=>it,ht=()=>lt,F=e=>{const t={},n=e.slice(1,-1).trim(),o=n.match(/\.([a-zA-Z0-9_-]+)/g);if(o){const h=o.map(m=>m.slice(1));t.class=h.join(" ")}const r=n.match(/#([a-zA-Z0-9_-]+)/);r&&r[1]&&(t.id=r[1]);const a=n.match(/([a-zA-Z0-9_-]+)=["']?([^"'\s]*)["']?/g);if(a)for(const h of a){const[m,d]=h.split("=");m&&d&&m!=="class"&&m!=="id"&&(t[m]=d.replace(/["']/g,""))}return t},ut=e=>{const t=e.lang?` class="language-${e.lang}"`:"",n=e.value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return`<pre><code${t}>${n}</code></pre>`},x=(e,t)=>{e.data||(e.data={}),e.data.hProperties||(e.data.hProperties={}),Object.entries(t).forEach(([n,o])=>{if(n==="class"){const r=e.data.hProperties.class;r?typeof r=="string"&&r.startsWith("language-")?e.data.hProperties.class=`${r} ${o}`:e.data.hProperties.class=`${r} ${o}`:e.data.hProperties.class=o}else e.data.hProperties[n]=o})},ft=()=>e=>{q.visit(e,(t,n,o)=>{if(t.type==="heading"&&t.children?.length>0){const r=t.children[t.children.length-1];if(r?.type==="text"&&r.value){const a=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(a){const h=a[1].trim(),m=a[2],d=F(m);r.value=h,x(t,d)}}}if(t.type==="paragraph"&&t.children?.length>0){const r=t.children[t.children.length-1];if(r?.type==="text"&&r.value){const a=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(a){const h=a[1].trim(),m=a[2],d=F(m);r.value=h,x(t,d)}}}if(t.type==="link"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const a=r.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],m=F(h);x(t,m),r.value=r.value.replace(a[0],"")}}}if(t.type==="image"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const a=r.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],m=F(h);x(t,m),r.value=r.value.replace(a[0],"")}}}if(t.type==="listItem"&&t.children?.length>0){const r=t.children[t.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const a=r.children[r.children.length-1];if(a?.type==="text"&&a.value){const h=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(h){const m=h[1].trim(),d=h[2],c=F(d);a.value=m,x(t,c)}}}}if(t.type==="list"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const a=r.children[0];if(a?.type==="text"&&a.value){const h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const m=h[1],d=F(m);x(t,d),o.children.splice(n+1,1)}}}}if(t.type==="blockquote"&&t.children?.length>0){const r=t.children[t.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const a=r.children[r.children.length-1];if(a?.type==="text"&&a.value){const h=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(h){const m=h[1].trim(),d=h[2],c=F(d);a.value=m,x(t,c)}}}}if(t.type==="blockquote"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const a=r.children[0];if(a?.type==="text"&&a.value){const h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const m=h[1],d=F(m);x(t,d),o.children.splice(n+1,1)}}}}if(t.type==="inlineCode"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const a=r.value.match(/^\s*(\{[^}]+\})/);if(a){const h=a[1],m=F(h);x(t,m),r.value=r.value.replace(a[0],"")}}}if(t.type==="code"&&t.meta){const r=t.meta.match(/\{([^}]+)\}/);if(r){const a=`{${r[1]}}`,h=F(a),m={type:"html",value:`<div class="${h.class||""}" ${Object.entries(h).filter(([d])=>d!=="class").map(([d,c])=>`${d}="${c}"`).join(" ")}>${ut(t)}</div>`};o&&typeof n=="number"&&(o.children[n]=m),t.meta=t.meta.replace(r[0],"").trim()||null}}})},dt=()=>e=>{q.visit(e,"element",t=>{if(t.tagName==="img"){const n=v.generateResponsiveImageStyles();t.properties||(t.properties={});const o=t.properties.style||"",r=o?`${o}; ${n}`:n;t.properties.style=r}})},{html:pt}=tt,Q={indent_size:2,indent_char:" ",max_preserve_newlines:2,preserve_newlines:!0,end_with_newline:!1,wrap_line_length:0,indent_inner_html:!0,indent_empty_lines:!1,unformatted:["code","pre","textarea"],content_unformatted:["pre","code","textarea"],extra_liners:[]},U=e=>{if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(U);if(e&&typeof e=="object"){const t=Object.entries(e).filter(([,o])=>o!==void 0).sort(([o],[r])=>o<r?-1:o>r?1:0),n={};for(const[o,r]of t)n[o]=U(r);return n}return e},j=e=>JSON.stringify(U(e??{})),z=e=>e.type==="text"||e.type==="inlineCode"?e.value||"":e.children&&Array.isArray(e.children)?e.children.map(z).join(""):"",mt=(e,t)=>`${e}-${t.join("-")}`,yt=e=>{const t=[],n=[];for(const o of e){const r=o.level;for(;n.length>r;)n.pop();for(;n.length<r;)n.push(0);const a=r-1;n[a]=(n[a]||0)+1;const h=n.slice(0,r);t.push({level:o.level,text:o.text,numbers:h})}return t},K=(e,t,n)=>{const o=v.generateHeadingId(t);return o!==void 0?`${e}-${o}`:n()},gt=e=>{const t=[],n=[];for(const o of e){const r={level:o.level,text:o.text,id:o.id,children:[]};for(;n.length>0;){const a=n[n.length-1];if(a&&a.level>=o.level)n.pop();else break}if(n.length===0)t.push(r);else{const a=n[n.length-1];a&&a.children.push(r)}n.push(r)}return t},wt=e=>{const{plugins:t=[],logger:n=V(),fetcher:o}=e,r=new Map;for(const s of t){if(r.has(s.name))throw new Error(`Plugin with name '${s.name}' is already registered`);r.set(s.name,s)}const a=async(s,u,f)=>{const p=r.get(s);return p?await p.processBlock(u,f):`<pre><code class="language-${s}">${v.escapeHtml(u)}</code></pre>`},h=(s,u,f)=>{const p={logger:n,signal:u,frontmatter:s,getUniqueId:f,fetcher:o};return()=>async y=>{const g=[];q.visit(y,"code",(w,k,b)=>{if(!w.lang||!r.has(w.lang))return;const $=(async()=>{const E={type:"html",value:await a(w.lang,w.value,p)};b&&typeof k=="number"&&(b.children[k]=E)})();g.push($)}),await Promise.all(g)}},m=(s,u,f=!1,p=!1,y="")=>()=>g=>{const w=[],k=[];q.visit(g,"heading",E=>{E.depth>=1&&E.depth<=6&&k.push(E)});let b=[];if(f){const E=k.map(N=>({level:N.depth,text:z(N)}));b=yt(E)}const $=[];k.forEach((E,N)=>{const O=z(E),T=E.data?.hProperties?.id;let H;if(T)H=T;else if(f&&p){const I=K(y,O,()=>u(O)).replace(`${y}-`,"");for(;$.length>0;){const C=$[$.length-1];if(C&&C.level>=E.depth)$.pop();else break}const P=$.map(C=>C.contentId);H=P.length>0?`${y}-${P.join("-")}-${I}`:`${y}-${I}`,$.push({level:E.depth,contentId:I})}else if(f&&N<b.length){const I=b[N];I?H=mt(y,I.numbers):H=u(O)}else H=u(O);E.data||(E.data={}),E.data.hProperties||(E.data.hProperties={}),T||(E.data.hProperties.id=H),w.push({level:E.depth,text:O,id:H})});const L=gt(w);s.push(...L)},d=s=>{throw n.error(`Failed to process markdown: ${s instanceof Error?s.message:"Unknown error"}`),new Error(`Failed to process markdown: ${s instanceof Error?s.message:"Unknown error"}`)},c=async(s,u,f,p,y,g)=>{const{signal:w,useContentStringHeaderId:k=!1,useHierarchicalHeadingId:b=!0,advancedOptions:$}=f??{},{allowDangerousHtml:L=!0,htmlOptions:E=Q,gfmOptions:N={},remarkPlugins:O=[],rehypePlugins:T=[]}=$||{},H=[];let I=0;const P=()=>`${u}-${++I}`;let _=st.unified().use(nt);if(O)for(const S of O)Array.isArray(S)?_=_.use(S[0],S[1]):_=_.use(S);let C=_.use(rt,N).use(ft).use(m(H,k?S=>K(u,S,P):P,b,k,u)).use(h(p,w,P)).use(at,{allowDangerousHtml:L}).use(dt).use(et,{allowDangerousHtml:L});if(T)for(const S of T)Array.isArray(S)?C=C.use(S[0],S[1]):C=C.use(S);const Z=await C.process(y),X=String(Z);return{html:pt(X,E),frontmatter:p,changed:g,headingTree:H,composeMarkdown:()=>g?ct(p,y):s}};return{process:async(s,u,f={})=>{try{const{data:p,content:y}=B(s);return await c(s,u,f,p,y,!1)}catch(p){return d(p)}},processWithFrontmatterTransform:async(s,u,f,p={})=>{try{const{data:y,content:g}=B(s),w=j(y),b=f({originalFrontmatter:y,markdownContent:g});if(b===void 0)return;const $=b,L=j(b===y?y:b)!==w;return await c(s,u,p,$,g,L)}catch(y){return d(y)}}}},vt=(e,t={})=>{const{maxRedirects:n=5,timeoutEachRedirect:o=1e4}=t;return{name:"oembed",processBlock:async(a,h)=>{const m=a.trim();if(!v.isValidUrl(m))throw new Error(`Invalid URL: ${m}`);try{const d=await v.fetchOEmbedData(m,n,o,h,e);return v.generateHtml(d,m,t)}catch(d){h.logger.warn("oEmbed fetch failed for URL:",m,d);const c=v.formatErrorInfo(d);return v.generateFallbackHtml(m,c)}}}},Et=(e={})=>({name:"card",processBlock:async(n,o)=>{const r=n.trim();if(!v.isValidUrl$1(r))throw new Error(`Invalid URL: ${r}`);try{const a=await v.fetchMetadata(r,e,o);return v.generateCardHtml(a,r,e)}catch(a){o.logger.warn("Card plugin fetch failed for URL:",r,a);const h=v.formatErrorInfo(a);return v.generateFallbackHtml$1(r,h)}}}),kt=(e={})=>{const{className:t="mermaid",includeId:n=!0}=e;return{name:"mermaid",processBlock:async(r,a)=>{const h=r.trim();if(!h){a.logger.warn("Mermaid plugin received empty content");const l=n?` id="${a.getUniqueId()}"`:"";return`<div class="${t}-wrapper">
15
15
  <style>
16
16
  .${t}-wrapper .${t} > svg {
17
17
  width: auto !important;
@@ -19,8 +19,8 @@ ${ct(e)}---
19
19
  max-width: none !important;
20
20
  }
21
21
  </style>
22
- <div class="${t}"${c}><!-- Empty mermaid content --></div>
23
- </div>`}const p=r?` id="${a.getUniqueId()}"`:"",d=h.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),o=`<div class="${t}-wrapper">
22
+ <div class="${t}"${l}><!-- Empty mermaid content --></div>
23
+ </div>`}const m=n?` id="${a.getUniqueId()}"`:"",d=h.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),c=`<div class="${t}-wrapper">
24
24
  <style>
25
25
  .${t}-wrapper .${t} > svg {
26
26
  width: auto !important;
@@ -28,8 +28,8 @@ ${ct(e)}---
28
28
  max-width: none !important;
29
29
  }
30
30
  </style>
31
- <div class="${t}"${p}>${d}</div>
32
- </div>`;return a.logger.debug("Mermaid plugin processed content:",{contentLength:h.length,className:t,includeId:r}),o}}};/*!
31
+ <div class="${t}"${m}>${d}</div>
32
+ </div>`;return a.logger.debug("Mermaid plugin processed content:",{contentLength:h.length,className:t,includeId:n}),c}}};/*!
33
33
  * name: async-primitives
34
34
  * version: 1.2.0
35
35
  * description: A collection of primitive functions for asynchronous operations
@@ -37,5 +37,5 @@ ${ct(e)}---
37
37
  * license: MIT
38
38
  * repository.url: https://github.com/kekyo/async-primitives.git
39
39
  * git.commit.hash: 3b7bffeaa8ae47aea6e8b0ef0f70e265a6d9ab08
40
- */const W=()=>{},G={release:W,[Symbol.dispose]:W},St=(e,t)=>{if(!e)return G;if(e.aborted){try{t()}catch(a){console.warn("AbortHook callback error: ",a)}return G}let r;r=()=>{if(r){e.removeEventListener("abort",r),r=void 0;try{t()}catch(a){console.warn("AbortHook callback error: ",a)}}};const s=()=>{r&&(e.removeEventListener("abort",r),r=void 0)};return e.addEventListener("abort",r,{once:!0}),{release:s,[Symbol.dispose]:s}},xt=e=>{typeof setImmediate=="function"?setImmediate(e):setTimeout(e,0)},q=()=>new Error("Lock acquisition was aborted"),Ft=e=>{let t=!0;const r=()=>{t&&(t=!1,e())};return{get isActive(){return t},release:r,[Symbol.dispose]:r}},J=(e=20)=>{let t=!1;const r=[];let s=0;const n=()=>{var c;if(t||r.length===0)return;const i=r.shift();if((c=i.signal)!=null&&c.aborted){i.reject(q()),a();return}t=!0;const l=Ft(h);i.resolve(l)},a=()=>{s++,s>=e?(s=0,xt(n)):n()},h=()=>{t&&(t=!1,a())},p=c=>{const i=r.indexOf(c);i!==-1&&r.splice(i,1)},d=async c=>{if(c){if(c.aborted)throw q();return new Promise((i,l)=>{const u={resolve:void 0,reject:void 0,signal:c},f=St(c,()=>{p(u),l(q())});u.resolve=m=>{f.release(),i(m)},u.reject=m=>{f.release(),l(m)},r.push(u),n()})}else return new Promise((i,l)=>{r.push({resolve:i,reject:l}),n()})};return{lock:d,waiter:{wait:d},get isLocked(){return t},get pendingCount(){return r.length}}},Ht=(e="cache:")=>{const t=J(),r=()=>{try{return typeof window<"u"&&typeof window.localStorage<"u"&&window.localStorage!==null}catch{return!1}},s=async()=>{if(!r())return;const o=Date.now(),c=[];for(let i=0;i<localStorage.length;i++){const l=localStorage.key(i);if(!l||!l.startsWith(e))continue;const u=localStorage.getItem(l);if(u)try{const f=JSON.parse(u);f.ttl!==void 0&&(f.ttl===0||o>f.timestamp+f.ttl)&&c.push(l)}catch{c.push(l)}}for(const i of c)localStorage.removeItem(i)};return{get:async o=>{if(!r())throw new Error("localStorage is not available in this environment");const c=e+o,i=localStorage.getItem(c);if(!i)return null;let l;try{l=JSON.parse(i)}catch{const u=await t.lock();try{return localStorage.removeItem(c),null}finally{u.release()}}if(l.ttl!==void 0&&(l.ttl===0||Date.now()>l.timestamp+l.ttl)){const f=await t.lock();try{const m=Date.now();return(l.ttl===0||m>l.timestamp+l.ttl)&&localStorage.removeItem(c),null}finally{f.release()}}return l.data},set:async(o,c,i)=>{if(!r())throw new Error("localStorage is not available in this environment");const l=e+o,u={data:c,timestamp:Date.now()};i!==void 0&&(u.ttl=i);const f=JSON.stringify(u),m=await t.lock();try{try{localStorage.setItem(l,f)}catch(y){if(y instanceof Error&&y.name==="QuotaExceededError"){await s();try{localStorage.setItem(l,f)}catch(w){throw new Error(`Failed to store cache entry: ${w}`)}}else throw new Error(`Failed to store cache entry: ${y}`)}}finally{m.release()}},delete:async o=>{if(!r())throw new Error("localStorage is not available in this environment");const c=e+o,i=await t.lock();try{localStorage.removeItem(c)}finally{i.release()}},clear:async()=>{if(!r())throw new Error("localStorage is not available in this environment");const o=[];for(let i=0;i<localStorage.length;i++){const l=localStorage.key(i);l&&l.startsWith(e)&&o.push(l)}if(o.length===0)return;const c=await t.lock();try{for(const i of o)localStorage.removeItem(i)}finally{c.release()}},size:async()=>{if(!r())throw new Error("localStorage is not available in this environment");const o=[];for(let i=0;i<localStorage.length;i++){const l=localStorage.key(i);l&&l.startsWith(e)&&o.push(l)}if(o.length===0)return 0;const c=await t.lock();try{const i=Date.now();let l=0;for(const u of o){const f=localStorage.getItem(u);if(f)try{const m=JSON.parse(f);if(m.ttl!==void 0&&(m.ttl===0||i>m.timestamp+m.ttl)){localStorage.removeItem(u);continue}l++}catch{localStorage.removeItem(u)}}return l}finally{c.release()}}}},Y=()=>{const e=new Map,t=J(),r=(d=Date.now())=>{const o=[];for(const[c,i]of e.entries())i.ttl!==void 0&&(i.ttl===0||d>i.timestamp+i.ttl)&&o.push(c);for(const c of o)e.delete(c);return o};return{get:async d=>{const o=e.get(d);if(!o)return null;if(o.ttl!==void 0&&(o.ttl===0||Date.now()>o.timestamp+o.ttl)){const i=await t.lock();try{const l=e.get(d);if(l&&l.ttl!==void 0){const u=Date.now();(l.ttl===0||u>l.timestamp+l.ttl)&&e.delete(d)}return null}finally{i.release()}}return o.data},set:async(d,o,c)=>{const i={data:o,timestamp:Date.now()};c!==void 0&&(i.ttl=c);const l=await t.lock();try{e.set(d,i)}finally{l.release()}},delete:async d=>{const o=await t.lock();try{e.delete(d)}finally{o.release()}},clear:async()=>{const d=await t.lock();try{e.clear()}finally{d.release()}},size:async()=>{if(Array.from(e.entries()).length===0)return 0;const o=await t.lock();try{return r(),e.size}finally{o.release()}}}},Ct=async e=>{try{const r=require("crypto").createHash("sha256");return r.update(e,"utf8"),r.digest("hex")}catch(t){throw new Error(`Failed to generate hash: ${t}`)}},Ot=e=>{if(typeof window<"u")throw new Error("File system cache is only available in Node.js environment, not in browsers");const t=J(),r=async o=>`${await Ct(o)}.json`,s=async()=>{try{const{promises:o}=require("fs");await o.mkdir(e,{recursive:!0})}catch(o){if(o.code!=="EEXIST")throw new Error(`Failed to create cache directory: ${o}`)}};return{get:async o=>{const c=await r(o);try{await s()}catch(m){throw new Error(`Failed to ensure cache directory: ${m}`)}const{promises:i}=require("fs"),u=require("path").join(e,c);let f;try{const m=await i.readFile(u,"utf-8");f=JSON.parse(m)}catch{return null}if(f.ttl!==void 0&&(f.ttl===0||Date.now()>f.timestamp+f.ttl)){const y=await t.lock();try{const w=Date.now();return(f.ttl===0||w>f.timestamp+f.ttl)&&await i.unlink(u),null}catch{return null}finally{y.release()}}return f.data},set:async(o,c,i)=>{const l=await r(o),u={data:c,timestamp:Date.now()};i!==void 0&&(u.ttl=i);const f=JSON.stringify(u,null,2),m=await t.lock();try{await s();const{promises:y}=require("fs"),g=require("path").join(e,l);try{await y.writeFile(g,f,"utf-8")}catch(b){throw new Error(`Failed to write cache entry: ${b}`)}}catch(y){throw new Error(`Failed to import required modules: ${y}`)}finally{m.release()}},delete:async o=>{const c=await r(o),i=await t.lock();try{await s();const{promises:l}=require("fs"),f=require("path").join(e,c);try{await l.unlink(f)}catch{}}catch(l){throw new Error(`Failed to import required modules: ${l}`)}finally{i.release()}},clear:async()=>{const o=await t.lock();try{await s();const{promises:c}=require("fs"),i=require("path"),u=(await c.readdir(e)).filter(f=>f.endsWith(".json"));for(const f of u){const m=i.join(e,f);try{await c.unlink(m)}catch{}}}catch(c){throw new Error(`Failed to import required modules: ${c}`)}finally{o.release()}},size:async()=>{await s();const{promises:o}=require("fs"),c=require("path"),l=(await o.readdir(e)).filter(f=>f.endsWith(".json"));if(l.length===0)return 0;const u=await t.lock();try{const f=Date.now();let m=0;for(const y of l){const w=c.join(e,y);try{const g=await o.readFile(w,"utf8"),b=JSON.parse(g);if(b.ttl!==void 0&&(b.ttl===0||f>b.timestamp+b.ttl)){await o.unlink(w);continue}m++}catch{try{await o.unlink(w)}catch{}}}return m}catch(f){throw new Error(`Failed to import required modules: ${f}`)}finally{u.release()}}}};function _(e,t,r){return`fetch:${e}:${t}:${r||"default"}`}const It=(e,t=6e4,r,s)=>{const{cache:n=!0,cacheTTL:a=3600*1e3,cacheFailures:h=!0,failureCacheTTL:p=300*1e3}=s||{},d=n?r||Y():void 0;return{rawFetcher:async(c,i,l,u)=>{if(n&&d){const y=_(c,i,e),w=await d.get(y);if(w)try{const g=JSON.parse(w);if(g.type==="success")return u?.info(`Cache HIT (success) for URL: ${c}`),new Response(g.data,{status:200,statusText:"OK",headers:{"Content-Type":i,"X-Cache":"HIT"}});if(g.type==="error"&&h)throw u?.info(`Cache HIT (error) for URL: ${c}`),new Error("Cached error");u?.debug(`Cache entry type ${g.type} not eligible for use, cacheFailures: ${h}`)}catch(g){if(u?.warn(`Failed to parse cached entry for URL ${c}:`,g),g instanceof SyntaxError)u?.debug("JSON parse error, continuing to network fetch");else throw g}else u?.info(`Cache MISS for URL: ${c}`)}let f,m=null;try{f=await k.fetchData(c,i,e,t,l,u)}catch(y){if(m=y,n&&d&&h)try{const w=_(c,i,e),g={type:"error",data:"",error:{message:m.message,...m.message.includes("HTTP error, status:")&&{status:parseInt(m.message.match(/status: (\d+)/)?.[1]||"0")}},timestamp:Date.now()};await d.set(w,JSON.stringify(g),p),u?.debug(`Cached error for URL: ${c}`)}catch(w){u?.warn(`Failed to cache error for URL ${c}:`,w),console.warn("Failed to cache error:",w)}throw m}if(n&&d&&f.ok)try{const y=await f.clone().text(),w=_(c,i,e),g={type:"success",data:y,timestamp:Date.now()};await d.set(w,JSON.stringify(g),a),u?.debug(`Cached successful response for URL: ${c}`)}catch(y){u?.warn(`Failed to cache response for URL ${c}:`,y),console.warn("Failed to cache response:",y)}return f},userAgent:e}},Lt=(e,t=6e4)=>({rawFetcher:async(s,n,a,h)=>(h?.debug(`Direct fetch for URL: ${s}`),await k.fetchData(s,n,e,t,a,h)),userAgent:e});exports.defaultProviderList=k.defaultProviderList;exports.fetchData=k.fetchData;exports.fetchJson=k.fetchJson;exports.fetchText=k.fetchText;exports.generateHeadingId=k.generateHeadingId;exports.createCachedFetcher=It;exports.createCardPlugin=bt;exports.createDirectFetcher=Lt;exports.createFileSystemCacheStorage=Ot;exports.createLocalCacheStorage=Ht;exports.createMarkdownProcessor=kt;exports.createMemoryCacheStorage=Y;exports.createMermaidPlugin=$t;exports.createOEmbedPlugin=Et;exports.defaultHtmlOptions=Q;exports.generateCacheKey=_;exports.getConsoleLogger=ut;exports.getNoOpLogger=V;
40
+ */const W=()=>{},G={release:W,[Symbol.dispose]:W},bt=(e,t)=>{if(!e)return G;if(e.aborted){try{t()}catch(a){console.warn("AbortHook callback error: ",a)}return G}let n;n=()=>{if(n){e.removeEventListener("abort",n),n=void 0;try{t()}catch(a){console.warn("AbortHook callback error: ",a)}}};const o=()=>{n&&(e.removeEventListener("abort",n),n=void 0)};return e.addEventListener("abort",n,{once:!0}),{release:o,[Symbol.dispose]:o}},$t=e=>{typeof setImmediate=="function"?setImmediate(e):setTimeout(e,0)},D=()=>new Error("Lock acquisition was aborted"),St=e=>{let t=!0;const n=()=>{t&&(t=!1,e())};return{get isActive(){return t},release:n,[Symbol.dispose]:n}},J=(e=20)=>{let t=!1;const n=[];let o=0;const r=()=>{var l;if(t||n.length===0)return;const i=n.shift();if((l=i.signal)!=null&&l.aborted){i.reject(D()),a();return}t=!0;const s=St(h);i.resolve(s)},a=()=>{o++,o>=e?(o=0,$t(r)):r()},h=()=>{t&&(t=!1,a())},m=l=>{const i=n.indexOf(l);i!==-1&&n.splice(i,1)},d=async l=>{if(l){if(l.aborted)throw D();return new Promise((i,s)=>{const u={resolve:void 0,reject:void 0,signal:l},f=bt(l,()=>{m(u),s(D())});u.resolve=p=>{f.release(),i(p)},u.reject=p=>{f.release(),s(p)},n.push(u),r()})}else return new Promise((i,s)=>{n.push({resolve:i,reject:s}),r()})};return{lock:d,waiter:{wait:d},get isLocked(){return t},get pendingCount(){return n.length}}},Ht=(e="cache:")=>{const t=J(),n=()=>{try{return typeof window<"u"&&typeof window.localStorage<"u"&&window.localStorage!==null}catch{return!1}},o=async()=>{if(!n())return;const c=Date.now(),l=[];for(let i=0;i<localStorage.length;i++){const s=localStorage.key(i);if(!s||!s.startsWith(e))continue;const u=localStorage.getItem(s);if(u)try{const f=JSON.parse(u);f.ttl!==void 0&&(f.ttl===0||c>f.timestamp+f.ttl)&&l.push(s)}catch{l.push(s)}}for(const i of l)localStorage.removeItem(i)};return{get:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const l=e+c,i=localStorage.getItem(l);if(!i)return null;let s;try{s=JSON.parse(i)}catch{const u=await t.lock();try{return localStorage.removeItem(l),null}finally{u.release()}}if(s.ttl!==void 0&&(s.ttl===0||Date.now()>s.timestamp+s.ttl)){const f=await t.lock();try{const p=Date.now();return(s.ttl===0||p>s.timestamp+s.ttl)&&localStorage.removeItem(l),null}finally{f.release()}}return s.data},set:async(c,l,i)=>{if(!n())throw new Error("localStorage is not available in this environment");const s=e+c,u={data:l,timestamp:Date.now()};i!==void 0&&(u.ttl=i);const f=JSON.stringify(u),p=await t.lock();try{try{localStorage.setItem(s,f)}catch(y){if(y instanceof Error&&y.name==="QuotaExceededError"){await o();try{localStorage.setItem(s,f)}catch(g){throw new Error(`Failed to store cache entry: ${g}`)}}else throw new Error(`Failed to store cache entry: ${y}`)}}finally{p.release()}},delete:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const l=e+c,i=await t.lock();try{localStorage.removeItem(l)}finally{i.release()}},clear:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let i=0;i<localStorage.length;i++){const s=localStorage.key(i);s&&s.startsWith(e)&&c.push(s)}if(c.length===0)return;const l=await t.lock();try{for(const i of c)localStorage.removeItem(i)}finally{l.release()}},size:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let i=0;i<localStorage.length;i++){const s=localStorage.key(i);s&&s.startsWith(e)&&c.push(s)}if(c.length===0)return 0;const l=await t.lock();try{const i=Date.now();let s=0;for(const u of c){const f=localStorage.getItem(u);if(f)try{const p=JSON.parse(f);if(p.ttl!==void 0&&(p.ttl===0||i>p.timestamp+p.ttl)){localStorage.removeItem(u);continue}s++}catch{localStorage.removeItem(u)}}return s}finally{l.release()}}}},Y=()=>{const e=new Map,t=J(),n=(d=Date.now())=>{const c=[];for(const[l,i]of e.entries())i.ttl!==void 0&&(i.ttl===0||d>i.timestamp+i.ttl)&&c.push(l);for(const l of c)e.delete(l);return c};return{get:async d=>{const c=e.get(d);if(!c)return null;if(c.ttl!==void 0&&(c.ttl===0||Date.now()>c.timestamp+c.ttl)){const i=await t.lock();try{const s=e.get(d);if(s&&s.ttl!==void 0){const u=Date.now();(s.ttl===0||u>s.timestamp+s.ttl)&&e.delete(d)}return null}finally{i.release()}}return c.data},set:async(d,c,l)=>{const i={data:c,timestamp:Date.now()};l!==void 0&&(i.ttl=l);const s=await t.lock();try{e.set(d,i)}finally{s.release()}},delete:async d=>{const c=await t.lock();try{e.delete(d)}finally{c.release()}},clear:async()=>{const d=await t.lock();try{e.clear()}finally{d.release()}},size:async()=>{if(Array.from(e.entries()).length===0)return 0;const c=await t.lock();try{return n(),e.size}finally{c.release()}}}},Ct=async e=>{try{const n=require("crypto").createHash("sha256");return n.update(e,"utf8"),n.digest("hex")}catch(t){throw new Error(`Failed to generate hash: ${t}`)}},Ft=e=>{if(typeof window<"u")throw new Error("File system cache is only available in Node.js environment, not in browsers");const t=J(),n=async c=>`${await Ct(c)}.json`,o=async()=>{try{const{promises:c}=require("fs");await c.mkdir(e,{recursive:!0})}catch(c){if(c.code!=="EEXIST")throw new Error(`Failed to create cache directory: ${c}`)}};return{get:async c=>{const l=await n(c);try{await o()}catch(p){throw new Error(`Failed to ensure cache directory: ${p}`)}const{promises:i}=require("fs"),u=require("path").join(e,l);let f;try{const p=await i.readFile(u,"utf-8");f=JSON.parse(p)}catch{return null}if(f.ttl!==void 0&&(f.ttl===0||Date.now()>f.timestamp+f.ttl)){const y=await t.lock();try{const g=Date.now();return(f.ttl===0||g>f.timestamp+f.ttl)&&await i.unlink(u),null}catch{return null}finally{y.release()}}return f.data},set:async(c,l,i)=>{const s=await n(c),u={data:l,timestamp:Date.now()};i!==void 0&&(u.ttl=i);const f=JSON.stringify(u,null,2),p=await t.lock();try{await o();const{promises:y}=require("fs"),w=require("path").join(e,s);try{await y.writeFile(w,f,"utf-8")}catch(k){throw new Error(`Failed to write cache entry: ${k}`)}}catch(y){throw new Error(`Failed to import required modules: ${y}`)}finally{p.release()}},delete:async c=>{const l=await n(c),i=await t.lock();try{await o();const{promises:s}=require("fs"),f=require("path").join(e,l);try{await s.unlink(f)}catch{}}catch(s){throw new Error(`Failed to import required modules: ${s}`)}finally{i.release()}},clear:async()=>{const c=await t.lock();try{await o();const{promises:l}=require("fs"),i=require("path"),u=(await l.readdir(e)).filter(f=>f.endsWith(".json"));for(const f of u){const p=i.join(e,f);try{await l.unlink(p)}catch{}}}catch(l){throw new Error(`Failed to import required modules: ${l}`)}finally{c.release()}},size:async()=>{await o();const{promises:c}=require("fs"),l=require("path"),s=(await c.readdir(e)).filter(f=>f.endsWith(".json"));if(s.length===0)return 0;const u=await t.lock();try{const f=Date.now();let p=0;for(const y of s){const g=l.join(e,y);try{const w=await c.readFile(g,"utf8"),k=JSON.parse(w);if(k.ttl!==void 0&&(k.ttl===0||f>k.timestamp+k.ttl)){await c.unlink(g);continue}p++}catch{try{await c.unlink(g)}catch{}}}return p}catch(f){throw new Error(`Failed to import required modules: ${f}`)}finally{u.release()}}}};function A(e,t,n){return`fetch:${e}:${t}:${n||"default"}`}const xt=(e,t=6e4,n,o)=>{const{cache:r=!0,cacheTTL:a=3600*1e3,cacheFailures:h=!0,failureCacheTTL:m=300*1e3}=o||{},d=r?n||Y():void 0;return{rawFetcher:async(l,i,s,u)=>{if(r&&d){const y=A(l,i,e),g=await d.get(y);if(g)try{const w=JSON.parse(g);if(w.type==="success")return u?.info(`Cache HIT (success) for URL: ${l}`),new Response(w.data,{status:200,statusText:"OK",headers:{"Content-Type":i,"X-Cache":"HIT"}});if(w.type==="error"&&h)throw u?.info(`Cache HIT (error) for URL: ${l}`),new Error("Cached error");u?.debug(`Cache entry type ${w.type} not eligible for use, cacheFailures: ${h}`)}catch(w){if(u?.warn(`Failed to parse cached entry for URL ${l}:`,w),w instanceof SyntaxError)u?.debug("JSON parse error, continuing to network fetch");else throw w}else u?.info(`Cache MISS for URL: ${l}`)}let f,p=null;try{f=await v.fetchData(l,i,e,t,s,u)}catch(y){if(p=y,r&&d&&h)try{const g=A(l,i,e),w={type:"error",data:"",error:{message:p.message,...p.message.includes("HTTP error, status:")&&{status:parseInt(p.message.match(/status: (\d+)/)?.[1]||"0")}},timestamp:Date.now()};await d.set(g,JSON.stringify(w),m),u?.debug(`Cached error for URL: ${l}`)}catch(g){u?.warn(`Failed to cache error for URL ${l}:`,g),console.warn("Failed to cache error:",g)}throw p}if(r&&d&&f.ok)try{const y=await f.clone().text(),g=A(l,i,e),w={type:"success",data:y,timestamp:Date.now()};await d.set(g,JSON.stringify(w),a),u?.debug(`Cached successful response for URL: ${l}`)}catch(y){u?.warn(`Failed to cache response for URL ${l}:`,y),console.warn("Failed to cache response:",y)}return f},userAgent:e}},Ot=(e,t=6e4)=>({rawFetcher:async(o,r,a,h)=>(h?.debug(`Direct fetch for URL: ${o}`),await v.fetchData(o,r,e,t,a,h)),userAgent:e});exports.defaultProviderList=v.defaultProviderList;exports.fetchData=v.fetchData;exports.fetchJson=v.fetchJson;exports.fetchText=v.fetchText;exports.generateHeadingId=v.generateHeadingId;exports.createCachedFetcher=xt;exports.createCardPlugin=Et;exports.createDirectFetcher=Ot;exports.createFileSystemCacheStorage=Ft;exports.createLocalCacheStorage=Ht;exports.createMarkdownProcessor=wt;exports.createMemoryCacheStorage=Y;exports.createMermaidPlugin=kt;exports.createOEmbedPlugin=vt;exports.defaultHtmlOptions=Q;exports.generateCacheKey=A;exports.getConsoleLogger=ht;exports.getNoOpLogger=V;
41
41
  //# sourceMappingURL=index.cjs.map