mark-deco 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/apply-title-from-h1.d.ts +8 -6
  2. package/dist/apply-title-from-h1.d.ts.map +1 -1
  3. package/dist/cache/filesystem.d.ts +2 -2
  4. package/dist/cache/index.d.ts +2 -2
  5. package/dist/cache/localstorage.d.ts +2 -2
  6. package/dist/cache/memory.d.ts +2 -2
  7. package/dist/fetcher.d.ts +2 -2
  8. package/dist/frontmatter.d.ts +2 -2
  9. package/dist/index.cjs +11 -11
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.mjs +766 -735
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/{internal-CDWALvfx.cjs → internal-B9A_9mrC.cjs} +3 -3
  16. package/dist/{internal-CDWALvfx.cjs.map → internal-B9A_9mrC.cjs.map} +1 -1
  17. package/dist/{internal-CV9E6fHH.js → internal-CyLf29uZ.js} +3 -3
  18. package/dist/{internal-CV9E6fHH.js.map → internal-CyLf29uZ.js.map} +1 -1
  19. package/dist/internal.cjs +3 -3
  20. package/dist/internal.d.ts +2 -2
  21. package/dist/internal.mjs +3 -3
  22. package/dist/logger.d.ts +2 -2
  23. package/dist/plugins/card/amazon-rules.d.ts +2 -2
  24. package/dist/plugins/card/fetcher.d.ts +2 -2
  25. package/dist/plugins/card/html-generator.d.ts +2 -2
  26. package/dist/plugins/card/index.d.ts +2 -2
  27. package/dist/plugins/card/ogp-rules.d.ts +2 -2
  28. package/dist/plugins/card/rule-engine.d.ts +2 -2
  29. package/dist/plugins/card/types.d.ts +2 -2
  30. package/dist/plugins/card/utils.d.ts +2 -2
  31. package/dist/plugins/card-plugin.d.ts +2 -2
  32. package/dist/plugins/mermaid/index.d.ts +2 -2
  33. package/dist/plugins/mermaid/types.d.ts +2 -2
  34. package/dist/plugins/mermaid-plugin.d.ts +2 -2
  35. package/dist/plugins/oembed/fetcher.d.ts +2 -2
  36. package/dist/plugins/oembed/html-generator.d.ts +2 -2
  37. package/dist/plugins/oembed/index.d.ts +2 -2
  38. package/dist/plugins/oembed/providers.d.ts +2 -2
  39. package/dist/plugins/oembed/providers.json.d.ts +2 -2
  40. package/dist/plugins/oembed/redirect-resolver.d.ts +2 -2
  41. package/dist/plugins/oembed/types.d.ts +2 -2
  42. package/dist/plugins/oembed/utils.d.ts +2 -2
  43. package/dist/plugins/oembed-plugin.d.ts +2 -2
  44. package/dist/plugins/remark-apply-title-from-h1.d.ts +8 -6
  45. package/dist/plugins/remark-apply-title-from-h1.d.ts.map +1 -1
  46. package/dist/plugins/remark-attr.d.ts +2 -2
  47. package/dist/plugins/responsive-images.d.ts +2 -2
  48. package/dist/plugins/shared/error-formatter.d.ts +2 -2
  49. package/dist/processor.d.ts +2 -2
  50. package/dist/processor.d.ts.map +1 -1
  51. package/dist/types.d.ts +14 -8
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/utils/heading.d.ts +10 -2
  54. package/dist/utils/heading.d.ts.map +1 -1
  55. package/dist/utils/responsive-image.d.ts +2 -2
  56. package/dist/utils.d.ts +2 -2
  57. package/package.json +10 -9
@@ -1,19 +1,21 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
- import { FrontmatterData, H1TitleTransform } from './types.js';
11
+ import { FrontmatterData, HeaderTitleTransform } 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
+ /** How to treat the first base-level heading */
16
+ readonly transform: HeaderTitleTransform;
17
+ /** Base heading level for markdown headings (default: 1) */
18
+ readonly headingBaseLevel: number;
17
19
  }
