mark-deco 0.12.0 → 0.13.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 +6 -4
- package/dist/apply-title-from-h1.d.ts.map +1 -1
- 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 +16 -16
- 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.mjs +455 -436
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-tQkd_UGz.cjs → internal-BYxuN1cP.cjs} +3 -3
- package/dist/{internal-tQkd_UGz.cjs.map → internal-BYxuN1cP.cjs.map} +1 -1
- package/dist/{internal-BJiq2VBv.js → internal-j-DRJERk.js} +3 -3
- package/dist/{internal-BJiq2VBv.js.map → internal-j-DRJERk.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 +10 -4
- package/dist/plugins/remark-apply-title-from-h1.d.ts.map +1 -1
- 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 +10 -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 +7 -7
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { FrontmatterData } from './types.js';
|
|
11
|
+
import { FrontmatterData, H1TitleTransform } from './types.js';
|
|
12
12
|
export interface ApplyTitleOptions {
|
|
13
13
|
/** Whether the caller allows writing heading text into frontmatter.title */
|
|
14
14
|
readonly allowTitleWrite: boolean;
|
|
15
|
+
/** How to treat the first H1 heading */
|
|
16
|
+
readonly transform: H1TitleTransform;
|
|
15
17
|
}
|
|
16
18
|
export interface ApplyTitleResult {
|
|
17
19
|
readonly content: string;
|
|
@@ -19,7 +21,7 @@ export interface ApplyTitleResult {
|
|
|
19
21
|
readonly titleWritten: boolean;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
|
-
* Apply the leading H1 heading to frontmatter.title and remove it from the markdown content
|
|
24
|
+
* Apply the leading H1 heading to frontmatter.title and optionally remove it from the markdown content
|
|
23
25
|
*/
|
|
24
26
|
export declare const applyTitleFromH1: (markdownContent: string, frontmatter: FrontmatterData, options: ApplyTitleOptions) => ApplyTitleResult;
|
|
25
27
|
//# sourceMappingURL=apply-title-from-h1.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-title-from-h1.d.ts","sourceRoot":"","sources":["../src/apply-title-from-h1.ts"],"names":[],"mappings":";;;;;;;;;AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"apply-title-from-h1.d.ts","sourceRoot":"","sources":["../src/apply-title-from-h1.ts"],"names":[],"mappings":";;;;;;;;;AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,iBAAiB,MAAM,EACvB,aAAa,eAAe,EAC5B,SAAS,iBAAiB,KACzB,gBA6EF,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
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.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
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.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
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.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
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.13.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: a57a326430fda951da873116177f76aa783d4413
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { FrontmatterData } from './types.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use strict";/*!
|
|
2
2
|
* name: mark-deco
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.13.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
|
|
10
|
-
`)?
|
|
11
|
-
`}function Q(e
|
|
12
|
-
${
|
|
13
|
-
`}${n}`}const q=()=>{},ut={debug:q,info:q,warn:q,error:q},dt={debug:console.debug,info:console.info,warn:console.warn,error:console.error},nt=()=>ut,ft=()=>dt,I=e=>{const t={},n=e.slice(1,-1).trim(),o=n.match(/\.([a-zA-Z0-9_-]+)/g);if(o){const h=o.map(f=>f.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[f,p]=h.split("=");f&&p&&f!=="class"&&f!=="id"&&(t[f]=p.replace(/["']/g,""))}return t},pt=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})},mt=()=>e=>{M.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(),f=a[2],p=I(f);r.value=h,P(t,p)}}}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(),f=a[2],p=I(f);r.value=h,P(t,p)}}}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],f=I(h);P(t,f),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],f=I(h);P(t,f),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 f=h[1].trim(),p=h[2],c=I(p);a.value=f,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 h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const f=h[1],p=I(f);P(t,p),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 f=h[1].trim(),p=h[2],c=I(p);a.value=f,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 h=a.value.match(/^\s*(\{[^}]+\})\s*$/);if(h){const f=h[1],p=I(f);P(t,p),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],f=I(h);P(t,f),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=I(a),f={type:"html",value:`<div class="${h.class||""}" ${Object.entries(h).filter(([p])=>p!=="class").map(([p,c])=>`${p}="${c}"`).join(" ")}>${pt(t)}</div>`};o&&typeof n=="number"&&(o.children[n]=f),t.meta=t.meta.replace(r[0],"").trim()||null}}})},yt=()=>e=>{M.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}})},D=e=>e?"value"in e&&typeof e.value=="string"?e.value:"children"in e&&Array.isArray(e.children)?e.children.map(t=>D(t)).join(""):"":"",gt=e=>{const{frontmatter:t,hasTitle:n,allowTitleWrite:o,onHeadingApplied:r}=e;return a=>{if(!t||!a.children||a.children.length===0)return;let h=0;for(;h<a.children.length;h++){const f=a.children[h];if(f.type==="heading"&&f.depth===1){const p=f,c=a.children[h+1],i=c&&c.position?c.position.start?.offset:void 0,l=D(p).trim();a.children.splice(h,1);let s=!1;!n&&o&&l.length>0&&(t.title=l,s=!0),r&&r({headingText:l,position:p.position,nextNodeStartOffset:i,titleWritten:s});break}if(!(f.type==="thematicBreak"||f.type==="html"&&typeof f.value=="string"&&f.value.trim()==="")&&!(f.type==="paragraph"&&f.children?.length===0))break}}},Y=(e,t,n)=>{const o=t!=null&&Object.prototype.hasOwnProperty.call(t,"title")&&t.title!==void 0&&t.title!==null;let r=!1,a=!1,h,f;const p=rt.unified().use(et).use(gt,{frontmatter:t,hasTitle:o,allowTitleWrite:n.allowTitleWrite,onHeadingApplied:i=>{r=!0,a=i.titleWritten;const l=i.position?.start?.offset??0;let s=i.position?.end?.offset??l;typeof i.nextNodeStartOffset=="number"&&i.nextNodeStartOffset>=s?s=i.nextNodeStartOffset:s=e.length,h=l,f=s}}),c=p.parse(e);return p.runSync(c),r&&h!==void 0&&f!==void 0?{content:e.slice(0,h)+e.slice(f),headingRemoved:!0,titleWritten:a}:{content:e,headingRemoved:!1,titleWritten:!1}},{html:wt}=ot,at={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=e=>{if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(J);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]=J(r);return n}return e},U=e=>JSON.stringify(J(e??{})),vt=(e,t)=>`${e}-${t.join("-")}`,bt=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},Z=(e,t,n)=>{const o=E.generateHeadingId(t);return o!==void 0?`${e}-${o}`:n()},Et=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},kt=e=>{const{plugins:t=[],logger:n=nt(),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,d)=>{const m=r.get(s);return m?await m.processBlock(u,d):`<pre><code class="language-${s}">${E.escapeHtml(u)}</code></pre>`},h=(s,u,d)=>{const m={logger:n,signal:u,frontmatter:s,getUniqueId:d,fetcher:o};return()=>async y=>{const w=[];M.visit(y,"code",(g,v,x)=>{if(!g.lang||!r.has(g.lang))return;const $=(async()=>{const b={type:"html",value:await a(g.lang,g.value,m)};x&&typeof v=="number"&&(x.children[v]=b)})();w.push($)}),await Promise.all(w)}},f=(s,u,d=!1,m=!1,y="")=>()=>w=>{const g=[],v=[];M.visit(w,"heading",b=>{b.depth>=1&&b.depth<=6&&v.push(b)});let x=[];if(d){const b=v.map(N=>({level:N.depth,text:D(N)}));x=bt(b)}const $=[];v.forEach((b,N)=>{const O=D(b),T=b.data?.hProperties?.id;let S;if(T)S=T;else if(d&&m){const L=Z(y,O,()=>u(O)).replace(`${y}-`,"");for(;$.length>0;){const k=$[$.length-1];if(k&&k.level>=b.depth)$.pop();else break}const R=$.map(k=>k.contentId);S=R.length>0?`${y}-${R.join("-")}-${L}`:`${y}-${L}`,$.push({level:b.depth,contentId:L})}else if(d&&N<x.length){const L=x[N];L?S=vt(y,L.numbers):S=u(O)}else S=u(O);b.data||(b.data={}),b.data.hProperties||(b.data.hProperties={}),T||(b.data.hProperties.id=S),g.push({level:b.depth,text:O,id:S})});const H=Et(g);s.push(...H)},p=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,d,m,y,w)=>{const{signal:g,useContentStringHeaderId:v=!1,useHierarchicalHeadingId:x=!0,advancedOptions:$}=d??{},{allowDangerousHtml:H=!0,htmlOptions:b=at,gfmOptions:N={},remarkPlugins:O=[],rehypePlugins:T=[]}=$||{},S=[];let L=0;const R=()=>`${u}-${++L}`;let F=rt.unified().use(et);if(O)for(const C of O)Array.isArray(C)?F=F.use(C[0],C[1]):F=F.use(C);let k=F.use(it,N).use(mt).use(f(S,v?C=>Z(u,C,R):R,x,v,u)).use(h(m,g,R)).use(lt,{allowDangerousHtml:H}).use(yt).use(ct,{allowDangerousHtml:H});if(T)for(const C of T)Array.isArray(C)?k=k.use(C[0],C[1]):k=k.use(C);const K=await k.process(y),_=String(K);return{html:wt(_,b),frontmatter:m,changed:w,headingTree:S,composeMarkdown:()=>w?Q(m,y):s,uniqueIdPrefix:u}};return{process:async(s,u,d={})=>{try{const{data:m,content:y}=V(s),w=d.applyTitleFromH1??!0;let g=y,v=!1,x=!1;if(w){const H=Y(g,m,{allowTitleWrite:!0});g=H.content,v=H.headingRemoved,x=H.titleWritten}return await c(s,u,d,m,g,v||x)}catch(m){return p(m)}},processWithFrontmatterTransform:async(s,u,d,m,y={})=>{try{const{data:w,content:g}=V(s),v=U(w),$=d({originalFrontmatter:w,markdownContent:g,uniqueIdPrefix:u});if($===void 0)return;const{frontmatter:H,uniqueIdPrefix:b}=$,N=b??u,O=y.applyTitleFromH1??!0;let T=g,S=!1;if(O){const A=Y(T,H,{allowTitleWrite:!0});T=A.content,S=A.headingRemoved||S}const R=U(H)!==v||S,F=await c(s,N,y,H,T,R);let k=F.frontmatter;if(m){const A={frontmatter:k,headingTree:F.headingTree};k=m(A)}const _=U(k)!==v||S,G=()=>_?Q(k,T):s;return{html:F.html,frontmatter:k,changed:_,headingTree:F.headingTree,composeMarkdown:G,uniqueIdPrefix:F.uniqueIdPrefix}}catch(w){return p(w)}}}},St=(e,t={})=>{const{maxRedirects:n=5,timeoutEachRedirect:o=1e4}=t;return{name:"oembed",processBlock:async(a,h)=>{const f=a.trim();if(!E.isValidUrl(f))throw new Error(`Invalid URL: ${f}`);try{const p=await E.fetchOEmbedData(f,n,o,h,e);return E.generateHtml(p,f,t)}catch(p){h.logger.warn("oEmbed fetch failed for URL:",f,p);const c=E.formatErrorInfo(p);return E.generateFallbackHtml(f,c)}}}},$t=(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 h=E.formatErrorInfo(a);return E.generateFallbackHtml$1(r,h)}}}),xt=(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 i=n?` id="${a.getUniqueId()}"`:"";return`<div class="${t}-wrapper">
|
|
8
|
+
* git.commit.hash: a57a326430fda951da873116177f76aa783d4413
|
|
9
|
+
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("js-beautify"),ie=require("rehype-stringify"),le=require("remark-gfm"),re=require("remark-parse"),he=require("remark-rehype"),ne=require("unified"),M=require("unist-util-visit"),z=require("js-yaml"),b=require("./internal-BYxuN1cP.cjs");function V(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=z.load(s,{schema:z.JSON_SCHEMA});return{data:o&&typeof o=="object"&&!Array.isArray(o)?o:{},content:r}}catch(o){const f=o instanceof Error?o.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${f}`)}}function de(t){if(!t||Object.keys(t).length===0)return"";const e=z.dump(t,{lineWidth:0});return typeof e!="string"||e.length===0?"":e.endsWith(`
|
|
10
|
+
`)?e:`${e}
|
|
11
|
+
`}function Q(t,e){const n=e??"";return`${`---
|
|
12
|
+
${de(t)}---
|
|
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">
|
|
14
14
|
<style>
|
|
15
|
-
.${
|
|
15
|
+
.${e}-wrapper .${e} > svg {
|
|
16
16
|
width: auto !important;
|
|
17
17
|
height: auto !important;
|
|
18
18
|
max-width: none !important;
|
|
19
19
|
}
|
|
20
20
|
</style>
|
|
21
|
-
<div class="${
|
|
22
|
-
</div>`}const
|
|
21
|
+
<div class="${e}"${l}><!-- Empty mermaid content --></div>
|
|
22
|
+
</div>`}const p=n?` id="${o.getUniqueId()}"`:"",u=f.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;
|
|
26
26
|
height: auto !important;
|
|
27
27
|
max-width: none !important;
|
|
28
28
|
}
|
|
29
29
|
</style>
|
|
30
|
-
<div class="${
|
|
31
|
-
</div>`;return
|
|
30
|
+
<div class="${e}"${p}>${u}</div>
|
|
31
|
+
</div>`;return o.logger.debug("Mermaid plugin processed content:",{contentLength:f.length,className:e,includeId:n}),c}}};/*!
|
|
32
32
|
* name: async-primitives
|
|
33
|
-
* version: 1.
|
|
33
|
+
* version: 1.5.0
|
|
34
34
|
* description: A collection of primitive functions for asynchronous operations
|
|
35
35
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
36
36
|
* license: MIT
|
|
37
37
|
* repository.url: https://github.com/kekyo/async-primitives.git
|
|
38
|
-
* git.commit.hash:
|
|
39
|
-
*/const X=()=>{},
|
|
38
|
+
* git.commit.hash: cd35465b7e9b9945049186e7eaeecc0bfba65766
|
|
39
|
+
*/const X=()=>{},ee={release:X,[Symbol.dispose]:X},te=t=>t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Operation aborted"),Ce=(t,e)=>{if(!t)return ee;if(t.aborted){try{e(te(t.reason))}catch(o){console.warn("AbortHook callback error: ",o)}return ee}let n;n=()=>{if(n){const o=t.reason;t.removeEventListener("abort",n),n=void 0;try{e(te(o))}catch(f){console.warn("AbortHook callback error: ",f)}}};const s=()=>{n&&(t.removeEventListener("abort",n),n=void 0)};return t.addEventListener("abort",n,{once:!0}),{release:s,[Symbol.dispose]:s}},Fe=t=>{typeof setImmediate=="function"?setImmediate(t):setTimeout(t,0)},W=()=>new Error("Lock acquisition was aborted"),Te=t=>{let e=!0;const n=()=>{e&&(e=!1,t())};return{get isActive(){return e},release:n,[Symbol.dispose]:n}},B=(t=20)=>{let e=!1;const n=[];let s=0;const r=()=>{var l;if(e||n.length===0)return;const i=n.shift();if((l=i.signal)!=null&&l.aborted){i.reject(W()),o();return}e=!0;const a=Te(f);i.resolve(a)},o=()=>{s++,s>=t?(s=0,Fe(r)):r()},f=()=>{e&&(e=!1,o())},p=l=>{const i=n.indexOf(l);i!==-1&&n.splice(i,1)},u=async l=>{if(l){if(l.aborted)throw W();return new Promise((i,a)=>{const h={resolve:void 0,reject:void 0,signal:l},d=Ce(l,()=>{p(h),a(W())});h.resolve=m=>{d.release(),i(m)},h.reject=m=>{d.release(),a(m)},n.push(h),r()})}else return new Promise((i,a)=>{n.push({resolve:i,reject:a}),r()})};return{lock:u,waiter:{wait:u},get isLocked(){return e},get pendingCount(){return n.length}}},Oe=(t="cache:")=>{const e=B(),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(),l=[];for(let i=0;i<localStorage.length;i++){const a=localStorage.key(i);if(!a||!a.startsWith(t))continue;const h=localStorage.getItem(a);if(h)try{const d=JSON.parse(h);d.ttl!==void 0&&(d.ttl===0||c>d.timestamp+d.ttl)&&l.push(a)}catch{l.push(a)}}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=t+c,i=localStorage.getItem(l);if(!i)return null;let a;try{a=JSON.parse(i)}catch{const h=await e.lock();try{return localStorage.removeItem(l),null}finally{h.release()}}if(a.ttl!==void 0&&(a.ttl===0||Date.now()>a.timestamp+a.ttl)){const d=await e.lock();try{const m=Date.now();return(a.ttl===0||m>a.timestamp+a.ttl)&&localStorage.removeItem(l),null}finally{d.release()}}return a.data},set:async(c,l,i)=>{if(!n())throw new Error("localStorage is not available in this environment");const a=t+c,h={data:l,timestamp:Date.now()};i!==void 0&&(h.ttl=i);const d=JSON.stringify(h),m=await e.lock();try{try{localStorage.setItem(a,d)}catch(g){if(g instanceof Error&&g.name==="QuotaExceededError"){await s();try{localStorage.setItem(a,d)}catch(y){throw new Error(`Failed to store cache entry: ${y}`)}}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 l=t+c,i=await e.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 a=localStorage.key(i);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return;const l=await e.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 a=localStorage.key(i);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return 0;const l=await e.lock();try{const i=Date.now();let a=0;for(const h of c){const d=localStorage.getItem(h);if(d)try{const m=JSON.parse(d);if(m.ttl!==void 0&&(m.ttl===0||i>m.timestamp+m.ttl)){localStorage.removeItem(h);continue}a++}catch{localStorage.removeItem(h)}}return a}finally{l.release()}}}},se=()=>{const t=new Map,e=B(),n=(u=Date.now())=>{const c=[];for(const[l,i]of t.entries())i.ttl!==void 0&&(i.ttl===0||u>i.timestamp+i.ttl)&&c.push(l);for(const l of c)t.delete(l);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 i=await e.lock();try{const a=t.get(u);if(a&&a.ttl!==void 0){const h=Date.now();(a.ttl===0||h>a.timestamp+a.ttl)&&t.delete(u)}return null}finally{i.release()}}return c.data},set:async(u,c,l)=>{const i={data:c,timestamp:Date.now()};l!==void 0&&(i.ttl=l);const a=await e.lock();try{t.set(u,i)}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=B(),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 l=await n(c);try{await s()}catch(m){throw new Error(`Failed to ensure cache directory: ${m}`)}const{promises:i}=require("fs"),h=require("path").join(t,l);let d;try{const m=await i.readFile(h,"utf-8");d=JSON.parse(m)}catch{return null}if(d.ttl!==void 0&&(d.ttl===0||Date.now()>d.timestamp+d.ttl)){const g=await e.lock();try{const y=Date.now();return(d.ttl===0||y>d.timestamp+d.ttl)&&await i.unlink(h),null}catch{return null}finally{g.release()}}return d.data},set:async(c,l,i)=>{const a=await n(c),h={data:l,timestamp:Date.now()};i!==void 0&&(h.ttl=i);const d=JSON.stringify(h,null,2),m=await e.lock();try{await s();const{promises:g}=require("fs"),w=require("path").join(t,a);try{await g.writeFile(w,d,"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 l=await n(c),i=await e.lock();try{await s();const{promises:a}=require("fs"),d=require("path").join(t,l);try{await a.unlink(d)}catch{}}catch(a){throw new Error(`Failed to import required modules: ${a}`)}finally{i.release()}},clear:async()=>{const c=await e.lock();try{await s();const{promises:l}=require("fs"),i=require("path"),h=(await l.readdir(t)).filter(d=>d.endsWith(".json"));for(const d of h){const m=i.join(t,d);try{await l.unlink(m)}catch{}}}catch(l){throw new Error(`Failed to import required modules: ${l}`)}finally{c.release()}},size:async()=>{await s();const{promises:c}=require("fs"),l=require("path"),a=(await c.readdir(t)).filter(d=>d.endsWith(".json"));if(a.length===0)return 0;const h=await e.lock();try{const d=Date.now();let m=0;for(const g of a){const y=l.join(t,g);try{const w=await c.readFile(y,"utf8"),v=JSON.parse(w);if(v.ttl!==void 0&&(v.ttl===0||d>v.timestamp+v.ttl)){await c.unlink(y);continue}m++}catch{try{await c.unlink(y)}catch{}}}return m}catch(d){throw new Error(`Failed to import required modules: ${d}`)}finally{h.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:f=!0,failureCacheTTL:p=300*1e3}=s||{},u=r?n||se():void 0;return{rawFetcher:async(l,i,a,h)=>{if(r&&u){const g=j(l,i,t),y=await u.get(g);if(y)try{const w=JSON.parse(y);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"&&f)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: ${f}`)}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 d,m=null;try{d=await b.fetchData(l,i,t,e,a,h)}catch(g){if(m=g,r&&u&&f)try{const y=j(l,i,t),w={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(y,JSON.stringify(w),p),h?.debug(`Cached error for URL: ${l}`)}catch(y){h?.warn(`Failed to cache error for URL ${l}:`,y),console.warn("Failed to cache error:",y)}throw m}if(r&&u&&d.ok)try{const g=await d.clone().text(),y=j(l,i,t),w={type:"success",data:g,timestamp:Date.now()};await u.set(y,JSON.stringify(w),o),h?.debug(`Cached successful response for URL: ${l}`)}catch(g){h?.warn(`Failed to cache response for URL ${l}:`,g),console.warn("Failed to cache response:",g)}return d},userAgent:t}},Le=(t,e=6e4)=>({rawFetcher:async(s,r,o,f)=>(f?.debug(`Direct fetch for URL: ${s}`),await b.fetchData(s,r,t,e,o,f)),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=se;exports.createMermaidPlugin=He;exports.createOEmbedPlugin=$e;exports.defaultHtmlOptions=oe;exports.generateCacheKey=j;exports.getConsoleLogger=pe;exports.getNoOpLogger=ae;
|
|
40
40
|
//# sourceMappingURL=index.cjs.map
|