mark-deco 0.12.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 +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 +417 -394
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-tQkd_UGz.cjs → internal-CDWALvfx.cjs} +3 -3
- package/dist/{internal-tQkd_UGz.cjs.map → internal-CDWALvfx.cjs.map} +1 -1
- package/dist/{internal-BJiq2VBv.js → internal-CV9E6fHH.js} +3 -3
- package/dist/{internal-BJiq2VBv.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 +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 +30 -9
- 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 +9 -9
|
@@ -1,17 +1,19 @@
|
|
|
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
|
-
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.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,40 +1,40 @@
|
|
|
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
|
|
10
|
-
`)?
|
|
11
|
-
`}function
|
|
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: 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
|
+
`)?e:`${e}
|
|
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;
|
|
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}"${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;
|
|
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:d.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
|
|
38
|
+
* git.commit.hash: cd35465b7e9b9945049186e7eaeecc0bfba65766
|
|
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
|