18
20
  export interface ApplyTitleResult {
19
21
  readonly content: string;
@@ -21,7 +23,7 @@ export interface ApplyTitleResult {
21
23
  readonly titleWritten: boolean;
22
24
  }
23
25
  /**
24
- * Apply the leading H1 heading to frontmatter.title and optionally remove it from the markdown content
26
+ * Apply the leading base-level heading to frontmatter.title and optionally remove it from the markdown content
25
27
  */
26
28
  export declare const applyTitleFromH1: (markdownContent: string, frontmatter: FrontmatterData, options: ApplyTitleOptions) => ApplyTitleResult;
27
29
  //# 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,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
+ {"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,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IACzC,4DAA4D;IAC5D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;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,gBA8EF,CAAC"}
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
11
  /**
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
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.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
11
  import { CacheStorage } from './cache/index.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 090ae78518ae17207fdb90e6fca59893315672fb
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
9
  */
10
10
 
11
11
  import { FrontmatterData } from './types.js';
package/dist/index.cjs CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";/*!
2
2
  * name: mark-deco
3
- * version: 0.14.0
3
+ * version: 0.15.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: 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(`
8
+ * git.commit.hash: e293e83ab3b88ab4bc77b92c51ee38275f33c948
9
+ */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=require("js-beautify"),fe=require("rehype-stringify"),ue=require("remark-gfm"),se=require("remark-parse"),pe=require("remark-rehype"),oe=require("unified"),W=require("unist-util-visit"),G=require("js-yaml"),E=require("./internal-B9A_9mrC.cjs");function Z(t){const e=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,n=t.match(e);if(!n)return{data:{},content:t};const o=n[1]||"",r=t.slice(n[0].length);try{const s=G.load(o,{schema:G.JSON_SCHEMA});return{data:s&&typeof s=="object"&&!Array.isArray(s)?s:{},content:r}}catch(s){const d=s instanceof Error?s.message:"Unknown YAML parsing error";throw new Error(`Failed to parse frontmatter YAML: ${d}`)}}function me(t){if(!t||Object.keys(t).length===0)return"";const e=G.dump(t,{lineWidth:0});return typeof e!="string"||e.length===0?"":e.endsWith(`
10
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");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">
11
+ `}function X(t,e){const n=e??"";return`${`---
12
+ ${me(t)}---
13
+ `}${n}`}const D=()=>{},ge={debug:D,info:D,warn:D,error:D},ye={debug:console.debug,info:console.info,warn:console.warn,error:console.error},ie=()=>ge,we=()=>ye,R=t=>{const e={},n=t.slice(1,-1).trim(),o=n.match(/\.([a-zA-Z0-9_-]+)/g);if(o){const d=o.map(m=>m.slice(1));e.class=d.join(" ")}const r=n.match(/#([a-zA-Z0-9_-]+)/);r&&r[1]&&(e.id=r[1]);const s=n.match(/([a-zA-Z0-9_-]+)=["']?([^"'\s]*)["']?/g);if(s)for(const d of s){const[m,u]=d.split("=");m&&u&&m!=="class"&&m!=="id"&&(e[m]=u.replace(/["']/g,""))}return e},ve=t=>{const e=t.lang?` class="language-${t.lang}"`:"",n=t.value.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return`<pre><code${e}>${n}</code></pre>`},A=(t,e)=>{t.data||(t.data={}),t.data.hProperties||(t.data.hProperties={}),Object.entries(e).forEach(([n,o])=>{if(n==="class"){const r=t.data.hProperties.class;r?typeof r=="string"&&r.startsWith("language-")?t.data.hProperties.class=`${r} ${o}`:t.data.hProperties.class=`${r} ${o}`:t.data.hProperties.class=o}else t.data.hProperties[n]=o})},be=()=>t=>{W.visit(t,(e,n,o)=>{if(e.type==="heading"&&e.children?.length>0){const r=e.children[e.children.length-1];if(r?.type==="text"&&r.value){const s=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(s){const d=s[1].trim(),m=s[2],u=R(m);r.value=d,A(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 s=r.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(s){const d=s[1].trim(),m=s[2],u=R(m);r.value=d,A(e,u)}}}if(e.type==="link"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const s=r.value.match(/^\s*(\{[^}]+\})/);if(s){const d=s[1],m=R(d);A(e,m),r.value=r.value.replace(s[0],"")}}}if(e.type==="image"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const s=r.value.match(/^\s*(\{[^}]+\})/);if(s){const d=s[1],m=R(d);A(e,m),r.value=r.value.replace(s[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 s=r.children[r.children.length-1];if(s?.type==="text"&&s.value){const d=s.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(d){const m=d[1].trim(),u=d[2],c=R(u);s.value=m,A(e,c)}}}}if(e.type==="list"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const s=r.children[0];if(s?.type==="text"&&s.value){const d=s.value.match(/^\s*(\{[^}]+\})\s*$/);if(d){const m=d[1],u=R(m);A(e,u),o.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 s=r.children[r.children.length-1];if(s?.type==="text"&&s.value){const d=s.value.match(/^(.*?)\s*(\{[^}]+\})\s*$/);if(d){const m=d[1].trim(),u=d[2],c=R(u);s.value=m,A(e,c)}}}}if(e.type==="blockquote"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="paragraph"&&r.children?.length===1){const s=r.children[0];if(s?.type==="text"&&s.value){const d=s.value.match(/^\s*(\{[^}]+\})\s*$/);if(d){const m=d[1],u=R(m);A(e,u),o.children.splice(n+1,1)}}}}if(e.type==="inlineCode"&&o&&typeof n=="number"){const r=o.children[n+1];if(r?.type==="text"&&r.value){const s=r.value.match(/^\s*(\{[^}]+\})/);if(s){const d=s[1],m=R(d);A(e,m),r.value=r.value.replace(s[0],"")}}}if(e.type==="code"&&e.meta){const r=e.meta.match(/\{([^}]+)\}/);if(r){const s=`{${r[1]}}`,d=R(s),m={type:"html",value:`<div class="${d.class||""}" ${Object.entries(d).filter(([u])=>u!=="class").map(([u,c])=>`${u}="${c}"`).join(" ")}>${ve(e)}</div>`};o&&typeof n=="number"&&(o.children[n]=m),e.meta=e.meta.replace(r[0],"").trim()||null}}})},Ee=()=>t=>{W.visit(t,"element",e=>{if(e.tagName==="img"){const n=E.generateResponsiveImageStyles();e.properties||(e.properties={});const o=e.properties.style||"",r=o?`${o}; ${n}`:n;e.properties.style=r}})},z=t=>t?"value"in t&&typeof t.value=="string"?t.value:"children"in t&&Array.isArray(t.children)?t.children.map(e=>z(e)).join(""):"":"",Q=t=>{if(!Number.isFinite(t))return 1;const e=Math.trunc(t);return Math.min(6,Math.max(1,e))},j=t=>Q(t??1),ke=t=>{const{frontmatter:e,hasTitle:n,transform:o,allowTitleWrite:r,headingBaseLevel:s,onHeadingApplied:d}=t,m=o==="extractAndRemove",u=j(s),c=u-1;return l=>{if(!e||!l.children||l.children.length===0)return;let h=0;for(;h<l.children.length;h++){const a=l.children[h];if(a.type==="heading"){const i=a;if(Q(i.depth+c)!==u)break;const p=l.children[h+1],g=p&&p.position?p.position.start?.offset:void 0,y=z(i).trim();m&&l.children.splice(h,1);let w=!1;!n&&r&&y.length>0&&(e.title=y,w=!0),d&&d({headingText:y,position:i.position,nextNodeStartOffset:g,titleWritten:w,headingRemoved:m});break}if(!(a.type==="thematicBreak"||a.type==="html"&&typeof a.value=="string"&&a.value.trim()==="")&&!(a.type==="paragraph"&&a.children?.length===0))break}}},ee=(t,e,n)=>{const{transform:o,allowTitleWrite:r,headingBaseLevel:s}=n;if(o==="none")return{content:t,headingRemoved:!1,titleWritten:!1};const d=e!=null&&Object.prototype.hasOwnProperty.call(e,"title")&&e.title!==void 0&&e.title!==null;let m=!1,u=!1,c,l;const h=oe.unified().use(se).use(ke,{frontmatter:e,hasTitle:d,transform:o,allowTitleWrite:r,headingBaseLevel:s,onHeadingApplied:i=>{if(m=i.headingRemoved,u=i.titleWritten,!i.headingRemoved)return;const f=i.position?.start?.offset??0;let p=i.position?.end?.offset??f;typeof i.nextNodeStartOffset=="number"&&i.nextNodeStartOffset>=p?p=i.nextNodeStartOffset:p=t.length,c=f,l=p}}),a=h.parse(t);return h.runSync(a),m&&c!==void 0&&l!==void 0?{content:t.slice(0,c)+t.slice(l),headingRemoved:!0,titleWritten:u}:{content:t,headingRemoved:!1,titleWritten:!1}},{html:Se}=de,ce={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:[]},V=t=>{if(t instanceof Date)return t.toISOString();if(Array.isArray(t))return t.map(V);if(t&&typeof t=="object"){const e=Object.entries(t).filter(([,o])=>o!==void 0).sort(([o],[r])=>o<r?-1:o>r?1:0),n={};for(const[o,r]of e)n[o]=V(r);return n}return t},J=t=>JSON.stringify(V(t??{})),$e=(t,e)=>`${t}-${e.join("-")}`,xe=(t,e)=>{const n=[],o=[],r=j(e);for(const s of t){const d=Math.max(1,s.level-r+1);for(;o.length>d;)o.pop();for(;o.length<d;)o.push(0);const m=d-1;o[m]=(o[m]||0)+1;const u=o.slice(0,d);n.push({level:s.level,text:s.text,numbers:u})}return n},te=(t,e,n)=>{const o=E.generateHeadingId(e);return o!==void 0?`${t}-${o}`:n()},He=t=>{const e=[],n=[];for(const o of t){const r={level:o.level,text:o.text,id:o.id,children:[]};for(;n.length>0;){const s=n[n.length-1];if(s&&s.level>=o.level)n.pop();else break}if(n.length===0)e.push(r);else{const s=n[n.length-1];s&&s.children.push(r)}n.push(r)}return e},Le=t=>{const{plugins:e=[],logger:n=ie(),fetcher:o}=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 s=async(a,i,f)=>{const p=r.get(a);return p?await p.processBlock(i,f):`<pre><code class="language-${a}">${E.escapeHtml(i)}</code></pre>`},d=(a,i,f)=>{const p={logger:n,signal:i,frontmatter:a,getUniqueId:f,fetcher:o};return()=>async g=>{const y=[];W.visit(g,"code",(w,b,S)=>{if(!w.lang||!r.has(w.lang))return;const O=(async()=>{const C={type:"html",value:await s(w.lang,w.value,p)};S&&typeof b=="number"&&(S.children[b]=C)})();y.push(O)}),await Promise.all(y)}},m=(a,i,f=!1,p=!1,g="",y=1)=>()=>w=>{const b=[],S=j(y),O=S-1,_=v=>Q(v+O),C=[];W.visit(w,"heading",v=>{if(v.depth>=1&&v.depth<=6){const L=_(v.depth);v.data||(v.data={}),v.data.hName=`h${L}`,C.push({node:v,level:L})}});let $=[];if(f){const v=C.map(({node:L,level:N})=>({level:N,text:z(L)}));$=xe(v,S)}const F=[];C.forEach(({node:v,level:L},N)=>{const P=z(v),x=v.data?.hProperties?.id;let k;if(x)k=x;else if(f&&p){const H=te(g,P,()=>i(P)).replace(`${g}-`,"");for(;F.length>0;){const I=F[F.length-1];if(I&&I.level>=L)F.pop();else break}const M=F.map(I=>I.contentId);k=M.length>0?`${g}-${M.join("-")}-${H}`:`${g}-${H}`,F.push({level:L,contentId:H})}else if(f&&N<$.length){const H=$[N];H?k=$e(g,H.numbers):k=i(P)}else k=i(P);v.data||(v.data={}),v.data.hProperties||(v.data.hProperties={}),x||(v.data.hProperties.id=k),b.push({level:L,text:P,id:k})});const q=He(b);a.push(...q)},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,i,f,p,g,y)=>{const{signal:w,useContentStringHeaderId:b=!1,useHierarchicalHeadingId:S=!0,headingBaseLevel:O,advancedOptions:_}=f??{},C=j(O),{allowDangerousHtml:$=!0,htmlOptions:F=ce,gfmOptions:q={},remarkPlugins:v=[],rehypePlugins:L=[]}=_||{},N=[];let P=0;const x=()=>`${i}-${++P}`;let k=oe.unified().use(se);if(v)for(const T of v)Array.isArray(T)?k=k.use(T[0],T[1]):k=k.use(T);let H=k.use(ue,q).use(be).use(m(N,b?T=>te(i,T,x):x,S,b,i,C)).use(d(p,w,x)).use(pe,{allowDangerousHtml:$}).use(Ee).use(fe,{allowDangerousHtml:$});if(L)for(const T of L)Array.isArray(T)?H=H.use(T[0],T[1]):H=H.use(T);const M=await H.process(g),B=String(M);return{html:Se(B,F),frontmatter:p,changed:y,headingTree:N,composeMarkdown:()=>y?X(p,g):a,uniqueIdPrefix:i}};return{process:async(a,i,f={})=>{try{const{data:p,content:g}=Z(a),y=j(f.headingBaseLevel),w=f.headerTitleTransform??"extractAndRemove";let b=g,S=!1,O=!1;if(w!=="none"){const $=ee(b,p,{allowTitleWrite:!0,transform:w,headingBaseLevel:y});b=$.content,S=$.headingRemoved,O=$.titleWritten}const _=S||O,C={...f,headingBaseLevel:y};return await c(a,i,C,p,b,_)}catch(p){return u(p)}},processWithFrontmatterTransform:async(a,i,f)=>{try{const{data:p,content:g}=Z(a),y=J(p),w={originalFrontmatter:p,markdownContent:g,uniqueIdPrefix:i},b=await f.preTransform(w);if(b===void 0)return;const{frontmatter:S,uniqueIdPrefix:O,headerTitleTransform:_}=b,C=O??i,$=j(f.headingBaseLevel),F=_??"extractAndRemove";let q=g,v=!1;if(F!=="none"){const I=ee(q,S,{allowTitleWrite:!0,transform:F,headingBaseLevel:$});q=I.content,v=I.headingRemoved||v}const N=J(S)!==y||v,P={...f,headingBaseLevel:$},x=await c(a,C,P,S,q,N);let k=x.frontmatter;if(f.postTransform){const I={frontmatter:k,headingTree:x.headingTree};k=await f.postTransform(I)}const M=J(k)!==y||v,B=()=>M?X(k,q):a;return{html:x.html,frontmatter:k,changed:M,headingTree:x.headingTree,composeMarkdown:B,uniqueIdPrefix:x.uniqueIdPrefix}}catch(p){return u(p)}}}},Te=(t,e={})=>{const{maxRedirects:n=5,timeoutEachRedirect:o=1e4}=e;return{name:"oembed",processBlock:async(s,d)=>{const m=s.trim();if(!E.isValidUrl(m))throw new Error(`Invalid URL: ${m}`);try{const u=await E.fetchOEmbedData(m,n,o,d,t);return E.generateHtml(u,m,e)}catch(u){d.logger.warn("oEmbed fetch failed for URL:",m,u);const c=E.formatErrorInfo(u);return E.generateFallbackHtml(m,c)}}}},Ce=(t={})=>({name:"card",processBlock:async(n,o)=>{const r=n.trim();if(!E.isValidUrl$1(r))throw new Error(`Invalid URL: ${r}`);try{const s=await E.fetchMetadata(r,t,o);return E.generateCardHtml(s,r,t)}catch(s){o.logger.warn("Card plugin fetch failed for URL:",r,s);const d=E.formatErrorInfo(s);return E.generateFallbackHtml$1(r,d)}}}),Fe=(t={})=>{const{className:e="mermaid",includeId:n=!0}=t;return{name:"mermaid",processBlock:async(r,s)=>{const d=r.trim();if(!d){s.logger.warn("Mermaid plugin received empty content");const l=n?` id="${s.getUniqueId()}"`:"";return`<div class="${e}-wrapper">
14
14
  <style>
15
15
  .${e}-wrapper .${e} > svg {
16
16
  width: auto !important;
@@ -18,8 +18,8 @@ ${fe(t)}---
18
18
  max-width: none !important;
19
19
  }
20
20
  </style>
21
- <div class="${e}"${h}><!-- Empty mermaid content --></div>
22
- </div>`}const p=n?` id="${o.getUniqueId()}"`:"",u=d.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),c=`<div class="${e}-wrapper">
21
+ <div class="${e}"${l}><!-- Empty mermaid content --></div>
22
+ </div>`}const m=n?` id="${s.getUniqueId()}"`:"",u=d.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),c=`<div class="${e}-wrapper">
23
23
  <style>
24
24
  .${e}-wrapper .${e} > svg {
25
25
  width: auto !important;
@@ -27,8 +27,8 @@ ${fe(t)}---
27
27
  max-width: none !important;
28
28
  }
29
29
  </style>
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}}};/*!
30
+ <div class="${e}"${m}>${u}</div>
31
+ </div>`;return s.logger.debug("Mermaid plugin processed content:",{contentLength:d.length,className:e,includeId:n}),c}}};/*!
32
32
  * name: async-primitives
33
33
  * version: 1.5.0
34
34
  * description: A collection of primitive functions for asynchronous operations
@@ -36,5 +36,5 @@ ${fe(t)}---
36
36
  * license: MIT
37
37
  * repository.url: https://github.com/kekyo/async-primitives.git
38
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;
39
+ */const re=()=>{},ne={release:re,[Symbol.dispose]:re},ae=t=>t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Operation aborted"),Oe=(t,e)=>{if(!t)return ne;if(t.aborted){try{e(ae(t.reason))}catch(s){console.warn("AbortHook callback error: ",s)}return ne}let n;n=()=>{if(n){const s=t.reason;t.removeEventListener("abort",n),n=void 0;try{e(ae(s))}catch(d){console.warn("AbortHook callback error: ",d)}}};const o=()=>{n&&(t.removeEventListener("abort",n),n=void 0)};return t.addEventListener("abort",n,{once:!0}),{release:o,[Symbol.dispose]:o}},Ie=t=>{typeof setImmediate=="function"?setImmediate(t):setTimeout(t,0)},K=()=>new Error("Lock acquisition was aborted"),Re=t=>{let e=!0;const n=()=>{e&&(e=!1,t())};return{get isActive(){return e},release:n,[Symbol.dispose]:n}},Y=(t=20)=>{let e=!1;const n=[];let o=0;const r=()=>{var l;if(e||n.length===0)return;const h=n.shift();if((l=h.signal)!=null&&l.aborted){h.reject(K()),s();return}e=!0;const a=Re(d);h.resolve(a)},s=()=>{o++,o>=t?(o=0,Ie(r)):r()},d=()=>{e&&(e=!1,s())},m=l=>{const h=n.indexOf(l);h!==-1&&n.splice(h,1)},u=async l=>{if(l){if(l.aborted)throw K();return new Promise((h,a)=>{const i={resolve:void 0,reject:void 0,signal:l},f=Oe(l,()=>{m(i),a(K())});i.resolve=p=>{f.release(),h(p)},i.reject=p=>{f.release(),a(p)},n.push(i),r()})}else return new Promise((h,a)=>{n.push({resolve:h,reject:a}),r()})};return{lock:u,waiter:{wait:u},get isLocked(){return e},get pendingCount(){return n.length}}},Ne=(t="cache:")=>{const e=Y(),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 h=0;h<localStorage.length;h++){const a=localStorage.key(h);if(!a||!a.startsWith(t))continue;const i=localStorage.getItem(a);if(i)try{const f=JSON.parse(i);f.ttl!==void 0&&(f.ttl===0||c>f.timestamp+f.ttl)&&l.push(a)}catch{l.push(a)}}for(const h of l)localStorage.removeItem(h)};return{get:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const l=t+c,h=localStorage.getItem(l);if(!h)return null;let a;try{a=JSON.parse(h)}catch{const i=await e.lock();try{return localStorage.removeItem(l),null}finally{i.release()}}if(a.ttl!==void 0&&(a.ttl===0||Date.now()>a.timestamp+a.ttl)){const f=await e.lock();try{const p=Date.now();return(a.ttl===0||p>a.timestamp+a.ttl)&&localStorage.removeItem(l),null}finally{f.release()}}return a.data},set:async(c,l,h)=>{if(!n())throw new Error("localStorage is not available in this environment");const a=t+c,i={data:l,timestamp:Date.now()};h!==void 0&&(i.ttl=h);const f=JSON.stringify(i),p=await e.lock();try{try{localStorage.setItem(a,f)}catch(g){if(g instanceof Error&&g.name==="QuotaExceededError"){await o();try{localStorage.setItem(a,f)}catch(y){throw new Error(`Failed to store cache entry: ${y}`)}}else throw new Error(`Failed to store cache entry: ${g}`)}}finally{p.release()}},delete:async c=>{if(!n())throw new Error("localStorage is not available in this environment");const l=t+c,h=await e.lock();try{localStorage.removeItem(l)}finally{h.release()}},clear:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let h=0;h<localStorage.length;h++){const a=localStorage.key(h);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return;const l=await e.lock();try{for(const h of c)localStorage.removeItem(h)}finally{l.release()}},size:async()=>{if(!n())throw new Error("localStorage is not available in this environment");const c=[];for(let h=0;h<localStorage.length;h++){const a=localStorage.key(h);a&&a.startsWith(t)&&c.push(a)}if(c.length===0)return 0;const l=await e.lock();try{const h=Date.now();let a=0;for(const i of c){const f=localStorage.getItem(i);if(f)try{const p=JSON.parse(f);if(p.ttl!==void 0&&(p.ttl===0||h>p.timestamp+p.ttl)){localStorage.removeItem(i);continue}a++}catch{localStorage.removeItem(i)}}return a}finally{l.release()}}}},le=()=>{const t=new Map,e=Y(),n=(u=Date.now())=>{const c=[];for(const[l,h]of t.entries())h.ttl!==void 0&&(h.ttl===0||u>h.timestamp+h.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 h=await e.lock();try{const a=t.get(u);if(a&&a.ttl!==void 0){const i=Date.now();(a.ttl===0||i>a.timestamp+a.ttl)&&t.delete(u)}return null}finally{h.release()}}return c.data},set:async(u,c,l)=>{const h={data:c,timestamp:Date.now()};l!==void 0&&(h.ttl=l);const a=await e.lock();try{t.set(u,h)}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()}}}},Pe=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}`)}},Ae=t=>{if(typeof window<"u")throw new Error("File system cache is only available in Node.js environment, not in browsers");const e=Y(),n=async c=>`${await Pe(c)}.json`,o=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 o()}catch(p){throw new Error(`Failed to ensure cache directory: ${p}`)}const{promises:h}=require("fs"),i=require("path").join(t,l);let f;try{const p=await h.readFile(i,"utf-8");f=JSON.parse(p)}catch{return null}if(f.ttl!==void 0&&(f.ttl===0||Date.now()>f.timestamp+f.ttl)){const g=await e.lock();try{const y=Date.now();return(f.ttl===0||y>f.timestamp+f.ttl)&&await h.unlink(i),null}catch{return null}finally{g.release()}}return f.data},set:async(c,l,h)=>{const a=await n(c),i={data:l,timestamp:Date.now()};h!==void 0&&(i.ttl=h);const f=JSON.stringify(i,null,2),p=await e.lock();try{await o();const{promises:g}=require("fs"),w=require("path").join(t,a);try{await g.writeFile(w,f,"utf-8")}catch(b){throw new Error(`Failed to write cache entry: ${b}`)}}catch(g){throw new Error(`Failed to import required modules: ${g}`)}finally{p.release()}},delete:async c=>{const l=await n(c),h=await e.lock();try{await o();const{promises:a}=require("fs"),f=require("path").join(t,l);try{await a.unlink(f)}catch{}}catch(a){throw new Error(`Failed to import required modules: ${a}`)}finally{h.release()}},clear:async()=>{const c=await e.lock();try{await o();const{promises:l}=require("fs"),h=require("path"),i=(await l.readdir(t)).filter(f=>f.endsWith(".json"));for(const f of i){const p=h.join(t,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"),a=(await c.readdir(t)).filter(f=>f.endsWith(".json"));if(a.length===0)return 0;const i=await e.lock();try{const f=Date.now();let p=0;for(const g of a){const y=l.join(t,g);try{const w=await c.readFile(y,"utf8"),b=JSON.parse(w);if(b.ttl!==void 0&&(b.ttl===0||f>b.timestamp+b.ttl)){await c.unlink(y);continue}p++}catch{try{await c.unlink(y)}catch{}}}return p}catch(f){throw new Error(`Failed to import required modules: ${f}`)}finally{i.release()}}}};function U(t,e,n){return`fetch:${t}:${e}:${n||"default"}`}const _e=(t,e=6e4,n,o)=>{const{cache:r=!0,cacheTTL:s=3600*1e3,cacheFailures:d=!0,failureCacheTTL:m=300*1e3}=o||{},u=r?n||le():void 0;return{rawFetcher:async(l,h,a,i)=>{if(r&&u){const g=U(l,h,t),y=await u.get(g);if(y)try{const w=JSON.parse(y);if(w.type==="success")return i?.info(`Cache HIT (success) for URL: ${l}`),new Response(w.data,{status:200,statusText:"OK",headers:{"Content-Type":h,"X-Cache":"HIT"}});if(w.type==="error"&&d)throw i?.info(`Cache HIT (error) for URL: ${l}`),new Error("Cached error");i?.debug(`Cache entry type ${w.type} not eligible for use, cacheFailures: ${d}`)}catch(w){if(i?.warn(`Failed to parse cached entry for URL ${l}:`,w),w instanceof SyntaxError)i?.debug("JSON parse error, continuing to network fetch");else throw w}else i?.info(`Cache MISS for URL: ${l}`)}let f,p=null;try{f=await E.fetchData(l,h,t,e,a,i)}catch(g){if(p=g,r&&u&&d)try{const y=U(l,h,t),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 u.set(y,JSON.stringify(w),m),i?.debug(`Cached error for URL: ${l}`)}catch(y){i?.warn(`Failed to cache error for URL ${l}:`,y),console.warn("Failed to cache error:",y)}throw p}if(r&&u&&f.ok)try{const g=await f.clone().text(),y=U(l,h,t),w={type:"success",data:g,timestamp:Date.now()};await u.set(y,JSON.stringify(w),s),i?.debug(`Cached successful response for URL: ${l}`)}catch(g){i?.warn(`Failed to cache response for URL ${l}:`,g),console.warn("Failed to cache response:",g)}return f},userAgent:t}},qe=(t,e=6e4)=>({rawFetcher:async(o,r,s,d)=>(d?.debug(`Direct fetch for URL: ${o}`),await E.fetchData(o,r,t,e,s,d)),userAgent:t});exports.defaultProviderList=E.defaultProviderList;exports.fetchData=E.fetchData;exports.fetchJson=E.fetchJson;exports.fetchText=E.fetchText;exports.generateHeadingId=E.generateHeadingId;exports.createCachedFetcher=_e;exports.createCardPlugin=Ce;exports.createDirectFetcher=qe;exports.createFileSystemCacheStorage=Ae;exports.createLocalCacheStorage=Ne;exports.createMarkdownProcessor=Le;exports.createMemoryCacheStorage=le;exports.createMermaidPlugin=Fe;exports.createOEmbedPlugin=Te;exports.defaultHtmlOptions=ce;exports.generateCacheKey=U;exports.getConsoleLogger=we;exports.getNoOpLogger=ie;
40
40
  //# sourceMappingURL=index.cjs.map