mark-deco 0.8.0 → 0.9.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/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 +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +260 -242
- package/dist/index.js.map +1 -1
- package/dist/internal-B7OqH3Vn.cjs +2 -2
- package/dist/internal-BLcZHfk2.js +2 -2
- package/dist/internal.cjs +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +2 -2
- 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-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 +33 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/responsive-image.d.ts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +6 -6
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
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.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
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.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
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.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
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.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
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.
|
|
3
|
+
* version: 0.9.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: d0e45da82482af0e17292db548313487c588061b
|
|
9
9
|
*/
|
|
10
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
10
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const et=require("js-beautify"),rt=require("rehype-stringify"),nt=require("remark-gfm"),at=require("remark-parse"),st=require("remark-rehype"),ot=require("unified"),A=require("unist-util-visit"),U=require("js-yaml"),E=require("./internal-B7OqH3Vn.cjs");function W(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=U.load(o,{schema:U.JSON_SCHEMA});return{data:a&&typeof a=="object"&&!Array.isArray(a)?a:{},content:r}}catch(a){const u=a instanceof Error?a.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${u}`)}}function ct(e){if(!e||Object.keys(e).length===0)return"";const t=U.dump(e,{lineWidth:0});return typeof t!="string"||t.length===0?"":t.endsWith(`
|
|
11
11
|
`)?t:`${t}
|
|
12
|
-
`}function
|
|
13
|
-
${
|
|
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},
|
|
12
|
+
`}function G(e,t){const n=t??"";return`${`---
|
|
13
|
+
${ct(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},Z=()=>it,ht=()=>lt,F=e=>{const t={},n=e.slice(1,-1).trim(),o=n.match(/\.([a-zA-Z0-9_-]+)/g);if(o){const u=o.map(m=>m.slice(1));t.class=u.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 u of a){const[m,d]=u.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,"&").replace(/</g,"<").replace(/>/g,">");return`<pre><code${t}>${n}</code></pre>`},P=(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=>{A.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 u=a[1].trim(),m=a[2],d=F(m);r.value=u,P(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 u=a[1].trim(),m=a[2],d=F(m);r.value=u,P(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 u=a[1],m=F(u);P(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 u=a[1],m=F(u);P(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 u=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(u){const m=u[1].trim(),d=u[2],c=F(d);a.value=m,P(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 u=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(u){const m=u[1],d=F(m);P(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 u=a.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(u){const m=u[1].trim(),d=u[2],c=F(d);a.value=m,P(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 u=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(u){const m=u[1],d=F(m);P(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 u=a[1],m=F(u);P(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]}}`,u=F(a),m={type:"html",value:`<div class="${u.class||""}" ${Object.entries(u).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=>{A.visit(e,"element",t=>{if(t.tagName==="img"){const n=E.generateResponsiveImageStyles();t.properties||(t.properties={});const o=t.properties.style||"",r=o?`${o}; ${n}`:n;t.properties.style=r}})},{html:pt}=et,X={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:[]},z=e=>{if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(z);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]=z(r);return n}return e},j=e=>JSON.stringify(z(e??{})),J=e=>e.type==="text"||e.type==="inlineCode"?e.value||"":e.children&&Array.isArray(e.children)?e.children.map(J).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 u=n.slice(0,r);t.push({level:o.level,text:o.text,numbers:u})}return t},V=(e,t,n)=>{const o=E.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=Z(),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,h,f)=>{const p=r.get(s);return p?await p.processBlock(h,f):`<pre><code class="language-${s}">${E.escapeHtml(h)}</code></pre>`},u=(s,h,f)=>{const p={logger:n,signal:h,frontmatter:s,getUniqueId:f,fetcher:o};return()=>async y=>{const g=[];A.visit(y,"code",(w,k,H)=>{if(!w.lang||!r.has(w.lang))return;const $=(async()=>{const v={type:"html",value:await a(w.lang,w.value,p)};H&&typeof k=="number"&&(H.children[k]=v)})();g.push($)}),await Promise.all(g)}},m=(s,h,f=!1,p=!1,y="")=>()=>g=>{const w=[],k=[];A.visit(g,"heading",v=>{v.depth>=1&&v.depth<=6&&k.push(v)});let H=[];if(f){const v=k.map(O=>({level:O.depth,text:J(O)}));H=yt(v)}const $=[];k.forEach((v,O)=>{const T=J(v),N=v.data?.hProperties?.id;let b;if(N)b=N;else if(f&&p){const S=V(y,T,()=>h(T)).replace(`${y}-`,"");for(;$.length>0;){const C=$[$.length-1];if(C&&C.level>=v.depth)$.pop();else break}const _=$.map(C=>C.contentId);b=_.length>0?`${y}-${_.join("-")}-${S}`:`${y}-${S}`,$.push({level:v.depth,contentId:S})}else if(f&&O<H.length){const S=H[O];S?b=mt(y,S.numbers):b=h(T)}else b=h(T);v.data||(v.data={}),v.data.hProperties||(v.data.hProperties={}),N||(v.data.hProperties.id=b),w.push({level:v.depth,text:T,id:b})});const I=gt(w);s.push(...I)},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,h,f,p,y,g)=>{const{signal:w,useContentStringHeaderId:k=!1,useHierarchicalHeadingId:H=!0,advancedOptions:$}=f??{},{allowDangerousHtml:I=!0,htmlOptions:v=X,gfmOptions:O={},remarkPlugins:T=[],rehypePlugins:N=[]}=$||{},b=[];let S=0;const _=()=>`${h}-${++S}`;let L=ot.unified().use(at);if(T)for(const x of T)Array.isArray(x)?L=L.use(x[0],x[1]):L=L.use(x);let C=L.use(nt,O).use(ft).use(m(b,k?x=>V(h,x,_):_,H,k,h)).use(u(p,w,_)).use(st,{allowDangerousHtml:I}).use(dt).use(rt,{allowDangerousHtml:I});if(N)for(const x of N)Array.isArray(x)?C=C.use(x[0],x[1]):C=C.use(x);const M=await C.process(y),K=String(M);return{html:pt(K,v),frontmatter:p,changed:g,headingTree:b,composeMarkdown:()=>g?G(p,y):s,uniqueIdPrefix:h}};return{process:async(s,h,f={})=>{try{const{data:p,content:y}=W(s);return await c(s,h,f,p,y,!1)}catch(p){return d(p)}},processWithFrontmatterTransform:async(s,h,f,p,y={})=>{try{const{data:g,content:w}=W(s),k=j(g),$=f({originalFrontmatter:g,markdownContent:w,uniqueIdPrefix:h});if($===void 0)return;const{frontmatter:I,uniqueIdPrefix:v}=$,O=v??h,N=(I===g?k:j(I))!==k,b=await c(s,O,y,I,w,N);let S=b.frontmatter;if(p){const M={frontmatter:S,headingTree:b.headingTree};S=p(M)}const L=j(S)!==k,C=()=>L?G(S,w):s;return{html:b.html,frontmatter:S,changed:L,headingTree:b.headingTree,composeMarkdown:C,uniqueIdPrefix:b.uniqueIdPrefix}}catch(g){return d(g)}}}},vt=(e,t={})=>{const{maxRedirects:n=5,timeoutEachRedirect:o=1e4}=t;return{name:"oembed",processBlock:async(a,u)=>{const m=a.trim();if(!E.isValidUrl(m))throw new Error(`Invalid URL: ${m}`);try{const d=await E.fetchOEmbedData(m,n,o,u,e);return E.generateHtml(d,m,t)}catch(d){u.logger.warn("oEmbed fetch failed for URL:",m,d);const c=E.formatErrorInfo(d);return E.generateFallbackHtml(m,c)}}}},Et=(e={})=>({name:"card",processBlock:async(n,o)=>{const r=n.trim();if(!E.isValidUrl$1(r))throw new Error(`Invalid URL: ${r}`);try{const a=await E.fetchMetadata(r,e,o);return E.generateCardHtml(a,r,e)}catch(a){o.logger.warn("Card plugin fetch failed for URL:",r,a);const u=E.formatErrorInfo(a);return E.generateFallbackHtml$1(r,u)}}}),kt=(e={})=>{const{className:t="mermaid",includeId:n=!0}=e;return{name:"mermaid",processBlock:async(r,a)=>{const u=r.trim();if(!u){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;
|
|
@@ -20,7 +20,7 @@ ${ot(e)}---
|
|
|
20
20
|
}
|
|
21
21
|
</style>
|
|
22
22
|
<div class="${t}"${l}><!-- Empty mermaid content --></div>
|
|
23
|
-
</div>`}const m=n?` id="${a.getUniqueId()}"`:"",d=
|
|
23
|
+
</div>`}const m=n?` id="${a.getUniqueId()}"`:"",d=u.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),c=`<div class="${t}-wrapper">
|
|
24
24
|
<style>
|
|
25
25
|
.${t}-wrapper .${t} > svg {
|
|
26
26
|
width: auto !important;
|
|
@@ -29,7 +29,7 @@ ${ot(e)}---
|
|
|
29
29
|
}
|
|
30
30
|
</style>
|
|
31
31
|
<div class="${t}"${m}>${d}</div>
|
|
32
|
-
</div>`;return a.logger.debug("Mermaid plugin processed content:",{contentLength:
|
|
32
|
+
</div>`;return a.logger.debug("Mermaid plugin processed content:",{contentLength:u.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 @@ ${ot(e)}---
|
|
|
37
37
|
* license: MIT
|
|
38
38
|
* repository.url: https://github.com/kekyo/async-primitives.git
|
|
39
39
|
* git.commit.hash: 3b7bffeaa8ae47aea6e8b0ef0f70e265a6d9ab08
|
|
40
|
-
*/const
|
|
40
|
+
*/const Q=()=>{},Y={release:Q,[Symbol.dispose]:Q},bt=(e,t)=>{if(!e)return Y;if(e.aborted){try{t()}catch(a){console.warn("AbortHook callback error: ",a)}return Y}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}},St=e=>{typeof setImmediate=="function"?setImmediate(e):setTimeout(e,0)},D=()=>new Error("Lock acquisition was aborted"),$t=e=>{let t=!0;const n=()=>{t&&(t=!1,e())};return{get isActive(){return t},release:n,[Symbol.dispose]:n}},B=(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=$t(u);i.resolve(s)},a=()=>{o++,o>=e?(o=0,St(r)):r()},u=()=>{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 h={resolve:void 0,reject:void 0,signal:l},f=bt(l,()=>{m(h),s(D())});h.resolve=p=>{f.release(),i(p)},h.reject=p=>{f.release(),s(p)},n.push(h),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}}},Ct=(e="cache:")=>{const t=B(),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 h=localStorage.getItem(s);if(h)try{const f=JSON.parse(h);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 h=await t.lock();try{return localStorage.removeItem(l),null}finally{h.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,h={data:l,timestamp:Date.now()};i!==void 0&&(h.ttl=i);const f=JSON.stringify(h),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 h of c){const f=localStorage.getItem(h);if(f)try{const p=JSON.parse(f);if(p.ttl!==void 0&&(p.ttl===0||i>p.timestamp+p.ttl)){localStorage.removeItem(h);continue}s++}catch{localStorage.removeItem(h)}}return s}finally{l.release()}}}},tt=()=>{const e=new Map,t=B(),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 h=Date.now();(s.ttl===0||h>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()}}}},xt=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}`)}},Ht=e=>{if(typeof window<"u")throw new Error("File system cache is only available in Node.js environment, not in browsers");const t=B(),n=async c=>`${await xt(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"),h=require("path").join(e,l);let f;try{const p=await i.readFile(h,"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(h),null}catch{return null}finally{y.release()}}return f.data},set:async(c,l,i)=>{const s=await n(c),h={data:l,timestamp:Date.now()};i!==void 0&&(h.ttl=i);const f=JSON.stringify(h,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"),h=(await l.readdir(e)).filter(f=>f.endsWith(".json"));for(const f of h){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 h=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{h.release()}}}};function q(e,t,n){return`fetch:${e}:${t}:${n||"default"}`}const Ft=(e,t=6e4,n,o)=>{const{cache:r=!0,cacheTTL:a=3600*1e3,cacheFailures:u=!0,failureCacheTTL:m=300*1e3}=o||{},d=r?n||tt():void 0;return{rawFetcher:async(l,i,s,h)=>{if(r&&d){const y=q(l,i,e),g=await d.get(y);if(g)try{const w=JSON.parse(g);if(w.type==="success")return h?.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"&&u)throw h?.info(`Cache HIT (error) for URL: ${l}`),new Error("Cached error");h?.debug(`Cache entry type ${w.type} not eligible for use, cacheFailures: ${u}`)}catch(w){if(h?.warn(`Failed to parse cached entry for URL ${l}:`,w),w instanceof SyntaxError)h?.debug("JSON parse error, continuing to network fetch");else throw w}else h?.info(`Cache MISS for URL: ${l}`)}let f,p=null;try{f=await E.fetchData(l,i,e,t,s,h)}catch(y){if(p=y,r&&d&&u)try{const g=q(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),h?.debug(`Cached error for URL: ${l}`)}catch(g){h?.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=q(l,i,e),w={type:"success",data:y,timestamp:Date.now()};await d.set(g,JSON.stringify(w),a),h?.debug(`Cached successful response for URL: ${l}`)}catch(y){h?.warn(`Failed to cache response for URL ${l}:`,y),console.warn("Failed to cache response:",y)}return f},userAgent:e}},It=(e,t=6e4)=>({rawFetcher:async(o,r,a,u)=>(u?.debug(`Direct fetch for URL: ${o}`),await E.fetchData(o,r,e,t,a,u)),userAgent:e});exports.defaultProviderList=E.defaultProviderList;exports.fetchData=E.fetchData;exports.fetchJson=E.fetchJson;exports.fetchText=E.fetchText;exports.generateHeadingId=E.generateHeadingId;exports.createCachedFetcher=Ft;exports.createCardPlugin=Et;exports.createDirectFetcher=It;exports.createFileSystemCacheStorage=Ht;exports.createLocalCacheStorage=Ct;exports.createMarkdownProcessor=wt;exports.createMemoryCacheStorage=tt;exports.createMermaidPlugin=kt;exports.createOEmbedPlugin=vt;exports.defaultHtmlOptions=X;exports.generateCacheKey=q;exports.getConsoleLogger=ht;exports.getNoOpLogger=Z;
|
|
41
41
|
//# sourceMappingURL=index.cjs.map
|