mark-deco 0.13.0 → 0.14.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/apply-title-from-h1.d.ts +2 -2
- package/dist/cache/filesystem.d.ts +2 -2
- package/dist/cache/index.d.ts +2 -2
- package/dist/cache/localstorage.d.ts +2 -2
- package/dist/cache/memory.d.ts +2 -2
- package/dist/fetcher.d.ts +2 -2
- package/dist/frontmatter.d.ts +2 -2
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +352 -348
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-BYxuN1cP.cjs → internal-CDWALvfx.cjs} +3 -3
- package/dist/{internal-BYxuN1cP.cjs.map → internal-CDWALvfx.cjs.map} +1 -1
- package/dist/{internal-j-DRJERk.js → internal-CV9E6fHH.js} +3 -3
- package/dist/{internal-j-DRJERk.js.map → internal-CV9E6fHH.js.map} +1 -1
- package/dist/internal.cjs +3 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.mjs +3 -3
- package/dist/logger.d.ts +2 -2
- package/dist/plugins/card/amazon-rules.d.ts +2 -2
- package/dist/plugins/card/fetcher.d.ts +2 -2
- package/dist/plugins/card/html-generator.d.ts +2 -2
- package/dist/plugins/card/index.d.ts +2 -2
- package/dist/plugins/card/ogp-rules.d.ts +2 -2
- package/dist/plugins/card/rule-engine.d.ts +2 -2
- package/dist/plugins/card/types.d.ts +2 -2
- package/dist/plugins/card/utils.d.ts +2 -2
- package/dist/plugins/card-plugin.d.ts +2 -2
- package/dist/plugins/mermaid/index.d.ts +2 -2
- package/dist/plugins/mermaid/types.d.ts +2 -2
- package/dist/plugins/mermaid-plugin.d.ts +2 -2
- package/dist/plugins/oembed/fetcher.d.ts +2 -2
- package/dist/plugins/oembed/html-generator.d.ts +2 -2
- package/dist/plugins/oembed/index.d.ts +2 -2
- package/dist/plugins/oembed/providers.d.ts +2 -2
- package/dist/plugins/oembed/providers.json.d.ts +2 -2
- package/dist/plugins/oembed/redirect-resolver.d.ts +2 -2
- package/dist/plugins/oembed/types.d.ts +2 -2
- package/dist/plugins/oembed/utils.d.ts +2 -2
- package/dist/plugins/oembed-plugin.d.ts +2 -2
- package/dist/plugins/remark-apply-title-from-h1.d.ts +2 -2
- package/dist/plugins/remark-attr.d.ts +2 -2
- package/dist/plugins/responsive-images.d.ts +2 -2
- package/dist/plugins/shared/error-formatter.d.ts +2 -2
- package/dist/processor.d.ts +2 -2
- package/dist/processor.d.ts.map +1 -1
- package/dist/types.d.ts +23 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/heading.d.ts +2 -2
- package/dist/utils/responsive-image.d.ts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +8 -8
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { FrontmatterData, H1TitleTransform } from './types.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { CacheStorage } from './index.js';
|
package/dist/cache/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { CacheStorage } from './index.js';
|
package/dist/cache/memory.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
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.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { CacheStorage } from './cache/index.js';
|
package/dist/frontmatter.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { FrontmatterData } from './types.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.14.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:
|
|
9
|
-
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("js-beautify"),ie=require("rehype-stringify"),le=require("remark-gfm"),
|
|
8
|
+
* git.commit.hash: 090ae78518ae17207fdb90e6fca59893315672fb
|
|
9
|
+
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("js-beautify"),ie=require("rehype-stringify"),le=require("remark-gfm"),te=require("remark-parse"),he=require("remark-rehype"),re=require("unified"),M=require("unist-util-visit"),J=require("js-yaml"),b=require("./internal-CDWALvfx.cjs");function G(t){const e=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,n=t.match(e);if(!n)return{data:{},content:t};const s=n[1]||"",r=t.slice(n[0].length);try{const o=J.load(s,{schema:J.JSON_SCHEMA});return{data:o&&typeof o=="object"&&!Array.isArray(o)?o:{},content:r}}catch(o){const d=o instanceof Error?o.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${d}`)}}function fe(t){if(!t||Object.keys(t).length===0)return"";const e=J.dump(t,{lineWidth:0});return typeof e!="string"||e.length===0?"":e.endsWith(`
|
|
10
10
|
`)?e:`${e}
|
|
11
|
-
`}function
|
|
12
|
-
${
|
|
13
|
-
`}${n}`}const q=()=>{},fe={debug:q,info:q,warn:q,error:q},ue={debug:console.debug,info:console.info,warn:console.warn,error:console.error},ae=()=>fe,pe=()=>ue,I=t=>{const e={},n=t.slice(1,-1).trim(),s=n.match(/\.([a-zA-Z0-9_-]+)/g);if(s){const f=s.map(p=>p.slice(1));e.class=f.join(" ")}const r=n.match(/#([a-zA-Z0-9_-]+)/);r&&r[1]&&(e.id=r[1]);const o=n.match(/([a-zA-Z0-9_-]+)=["']?([^"'\s]*)["']?/g);if(o)for(const f of o){const[p,u]=f.split("=");p&&u&&p!=="class"&&p!=="id"&&(e[p]=u.replace(/["']/g,""))}return e},me=t=>{const e=t.lang?` class="language-${t.lang}"`:"",n=t.value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return`<pre><code${e}>${n}</code></pre>`},L=(t,e)=>{t.data||(t.data={}),t.data.hProperties||(t.data.hProperties={}),Object.entries(e).forEach(([n,s])=>{if(n==="class"){const r=t.data.hProperties.class;r?typeof r=="string"&&r.startsWith("language-")?t.data.hProperties.class=`${r} ${s}`:t.data.hProperties.class=`${r} ${s}`:t.data.hProperties.class=s}else t.data.hProperties[n]=s})},ge=()=>t=>{M.visit(t,(e,n,s)=>{if(e.type==="heading"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="text"&&r.value){const o=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(o){const f=o[1].trim(),p=o[2],u=I(p);r.value=f,L(e,u)}}}if(e.type==="paragraph"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="text"&&r.value){const o=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(o){const f=o[1].trim(),p=o[2],u=I(p);r.value=f,L(e,u)}}}if(e.type==="link"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const f=o[1],p=I(f);L(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="image"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const f=o[1],p=I(f);L(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="listItem"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const o=r.children[r.children.length-1];if(o?.type==="text"&&o.value){const f=o.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(f){const p=f[1].trim(),u=f[2],c=I(u);o.value=p,L(e,c)}}}}if(e.type==="list"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const o=r.children[0];if(o?.type==="text"&&o.value){const f=o.value.match(/^\s*(\{[^}]+\})\s*$/);if(f){const p=f[1],u=I(p);L(e,u),s.children.splice(n+1,1)}}}}if(e.type==="blockquote"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const o=r.children[r.children.length-1];if(o?.type==="text"&&o.value){const f=o.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(f){const p=f[1].trim(),u=f[2],c=I(u);o.value=p,L(e,c)}}}}if(e.type==="blockquote"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const o=r.children[0];if(o?.type==="text"&&o.value){const f=o.value.match(/^\s*(\{[^}]+\})\s*$/);if(f){const p=f[1],u=I(p);L(e,u),s.children.splice(n+1,1)}}}}if(e.type==="inlineCode"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const f=o[1],p=I(f);L(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="code"&&e.meta){const r=e.meta.match(/\{([^}]+)\}/);if(r){const o=`{${r[1]}}`,f=I(o),p={type:"html",value:`<div class="${f.class||""}" ${Object.entries(f).filter(([u])=>u!=="class").map(([u,c])=>`${u}="${c}"`).join(" ")}>${me(e)}</div>`};s&&typeof n=="number"&&(s.children[n]=p),e.meta=e.meta.replace(r[0],"").trim()||null}}})},ye=()=>t=>{M.visit(t,"element",e=>{if(e.tagName==="img"){const n=b.generateResponsiveImageStyles();e.properties||(e.properties={});const s=e.properties.style||"",r=s?`${s}; ${n}`:n;e.properties.style=r}})},D=t=>t?"value"in t&&typeof t.value=="string"?t.value:"children"in t&&Array.isArray(t.children)?t.children.map(e=>D(e)).join(""):"":"",we=t=>{const{frontmatter:e,hasTitle:n,transform:s,allowTitleWrite:r,onHeadingApplied:o}=t,f=s==="extractAndRemove";return p=>{if(!e||!p.children||p.children.length===0)return;let u=0;for(;u<p.children.length;u++){const c=p.children[u];if(c.type==="heading"&&c.depth===1){const l=c,i=p.children[u+1],a=i&&i.position?i.position.start?.offset:void 0,h=D(l).trim();f&&p.children.splice(u,1);let d=!1;!n&&r&&h.length>0&&(e.title=h,d=!0),o&&o({headingText:h,position:l.position,nextNodeStartOffset:a,titleWritten:d,headingRemoved:f});break}if(!(c.type==="thematicBreak"||c.type==="html"&&typeof c.value=="string"&&c.value.trim()==="")&&!(c.type==="paragraph"&&c.children?.length===0))break}}},Y=(t,e,n)=>{const{transform:s,allowTitleWrite:r}=n;if(s==="none")return{content:t,headingRemoved:!1,titleWritten:!1};const o=e!=null&&Object.prototype.hasOwnProperty.call(e,"title")&&e.title!==void 0&&e.title!==null;let f=!1,p=!1,u,c;const l=ne.unified().use(re).use(we,{frontmatter:e,hasTitle:o,transform:s,allowTitleWrite:r,onHeadingApplied:a=>{if(f=a.headingRemoved,p=a.titleWritten,!a.headingRemoved)return;const h=a.position?.start?.offset??0;let d=a.position?.end?.offset??h;typeof a.nextNodeStartOffset=="number"&&a.nextNodeStartOffset>=d?d=a.nextNodeStartOffset:d=t.length,u=h,c=d}}),i=l.parse(t);return l.runSync(i),f&&u!==void 0&&c!==void 0?{content:t.slice(0,u)+t.slice(c),headingRemoved:!0,titleWritten:p}:{content:t,headingRemoved:!1,titleWritten:!1}},{html:ve}=ce,oe={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:[]},J=t=>{if(t instanceof Date)return t.toISOString();if(Array.isArray(t))return t.map(J);if(t&&typeof t=="object"){const e=Object.entries(t).filter(([,s])=>s!==void 0).sort(([s],[r])=>s<r?-1:s>r?1:0),n={};for(const[s,r]of e)n[s]=J(r);return n}return t},U=t=>JSON.stringify(J(t??{})),Ee=(t,e)=>`${t}-${e.join("-")}`,be=t=>{const e=[],n=[];for(const s of t){const r=s.level;for(;n.length>r;)n.pop();for(;n.length<r;)n.push(0);const o=r-1;n[o]=(n[o]||0)+1;const f=n.slice(0,r);e.push({level:s.level,text:s.text,numbers:f})}return e},Z=(t,e,n)=>{const s=b.generateHeadingId(e);return s!==void 0?`${t}-${s}`:n()},Se=t=>{const e=[],n=[];for(const s of t){const r={level:s.level,text:s.text,id:s.id,children:[]};for(;n.length>0;){const o=n[n.length-1];if(o&&o.level>=s.level)n.pop();else break}if(n.length===0)e.push(r);else{const o=n[n.length-1];o&&o.children.push(r)}n.push(r)}return e},ke=t=>{const{plugins:e=[],logger:n=ae(),fetcher:s}=t,r=new Map;for(const a of e){if(r.has(a.name))throw new Error(`Plugin with name '${a.name}' is already registered`);r.set(a.name,a)}const o=async(a,h,d)=>{const m=r.get(a);return m?await m.processBlock(h,d):`<pre><code class="language-${a}">${b.escapeHtml(h)}</code></pre>`},f=(a,h,d)=>{const m={logger:n,signal:h,frontmatter:a,getUniqueId:d,fetcher:s};return()=>async g=>{const y=[];M.visit(g,"code",(w,v,x)=>{if(!w.lang||!r.has(w.lang))return;const $=(async()=>{const E={type:"html",value:await o(w.lang,w.value,m)};x&&typeof v=="number"&&(x.children[v]=E)})();y.push($)}),await Promise.all(y)}},p=(a,h,d=!1,m=!1,g="")=>()=>y=>{const w=[],v=[];M.visit(y,"heading",E=>{E.depth>=1&&E.depth<=6&&v.push(E)});let x=[];if(d){const E=v.map(R=>({level:R.depth,text:D(R)}));x=be(E)}const $=[];v.forEach((E,R)=>{const T=D(E),O=E.data?.hProperties?.id;let k;if(O)k=O;else if(d&&m){const N=Z(g,T,()=>h(T)).replace(`${g}-`,"");for(;$.length>0;){const S=$[$.length-1];if(S&&S.level>=E.depth)$.pop();else break}const P=$.map(S=>S.contentId);k=P.length>0?`${g}-${P.join("-")}-${N}`:`${g}-${N}`,$.push({level:E.depth,contentId:N})}else if(d&&R<x.length){const N=x[R];N?k=Ee(g,N.numbers):k=h(T)}else k=h(T);E.data||(E.data={}),E.data.hProperties||(E.data.hProperties={}),O||(E.data.hProperties.id=k),w.push({level:E.depth,text:T,id:k})});const H=Se(w);a.push(...H)},u=a=>{throw n.error(`Failed to process markdown: ${a instanceof Error?a.message:"Unknown error"}`),new Error(`Failed to process markdown: ${a instanceof Error?a.message:"Unknown error"}`)},c=async(a,h,d,m,g,y)=>{const{signal:w,useContentStringHeaderId:v=!1,useHierarchicalHeadingId:x=!0,advancedOptions:$}=d??{},{allowDangerousHtml:H=!0,htmlOptions:E=oe,gfmOptions:R={},remarkPlugins:T=[],rehypePlugins:O=[]}=$||{},k=[];let N=0;const P=()=>`${h}-${++N}`;let F=ne.unified().use(re);if(T)for(const C of T)Array.isArray(C)?F=F.use(C[0],C[1]):F=F.use(C);let S=F.use(le,R).use(ge).use(p(k,v?C=>Z(h,C,P):P,x,v,h)).use(f(m,w,P)).use(he,{allowDangerousHtml:H}).use(ye).use(ie,{allowDangerousHtml:H});if(O)for(const C of O)Array.isArray(C)?S=S.use(C[0],C[1]):S=S.use(C);const K=await S.process(g),_=String(K);return{html:ve(_,E),frontmatter:m,changed:y,headingTree:k,composeMarkdown:()=>y?Q(m,g):a,uniqueIdPrefix:h}};return{process:async(a,h,d={})=>{try{const{data:m,content:g}=V(a),y=d.h1TitleTransform??"extractAndRemove";let w=g,v=!1,x=!1;if(y!=="none"){const H=Y(w,m,{allowTitleWrite:!0,transform:y});w=H.content,v=H.headingRemoved,x=H.titleWritten}return await c(a,h,d,m,w,v||x)}catch(m){return u(m)}},processWithFrontmatterTransform:async(a,h,d,m,g={})=>{try{const{data:y,content:w}=V(a),v=U(y),$=await d({originalFrontmatter:y,markdownContent:w,uniqueIdPrefix:h});if($===void 0)return;const{frontmatter:H,uniqueIdPrefix:E}=$,R=E??h,T=g.h1TitleTransform??"extractAndRemove";let O=w,k=!1;if(T!=="none"){const A=Y(O,H,{allowTitleWrite:!0,transform:T});O=A.content,k=A.headingRemoved||k}const P=U(H)!==v||k,F=await c(a,R,g,H,O,P);let S=F.frontmatter;if(m){const A={frontmatter:S,headingTree:F.headingTree};S=await m(A)}const _=U(S)!==v||k,G=()=>_?Q(S,O):a;return{html:F.html,frontmatter:S,changed:_,headingTree:F.headingTree,composeMarkdown:G,uniqueIdPrefix:F.uniqueIdPrefix}}catch(y){return u(y)}}}},$e=(t,e={})=>{const{maxRedirects:n=5,timeoutEachRedirect:s=1e4}=e;return{name:"oembed",processBlock:async(o,f)=>{const p=o.trim();if(!b.isValidUrl(p))throw new Error(`Invalid URL: ${p}`);try{const u=await b.fetchOEmbedData(p,n,s,f,t);return b.generateHtml(u,p,e)}catch(u){f.logger.warn("oEmbed fetch failed for URL:",p,u);const c=b.formatErrorInfo(u);return b.generateFallbackHtml(p,c)}}}},xe=(t={})=>({name:"card",processBlock:async(n,s)=>{const r=n.trim();if(!b.isValidUrl$1(r))throw new Error(`Invalid URL: ${r}`);try{const o=await b.fetchMetadata(r,t,s);return b.generateCardHtml(o,r,t)}catch(o){s.logger.warn("Card plugin fetch failed for URL:",r,o);const f=b.formatErrorInfo(o);return b.generateFallbackHtml$1(r,f)}}}),He=(t={})=>{const{className:e="mermaid",includeId:n=!0}=t;return{name:"mermaid",processBlock:async(r,o)=>{const f=r.trim();if(!f){o.logger.warn("Mermaid plugin received empty content");const l=n?` id="${o.getUniqueId()}"`:"";return`<div class="${e}-wrapper">
|
|
11
|
+
`}function V(t,e){const n=e??"";return`${`---
|
|
12
|
+
${fe(t)}---
|
|
13
|
+
`}${n}`}const q=()=>{},de={debug:q,info:q,warn:q,error:q},ue={debug:console.debug,info:console.info,warn:console.warn,error:console.error},ne=()=>de,pe=()=>ue,L=t=>{const e={},n=t.slice(1,-1).trim(),s=n.match(/\.([a-zA-Z0-9_-]+)/g);if(s){const d=s.map(p=>p.slice(1));e.class=d.join(" ")}const r=n.match(/#([a-zA-Z0-9_-]+)/);r&&r[1]&&(e.id=r[1]);const o=n.match(/([a-zA-Z0-9_-]+)=["']?([^"'\s]*)["']?/g);if(o)for(const d of o){const[p,u]=d.split("=");p&&u&&p!=="class"&&p!=="id"&&(e[p]=u.replace(/["']/g,""))}return e},me=t=>{const e=t.lang?` class="language-${t.lang}"`:"",n=t.value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return`<pre><code${e}>${n}</code></pre>`},P=(t,e)=>{t.data||(t.data={}),t.data.hProperties||(t.data.hProperties={}),Object.entries(e).forEach(([n,s])=>{if(n==="class"){const r=t.data.hProperties.class;r?typeof r=="string"&&r.startsWith("language-")?t.data.hProperties.class=`${r} ${s}`:t.data.hProperties.class=`${r} ${s}`:t.data.hProperties.class=s}else t.data.hProperties[n]=s})},ge=()=>t=>{M.visit(t,(e,n,s)=>{if(e.type==="heading"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="text"&&r.value){const o=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(o){const d=o[1].trim(),p=o[2],u=L(p);r.value=d,P(e,u)}}}if(e.type==="paragraph"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="text"&&r.value){const o=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(o){const d=o[1].trim(),p=o[2],u=L(p);r.value=d,P(e,u)}}}if(e.type==="link"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const d=o[1],p=L(d);P(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="image"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const d=o[1],p=L(d);P(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="listItem"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const o=r.children[r.children.length-1];if(o?.type==="text"&&o.value){const d=o.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(d){const p=d[1].trim(),u=d[2],c=L(u);o.value=p,P(e,c)}}}}if(e.type==="list"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const o=r.children[0];if(o?.type==="text"&&o.value){const d=o.value.match(/^\s*(\{[^}]+\})\s*$/);if(d){const p=d[1],u=L(p);P(e,u),s.children.splice(n+1,1)}}}}if(e.type==="blockquote"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="paragraph"&&r.children?.length>0){const o=r.children[r.children.length-1];if(o?.type==="text"&&o.value){const d=o.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(d){const p=d[1].trim(),u=d[2],c=L(u);o.value=p,P(e,c)}}}}if(e.type==="blockquote"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const o=r.children[0];if(o?.type==="text"&&o.value){const d=o.value.match(/^\s*(\{[^}]+\})\s*$/);if(d){const p=d[1],u=L(p);P(e,u),s.children.splice(n+1,1)}}}}if(e.type==="inlineCode"&&s&&typeof n=="number"){const r=s.children[n+1];if(r?.type==="text"&&r.value){const o=r.value.match(/^\s*(\{[^}]+\})/);if(o){const d=o[1],p=L(d);P(e,p),r.value=r.value.replace(o[0],"")}}}if(e.type==="code"&&e.meta){const r=e.meta.match(/\{([^}]+)\}/);if(r){const o=`{${r[1]}}`,d=L(o),p={type:"html",value:`<div class="${d.class||""}" ${Object.entries(d).filter(([u])=>u!=="class").map(([u,c])=>`${u}="${c}"`).join(" ")}>${me(e)}</div>`};s&&typeof n=="number"&&(s.children[n]=p),e.meta=e.meta.replace(r[0],"").trim()||null}}})},ye=()=>t=>{M.visit(t,"element",e=>{if(e.tagName==="img"){const n=b.generateResponsiveImageStyles();e.properties||(e.properties={});const s=e.properties.style||"",r=s?`${s}; ${n}`:n;e.properties.style=r}})},D=t=>t?"value"in t&&typeof t.value=="string"?t.value:"children"in t&&Array.isArray(t.children)?t.children.map(e=>D(e)).join(""):"":"",we=t=>{const{frontmatter:e,hasTitle:n,transform:s,allowTitleWrite:r,onHeadingApplied:o}=t,d=s==="extractAndRemove";return p=>{if(!e||!p.children||p.children.length===0)return;let u=0;for(;u<p.children.length;u++){const c=p.children[u];if(c.type==="heading"&&c.depth===1){const h=c,l=p.children[u+1],a=l&&l.position?l.position.start?.offset:void 0,f=D(h).trim();d&&p.children.splice(u,1);let i=!1;!n&&r&&f.length>0&&(e.title=f,i=!0),o&&o({headingText:f,position:h.position,nextNodeStartOffset:a,titleWritten:i,headingRemoved:d});break}if(!(c.type==="thematicBreak"||c.type==="html"&&typeof c.value=="string"&&c.value.trim()==="")&&!(c.type==="paragraph"&&c.children?.length===0))break}}},Q=(t,e,n)=>{const{transform:s,allowTitleWrite:r}=n;if(s==="none")return{content:t,headingRemoved:!1,titleWritten:!1};const o=e!=null&&Object.prototype.hasOwnProperty.call(e,"title")&&e.title!==void 0&&e.title!==null;let d=!1,p=!1,u,c;const h=re.unified().use(te).use(we,{frontmatter:e,hasTitle:o,transform:s,allowTitleWrite:r,onHeadingApplied:a=>{if(d=a.headingRemoved,p=a.titleWritten,!a.headingRemoved)return;const f=a.position?.start?.offset??0;let i=a.position?.end?.offset??f;typeof a.nextNodeStartOffset=="number"&&a.nextNodeStartOffset>=i?i=a.nextNodeStartOffset:i=t.length,u=f,c=i}}),l=h.parse(t);return h.runSync(l),d&&u!==void 0&&c!==void 0?{content:t.slice(0,u)+t.slice(c),headingRemoved:!0,titleWritten:p}:{content:t,headingRemoved:!1,titleWritten:!1}},{html:ve}=ce,ae={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:[]},B=t=>{if(t instanceof Date)return t.toISOString();if(Array.isArray(t))return t.map(B);if(t&&typeof t=="object"){const e=Object.entries(t).filter(([,s])=>s!==void 0).sort(([s],[r])=>s<r?-1:s>r?1:0),n={};for(const[s,r]of e)n[s]=B(r);return n}return t},W=t=>JSON.stringify(B(t??{})),Ee=(t,e)=>`${t}-${e.join("-")}`,be=t=>{const e=[],n=[];for(const s of t){const r=s.level;for(;n.length>r;)n.pop();for(;n.length<r;)n.push(0);const o=r-1;n[o]=(n[o]||0)+1;const d=n.slice(0,r);e.push({level:s.level,text:s.text,numbers:d})}return e},Y=(t,e,n)=>{const s=b.generateHeadingId(e);return s!==void 0?`${t}-${s}`:n()},Se=t=>{const e=[],n=[];for(const s of t){const r={level:s.level,text:s.text,id:s.id,children:[]};for(;n.length>0;){const o=n[n.length-1];if(o&&o.level>=s.level)n.pop();else break}if(n.length===0)e.push(r);else{const o=n[n.length-1];o&&o.children.push(r)}n.push(r)}return e},ke=t=>{const{plugins:e=[],logger:n=ne(),fetcher:s}=t,r=new Map;for(const a of e){if(r.has(a.name))throw new Error(`Plugin with name '${a.name}' is already registered`);r.set(a.name,a)}const o=async(a,f,i)=>{const m=r.get(a);return m?await m.processBlock(f,i):`<pre><code class="language-${a}">${b.escapeHtml(f)}</code></pre>`},d=(a,f,i)=>{const m={logger:n,signal:f,frontmatter:a,getUniqueId:i,fetcher:s};return()=>async g=>{const w=[];M.visit(g,"code",(y,v,S)=>{if(!y.lang||!r.has(y.lang))return;const k=(async()=>{const E={type:"html",value:await o(y.lang,y.value,m)};S&&typeof v=="number"&&(S.children[v]=E)})();w.push(k)}),await Promise.all(w)}},p=(a,f,i=!1,m=!1,g="")=>()=>w=>{const y=[],v=[];M.visit(w,"heading",E=>{E.depth>=1&&E.depth<=6&&v.push(E)});let S=[];if(i){const E=v.map(R=>({level:R.depth,text:D(R)}));S=be(E)}const k=[];v.forEach((E,R)=>{const $=D(E),F=E.data?.hProperties?.id;let O;if(F)O=F;else if(i&&m){const N=Y(g,$,()=>f($)).replace(`${g}-`,"");for(;k.length>0;){const I=k[k.length-1];if(I&&I.level>=E.depth)k.pop();else break}const x=k.map(I=>I.contentId);O=x.length>0?`${g}-${x.join("-")}-${N}`:`${g}-${N}`,k.push({level:E.depth,contentId:N})}else if(i&&R<S.length){const N=S[R];N?O=Ee(g,N.numbers):O=f($)}else O=f($);E.data||(E.data={}),E.data.hProperties||(E.data.hProperties={}),F||(E.data.hProperties.id=O),y.push({level:E.depth,text:$,id:O})});const C=Se(y);a.push(...C)},u=a=>{throw n.error(`Failed to process markdown: ${a instanceof Error?a.message:"Unknown error"}`),new Error(`Failed to process markdown: ${a instanceof Error?a.message:"Unknown error"}`)},c=async(a,f,i,m,g,w)=>{const{signal:y,useContentStringHeaderId:v=!1,useHierarchicalHeadingId:S=!0,advancedOptions:k}=i??{},{allowDangerousHtml:C=!0,htmlOptions:E=ae,gfmOptions:R={},remarkPlugins:$=[],rehypePlugins:F=[]}=k||{},O=[];let N=0;const x=()=>`${f}-${++N}`;let H=re.unified().use(te);if($)for(const T of $)Array.isArray(T)?H=H.use(T[0],T[1]):H=H.use(T);let I=H.use(le,R).use(ge).use(p(O,v?T=>Y(f,T,x):x,S,v,f)).use(d(m,y,x)).use(he,{allowDangerousHtml:C}).use(ye).use(ie,{allowDangerousHtml:C});if(F)for(const T of F)Array.isArray(T)?I=I.use(T[0],T[1]):I=I.use(T);const _=await I.process(g),U=String(_);return{html:ve(U,E),frontmatter:m,changed:w,headingTree:O,composeMarkdown:()=>w?V(m,g):a,uniqueIdPrefix:f}};return{process:async(a,f,i={})=>{try{const{data:m,content:g}=G(a),w=i.h1TitleTransform??"extractAndRemove";let y=g,v=!1,S=!1;if(w!=="none"){const C=Q(y,m,{allowTitleWrite:!0,transform:w});y=C.content,v=C.headingRemoved,S=C.titleWritten}return await c(a,f,i,m,y,v||S)}catch(m){return u(m)}},processWithFrontmatterTransform:async(a,f,i)=>{try{const{data:m,content:g}=G(a),w=W(m),y={originalFrontmatter:m,markdownContent:g,uniqueIdPrefix:f},v=await i.preTransform(y);if(v===void 0)return;const{frontmatter:S,uniqueIdPrefix:k,h1TitleTransform:C}=v,E=k??f,R=C??"extractAndRemove";let $=g,F=!1;if(R!=="none"){const A=Q($,S,{allowTitleWrite:!0,transform:R});$=A.content,F=A.headingRemoved||F}const N=W(S)!==w||F,x=await c(a,E,i,S,$,N);let H=x.frontmatter;if(i.postTransform){const A={frontmatter:H,headingTree:x.headingTree};H=await i.postTransform(A)}const _=W(H)!==w||F,U=()=>_?V(H,$):a;return{html:x.html,frontmatter:H,changed:_,headingTree:x.headingTree,composeMarkdown:U,uniqueIdPrefix:x.uniqueIdPrefix}}catch(m){return u(m)}}}},$e=(t,e={})=>{const{maxRedirects:n=5,timeoutEachRedirect:s=1e4}=e;return{name:"oembed",processBlock:async(o,d)=>{const p=o.trim();if(!b.isValidUrl(p))throw new Error(`Invalid URL: ${p}`);try{const u=await b.fetchOEmbedData(p,n,s,d,t);return b.generateHtml(u,p,e)}catch(u){d.logger.warn("oEmbed fetch failed for URL:",p,u);const c=b.formatErrorInfo(u);return b.generateFallbackHtml(p,c)}}}},xe=(t={})=>({name:"card",processBlock:async(n,s)=>{const r=n.trim();if(!b.isValidUrl$1(r))throw new Error(`Invalid URL: ${r}`);try{const o=await b.fetchMetadata(r,t,s);return b.generateCardHtml(o,r,t)}catch(o){s.logger.warn("Card plugin fetch failed for URL:",r,o);const d=b.formatErrorInfo(o);return b.generateFallbackHtml$1(r,d)}}}),He=(t={})=>{const{className:e="mermaid",includeId:n=!0}=t;return{name:"mermaid",processBlock:async(r,o)=>{const d=r.trim();if(!d){o.logger.warn("Mermaid plugin received empty content");const h=n?` id="${o.getUniqueId()}"`:"";return`<div class="${e}-wrapper">
|
|
14
14
|
<style>
|
|
15
15
|
.${e}-wrapper .${e} > svg {
|
|
16
16
|
width: auto !important;
|
|
@@ -18,8 +18,8 @@ ${de(t)}---
|
|
|
18
18
|
max-width: none !important;
|
|
19
19
|
}
|
|
20
20
|
</style>
|
|
21
|
-
<div class="${e}"${
|
|
22
|
-
</div>`}const p=n?` id="${o.getUniqueId()}"`:"",u=
|
|
21
|
+
<div class="${e}"${h}><!-- Empty mermaid content --></div>
|
|
22
|
+
</div>`}const p=n?` id="${o.getUniqueId()}"`:"",u=d.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),c=`<div class="${e}-wrapper">
|
|
23
23
|
<style>
|
|
24
24
|
.${e}-wrapper .${e} > svg {
|
|
25
25
|
width: auto !important;
|
|
@@ -28,7 +28,7 @@ ${de(t)}---
|
|
|
28
28
|
}
|
|
29
29
|
</style>
|
|
30
30
|
<div class="${e}"${p}>${u}</div>
|
|
31
|
-
</div>`;return o.logger.debug("Mermaid plugin processed content:",{contentLength:
|
|
31
|
+
</div>`;return o.logger.debug("Mermaid plugin processed content:",{contentLength:d.length,className:e,includeId:n}),c}}};/*!
|
|
32
32
|
* name: async-primitives
|
|
33
33
|
* version: 1.5.0
|
|
34
34
|
* description: A collection of primitive functions for asynchronous operations
|
|
@@ -36,5 +36,5 @@ ${de(t)}---
|
|
|
36
36
|
* license: MIT
|
|
37
37
|
* repository.url: https://github.com/kekyo/async-primitives.git
|
|
38
38
|
* git.commit.hash: cd35465b7e9b9945049186e7eaeecc0bfba65766
|
|
39
|
-
*/const
|
|
39
|
+
*/const Z=()=>{},X={release:Z,[Symbol.dispose]:Z},ee=t=>t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Operation aborted"),Te=(t,e)=>{if(!t)return X;if(t.aborted){try{e(ee(t.reason))}catch(o){console.warn("AbortHook callback error: ",o)}return X}let n;n=()=>{if(n){const o=t.reason;t.removeEventListener("abort",n),n=void 0;try{e(ee(o))}catch(d){console.warn("AbortHook callback error: ",d)}}};const s=()=>{n&&(t.removeEventListener("abort",n),n=void 0)};return t.addEventListener("abort",n,{once:!0}),{release:s,[Symbol.dispose]:s}},Ce=t=>{typeof setImmediate=="function"?setImmediate(t):setTimeout(t,0)},z=()=>new Error("Lock acquisition was aborted"),Fe=t=>{let e=!0;const n=()=>{e&&(e=!1,t())};return{get isActive(){return e},release:n,[Symbol.dispose]:n}},K=(t=20)=>{let e=!1;const n=[];let s=0;const r=()=>{var h;if(e||n.length===0)return;const l=n.shift();if((h=l.signal)!=null&&h.aborted){l.reject(z()),o();return}e=!0;const a=Fe(d);l.resolve(a)},o=()=>{s++,s>=t?(s=0,Ce(r)):r()},d=()=>{e&&(e=!1,o())},p=h=>{const l=n.indexOf(h);l!==-1&&n.splice(l,1)},u=async h=>{if(h){if(h.aborted)throw z();return new Promise((l,a)=>{const f={resolve:void 0,reject:void 0,signal:h},i=Te(h,()=>{p(f),a(z())});f.resolve=m=>{i.release(),l(m)},f.reject=m=>{i.release(),a(m)},n.push(f),r()})}else return new Promise((l,a)=>{n.push({resolve:l,reject:a}),r()})};return{lock:u,waiter:{wait:u},get isLocked(){return e},get pendingCount(){return n.length}}},Oe=(t="cache:")=>{const e=K(),n=()=>{try{return typeof window<"u"&&typeof window.localStorage<"u"&&window.localStorage!==null}catch{return!1}},s=async()=>{if(!n())return;const c=Date.now(),h=[];for(let l=0;l<localStorage.length;l++){const a=localStorage.key(l);if(!a||!a.startsWith(t))continue;const f=localStorage.getItem(a);if(f)try{const i=JSON.parse(f);i.ttl!==void 0&&(i.ttl===0||c>i.timestamp+i.ttl)&&h.push(a)}catch{h.push(a)}}for(const l of h)localStorage.removeItem(l)};return{get:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const h=t+c,l=localStorage.getItem(h);if(!l)return null;let a;try{a=JSON.parse(l)}catch{const f=await e.lock();try{return localStorage.removeItem(h),null}finally{f.release()}}if(a.ttl!==void 0&&(a.ttl===0||Date.now()>a.timestamp+a.ttl)){const i=await e.lock();try{const m=Date.now();return(a.ttl===0||m>a.timestamp+a.ttl)&&localStorage.removeItem(h),null}finally{i.release()}}return a.data},set:async(c,h,l)=>{if(!n())throw new Error("localStorage is not available in this environment");const a=t+c,f={data:h,timestamp:Date.now()};l!==void 0&&(f.ttl=l);const i=JSON.stringify(f),m=await e.lock();try{try{localStorage.setItem(a,i)}catch(g){if(g instanceof Error&&g.name==="QuotaExceededError"){await s();try{localStorage.setItem(a,i)}catch(w){throw new Error(`Failed to store cache entry: ${w}`)}}else throw new Error(`Failed to store cache entry: ${g}`)}}finally{m.release()}},delete:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const h=t+c,l=await e.lock();try{localStorage.removeItem(h)}finally{l.release()}},clear:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let l=0;l<localStorage.length;l++){const a=localStorage.key(l);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return;const h=await e.lock();try{for(const l of c)localStorage.removeItem(l)}finally{h.release()}},size:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let l=0;l<localStorage.length;l++){const a=localStorage.key(l);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return 0;const h=await e.lock();try{const l=Date.now();let a=0;for(const f of c){const i=localStorage.getItem(f);if(i)try{const m=JSON.parse(i);if(m.ttl!==void 0&&(m.ttl===0||l>m.timestamp+m.ttl)){localStorage.removeItem(f);continue}a++}catch{localStorage.removeItem(f)}}return a}finally{h.release()}}}},oe=()=>{const t=new Map,e=K(),n=(u=Date.now())=>{const c=[];for(const[h,l]of t.entries())l.ttl!==void 0&&(l.ttl===0||u>l.timestamp+l.ttl)&&c.push(h);for(const h of c)t.delete(h);return c};return{get:async u=>{const c=t.get(u);if(!c)return null;if(c.ttl!==void 0&&(c.ttl===0||Date.now()>c.timestamp+c.ttl)){const l=await e.lock();try{const a=t.get(u);if(a&&a.ttl!==void 0){const f=Date.now();(a.ttl===0||f>a.timestamp+a.ttl)&&t.delete(u)}return null}finally{l.release()}}return c.data},set:async(u,c,h)=>{const l={data:c,timestamp:Date.now()};h!==void 0&&(l.ttl=h);const a=await e.lock();try{t.set(u,l)}finally{a.release()}},delete:async u=>{const c=await e.lock();try{t.delete(u)}finally{c.release()}},clear:async()=>{const u=await e.lock();try{t.clear()}finally{u.release()}},size:async()=>{if(Array.from(t.entries()).length===0)return 0;const c=await e.lock();try{return n(),t.size}finally{c.release()}}}},Ie=async t=>{try{const n=require("crypto").createHash("sha256");return n.update(t,"utf8"),n.digest("hex")}catch(e){throw new Error(`Failed to generate hash: ${e}`)}},Re=t=>{if(typeof window<"u")throw new Error("File system cache is only available in Node.js environment, not in browsers");const e=K(),n=async c=>`${await Ie(c)}.json`,s=async()=>{try{const{promises:c}=require("fs");await c.mkdir(t,{recursive:!0})}catch(c){if(c.code!=="EEXIST")throw new Error(`Failed to create cache directory: ${c}`)}};return{get:async c=>{const h=await n(c);try{await s()}catch(m){throw new Error(`Failed to ensure cache directory: ${m}`)}const{promises:l}=require("fs"),f=require("path").join(t,h);let i;try{const m=await l.readFile(f,"utf-8");i=JSON.parse(m)}catch{return null}if(i.ttl!==void 0&&(i.ttl===0||Date.now()>i.timestamp+i.ttl)){const g=await e.lock();try{const w=Date.now();return(i.ttl===0||w>i.timestamp+i.ttl)&&await l.unlink(f),null}catch{return null}finally{g.release()}}return i.data},set:async(c,h,l)=>{const a=await n(c),f={data:h,timestamp:Date.now()};l!==void 0&&(f.ttl=l);const i=JSON.stringify(f,null,2),m=await e.lock();try{await s();const{promises:g}=require("fs"),y=require("path").join(t,a);try{await g.writeFile(y,i,"utf-8")}catch(v){throw new Error(`Failed to write cache entry: ${v}`)}}catch(g){throw new Error(`Failed to import required modules: ${g}`)}finally{m.release()}},delete:async c=>{const h=await n(c),l=await e.lock();try{await s();const{promises:a}=require("fs"),i=require("path").join(t,h);try{await a.unlink(i)}catch{}}catch(a){throw new Error(`Failed to import required modules: ${a}`)}finally{l.release()}},clear:async()=>{const c=await e.lock();try{await s();const{promises:h}=require("fs"),l=require("path"),f=(await h.readdir(t)).filter(i=>i.endsWith(".json"));for(const i of f){const m=l.join(t,i);try{await h.unlink(m)}catch{}}}catch(h){throw new Error(`Failed to import required modules: ${h}`)}finally{c.release()}},size:async()=>{await s();const{promises:c}=require("fs"),h=require("path"),a=(await c.readdir(t)).filter(i=>i.endsWith(".json"));if(a.length===0)return 0;const f=await e.lock();try{const i=Date.now();let m=0;for(const g of a){const w=h.join(t,g);try{const y=await c.readFile(w,"utf8"),v=JSON.parse(y);if(v.ttl!==void 0&&(v.ttl===0||i>v.timestamp+v.ttl)){await c.unlink(w);continue}m++}catch{try{await c.unlink(w)}catch{}}}return m}catch(i){throw new Error(`Failed to import required modules: ${i}`)}finally{f.release()}}}};function j(t,e,n){return`fetch:${t}:${e}:${n||"default"}`}const Ne=(t,e=6e4,n,s)=>{const{cache:r=!0,cacheTTL:o=3600*1e3,cacheFailures:d=!0,failureCacheTTL:p=300*1e3}=s||{},u=r?n||oe():void 0;return{rawFetcher:async(h,l,a,f)=>{if(r&&u){const g=j(h,l,t),w=await u.get(g);if(w)try{const y=JSON.parse(w);if(y.type==="success")return f?.info(`Cache HIT (success) for URL: ${h}`),new Response(y.data,{status:200,statusText:"OK",headers:{"Content-Type":l,"X-Cache":"HIT"}});if(y.type==="error"&&d)throw f?.info(`Cache HIT (error) for URL: ${h}`),new Error("Cached error");f?.debug(`Cache entry type ${y.type} not eligible for use, cacheFailures: ${d}`)}catch(y){if(f?.warn(`Failed to parse cached entry for URL ${h}:`,y),y instanceof SyntaxError)f?.debug("JSON parse error, continuing to network fetch");else throw y}else f?.info(`Cache MISS for URL: ${h}`)}let i,m=null;try{i=await b.fetchData(h,l,t,e,a,f)}catch(g){if(m=g,r&&u&&d)try{const w=j(h,l,t),y={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 u.set(w,JSON.stringify(y),p),f?.debug(`Cached error for URL: ${h}`)}catch(w){f?.warn(`Failed to cache error for URL ${h}:`,w),console.warn("Failed to cache error:",w)}throw m}if(r&&u&&i.ok)try{const g=await i.clone().text(),w=j(h,l,t),y={type:"success",data:g,timestamp:Date.now()};await u.set(w,JSON.stringify(y),o),f?.debug(`Cached successful response for URL: ${h}`)}catch(g){f?.warn(`Failed to cache response for URL ${h}:`,g),console.warn("Failed to cache response:",g)}return i},userAgent:t}},Le=(t,e=6e4)=>({rawFetcher:async(s,r,o,d)=>(d?.debug(`Direct fetch for URL: ${s}`),await b.fetchData(s,r,t,e,o,d)),userAgent:t});exports.defaultProviderList=b.defaultProviderList;exports.fetchData=b.fetchData;exports.fetchJson=b.fetchJson;exports.fetchText=b.fetchText;exports.generateHeadingId=b.generateHeadingId;exports.createCachedFetcher=Ne;exports.createCardPlugin=xe;exports.createDirectFetcher=Le;exports.createFileSystemCacheStorage=Re;exports.createLocalCacheStorage=Oe;exports.createMarkdownProcessor=ke;exports.createMemoryCacheStorage=oe;exports.createMermaidPlugin=He;exports.createOEmbedPlugin=$e;exports.defaultHtmlOptions=ae;exports.generateCacheKey=j;exports.getConsoleLogger=pe;exports.getNoOpLogger=ne;
|
|
40
40
|
//# sourceMappingURL=index.cjs.map
|