@vectojs/markdown 0.1.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/README.md +33 -0
- package/dist/Markdown.d.ts +107 -0
- package/dist/MarkdownWorker.d.ts +1 -0
- package/dist/MarkdownWorkerSource.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1018 -0
- package/dist/index.mjs +994 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1018 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CodeBlock: () => CodeBlock,
|
|
24
|
+
Markdown: () => Markdown
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/Markdown.ts
|
|
29
|
+
var import_core = require("@vectojs/core");
|
|
30
|
+
var import_marked = require("marked");
|
|
31
|
+
var import_mathjax = require("mathjax-full/js/mathjax.js");
|
|
32
|
+
var import_tex = require("mathjax-full/js/input/tex.js");
|
|
33
|
+
var import_svg = require("mathjax-full/js/output/svg.js");
|
|
34
|
+
var import_liteAdaptor = require("mathjax-full/js/adaptors/liteAdaptor.js");
|
|
35
|
+
var import_html = require("mathjax-full/js/handlers/html.js");
|
|
36
|
+
var import_AllPackages = require("mathjax-full/js/input/tex/AllPackages.js");
|
|
37
|
+
var import_ui = require("@vectojs/ui");
|
|
38
|
+
|
|
39
|
+
// src/MarkdownWorkerSource.ts
|
|
40
|
+
var WORKER_SOURCE_STRING = '"use strict";(()=>{function H(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var T=H();function ae(r){T=r}var R={exec:()=>null};function z(r){let e=[];return t=>{let s=Math.max(0,Math.min(3,t-1)),n=e[s];return n||(n=r(s),e[s]=n),n}}function u(r,e=""){let t=typeof r=="string"?r:r.source,s={replace:(n,i)=>{let l=typeof i=="string"?i:i.source;return l=l.replace(x.caret,"$1"),t=t.replace(n,l),s},getRegex:()=>new RegExp(t,e)};return s}var we=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),x={codeRemoveIndent:/^(?: {1,4}| {0,3}\\t)/gm,outputLinkReplace:/\\\\([\\[\\]])/g,indentCodeCompensation:/^(\\s+)(?:```)/,beginningSpace:/^\\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\\n/g,tabCharGlobal:/\\t/g,multipleSpaceGlobal:/\\s+/g,blankLine:/^[ \\t]*$/,doubleBlankLine:/\\n[ \\t]*\\n[ \\t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\\n {0,3}((?:=+|-+) *)(?=\\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \\t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\\[[ xX]\\] +\\S/,listReplaceTask:/^\\[[ xX]\\] +/,listTaskCheckbox:/\\[[ xX]\\]/,anyLine:/\\n.*\\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\\||\\| *$/g,tableRowBlankLine:/\\n[ \\t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\\s|>)/i,endPreScriptTag:/^<\\/(pre|code|kbd|script)(\\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^\'"]*[^\\s])\\s+([\'"])(.*)\\2/,unicodeAlphaNumeric:/[\\p{L}\\p{N}]/u,escapeTest:/[&<>"\']/,escapeReplace:/[&<>"\']/g,escapeTestNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/,escapeReplaceNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/g,caret:/(^|[^\\[])\\^/g,percentDecode:/%25/g,findPipe:/\\|/g,splitPipe:/ \\|/,slashPipe:/\\\\\\|/g,carriageReturn:/\\r\\n|\\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\\S*/,endingNewline:/\\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\\\n]*)?(?:\\\\n|$))`),nextBulletRegex:z(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\\\d{1,9}[.)])((?:[ ][^\\\\n]*)?(?:\\\\n|$))`)),hrRegex:z(r=>new RegExp(`^ {0,${r}}((?:- *){3,}|(?:_ *){3,}|(?:\\\\* *){3,})(?:\\\\n+|$)`)),fencesBeginRegex:z(r=>new RegExp(`^ {0,${r}}(?:\\`\\`\\`|~~~)`)),headingBeginRegex:z(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:z(r=>new RegExp(`^ {0,${r}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:z(r=>new RegExp(`^ {0,${r}}>`))},me=/^(?:[ \\t]*(?:\\n|$))+/,ye=/^((?: {4}| {0,3}\\t)[^\\n]+(?:\\n(?:[ \\t]*(?:\\n|$))*)?)+/,$e=/^ {0,3}(`{3,}(?=[^`\\n]*(?:\\n|$))|~{3,})([^\\n]*)(?:\\n|$)(?:|([\\s\\S]*?)(?:\\n|$))(?: {0,3}\\1[~`]* *(?=\\n|$)|$)/,I=/^ {0,3}((?:-[\\t ]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})(?:\\n+|$)/,Re=/^ {0,3}(#{1,6})(?=\\s|$)(.*)(?:\\n+|$)/,O=/ {0,3}(?:[*+-]|\\d{1,9}[.)])/,oe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\\n(?!\\s*?\\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,ce=u(oe).replace(/bull/g,O).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/\\|table/g,"").getRegex(),Se=u(oe).replace(/bull/g,O).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/table/g,/ {0,3}\\|?(?:[:\\- ]*\\|)+[\\:\\- ]*\\n/).getRegex(),N=/^([^\\n]+(?:\\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\\n)[^\\n]+)*)/,Te=/^[^\\n]+/,G=/(?!\\s*\\])(?:\\\\[\\s\\S]|[^\\[\\]\\\\])+/,ze=u(/^ {0,3}\\[(label)\\]: *(?:\\n[ \\t]*)?([^<\\s][^\\s]*|<.*?>)(?:(?: +(?:\\n[ \\t]*)?| *\\n[ \\t]*)(title))? *(?:\\n+|$)/).replace("label",G).replace("title",/(?:"(?:\\\\"?|[^"\\\\])*"|\'[^\'\\n]*(?:\\n[^\'\\n]+)*\\n?\'|\\([^()]*\\))/).getRegex(),Ae=u(/^(bull)([ \\t][^\\n]*?)?(?:\\n|$)/).replace(/bull/g,O).getRegex(),q="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",X=/<!--(?:-?>|[\\s\\S]*?(?:-->|$))/,Pe=u("^ {0,3}(?:<(script|pre|style|textarea)[\\\\s>][\\\\s\\\\S]*?(?:</\\\\1>[^\\\\n]*\\\\n+|$)|comment[^\\\\n]*(\\\\n+|$)|<\\\\?[\\\\s\\\\S]*?(?:\\\\?>[^\\\\n]*\\\\n+|$)|<![A-Z][\\\\s\\\\S]*?(?:>[^\\\\n]*\\\\n+|$)|<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?(?:\\\\]\\\\]>[^\\\\n]*\\\\n+|$)|</?(tag)(?: +|\\\\n|/?>)[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|<(?!script|pre|style|textarea)([a-z][\\\\w-]*)(?:attribute)*? */?>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|</(?!script|pre|style|textarea)[a-z][\\\\w-]*\\\\s*>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$))","i").replace("comment",X).replace("tag",q).replace("attribute",/ +[a-zA-Z:_][\\w.:-]*(?: *= *"[^"\\n]*"| *= *\'[^\'\\n]*\'| *= *[^\\s"\'=<>`]+)?/).getRegex(),he=r=>u(N).replace("hr",I).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n").replace("list",r).replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex(),_e=he(/ {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]/),Le=he(/ {0,3}(?:[*+-]|\\d{1,9}[.)])[ \\t]+[^ \\t\\n]/),Ie=u(/^( {0,3}> ?(paragraph|[^\\n]*)(?:\\n|$))+/).replace("paragraph",Le).getRegex(),W={blockquote:Ie,code:ye,def:ze,fences:$e,heading:Re,hr:I,html:Pe,lheading:ce,list:Ae,newline:me,paragraph:_e,table:R,text:Te},ee=u("^ *([^\\\\n ].*)\\\\n {0,3}((?:\\\\| *)?:?-+:? *(?:\\\\| *:?-+:? *)*(?:\\\\| *)?)(?:\\\\n((?:(?! *\\\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\\\n|$))*)\\\\n*|$)").replace("hr",I).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex(),Ee={...W,lheading:Se,table:ee,paragraph:u(N).replace("hr",I).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("table",ee).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]+[^ \\\\t\\\\n]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex()},Ce={...W,html:u(`^ *(?:comment *(?:\\\\n|\\\\s*$)|<(tag)[\\\\s\\\\S]+?</\\\\1> *(?:\\\\n{2,}|\\\\s*$)|<tag(?:"[^"]*"|\'[^\']*\'|\\\\s[^\'"/>\\\\s]*)*?/?> *(?:\\\\n{2,}|\\\\s*$))`).replace("comment",X).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\\\b)\\\\w+(?!:|[^\\\\w\\\\s@]*@)\\\\b").getRegex(),def:/^ *\\[([^\\]]+)\\]: *<?([^\\s>]+)>?(?: +(["(][^\\n]+[")]))? *(?:\\n+|$)/,heading:/^(#{1,6})(.*)(?:\\n+|$)/,fences:R,lheading:/^(.+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,paragraph:u(N).replace("hr",I).replace("heading",` *#{1,6} *[^\n]`).replace("lheading",ce).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},ve=/^\\\\([!"#$%&\'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~])/,Be=/^(`+)([^`]|[^`][\\s\\S]*?[^`])\\1(?!`)/,pe=/^( {2,}|\\\\)\\n(?!\\s*$)/,qe=/^(`+|[^`])(?:(?= {2,}\\n)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*_]|\\b_|$)|[^ ](?= {2,}\\n)))/,A=/[\\p{P}\\p{S}]/u,Z=/[\\s\\p{P}\\p{S}]/u,F=/[^\\s\\p{P}\\p{S}]/u,Ze=u(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Z).getRegex(),ue=/(?!~)[\\p{P}\\p{S}]/u,De=/(?!~)[\\s\\p{P}\\p{S}]/u,Me=/(?:[^\\s\\p{P}\\p{S}]|~)/u,Qe=u(/link|precode-code|html/,"g").replace("link",/\\[(?:[^\\[\\]`]|(?<a>`+)[^`]+\\k<a>(?!`))*?\\]\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)]|\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)])*\\))*\\)/).replace("precode-",we?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),ge=/^(?:\\*+(?:((?!\\*)punct)|([^\\s*]))?)|^_+(?:((?!_)punct)|([^\\s_]))?/,je=u(ge,"u").replace(/punct/g,A).getRegex(),He=u(ge,"u").replace(/punct/g,ue).getRegex(),ke="^[^_*]*?__[^_*]*?\\\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\\\*)punct(\\\\*+)(?=[\\\\s]|$)|notPunctSpace(\\\\*+)(?!\\\\*)(?=punctSpace|$)|(?!\\\\*)punctSpace(\\\\*+)(?=notPunctSpace)|[\\\\s](\\\\*+)(?!\\\\*)(?=punct)|(?!\\\\*)punct(\\\\*+)(?!\\\\*)(?=punct)|notPunctSpace(\\\\*+)(?=notPunctSpace)",Oe=u(ke,"gu").replace(/notPunctSpace/g,F).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),Ne=u(ke,"gu").replace(/notPunctSpace/g,Me).replace(/punctSpace/g,De).replace(/punct/g,ue).getRegex(),Ge=u("^[^_*]*?\\\\*\\\\*[^_*]*?_[^_*]*?(?=\\\\*\\\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,F).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),Xe=u(/^~~?(?:((?!~)punct)|[^\\s~])/,"u").replace(/punct/g,A).getRegex(),We="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Fe=u(We,"gu").replace(/notPunctSpace/g,F).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),Ue=u(/\\\\(punct)/,"gu").replace(/punct/g,A).getRegex(),Je=u(/^<(scheme:[^\\s\\x00-\\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&\'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ke=u(X).replace("(?:-->|$)","-->").getRegex(),Ve=u("^comment|^</[a-zA-Z][\\\\w:-]*\\\\s*>|^<[a-zA-Z][\\\\w-]*(?:attribute)*?\\\\s*/?>|^<\\\\?[\\\\s\\\\S]*?\\\\?>|^<![a-zA-Z]+\\\\s[\\\\s\\\\S]*?>|^<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?\\\\]\\\\]>").replace("comment",Ke).replace("attribute",/\\s+[a-zA-Z:_][\\w.:-]*(?:\\s*=\\s*"[^"]*"|\\s*=\\s*\'[^\']*\'|\\s*=\\s*[^\\s"\'=<>`]+)?/).getRegex(),C=/(?:\\[(?:\\\\[\\s\\S]|[^\\[\\]\\\\])*\\]|\\\\[\\s\\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\\])|[^\\[\\]\\\\`])*?/,Ye=u(/^!?\\[(label)\\]\\(\\s*(href)(?:(?:[ \\t]+(?:\\n[ \\t]*)?|\\n[ \\t]*)(title))?\\s*\\)/).replace("label",C).replace("href",/<(?:\\\\.|[^\\n<>\\\\])+>|[^ \\t\\n\\x00-\\x1f]+|(?=\\))/).replace("title",/"(?:\\\\"?|[^"\\\\])*"|\'(?:\\\\\'?|[^\'\\\\])*\'|\\((?:\\\\\\)?|[^)\\\\])*\\)/).getRegex(),de=u(/^!?\\[(label)\\]\\[(ref)\\]/).replace("label",C).replace("ref",G).getRegex(),fe=u(/^!?\\[(ref)\\](?:\\[\\])?/).replace("ref",G).getRegex(),et=u("reflink|nolink(?!\\\\()","g").replace("reflink",de).replace("nolink",fe).getRegex(),te=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,U={_backpedal:R,anyPunctuation:Ue,autolink:Je,blockSkip:Qe,br:pe,code:Be,del:R,delLDelim:R,delRDelim:R,emStrongLDelim:je,emStrongRDelimAst:Oe,emStrongRDelimUnd:Ge,escape:ve,link:Ye,nolink:fe,punctuation:Ze,reflink:de,reflinkSearch:et,tag:Ve,text:qe,url:R},tt={...U,link:u(/^!?\\[(label)\\]\\((.*?)\\)/).replace("label",C).getRegex(),reflink:u(/^!?\\[(label)\\]\\s*\\[([^\\]]*)\\]/).replace("label",C).getRegex()},M={...U,emStrongRDelimAst:Ne,emStrongLDelim:He,delLDelim:Xe,delRDelim:Fe,url:u(/^((?:protocol):\\/\\/|www\\.)(?:[a-zA-Z0-9\\-]+\\.?)+[^\\s<]*|^email/).replace("protocol",te).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_\'"~()&]+|\\([^)]*\\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_\'"~)]+(?!$))+/,del:/^(~~?)(?=[^\\s~])((?:\\\\[\\s\\S]|[^\\\\])*?(?:\\\\[\\s\\S]|[^\\s~\\\\]))\\1(?=[^~]|$)/,text:u(/^([`~]+|[^`~])(?:(?= {2,}\\n)|(?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*~_]|\\b_|protocol:\\/\\/|www\\.|$)|[^ ](?= {2,}\\n)|[^a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-](?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)))/).replace("protocol",te).getRegex()},rt={...M,br:u(pe).replace("{2,}","*").getRegex(),text:u(M.text).replace("\\\\b_","\\\\b_| {2,}\\\\n").replace(/\\{2,\\}/g,"*").getRegex()},E={normal:W,gfm:Ee,pedantic:Ce},_={normal:U,gfm:M,breaks:rt,pedantic:tt},nt={"&":"&","<":"<",">":">",\'"\':""","\'":"'"},re=r=>nt[r];function m(r,e){if(e){if(x.escapeTest.test(r))return r.replace(x.escapeReplace,re)}else if(x.escapeTestNoEncode.test(r))return r.replace(x.escapeReplaceNoEncode,re);return r}function ne(r){try{r=encodeURI(r).replace(x.percentDecode,"%")}catch{return null}return r}function se(r,e){let t=r.replace(x.findPipe,(i,l,a)=>{let c=!1,o=l;for(;--o>=0&&a[o]==="\\\\";)c=!c;return c?"|":" |"}),s=t.split(x.splitPipe),n=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;n<s.length;n++)s[n]=s[n].trim().replace(x.slashPipe,"|");return s}function $(r,e,t){let s=r.length;if(s===0)return"";let n=0;for(;n<s;){let i=r.charAt(s-n-1);if(i===e&&!t)n++;else if(i!==e&&t)n++;else break}return r.slice(0,s-n)}function ie(r){let e=r.split(`\n`),t=e.length-1;for(;t>=0&&x.blankLine.test(e[t]);)t--;return e.length-t<=2?r:e.slice(0,t+1).join(`\n`)}function st(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let s=0;s<r.length;s++)if(r[s]==="\\\\")s++;else if(r[s]===e[0])t++;else if(r[s]===e[1]&&(t--,t<0))return s;return t>0?-2:-1}function it(r,e=0){let t=e,s="";for(let n of r)if(n===" "){let i=4-t%4;s+=" ".repeat(i),t+=i}else s+=n,t++;return s}function le(r,e,t,s,n){let i=e.href,l=e.title||null,a=r[1].replace(n.other.outputLinkReplace,"$1");s.state.inLink=!0;let c={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:i,title:l,text:a,tokens:s.inlineTokens(a)};return s.state.inLink=!1,c}function lt(r,e,t){let s=r.match(t.other.indentCodeCompensation);if(s===null)return e;let n=s[1];return e.split(`\n`).map(i=>{let l=i.match(t.other.beginningSpace);if(l===null)return i;let[a]=l;return a.length>=n.length?i.slice(n.length):i}).join(`\n`)}var v=class{options;rules;lexer;constructor(r){this.options=r||T}space(r){let e=this.rules.block.newline.exec(r);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(r){let e=this.rules.block.code.exec(r);if(e){let t=this.options.pedantic?e[0]:ie(e[0]),s=t.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t,codeBlockStyle:"indented",text:s}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],s=lt(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(r){let e=this.rules.block.heading.exec(r);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let s=$(t,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(t=s.trim())}return{type:"heading",raw:$(e[0],`\n`),depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(r){let e=this.rules.block.hr.exec(r);if(e)return{type:"hr",raw:$(e[0],`\n`)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=$(e[0],`\n`).split(`\n`),s="",n="",i=[];for(;t.length>0;){let l=!1,a=[],c;for(c=0;c<t.length;c++)if(this.rules.other.blockquoteStart.test(t[c]))a.push(t[c]),l=!0;else if(!l)a.push(t[c]);else break;t=t.slice(c);let o=a.join(`\n`),p=o.replace(this.rules.other.blockquoteSetextReplace,`\n $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}\n${o}`:o,n=n?`${n}\n${p}`:p;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=h,t.length===0)break;let g=i.at(-1);if(g?.type==="code")break;if(g?.type==="blockquote"){let f=g,d=f.raw+`\n`+t.join(`\n`),y=this.blockquote(d);i[i.length-1]=y,s=s.substring(0,s.length-f.raw.length)+y.raw,n=n.substring(0,n.length-f.text.length)+y.text;break}else if(g?.type==="list"){let f=g,d=f.raw+`\n`+t.join(`\n`),y=this.list(d);i[i.length-1]=y,s=s.substring(0,s.length-g.raw.length)+y.raw,n=n.substring(0,n.length-f.raw.length)+y.raw,t=d.substring(i.at(-1).raw.length).split(`\n`);continue}}return{type:"blockquote",raw:s,tokens:i,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),s=t.length>1,n={type:"list",raw:"",ordered:s,start:s?+t.slice(0,-1):"",loose:!1,items:[]};t=s?`\\\\d{1,9}\\\\${t.slice(-1)}`:`\\\\${t}`,this.options.pedantic&&(t=s?t:"[*+-]");let i=this.rules.other.listItemRegex(t),l=!1;for(;r;){let c=!1,o="",p="";if(!(e=i.exec(r))||this.rules.block.hr.test(r))break;o=e[0],r=r.substring(o.length);let h=it(e[2].split(`\n`,1)[0],e[1].length),g=r.split(`\n`,1)[0],f=!h.trim(),d=0;if(this.options.pedantic?(d=2,p=h.trimStart()):f?d=e[1].length+1:(d=h.search(this.rules.other.nonSpaceChar),d=d>4?1:d,p=h.slice(d),d+=e[1].length),f&&this.rules.other.blankLine.test(g)&&(o+=g+`\n`,r=r.substring(g.length+1),c=!0),!c){let y=this.rules.other.nextBulletRegex(d),K=this.rules.other.hrRegex(d),V=this.rules.other.fencesBeginRegex(d),Y=this.rules.other.headingBeginRegex(d),xe=this.rules.other.htmlBeginRegex(d),be=this.rules.other.blockquoteBeginRegex(d);for(;r;){let D=r.split(`\n`,1)[0],P;if(g=D,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),P=g):P=g.replace(this.rules.other.tabCharGlobal," "),V.test(g)||Y.test(g)||xe.test(g)||be.test(g)||y.test(g)||K.test(g))break;if(P.search(this.rules.other.nonSpaceChar)>=d||!g.trim())p+=`\n`+P.slice(d);else{if(f||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||V.test(h)||Y.test(h)||K.test(h))break;p+=`\n`+g}f=!g.trim(),o+=D+`\n`,r=r.substring(D.length+1),h=P.slice(d)}}n.loose||(l?n.loose=!0:this.rules.other.doubleBlankLine.test(o)&&(l=!0)),n.items.push({type:"list_item",raw:o,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=o}let a=n.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let c of n.items){this.lexer.state.top=!1,c.tokens=this.lexer.blockTokens(c.text,[]);let o=c.tokens[0];if(c.task&&(o?.type==="text"||o?.type==="paragraph")){c.text=c.text.replace(this.rules.other.listReplaceTask,""),o.raw=o.raw.replace(this.rules.other.listReplaceTask,""),o.text=o.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(c.raw);if(p){let h={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};c.checked=h.checked,n.loose?c.tokens[0]&&["paragraph","text"].includes(c.tokens[0].type)&&"tokens"in c.tokens[0]&&c.tokens[0].tokens?(c.tokens[0].raw=h.raw+c.tokens[0].raw,c.tokens[0].text=h.raw+c.tokens[0].text,c.tokens[0].tokens.unshift(h)):c.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):c.tokens.unshift(h)}}else c.task&&(c.task=!1);if(!n.loose){let p=c.tokens.filter(g=>g.type==="space"),h=p.length>0&&p.some(g=>this.rules.other.anyLine.test(g.raw));n.loose=h}}if(n.loose)for(let c of n.items){c.loose=!0;for(let o of c.tokens)o.type==="text"&&(o.type="paragraph")}return n}}html(r){let e=this.rules.block.html.exec(r);if(e){let t=ie(e[0]);return{type:"html",block:!0,raw:t,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:t}}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:$(e[0],`\n`),href:s,title:n}}}table(r){let e=this.rules.block.table.exec(r);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=se(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`\n`):[],i={type:"table",raw:$(e[0],`\n`),header:[],align:[],rows:[]};if(t.length===s.length){for(let l of s)this.rules.other.tableAlignRight.test(l)?i.align.push("right"):this.rules.other.tableAlignCenter.test(l)?i.align.push("center"):this.rules.other.tableAlignLeft.test(l)?i.align.push("left"):i.align.push(null);for(let l=0;l<t.length;l++)i.header.push({text:t[l],tokens:this.lexer.inline(t[l]),header:!0,align:i.align[l]});for(let l of n)i.rows.push(se(l,i.header.length).map((a,c)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:i.align[c]})));return i}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e){let t=e[1].trim();return{type:"heading",raw:$(e[0],`\n`),depth:e[2].charAt(0)==="="?1:2,text:t,tokens:this.lexer.inline(t)}}}paragraph(r){let e=this.rules.block.paragraph.exec(r);if(e){let t=e[1].charAt(e[1].length-1)===`\n`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let i=$(t.slice(0,-1),"\\\\");if((t.length-i.length)%2===0)return}else{let i=st(e[2],"()");if(i===-2)return;if(i>-1){let l=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let s=e[2],n="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],n=i[3])}else n=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?s=s.slice(1):s=s.slice(1,-1)),le(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let s=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[s.toLowerCase()];if(!n){let i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return le(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let s=this.rules.inline.emStrongLDelim.exec(r);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,l,a=n,c=0,o=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(o.lastIndex=0,e=e.slice(-1*r.length+n);(s=o.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(l=[...i].length,s[3]||s[4]){a+=l;continue}else if((s[5]||s[6])&&n%3&&!((n+l)%3)){c+=l;continue}if(a-=l,a>0)continue;l=Math.min(l,l+a+c);let p=[...s[0]][0].length,h=r.slice(0,n+s.index+p+l);if(Math.min(n,l)%2){let f=h.slice(1,-1);return{type:"em",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}let g=h.slice(2,-2);return{type:"strong",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return s&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return{type:"br",raw:e[0]}}del(r,e,t=""){let s=this.rules.inline.delLDelim.exec(r);if(s&&(!s[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,l,a=n,c=this.rules.inline.delRDelim;for(c.lastIndex=0,e=e.slice(-1*r.length+n);(s=c.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(l=[...i].length,l!==n))continue;if(s[3]||s[4]){a+=l;continue}if(a-=l,a>0)continue;l=Math.min(l,l+a);let o=[...s[0]][0].length,p=r.slice(0,n+s.index+o+l),h=p.slice(n,-n);return{type:"del",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,s;return e[2]==="@"?(t=e[1],s="mailto:"+t):(t=e[1],s=t),{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,s;if(e[2]==="@")t=e[0],s="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},b=class Q{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||T,this.options.tokenizer=this.options.tokenizer||new v,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:x,block:E.normal,inline:_.normal};this.options.pedantic?(t.block=E.pedantic,t.inline=_.pedantic):this.options.gfm&&(t.block=E.gfm,this.options.breaks?t.inline=_.breaks:t.inline=_.gfm),this.tokenizer.rules=t}static get rules(){return{block:E,inline:_}}static lex(e,t){return new Q(t).lex(e)}static lexInline(e,t){return new Q(t).inlineTokens(e)}lex(e){e=e.replace(x.carriageReturn,`\n`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let s=this.inlineQueue[t];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(x.tabCharGlobal," ").replace(x.spaceLine,""));let n=1/0;for(;e;){if(e.length<n)n=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(a=>(i=a.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let a=t.at(-1);i.raw.length===1&&a!==void 0?a.raw+=`\n`:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`\n`)?"":`\n`)+i.raw,a.text+=`\n`+i.text,this.inlineQueue.at(-1).src=a.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`\n`)?"":`\n`)+i.raw,a.text+=`\n`+i.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let l=e;if(this.options.extensions?.startBlock){let a=1/0,c=e.slice(1),o;this.options.extensions.startBlock.forEach(p=>{o=p.call({lexer:this},c),typeof o=="number"&&o>=0&&(a=Math.min(a,o))}),a<1/0&&a>=0&&(l=e.substring(0,a+1))}if(this.state.top&&(i=this.tokenizer.paragraph(l))){let a=t.at(-1);s&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`\n`)?"":`\n`)+i.raw,a.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(i),s=l.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`\n`)?"":`\n`)+i.raw,a.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let s=e,n=null;if(this.tokens.links){let o=Object.keys(this.tokens.links);if(o.length>0)for(;(n=this.tokenizer.rules.inline.reflinkSearch.exec(s))!==null;)o.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(n=this.tokenizer.rules.inline.anyPunctuation.exec(s))!==null;)s=s.slice(0,n.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(n=this.tokenizer.rules.inline.blockSkip.exec(s))!==null;)i=n[2]?n[2].length:0,s=s.slice(0,n.index+i)+"["+"a".repeat(n[0].length-i-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let l=!1,a="",c=1/0;for(;e;){if(e.length<c)c=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}l||(a=""),l=!1;let o;if(this.options.extensions?.inline?.some(h=>(o=h.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),!0):!1))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let h=t.at(-1);o.type==="text"&&h?.type==="text"?(h.raw+=o.raw,h.text+=o.text):t.push(o);continue}if(o=this.tokenizer.emStrong(e,s,a)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.del(e,s,a)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),t.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),t.push(o);continue}let p=e;if(this.options.extensions?.startInline){let h=1/0,g=e.slice(1),f;this.options.extensions.startInline.forEach(d=>{f=d.call({lexer:this},g),typeof f=="number"&&f>=0&&(h=Math.min(h,f))}),h<1/0&&h>=0&&(p=e.substring(0,h+1))}if(o=this.tokenizer.inlineText(p)){e=e.substring(o.raw.length),o.raw.slice(-1)!=="_"&&(a=o.raw.slice(-1)),l=!0;let h=t.at(-1);h?.type==="text"?(h.raw+=o.raw,h.text+=o.text):t.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}},B=class{options;parser;constructor(r){this.options=r||T}space(r){return""}code({text:r,lang:e,escaped:t}){let s=(e||"").match(x.notSpaceStart)?.[0],n=r.replace(x.endingNewline,"")+`\n`;return s?\'<pre><code class="language-\'+m(s)+\'">\'+(t?n:m(n,!0))+`</code></pre>\n`:"<pre><code>"+(t?n:m(n,!0))+`</code></pre>\n`}blockquote({tokens:r}){return`<blockquote>\n${this.parser.parse(r)}</blockquote>\n`}html({text:r}){return r}def(r){return""}heading({tokens:r,depth:e}){return`<h${e}>${this.parser.parseInline(r)}</h${e}>\n`}hr(r){return`<hr>\n`}list(r){let e=r.ordered,t=r.start,s="";for(let l=0;l<r.items.length;l++){let a=r.items[l];s+=this.listitem(a)}let n=e?"ol":"ul",i=e&&t!==1?\' start="\'+t+\'"\':"";return"<"+n+i+`>\n`+s+"</"+n+`>\n`}listitem(r){return`<li>${this.parser.parse(r.tokens)}</li>\n`}checkbox({checked:r}){return"<input "+(r?\'checked="" \':"")+\'disabled="" type="checkbox"> \'}paragraph({tokens:r}){return`<p>${this.parser.parseInline(r)}</p>\n`}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let s="";for(let n=0;n<r.rows.length;n++){let i=r.rows[n];t="";for(let l=0;l<i.length;l++)t+=this.tablecell(i[l]);s+=this.tablerow({text:t})}return s&&(s=`<tbody>${s}</tbody>`),`<table>\n<thead>\n`+e+`</thead>\n`+s+`</table>\n`}tablerow({text:r}){return`<tr>\n${r}</tr>\n`}tablecell(r){let e=this.parser.parseInline(r.tokens),t=r.header?"th":"td";return(r.align?`<${t} align="${r.align}">`:`<${t}>`)+e+`</${t}>\n`}strong({tokens:r}){return`<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return`<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return`<code>${m(r,!0)}</code>`}br(r){return"<br>"}del({tokens:r}){return`<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let s=this.parser.parseInline(t),n=ne(r);if(n===null)return s;r=n;let i=\'<a href="\'+r+\'"\';return e&&(i+=\' title="\'+m(e)+\'"\'),i+=">"+s+"</a>",i}image({href:r,title:e,text:t,tokens:s}){s&&(t=this.parser.parseInline(s,this.parser.textRenderer));let n=ne(r);if(n===null)return m(t);r=n;let i=`<img src="${r}" alt="${m(t)}"`;return e&&(i+=` title="${m(e)}"`),i+=">",i}text(r){return"tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:m(r.text)}},J=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return""+r}image({text:r}){return""+r}br(){return""}checkbox({raw:r}){return r}},w=class j{options;renderer;textRenderer;constructor(e){this.options=e||T,this.options.renderer=this.options.renderer||new B,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new J}static parse(e,t){return new j(t).parse(e)}static parseInline(e,t){return new j(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let s=0;s<e.length;s++){let n=e[s];if(this.options.extensions?.renderers?.[n.type]){let l=n,a=this.options.extensions.renderers[l.type].call({parser:this},l);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(l.type)){t+=a||"";continue}}let i=n;switch(i.type){case"space":{t+=this.renderer.space(i);break}case"hr":{t+=this.renderer.hr(i);break}case"heading":{t+=this.renderer.heading(i);break}case"code":{t+=this.renderer.code(i);break}case"table":{t+=this.renderer.table(i);break}case"blockquote":{t+=this.renderer.blockquote(i);break}case"list":{t+=this.renderer.list(i);break}case"checkbox":{t+=this.renderer.checkbox(i);break}case"html":{t+=this.renderer.html(i);break}case"def":{t+=this.renderer.def(i);break}case"paragraph":{t+=this.renderer.paragraph(i);break}case"text":{t+=this.renderer.text(i);break}default:{let l=\'Token with "\'+i.type+\'" type was not found.\';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let s="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let a=this.options.extensions.renderers[i.type].call({parser:this},i);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=a||"";continue}}let l=i;switch(l.type){case"escape":{s+=t.text(l);break}case"html":{s+=t.html(l);break}case"link":{s+=t.link(l);break}case"image":{s+=t.image(l);break}case"checkbox":{s+=t.checkbox(l);break}case"strong":{s+=t.strong(l);break}case"em":{s+=t.em(l);break}case"codespan":{s+=t.codespan(l);break}case"br":{s+=t.br(l);break}case"del":{s+=t.del(l);break}case"text":{s+=t.text(l);break}default:{let a=\'Token with "\'+l.type+\'" type was not found.\';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}},L=class{options;block;constructor(r){this.options=r||T}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}emStrongMask(r){return r}provideLexer(r=this.block){return r?b.lex:b.lexInline}provideParser(r=this.block){return r?w.parse:w.parseInline}},at=class{defaults=H();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=w;Renderer=B;TextRenderer=J;Lexer=b;Tokenizer=v;Hooks=L;constructor(...r){this.use(...r)}walkTokens(r,e){let t=[];for(let s of r)switch(t=t.concat(e.call(this,s)),s.type){case"table":{let n=s;for(let i of n.header)t=t.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let l of i)t=t.concat(this.walkTokens(l.tokens,e));break}case"list":{let n=s;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=s;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let l=n[i].flat(1/0);t=t.concat(this.walkTokens(l,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let s={...t};if(s.async=this.defaults.async||s.async||!1,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...l){let a=n.renderer.apply(this,l);return a===!1&&(a=i.apply(this,l)),a}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be \'block\' or \'inline\'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),s.extensions=e),t.renderer){let n=this.defaults.renderer||new B(this.defaults);for(let i in t.renderer){if(!(i in n))throw new Error(`renderer \'${i}\' does not exist`);if(["options","parser"].includes(i))continue;let l=i,a=t.renderer[l],c=n[l];n[l]=(...o)=>{let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p||""}}s.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new v(this.defaults);for(let i in t.tokenizer){if(!(i in n))throw new Error(`tokenizer \'${i}\' does not exist`);if(["options","rules","lexer"].includes(i))continue;let l=i,a=t.tokenizer[l],c=n[l];n[l]=(...o)=>{let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p}}s.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new L;for(let i in t.hooks){if(!(i in n))throw new Error(`hook \'${i}\' does not exist`);if(["options","block"].includes(i))continue;let l=i,a=t.hooks[l],c=n[l];L.passThroughHooks.has(i)?n[l]=o=>{if(this.defaults.async&&L.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await a.call(n,o);return c.call(n,h)})();let p=a.call(n,o);return c.call(n,p)}:n[l]=(...o)=>{if(this.defaults.async)return(async()=>{let h=await a.apply(n,o);return h===!1&&(h=await c.apply(n,o)),h})();let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p}}s.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,i=t.walkTokens;s.walkTokens=function(l){let a=[];return a.push(i.call(this,l)),n&&(a=a.concat(n.call(this,l))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return b.lex(r,e??this.defaults)}parser(r,e){return w.parse(r,e??this.defaults)}parseMarkdown(r){return(e,t)=>{let s={...t},n={...this.defaults,...s},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=r),n.async)return(async()=>{let l=n.hooks?await n.hooks.preprocess(e):e,a=await(n.hooks?await n.hooks.provideLexer(r):r?b.lex:b.lexInline)(l,n),c=n.hooks?await n.hooks.processAllTokens(a):a;n.walkTokens&&await Promise.all(this.walkTokens(c,n.walkTokens));let o=await(n.hooks?await n.hooks.provideParser(r):r?w.parse:w.parseInline)(c,n);return n.hooks?await n.hooks.postprocess(o):o})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let l=(n.hooks?n.hooks.provideLexer(r):r?b.lex:b.lexInline)(e,n);n.hooks&&(l=n.hooks.processAllTokens(l)),n.walkTokens&&this.walkTokens(l,n.walkTokens);let a=(n.hooks?n.hooks.provideParser(r):r?w.parse:w.parseInline)(l,n);return n.hooks&&(a=n.hooks.postprocess(a)),a}catch(l){return i(l)}}}onError(r,e){return t=>{if(t.message+=`\nPlease report this to https://github.com/markedjs/marked.`,r){let s="<p>An error occurred:</p><pre>"+m(t.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(t);throw t}}},S=new at;function k(r,e){return S.parse(r,e)}k.options=k.setOptions=function(r){return S.setOptions(r),k.defaults=S.defaults,ae(k.defaults),k};k.getDefaults=H;k.defaults=T;k.use=function(...r){return S.use(...r),k.defaults=S.defaults,ae(k.defaults),k};k.walkTokens=function(r,e){return S.walkTokens(r,e)};k.parseInline=S.parseInline;k.Parser=w;k.parser=w.parse;k.Renderer=B;k.TextRenderer=J;k.Lexer=b;k.lexer=b.lex;k.Tokenizer=v;k.Hooks=L;k.parse=k;var ot=k.options,ct=k.setOptions,ht=k.use,pt=k.walkTokens,ut=k.parseInline;var gt=w.parse,kt=b.lex;k.use({extensions:[{name:"inlineMath",level:"inline",start(r){return r.match(/\\$/)?.index},tokenizer(r){let e=/^\\$([^$]+)\\$/.exec(r);if(e)return{type:"inlineMath",raw:e[0],text:e[1].trim()}},renderer(r){return r.raw}}]});self.onmessage=r=>{let e=r.data;if(typeof e!="object"||e===null)return;let{id:t,text:s,oldRaws:n}=e;if(typeof s=="string")try{let i=k.lexer(s),l=0;if(Array.isArray(n)){let a=Math.min(n.length,i.length);for(;l<a&&n[l]===i[l].raw;l++);}self.postMessage({id:t,matchLen:l,tail:i.slice(l)})}catch(i){self.postMessage({id:t,error:String(i)})}};})();\n';
|
|
41
|
+
|
|
42
|
+
// src/Markdown.ts
|
|
43
|
+
import_marked.marked.use({
|
|
44
|
+
extensions: [
|
|
45
|
+
{
|
|
46
|
+
name: "inlineMath",
|
|
47
|
+
level: "inline",
|
|
48
|
+
start(src) {
|
|
49
|
+
return src.match(/\$/)?.index;
|
|
50
|
+
},
|
|
51
|
+
tokenizer(src) {
|
|
52
|
+
const match = /^\$([^$]+)\$/.exec(src);
|
|
53
|
+
if (match) {
|
|
54
|
+
return {
|
|
55
|
+
type: "inlineMath",
|
|
56
|
+
raw: match[0],
|
|
57
|
+
text: match[1].trim()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
},
|
|
62
|
+
renderer(token) {
|
|
63
|
+
return token.raw;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
var adaptor = (0, import_liteAdaptor.liteAdaptor)();
|
|
69
|
+
(0, import_html.RegisterHTMLHandler)(adaptor);
|
|
70
|
+
var tex = new import_tex.TeX({ packages: import_AllPackages.AllPackages });
|
|
71
|
+
var svg = new import_svg.SVG({ fontCache: "local" });
|
|
72
|
+
var htmlMathJax = import_mathjax.mathjax.document("", { InputJax: tex, OutputJax: svg });
|
|
73
|
+
function renderMathToSVGDataURI(formula, displayMode) {
|
|
74
|
+
try {
|
|
75
|
+
const node = htmlMathJax.convert(formula, { display: displayMode });
|
|
76
|
+
const svgString = adaptor.innerHTML(node);
|
|
77
|
+
const wMatch = svgString.match(/width="([^"]+)ex"/);
|
|
78
|
+
const hMatch = svgString.match(/height="([^"]+)ex"/);
|
|
79
|
+
const wEx = wMatch ? parseFloat(wMatch[1]) : 10;
|
|
80
|
+
const hEx = hMatch ? parseFloat(hMatch[1]) : 2;
|
|
81
|
+
const width = wEx * 8;
|
|
82
|
+
const height = hEx * 8;
|
|
83
|
+
const base64 = btoa(unescape(encodeURIComponent(svgString)));
|
|
84
|
+
return { uri: `data:image/svg+xml;base64,${base64}`, width, height };
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error("MathJax error", e);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var markdownWorker = null;
|
|
91
|
+
var workerIdCounter = 0;
|
|
92
|
+
var workerCallbacks = /* @__PURE__ */ new Map();
|
|
93
|
+
function runSyncFallback(entry) {
|
|
94
|
+
try {
|
|
95
|
+
entry.cb(0, import_marked.marked.lexer(entry.text));
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.warn("Markdown sync fallback parse failed", err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (typeof Worker !== "undefined") {
|
|
101
|
+
try {
|
|
102
|
+
const blob = new Blob([WORKER_SOURCE_STRING], { type: "application/javascript" });
|
|
103
|
+
markdownWorker = new Worker(URL.createObjectURL(blob));
|
|
104
|
+
markdownWorker.onmessage = (e) => {
|
|
105
|
+
const { id, matchLen, tail, error } = e.data;
|
|
106
|
+
const entry = workerCallbacks.get(id);
|
|
107
|
+
if (entry) {
|
|
108
|
+
workerCallbacks.delete(id);
|
|
109
|
+
if (!error) entry.cb(matchLen, tail);
|
|
110
|
+
else runSyncFallback(entry);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
markdownWorker.onerror = () => {
|
|
114
|
+
const pending = [...workerCallbacks.values()];
|
|
115
|
+
workerCallbacks.clear();
|
|
116
|
+
markdownWorker = null;
|
|
117
|
+
for (const entry of pending) runSyncFallback(entry);
|
|
118
|
+
};
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.warn("Failed to initialize MarkdownWorker", err);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
var DEFAULT_THEME = {
|
|
124
|
+
textColor: "#e2e8f0",
|
|
125
|
+
headingColor: "#f8fafc",
|
|
126
|
+
codeColor: "#a5f3fc",
|
|
127
|
+
codeBgColor: "rgba(30, 41, 59, 0.85)",
|
|
128
|
+
quoteBorderColor: "#6366f1",
|
|
129
|
+
quoteTextColor: "#94a3b8",
|
|
130
|
+
hrColor: "rgba(148, 163, 184, 0.3)",
|
|
131
|
+
tableBgColor: "rgba(15, 15, 25, 0.4)",
|
|
132
|
+
tableHeaderBgColor: "rgba(255, 255, 255, 0.08)",
|
|
133
|
+
bodyFont: "Inter, system-ui, sans-serif",
|
|
134
|
+
codeFont: 'ui-monospace, "JetBrains Mono", "Fira Code", monospace',
|
|
135
|
+
fontSize: 16
|
|
136
|
+
};
|
|
137
|
+
var HorizontalRule = class extends import_core.Entity {
|
|
138
|
+
color;
|
|
139
|
+
constructor(w, color) {
|
|
140
|
+
super();
|
|
141
|
+
this.width = w;
|
|
142
|
+
this.height = 1;
|
|
143
|
+
this.color = color;
|
|
144
|
+
}
|
|
145
|
+
isPointInside() {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
render(r) {
|
|
149
|
+
r.beginPath();
|
|
150
|
+
r.moveTo(0, 0);
|
|
151
|
+
r.lineTo(this.width, 0);
|
|
152
|
+
r.stroke(this.color, 1);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var QuoteBorder = class extends import_core.Entity {
|
|
156
|
+
color;
|
|
157
|
+
constructor(height, color) {
|
|
158
|
+
super();
|
|
159
|
+
this.width = 4;
|
|
160
|
+
this.height = height;
|
|
161
|
+
this.color = color;
|
|
162
|
+
}
|
|
163
|
+
isPointInside() {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
render(r) {
|
|
167
|
+
r.beginPath();
|
|
168
|
+
r.roundRect(0, 0, this.width, this.height, 2);
|
|
169
|
+
r.fill(this.color);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var MarkdownContainer = class extends import_core.Entity {
|
|
173
|
+
isPointInside(_globalX, _globalY) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
render(_r) {
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var KEYWORD_SETS = {
|
|
180
|
+
js: /* @__PURE__ */ new Set([
|
|
181
|
+
"const",
|
|
182
|
+
"let",
|
|
183
|
+
"var",
|
|
184
|
+
"function",
|
|
185
|
+
"return",
|
|
186
|
+
"if",
|
|
187
|
+
"else",
|
|
188
|
+
"for",
|
|
189
|
+
"while",
|
|
190
|
+
"class",
|
|
191
|
+
"extends",
|
|
192
|
+
"new",
|
|
193
|
+
"this",
|
|
194
|
+
"import",
|
|
195
|
+
"export",
|
|
196
|
+
"from",
|
|
197
|
+
"default",
|
|
198
|
+
"async",
|
|
199
|
+
"await",
|
|
200
|
+
"try",
|
|
201
|
+
"catch",
|
|
202
|
+
"throw",
|
|
203
|
+
"of",
|
|
204
|
+
"in",
|
|
205
|
+
"typeof",
|
|
206
|
+
"instanceof",
|
|
207
|
+
"switch",
|
|
208
|
+
"case",
|
|
209
|
+
"break",
|
|
210
|
+
"continue",
|
|
211
|
+
"null",
|
|
212
|
+
"undefined",
|
|
213
|
+
"true",
|
|
214
|
+
"false"
|
|
215
|
+
]),
|
|
216
|
+
ts: /* @__PURE__ */ new Set([
|
|
217
|
+
"const",
|
|
218
|
+
"let",
|
|
219
|
+
"var",
|
|
220
|
+
"function",
|
|
221
|
+
"return",
|
|
222
|
+
"if",
|
|
223
|
+
"else",
|
|
224
|
+
"for",
|
|
225
|
+
"while",
|
|
226
|
+
"class",
|
|
227
|
+
"extends",
|
|
228
|
+
"new",
|
|
229
|
+
"this",
|
|
230
|
+
"import",
|
|
231
|
+
"export",
|
|
232
|
+
"from",
|
|
233
|
+
"default",
|
|
234
|
+
"async",
|
|
235
|
+
"await",
|
|
236
|
+
"try",
|
|
237
|
+
"catch",
|
|
238
|
+
"throw",
|
|
239
|
+
"of",
|
|
240
|
+
"in",
|
|
241
|
+
"typeof",
|
|
242
|
+
"instanceof",
|
|
243
|
+
"switch",
|
|
244
|
+
"case",
|
|
245
|
+
"break",
|
|
246
|
+
"continue",
|
|
247
|
+
"null",
|
|
248
|
+
"undefined",
|
|
249
|
+
"true",
|
|
250
|
+
"false",
|
|
251
|
+
"type",
|
|
252
|
+
"interface",
|
|
253
|
+
"enum",
|
|
254
|
+
"as",
|
|
255
|
+
"is",
|
|
256
|
+
"readonly",
|
|
257
|
+
"implements",
|
|
258
|
+
"abstract",
|
|
259
|
+
"public",
|
|
260
|
+
"private",
|
|
261
|
+
"protected",
|
|
262
|
+
"static",
|
|
263
|
+
"void",
|
|
264
|
+
"never",
|
|
265
|
+
"any",
|
|
266
|
+
"unknown"
|
|
267
|
+
]),
|
|
268
|
+
py: /* @__PURE__ */ new Set([
|
|
269
|
+
"def",
|
|
270
|
+
"class",
|
|
271
|
+
"return",
|
|
272
|
+
"if",
|
|
273
|
+
"elif",
|
|
274
|
+
"else",
|
|
275
|
+
"for",
|
|
276
|
+
"while",
|
|
277
|
+
"import",
|
|
278
|
+
"from",
|
|
279
|
+
"as",
|
|
280
|
+
"with",
|
|
281
|
+
"try",
|
|
282
|
+
"except",
|
|
283
|
+
"raise",
|
|
284
|
+
"finally",
|
|
285
|
+
"pass",
|
|
286
|
+
"break",
|
|
287
|
+
"continue",
|
|
288
|
+
"and",
|
|
289
|
+
"or",
|
|
290
|
+
"not",
|
|
291
|
+
"in",
|
|
292
|
+
"is",
|
|
293
|
+
"None",
|
|
294
|
+
"True",
|
|
295
|
+
"False",
|
|
296
|
+
"yield",
|
|
297
|
+
"lambda",
|
|
298
|
+
"global",
|
|
299
|
+
"nonlocal",
|
|
300
|
+
"del",
|
|
301
|
+
"assert",
|
|
302
|
+
"async",
|
|
303
|
+
"await"
|
|
304
|
+
]),
|
|
305
|
+
rust: /* @__PURE__ */ new Set([
|
|
306
|
+
"fn",
|
|
307
|
+
"let",
|
|
308
|
+
"mut",
|
|
309
|
+
"const",
|
|
310
|
+
"if",
|
|
311
|
+
"else",
|
|
312
|
+
"for",
|
|
313
|
+
"while",
|
|
314
|
+
"loop",
|
|
315
|
+
"match",
|
|
316
|
+
"return",
|
|
317
|
+
"struct",
|
|
318
|
+
"enum",
|
|
319
|
+
"impl",
|
|
320
|
+
"trait",
|
|
321
|
+
"pub",
|
|
322
|
+
"use",
|
|
323
|
+
"mod",
|
|
324
|
+
"crate",
|
|
325
|
+
"self",
|
|
326
|
+
"super",
|
|
327
|
+
"where",
|
|
328
|
+
"as",
|
|
329
|
+
"in",
|
|
330
|
+
"ref",
|
|
331
|
+
"move",
|
|
332
|
+
"async",
|
|
333
|
+
"await",
|
|
334
|
+
"true",
|
|
335
|
+
"false",
|
|
336
|
+
"type",
|
|
337
|
+
"unsafe",
|
|
338
|
+
"extern",
|
|
339
|
+
"dyn",
|
|
340
|
+
"static"
|
|
341
|
+
])
|
|
342
|
+
};
|
|
343
|
+
KEYWORD_SETS["javascript"] = KEYWORD_SETS["js"];
|
|
344
|
+
KEYWORD_SETS["typescript"] = KEYWORD_SETS["ts"];
|
|
345
|
+
KEYWORD_SETS["python"] = KEYWORD_SETS["py"];
|
|
346
|
+
KEYWORD_SETS["rs"] = KEYWORD_SETS["rust"];
|
|
347
|
+
function highlightLine(line, lang, theme) {
|
|
348
|
+
const keywords = KEYWORD_SETS[lang];
|
|
349
|
+
if (!keywords) {
|
|
350
|
+
return [{ text: line, color: theme.codeColor }];
|
|
351
|
+
}
|
|
352
|
+
const segments = [];
|
|
353
|
+
const KEYWORD_COLOR = "#c084fc";
|
|
354
|
+
const STRING_COLOR = "#86efac";
|
|
355
|
+
const COMMENT_COLOR = "#64748b";
|
|
356
|
+
const NUMBER_COLOR = "#fbbf24";
|
|
357
|
+
let i = 0;
|
|
358
|
+
let buf = "";
|
|
359
|
+
const flush = (color) => {
|
|
360
|
+
if (buf) {
|
|
361
|
+
segments.push({ text: buf, color });
|
|
362
|
+
buf = "";
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
while (i < line.length) {
|
|
366
|
+
const ch = line[i];
|
|
367
|
+
if (ch === "/" && line[i + 1] === "/") {
|
|
368
|
+
flush(theme.codeColor);
|
|
369
|
+
segments.push({ text: line.slice(i), color: COMMENT_COLOR });
|
|
370
|
+
return segments;
|
|
371
|
+
}
|
|
372
|
+
if (ch === "#" && (lang === "py" || lang === "python" || lang === "rust" || lang === "rs")) {
|
|
373
|
+
flush(theme.codeColor);
|
|
374
|
+
segments.push({ text: line.slice(i), color: COMMENT_COLOR });
|
|
375
|
+
return segments;
|
|
376
|
+
}
|
|
377
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
378
|
+
flush(theme.codeColor);
|
|
379
|
+
const quote = ch;
|
|
380
|
+
let j = i + 1;
|
|
381
|
+
while (j < line.length && line[j] !== quote) {
|
|
382
|
+
if (line[j] === "\\") j++;
|
|
383
|
+
j++;
|
|
384
|
+
}
|
|
385
|
+
j++;
|
|
386
|
+
segments.push({ text: line.slice(i, j), color: STRING_COLOR });
|
|
387
|
+
i = j;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (/\d/.test(ch) && (i === 0 || /[\s(,=+\-*/<>[\]{}:;]/.test(line[i - 1]))) {
|
|
391
|
+
flush(theme.codeColor);
|
|
392
|
+
let j = i;
|
|
393
|
+
while (j < line.length && /[\d._xXa-fA-F]/.test(line[j])) j++;
|
|
394
|
+
segments.push({ text: line.slice(i, j), color: NUMBER_COLOR });
|
|
395
|
+
i = j;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (/[a-zA-Z_]/.test(ch)) {
|
|
399
|
+
flush(theme.codeColor);
|
|
400
|
+
let j = i;
|
|
401
|
+
while (j < line.length && /[a-zA-Z0-9_]/.test(line[j])) j++;
|
|
402
|
+
const word = line.slice(i, j);
|
|
403
|
+
segments.push({ text: word, color: keywords.has(word) ? KEYWORD_COLOR : theme.codeColor });
|
|
404
|
+
i = j;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
buf += ch;
|
|
408
|
+
i++;
|
|
409
|
+
}
|
|
410
|
+
flush(theme.codeColor);
|
|
411
|
+
return segments;
|
|
412
|
+
}
|
|
413
|
+
var CodeBlock = class extends import_ui.UIComponent {
|
|
414
|
+
lines;
|
|
415
|
+
grid = null;
|
|
416
|
+
cellWidth = 0;
|
|
417
|
+
source;
|
|
418
|
+
lang;
|
|
419
|
+
theme;
|
|
420
|
+
lineH = 24;
|
|
421
|
+
pad = 18;
|
|
422
|
+
codeFont;
|
|
423
|
+
selectable;
|
|
424
|
+
constructor(code, lang, maxWidth, theme, selectable = true) {
|
|
425
|
+
super();
|
|
426
|
+
this.source = code;
|
|
427
|
+
this.lang = lang;
|
|
428
|
+
this.theme = theme;
|
|
429
|
+
this.codeFont = `15px ${theme.codeFont}`;
|
|
430
|
+
this.selectable = selectable;
|
|
431
|
+
this.lines = [];
|
|
432
|
+
this.width = maxWidth;
|
|
433
|
+
this.buildLines(code);
|
|
434
|
+
}
|
|
435
|
+
/** Re-parse code content (e.g. for live editing). */
|
|
436
|
+
setCode(code, lang) {
|
|
437
|
+
if (lang !== void 0) this.lang = lang;
|
|
438
|
+
this.source = code;
|
|
439
|
+
this.buildLines(code);
|
|
440
|
+
this.scene?.markDirty();
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
/** Enable or disable browser-native selection for this code block. */
|
|
444
|
+
setSelectable(selectable) {
|
|
445
|
+
this.selectable = selectable;
|
|
446
|
+
this.scene?.markDirty();
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
getContentProjection() {
|
|
450
|
+
if (!this.source) return null;
|
|
451
|
+
const grid = this.ensureGrid();
|
|
452
|
+
return {
|
|
453
|
+
text: this.source,
|
|
454
|
+
font: this.codeFont,
|
|
455
|
+
lineHeight: this.lineH,
|
|
456
|
+
// Every row is absolutely positioned from the same local coordinates as
|
|
457
|
+
// render(). A single pre-wrap DOM text node would introduce browser
|
|
458
|
+
// wrapping for long source lines that canvas intentionally keeps intact.
|
|
459
|
+
lines: grid.lines.map((line, row) => ({
|
|
460
|
+
text: this.source.slice(line.sourceStart, line.sourceEnd),
|
|
461
|
+
separatorAfter: this.source.slice(line.sourceEnd, line.nextSourceStart) || void 0,
|
|
462
|
+
x: this.pad,
|
|
463
|
+
y: this.pad + row * this.lineH,
|
|
464
|
+
baseline: this.lineH * 0.75,
|
|
465
|
+
font: this.codeFont,
|
|
466
|
+
lineHeight: this.lineH
|
|
467
|
+
})),
|
|
468
|
+
selectable: this.selectable,
|
|
469
|
+
// render() draws cell-by-cell (no ligatures can form); the DOM copy
|
|
470
|
+
// must not ligate either or Firefox selection geometry drifts.
|
|
471
|
+
ligatures: "none",
|
|
472
|
+
grid
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
buildLines(code) {
|
|
476
|
+
const rawLines = code.split(/\r\n|\r|\n/);
|
|
477
|
+
this.lines = rawLines.map((l) => highlightLine(l, this.lang, this.theme));
|
|
478
|
+
this.grid = null;
|
|
479
|
+
this.height = this.pad * 2 + rawLines.length * this.lineH;
|
|
480
|
+
}
|
|
481
|
+
ensureGrid() {
|
|
482
|
+
const cellWidth = this.cellWidth || Math.max(1, (0, import_ui.measureText)("M", this.codeFont));
|
|
483
|
+
if (!this.grid || this.grid.source !== this.source || this.grid.font !== this.codeFont || this.grid.cellWidth !== cellWidth) {
|
|
484
|
+
this.grid = (0, import_core.prepareContentGrid)(this.source, {
|
|
485
|
+
font: this.codeFont,
|
|
486
|
+
cellWidth,
|
|
487
|
+
lineHeight: this.lineH,
|
|
488
|
+
baseline: this.lineH * 0.75
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return this.grid;
|
|
492
|
+
}
|
|
493
|
+
/** Code blocks are decorative — not interactive. */
|
|
494
|
+
isPointInside() {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
render(r) {
|
|
498
|
+
r.beginPath();
|
|
499
|
+
r.roundRect(0, 0, this.width, this.height, 8);
|
|
500
|
+
r.fill(this.theme.codeBgColor);
|
|
501
|
+
const grid = this.ensureGrid();
|
|
502
|
+
for (let row = 0; row < grid.lines.length; row++) {
|
|
503
|
+
const yBaseline = this.pad + row * this.lineH + this.lineH * 0.75;
|
|
504
|
+
const segments = this.lines[row];
|
|
505
|
+
let segmentIndex = 0;
|
|
506
|
+
let segmentEnd = segments[0]?.text.length ?? 0;
|
|
507
|
+
const lineStart = grid.lines[row].sourceStart;
|
|
508
|
+
for (const cell of grid.lines[row].cells) {
|
|
509
|
+
const localSourceStart = cell.sourceStart - lineStart;
|
|
510
|
+
while (segmentIndex < segments.length - 1 && localSourceStart >= segmentEnd) {
|
|
511
|
+
segmentIndex++;
|
|
512
|
+
segmentEnd += segments[segmentIndex].text.length;
|
|
513
|
+
}
|
|
514
|
+
const sourceText = this.source.slice(cell.sourceStart, cell.sourceEnd);
|
|
515
|
+
if (cell.advance <= 0 || sourceText === " " || sourceText === " ") continue;
|
|
516
|
+
r.fillText(
|
|
517
|
+
cell.glyph,
|
|
518
|
+
this.pad + cell.x,
|
|
519
|
+
yBaseline,
|
|
520
|
+
this.codeFont,
|
|
521
|
+
segments[segmentIndex]?.color ?? this.theme.codeColor
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
function decodeEntities(text) {
|
|
528
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
529
|
+
}
|
|
530
|
+
function collectSpans(tokens, inherited, theme, out) {
|
|
531
|
+
for (const token of tokens) {
|
|
532
|
+
switch (token.type) {
|
|
533
|
+
case "strong": {
|
|
534
|
+
const t = token;
|
|
535
|
+
if (t.tokens) {
|
|
536
|
+
collectSpans(t.tokens, { ...inherited, bold: true }, theme, out);
|
|
537
|
+
} else {
|
|
538
|
+
out.push({ text: decodeEntities(t.text), style: { ...inherited, bold: true } });
|
|
539
|
+
}
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
case "em": {
|
|
543
|
+
const t = token;
|
|
544
|
+
if (t.tokens) {
|
|
545
|
+
collectSpans(t.tokens, { ...inherited, italic: true }, theme, out);
|
|
546
|
+
} else {
|
|
547
|
+
out.push({ text: decodeEntities(t.text), style: { ...inherited, italic: true } });
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case "codespan": {
|
|
552
|
+
const t = token;
|
|
553
|
+
out.push({ text: decodeEntities(t.text), style: { ...inherited, color: theme.codeColor } });
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
case "br": {
|
|
557
|
+
out.push({ text: "\n" });
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
case "html": {
|
|
561
|
+
const t = token;
|
|
562
|
+
const raw = t.raw ?? t.text ?? "";
|
|
563
|
+
const brCount = (raw.match(/<br\s*\/?>/gi) ?? []).length;
|
|
564
|
+
for (let i = 0; i < brCount; i++) out.push({ text: "\n" });
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
case "inlineMath": {
|
|
568
|
+
const t = token;
|
|
569
|
+
out.push({ text: decodeEntities(t.raw), style: { ...inherited, color: "#fcd34d" } });
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
case "link": {
|
|
573
|
+
const t = token;
|
|
574
|
+
const linkStyle = { ...inherited, href: t.href, color: "#38bdf8" };
|
|
575
|
+
if (t.tokens && t.tokens.length > 0) {
|
|
576
|
+
collectSpans(t.tokens, linkStyle, theme, out);
|
|
577
|
+
} else {
|
|
578
|
+
out.push({ text: decodeEntities(t.text), style: linkStyle });
|
|
579
|
+
}
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case "text": {
|
|
583
|
+
const t = token;
|
|
584
|
+
if ("tokens" in t && t.tokens?.length) {
|
|
585
|
+
collectSpans(t.tokens, inherited, theme, out);
|
|
586
|
+
} else {
|
|
587
|
+
const decoded = decodeEntities(t.text);
|
|
588
|
+
if (decoded) {
|
|
589
|
+
const style = Object.keys(inherited).length > 0 ? inherited : void 0;
|
|
590
|
+
out.push({ text: decoded, style });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
default: {
|
|
596
|
+
if ("text" in token) {
|
|
597
|
+
const decoded = decodeEntities(token.text);
|
|
598
|
+
if (decoded) {
|
|
599
|
+
const style = Object.keys(inherited).length > 0 ? inherited : void 0;
|
|
600
|
+
out.push({ text: decoded, style });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function renderInlineToRichText(tokens, fallbackText, font, color, maxWidth, theme, selectable, onLinkClick) {
|
|
609
|
+
const spans = [];
|
|
610
|
+
if (tokens && tokens.length > 0) {
|
|
611
|
+
collectSpans(tokens, {}, theme, spans);
|
|
612
|
+
}
|
|
613
|
+
if (spans.length === 0) {
|
|
614
|
+
spans.push({ text: decodeEntities(fallbackText) });
|
|
615
|
+
}
|
|
616
|
+
return new import_ui.RichText(spans, {
|
|
617
|
+
font,
|
|
618
|
+
color,
|
|
619
|
+
maxWidth,
|
|
620
|
+
linkColor: "#38bdf8",
|
|
621
|
+
selectable,
|
|
622
|
+
onLinkClick
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
var Markdown = class extends import_ui.UIComponent {
|
|
626
|
+
content;
|
|
627
|
+
maxWidth;
|
|
628
|
+
theme;
|
|
629
|
+
onLinkClick;
|
|
630
|
+
selectable;
|
|
631
|
+
onLayoutUpdated;
|
|
632
|
+
rawMarkdown;
|
|
633
|
+
tokens;
|
|
634
|
+
// At most one worker lex request in flight at a time. Required for the
|
|
635
|
+
// delta-transfer protocol below to be safe: the request captures a
|
|
636
|
+
// snapshot of `this.tokens` to reconstruct the full array from the
|
|
637
|
+
// worker's (matchLen, tail) response, and that snapshot would go stale if
|
|
638
|
+
// another request's callback could run — and mutate `this.tokens` — while
|
|
639
|
+
// this one is still pending. `appendPending` means "more text arrived
|
|
640
|
+
// while a request was in flight"; the in-flight callback re-dispatches
|
|
641
|
+
// with the latest accumulated text once it resolves.
|
|
642
|
+
appendInFlight = false;
|
|
643
|
+
appendPending = false;
|
|
644
|
+
constructor(markdownText, opts = {}) {
|
|
645
|
+
super();
|
|
646
|
+
this.maxWidth = opts.maxWidth ?? 800;
|
|
647
|
+
this.theme = { ...DEFAULT_THEME, ...opts.theme };
|
|
648
|
+
this.onLinkClick = opts.onLinkClick;
|
|
649
|
+
this.selectable = opts.selectable ?? true;
|
|
650
|
+
this.content = new import_ui.Stack({ direction: "vertical", gap: 16 });
|
|
651
|
+
this.add(this.content);
|
|
652
|
+
this.rawMarkdown = markdownText;
|
|
653
|
+
this.tokens = [];
|
|
654
|
+
this.renderMarkdown(markdownText);
|
|
655
|
+
}
|
|
656
|
+
renderMarkdown(text) {
|
|
657
|
+
const tokens = import_marked.marked.lexer(text);
|
|
658
|
+
this.tokens = tokens;
|
|
659
|
+
for (const token of tokens) {
|
|
660
|
+
const el = this.renderToken(token);
|
|
661
|
+
if (el) {
|
|
662
|
+
this.content.add(el);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
this.width = this.content.width;
|
|
666
|
+
this.height = this.content.height;
|
|
667
|
+
}
|
|
668
|
+
/** Replace all markdown content (full rebuild). */
|
|
669
|
+
setContent(markdown) {
|
|
670
|
+
this.rawMarkdown = markdown;
|
|
671
|
+
while (this.content.children.length > 0) {
|
|
672
|
+
this.content.remove(this.content.children[this.content.children.length - 1]);
|
|
673
|
+
}
|
|
674
|
+
this.tokens = [];
|
|
675
|
+
this.renderMarkdown(markdown);
|
|
676
|
+
return this;
|
|
677
|
+
}
|
|
678
|
+
/** Enable or disable native selection for existing and future Markdown text. */
|
|
679
|
+
setSelectable(selectable) {
|
|
680
|
+
this.selectable = selectable;
|
|
681
|
+
const apply = (entity) => {
|
|
682
|
+
const candidate = entity;
|
|
683
|
+
candidate.setSelectable?.(selectable);
|
|
684
|
+
for (const child of entity.children) apply(child);
|
|
685
|
+
};
|
|
686
|
+
for (const child of this.content.children) apply(child);
|
|
687
|
+
this.scene?.markDirty();
|
|
688
|
+
return this;
|
|
689
|
+
}
|
|
690
|
+
/** Append a markdown chunk incrementally. Reuses unchanged prefix entities. */
|
|
691
|
+
appendMarkdown(chunk) {
|
|
692
|
+
this.rawMarkdown += chunk;
|
|
693
|
+
if (!markdownWorker) {
|
|
694
|
+
const newTokens = import_marked.marked.lexer(this.rawMarkdown);
|
|
695
|
+
this.updateTokens(newTokens);
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
if (this.appendInFlight) {
|
|
699
|
+
this.appendPending = true;
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
this.dispatchAppend();
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
705
|
+
dispatchAppend() {
|
|
706
|
+
if (!markdownWorker) return;
|
|
707
|
+
this.appendInFlight = true;
|
|
708
|
+
const id = workerIdCounter++;
|
|
709
|
+
const oldTokensSnapshot = this.tokens;
|
|
710
|
+
const oldRaws = oldTokensSnapshot.map((t) => t.raw);
|
|
711
|
+
workerCallbacks.set(id, {
|
|
712
|
+
cb: (matchLen, tail) => {
|
|
713
|
+
this.appendInFlight = false;
|
|
714
|
+
const newTokens = [...oldTokensSnapshot.slice(0, matchLen), ...tail];
|
|
715
|
+
this.updateTokens(newTokens);
|
|
716
|
+
if (this.appendPending) {
|
|
717
|
+
this.appendPending = false;
|
|
718
|
+
this.dispatchAppend();
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
text: this.rawMarkdown
|
|
722
|
+
});
|
|
723
|
+
markdownWorker.postMessage({ id, text: this.rawMarkdown, oldRaws });
|
|
724
|
+
}
|
|
725
|
+
updateTokens(newTokens) {
|
|
726
|
+
const oldTokens = this.tokens;
|
|
727
|
+
const oldChildren = [...this.content.children];
|
|
728
|
+
let matchLen = 0;
|
|
729
|
+
const minLen = Math.min(oldTokens.length, newTokens.length);
|
|
730
|
+
let childIdx = 0;
|
|
731
|
+
const oldTokenToChild = [];
|
|
732
|
+
for (let i = 0; i < oldTokens.length; i++) {
|
|
733
|
+
oldTokenToChild.push(childIdx);
|
|
734
|
+
if (oldTokens[i].type !== "space") childIdx++;
|
|
735
|
+
}
|
|
736
|
+
for (let i = 0; i < minLen; i++) {
|
|
737
|
+
if (oldTokens[i].raw === newTokens[i].raw) {
|
|
738
|
+
matchLen++;
|
|
739
|
+
} else {
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (matchLen === oldTokens.length - 1 && matchLen < newTokens.length && oldTokens[matchLen]?.type === newTokens[matchLen]?.type && newTokens[matchLen]?.type === "paragraph") {
|
|
744
|
+
const entityIdx = oldTokenToChild[matchLen];
|
|
745
|
+
const existingEntity = oldChildren[entityIdx];
|
|
746
|
+
if (existingEntity && "setSpans" in existingEntity) {
|
|
747
|
+
const pToken = newTokens[matchLen];
|
|
748
|
+
const t = this.theme;
|
|
749
|
+
const spans = [];
|
|
750
|
+
if (pToken.tokens && pToken.tokens.length > 0) {
|
|
751
|
+
collectSpans(pToken.tokens, {}, t, spans);
|
|
752
|
+
}
|
|
753
|
+
if (spans.length === 0) {
|
|
754
|
+
spans.push({ text: pToken.text });
|
|
755
|
+
}
|
|
756
|
+
existingEntity.setSpans(spans);
|
|
757
|
+
matchLen++;
|
|
758
|
+
this.content.resizeLastChild(existingEntity);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
for (let i = 0; i < oldTokens.length; i++) {
|
|
762
|
+
if (i >= matchLen && oldTokens[i].type !== "space") {
|
|
763
|
+
const idx = oldTokenToChild[i];
|
|
764
|
+
if (idx < oldChildren.length) {
|
|
765
|
+
this.content.remove(oldChildren[idx]);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
for (let i = matchLen; i < newTokens.length; i++) {
|
|
770
|
+
const el = this.renderToken(newTokens[i]);
|
|
771
|
+
if (el) this.content.add(el);
|
|
772
|
+
}
|
|
773
|
+
this.tokens = newTokens;
|
|
774
|
+
this.width = this.content.width;
|
|
775
|
+
this.height = this.content.height;
|
|
776
|
+
this.scene?.markDirty();
|
|
777
|
+
if (this.onLayoutUpdated) {
|
|
778
|
+
this.onLayoutUpdated();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
renderToken(token) {
|
|
782
|
+
const t = this.theme;
|
|
783
|
+
const bodyFont = `${t.fontSize}px ${t.bodyFont}`;
|
|
784
|
+
switch (token.type) {
|
|
785
|
+
// ── Headings ─────────────────────────────────────────────────────
|
|
786
|
+
case "heading": {
|
|
787
|
+
const hToken = token;
|
|
788
|
+
const sizes = [32, 28, 24, 20, 18, 16];
|
|
789
|
+
const size = sizes[Math.min(hToken.depth - 1, 5)];
|
|
790
|
+
const headingFont = `bold ${size}px ${t.bodyFont}`;
|
|
791
|
+
return renderInlineToRichText(
|
|
792
|
+
hToken.tokens,
|
|
793
|
+
hToken.text,
|
|
794
|
+
headingFont,
|
|
795
|
+
t.headingColor,
|
|
796
|
+
this.maxWidth,
|
|
797
|
+
t,
|
|
798
|
+
this.selectable,
|
|
799
|
+
this.onLinkClick
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
// ── Paragraphs ───────────────────────────────────────────────────
|
|
803
|
+
case "paragraph": {
|
|
804
|
+
const pToken = token;
|
|
805
|
+
if (!pToken.tokens || !pToken.tokens.some((t2) => t2.type === "image")) {
|
|
806
|
+
return renderInlineToRichText(
|
|
807
|
+
pToken.tokens,
|
|
808
|
+
pToken.text,
|
|
809
|
+
bodyFont,
|
|
810
|
+
t.textColor,
|
|
811
|
+
this.maxWidth,
|
|
812
|
+
t,
|
|
813
|
+
this.selectable,
|
|
814
|
+
this.onLinkClick
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const stack = new import_ui.Stack({ direction: "vertical", gap: 16, maxWidth: this.maxWidth });
|
|
818
|
+
let currentTokens = [];
|
|
819
|
+
const flushText = () => {
|
|
820
|
+
if (currentTokens.length > 0) {
|
|
821
|
+
stack.add(
|
|
822
|
+
renderInlineToRichText(
|
|
823
|
+
currentTokens,
|
|
824
|
+
"",
|
|
825
|
+
bodyFont,
|
|
826
|
+
t.textColor,
|
|
827
|
+
this.maxWidth,
|
|
828
|
+
t,
|
|
829
|
+
this.selectable,
|
|
830
|
+
this.onLinkClick
|
|
831
|
+
)
|
|
832
|
+
);
|
|
833
|
+
currentTokens = [];
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
for (const child of pToken.tokens) {
|
|
837
|
+
if (child.type === "image") {
|
|
838
|
+
flushText();
|
|
839
|
+
const imgToken = child;
|
|
840
|
+
const initialWidth = Math.min(800, this.maxWidth);
|
|
841
|
+
const initialHeight = Math.round(initialWidth * 0.6);
|
|
842
|
+
const img = new import_ui.Image(imgToken.href, {
|
|
843
|
+
width: initialWidth,
|
|
844
|
+
height: initialHeight,
|
|
845
|
+
alt: imgToken.text,
|
|
846
|
+
radius: 8,
|
|
847
|
+
onLoad: () => {
|
|
848
|
+
const bmp = img.bitmap;
|
|
849
|
+
if (bmp && bmp.naturalWidth && bmp.naturalHeight) {
|
|
850
|
+
const aspect = bmp.naturalHeight / bmp.naturalWidth;
|
|
851
|
+
img.width = Math.min(bmp.naturalWidth, this.maxWidth);
|
|
852
|
+
img.height = Math.round(img.width * aspect);
|
|
853
|
+
if (this.scene) this.scene.markDirty();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
stack.add(img);
|
|
858
|
+
} else {
|
|
859
|
+
currentTokens.push(child);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
flushText();
|
|
863
|
+
return stack;
|
|
864
|
+
}
|
|
865
|
+
// ── Code blocks ──────────────────────────────────────────────────
|
|
866
|
+
case "code": {
|
|
867
|
+
const codeToken = token;
|
|
868
|
+
const lang = (codeToken.lang ?? "").toLowerCase();
|
|
869
|
+
if (lang === "math" || lang === "latex" || lang === "tex") {
|
|
870
|
+
const mathData = renderMathToSVGDataURI(codeToken.text, true);
|
|
871
|
+
if (mathData) {
|
|
872
|
+
const mathImg = new import_ui.Image(mathData.uri, {
|
|
873
|
+
width: Math.min(this.maxWidth, mathData.width),
|
|
874
|
+
height: mathData.height * Math.min(1, this.maxWidth / mathData.width),
|
|
875
|
+
alt: codeToken.text
|
|
876
|
+
});
|
|
877
|
+
const wrapper = new MarkdownContainer();
|
|
878
|
+
mathImg.x = 16;
|
|
879
|
+
mathImg.y = 8;
|
|
880
|
+
wrapper.add(mathImg);
|
|
881
|
+
wrapper.width = mathImg.width + 16;
|
|
882
|
+
wrapper.height = mathImg.height + 16;
|
|
883
|
+
return wrapper;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return new CodeBlock(codeToken.text, lang, this.maxWidth, t, this.selectable);
|
|
887
|
+
}
|
|
888
|
+
// ── Blockquotes ──────────────────────────────────────────────────
|
|
889
|
+
case "blockquote": {
|
|
890
|
+
const bqToken = token;
|
|
891
|
+
const innerStack = new import_ui.Stack({ direction: "vertical", gap: 8 });
|
|
892
|
+
if (bqToken.tokens) {
|
|
893
|
+
for (const inner of bqToken.tokens) {
|
|
894
|
+
const el = this.renderToken(inner);
|
|
895
|
+
if (el) {
|
|
896
|
+
const wrapper = new MarkdownContainer();
|
|
897
|
+
el.x = 16;
|
|
898
|
+
wrapper.add(el);
|
|
899
|
+
wrapper.width = el.width + 16;
|
|
900
|
+
wrapper.height = el.height;
|
|
901
|
+
innerStack.add(wrapper);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const border = new QuoteBorder(innerStack.height || 20, t.quoteBorderColor);
|
|
906
|
+
const container = new MarkdownContainer();
|
|
907
|
+
border.x = 0;
|
|
908
|
+
border.y = 0;
|
|
909
|
+
container.add(border);
|
|
910
|
+
innerStack.y = 0;
|
|
911
|
+
innerStack.x = 0;
|
|
912
|
+
container.add(innerStack);
|
|
913
|
+
container.width = this.maxWidth;
|
|
914
|
+
container.height = Math.max(border.height, innerStack.height);
|
|
915
|
+
return container;
|
|
916
|
+
}
|
|
917
|
+
// ── Lists ────────────────────────────────────────────────────────
|
|
918
|
+
case "list": {
|
|
919
|
+
const listToken = token;
|
|
920
|
+
const listStack = new import_ui.Stack({ direction: "vertical", gap: 6 });
|
|
921
|
+
for (let i = 0; i < listToken.items.length; i++) {
|
|
922
|
+
const item = listToken.items[i];
|
|
923
|
+
const bullet = listToken.ordered ? `${Number(listToken.start ?? 1) + i}. ` : "\u2022 ";
|
|
924
|
+
const itemSpans = [{ text: bullet }];
|
|
925
|
+
if (item.tokens && item.tokens.length > 0) {
|
|
926
|
+
for (const inner of item.tokens) {
|
|
927
|
+
if (inner.type === "text" && "tokens" in inner && inner.tokens?.length) {
|
|
928
|
+
collectSpans(inner.tokens, {}, t, itemSpans);
|
|
929
|
+
} else if ("tokens" in inner && inner.tokens?.length) {
|
|
930
|
+
collectSpans(inner.tokens, {}, t, itemSpans);
|
|
931
|
+
} else if ("text" in inner) {
|
|
932
|
+
itemSpans.push({ text: decodeEntities(inner.text) });
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
itemSpans.push({ text: decodeEntities(item.text) });
|
|
937
|
+
}
|
|
938
|
+
const itemRt = new import_ui.RichText(itemSpans, {
|
|
939
|
+
font: bodyFont,
|
|
940
|
+
color: t.textColor,
|
|
941
|
+
maxWidth: this.maxWidth - 24,
|
|
942
|
+
linkColor: "#38bdf8",
|
|
943
|
+
selectable: this.selectable,
|
|
944
|
+
onLinkClick: this.onLinkClick
|
|
945
|
+
});
|
|
946
|
+
itemRt.x = 12;
|
|
947
|
+
listStack.add(itemRt);
|
|
948
|
+
}
|
|
949
|
+
return listStack;
|
|
950
|
+
}
|
|
951
|
+
// ── Table ────────────────────────────────────────────────────────
|
|
952
|
+
case "table": {
|
|
953
|
+
const tblToken = token;
|
|
954
|
+
const buildCell = (cell, header) => {
|
|
955
|
+
const spans = [];
|
|
956
|
+
collectSpans(cell.tokens, {}, t, spans);
|
|
957
|
+
if (spans.length === 0) return decodeEntities(cell.text);
|
|
958
|
+
return new import_ui.RichText(spans, {
|
|
959
|
+
font: `${t.fontSize - 2}px ${t.bodyFont}`,
|
|
960
|
+
color: header ? t.headingColor : t.textColor,
|
|
961
|
+
baseStyle: header ? { bold: true } : void 0,
|
|
962
|
+
linkColor: "#38bdf8",
|
|
963
|
+
selectable: this.selectable,
|
|
964
|
+
onLinkClick: this.onLinkClick
|
|
965
|
+
});
|
|
966
|
+
};
|
|
967
|
+
const headers = tblToken.header.map((cell) => buildCell(cell, true));
|
|
968
|
+
const rows = tblToken.rows.map((row) => row.map((cell) => buildCell(cell, false)));
|
|
969
|
+
return new import_ui.Table({
|
|
970
|
+
headers,
|
|
971
|
+
rows,
|
|
972
|
+
width: this.maxWidth,
|
|
973
|
+
textColor: t.textColor,
|
|
974
|
+
headerTextColor: t.headingColor,
|
|
975
|
+
font: `${t.fontSize - 2}px ${t.bodyFont}`,
|
|
976
|
+
borderColor: t.hrColor,
|
|
977
|
+
bg: t.tableBgColor,
|
|
978
|
+
headerBg: t.tableHeaderBgColor,
|
|
979
|
+
selectable: this.selectable
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
// ── Horizontal rule ──────────────────────────────────────────────
|
|
983
|
+
case "hr":
|
|
984
|
+
return new HorizontalRule(this.maxWidth, t.hrColor);
|
|
985
|
+
// ── Whitespace ───────────────────────────────────────────────────
|
|
986
|
+
case "space":
|
|
987
|
+
return null;
|
|
988
|
+
// ── HTML (Support raw SVGs) ──────────────────────────────────────
|
|
989
|
+
case "html": {
|
|
990
|
+
const htmlToken = token;
|
|
991
|
+
if (htmlToken.text.toLowerCase().includes("<svg") && htmlToken.text.toLowerCase().includes("</svg>")) {
|
|
992
|
+
return new import_core.SVGEntity(htmlToken.text);
|
|
993
|
+
}
|
|
994
|
+
return null;
|
|
995
|
+
}
|
|
996
|
+
// ── Fallback ─────────────────────────────────────────────────────
|
|
997
|
+
default:
|
|
998
|
+
if ("text" in token) {
|
|
999
|
+
return new import_ui.Text(token.text, {
|
|
1000
|
+
font: bodyFont,
|
|
1001
|
+
color: t.textColor,
|
|
1002
|
+
maxWidth: this.maxWidth,
|
|
1003
|
+
lineHeight: 24,
|
|
1004
|
+
selectable: this.selectable
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
/** Structural — children draw themselves. */
|
|
1011
|
+
render(_r) {
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1015
|
+
0 && (module.exports = {
|
|
1016
|
+
CodeBlock,
|
|
1017
|
+
Markdown
|
|
1018
|
+
});
|