@tomflow/chatloop-tools 0.9.41 → 0.9.42
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/package.json +1 -1
- package/providers/document.mjs +3 -2
- package/ui/document/render-content.js +2 -0
- package/ui/document/view-app.js +11 -2
- package/ui/document/view.html +23 -23
package/package.json
CHANGED
package/providers/document.mjs
CHANGED
|
@@ -19,12 +19,13 @@ const documentSchema={type:'object',additionalProperties:false,
|
|
|
19
19
|
required:['title','content'],properties:{
|
|
20
20
|
title:{type:'string',minLength:1,maxLength:180},
|
|
21
21
|
content:{type:'string',minLength:1,maxLength:262144},
|
|
22
|
-
format:{type:'string',minLength:1,maxLength:80
|
|
22
|
+
format:{type:'string',minLength:1,maxLength:80,
|
|
23
|
+
description:'Content format. For Markdown source use text/markdown; omitted defaults to text/markdown. markdown/md aliases also render. Unknown formats remain safe raw text.'},
|
|
23
24
|
subtitle:{type:'string',maxLength:500}
|
|
24
25
|
}};
|
|
25
26
|
const tools=[
|
|
26
27
|
{name:'chat_loop_document__show',
|
|
27
|
-
description:'Display an independent
|
|
28
|
+
description:'Display an independent rich Document App with full-source copy. Set document.format to text/markdown for Markdown headings, lists and tables (also the default). The caller Skill owns content, versions and approval. Call this BEFORE the separate Form App; never put Form controls in Document.',
|
|
28
29
|
inputSchema:{type:'object',additionalProperties:false,required:['document'],
|
|
29
30
|
properties:{documentId:{type:'string',pattern:IDENT.source},
|
|
30
31
|
document:documentSchema}},
|
|
@@ -136,6 +136,8 @@ function diagram(root,source,copy){
|
|
|
136
136
|
}
|
|
137
137
|
const renderers=new Map([
|
|
138
138
|
['text/markdown',markdown],['text/x-markdown',markdown],
|
|
139
|
+
['markdown',markdown],['md',markdown],['text/md',markdown],
|
|
140
|
+
['application/markdown',markdown],
|
|
139
141
|
['text/plain',plain],['application/json',json],
|
|
140
142
|
['text/mermaid',diagram],['text/x-mermaid',diagram]
|
|
141
143
|
]);
|
package/ui/document/view-app.js
CHANGED
|
@@ -115,13 +115,22 @@ function render(result){
|
|
|
115
115
|
$('subtitle').textContent=view.subtitle;
|
|
116
116
|
const contents=$('content'),format=view.format;
|
|
117
117
|
const rendered=renderContent(contents,format,view.content,copyText);
|
|
118
|
+
// A standalone Document header already shows this title. Keep the source
|
|
119
|
+
// untouched for full-copy while avoiding an identical visible H1 twice.
|
|
120
|
+
const firstHeading=contents.querySelector(':scope > h1');
|
|
121
|
+
const normalize=value=>value.replace(/\s+/g,' ').trim();
|
|
122
|
+
const duplicateTitle=firstHeading&&normalize(firstHeading.textContent)===
|
|
123
|
+
normalize(view.title);
|
|
124
|
+
const duplicateId=duplicateTitle?firstHeading.id:null;
|
|
125
|
+
if(duplicateTitle)firstHeading.remove();
|
|
126
|
+
const visibleHeadings=rendered.headings.filter(heading=>heading.id!==duplicateId);
|
|
118
127
|
$('copy-all').disabled=false;
|
|
119
128
|
$('copy-all').textContent='复制全文';
|
|
120
129
|
$('copy-all').onclick=()=>void copyText(view.content,$('copy-all'));
|
|
121
130
|
const toc=$('toc'),links=$('toc-links');
|
|
122
131
|
links.replaceChildren();
|
|
123
|
-
toc.hidden=!
|
|
124
|
-
for(const heading of
|
|
132
|
+
toc.hidden=!visibleHeadings.length;
|
|
133
|
+
for(const heading of visibleHeadings.slice(0,100)){
|
|
125
134
|
const a=document.createElement('a');
|
|
126
135
|
a.href='#'+heading.id;
|
|
127
136
|
a.textContent=heading.text;
|
package/ui/document/view.html
CHANGED
|
@@ -91,32 +91,32 @@ border:1px dashed var(--line);padding:5px 8px}
|
|
|
91
91
|
<article id="content" aria-label="文档内容"></article>
|
|
92
92
|
<span id="status" role="status" aria-live="polite">正在连接文档服务…</span>
|
|
93
93
|
</main>
|
|
94
|
-
<script>(()=>{function
|
|
95
|
-
]`).replace("lheading",
|
|
94
|
+
<script>(()=>{function se(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var N=se();function Te(t){N=t}var Z={exec:()=>null};function g(t,e=""){let n=typeof t=="string"?t:t.source,s={replace:(r,l)=>{let i=typeof l=="string"?l:l.source;return i=i.replace(T.caret,"$1"),n=n.replace(r,i),s},getRegex:()=>new RegExp(n,e)};return s}var T={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,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ 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,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Xe=/^(?:[ \t]*(?:\n|$))+/,Je=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ye=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,j=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ke=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ie=/(?:[*+-]|\d{1,9}[.)])/,Re=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Se=g(Re).replace(/bull/g,ie).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(),et=g(Re).replace(/bull/g,ie).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(),le=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,tt=/^[^\n]+/,ae=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,nt=g(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ae).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),rt=g(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ie).getRegex(),J="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",oe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,st=g("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\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",oe).replace("tag",J).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ee=g(le).replace("hr",j).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"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",J).getRegex(),it=g(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ee).getRegex(),ce={blockquote:it,code:Je,def:nt,fences:Ye,heading:Ke,hr:j,html:st,lheading:Se,list:rt,newline:Xe,paragraph:Ee,table:Z,text:tt},me=g("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",j).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[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",J).getRegex(),lt={...ce,lheading:et,table:me,paragraph:g(le).replace("hr",j).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",me).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",J).getRegex()},at={...ce,html:g(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",oe).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:Z,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:g(le).replace("hr",j).replace("heading",` *#{1,6} *[^
|
|
95
|
+
]`).replace("lheading",Se).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},ot=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ct=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,$e=/^( {2,}|\\)\n(?!\s*$)/,ht=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Y=/[\p{P}\p{S}]/u,he=/[\s\p{P}\p{S}]/u,Ae=/[^\s\p{P}\p{S}]/u,pt=g(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,he).getRegex(),Ce=/(?!~)[\p{P}\p{S}]/u,ut=/(?!~)[\s\p{P}\p{S}]/u,dt=/(?:[^\s\p{P}\p{S}]|~)/u,gt=/\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g,ze=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,ft=g(ze,"u").replace(/punct/g,Y).getRegex(),kt=g(ze,"u").replace(/punct/g,Ce).getRegex(),_e="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",mt=g(_e,"gu").replace(/notPunctSpace/g,Ae).replace(/punctSpace/g,he).replace(/punct/g,Y).getRegex(),xt=g(_e,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,ut).replace(/punct/g,Ce).getRegex(),bt=g("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ae).replace(/punctSpace/g,he).replace(/punct/g,Y).getRegex(),wt=g(/\\(punct)/,"gu").replace(/punct/g,Y).getRegex(),yt=g(/^<(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(),Tt=g(oe).replace("(?:-->|$)","-->").getRegex(),Rt=g("^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",Tt).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),F=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,St=g(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",F).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ie=g(/^!?\[(label)\]\[(ref)\]/).replace("label",F).replace("ref",ae).getRegex(),ve=g(/^!?\[(ref)\](?:\[\])?/).replace("ref",ae).getRegex(),Et=g("reflink|nolink(?!\\()","g").replace("reflink",Ie).replace("nolink",ve).getRegex(),pe={_backpedal:Z,anyPunctuation:wt,autolink:yt,blockSkip:gt,br:$e,code:ct,del:Z,emStrongLDelim:ft,emStrongRDelimAst:mt,emStrongRDelimUnd:bt,escape:ot,link:St,nolink:ve,punctuation:pt,reflink:Ie,reflinkSearch:Et,tag:Rt,text:ht,url:Z},$t={...pe,link:g(/^!?\[(label)\]\((.*?)\)/).replace("label",F).getRegex(),reflink:g(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",F).getRegex()},te={...pe,emStrongRDelimAst:xt,emStrongLDelim:kt,url:g(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").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:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},At={...te,br:g($e).replace("{2,}","*").getRegex(),text:g(te.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},W={normal:ce,gfm:lt,pedantic:at},q={normal:pe,gfm:te,breaks:At,pedantic:$t},Ct={"&":"&","<":"<",">":">",'"':""","'":"'"},xe=t=>Ct[t];function A(t,e){if(e){if(T.escapeTest.test(t))return t.replace(T.escapeReplace,xe)}else if(T.escapeTestNoEncode.test(t))return t.replace(T.escapeReplaceNoEncode,xe);return t}function be(t){try{t=encodeURI(t).replace(T.percentDecode,"%")}catch{return null}return t}function we(t,e){let n=t.replace(T.findPipe,(l,i,a)=>{let o=!1,c=i;for(;--c>=0&&a[c]==="\\";)o=!o;return o?"|":" |"}),s=n.split(T.splitPipe),r=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(;r<s.length;r++)s[r]=s[r].trim().replace(T.slashPipe,"|");return s}function H(t,e,n){let s=t.length;if(s===0)return"";let r=0;for(;r<s;){let l=t.charAt(s-r-1);if(l===e&&!n)r++;else if(l!==e&&n)r++;else break}return t.slice(0,s-r)}function zt(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let s=0;s<t.length;s++)if(t[s]==="\\")s++;else if(t[s]===e[0])n++;else if(t[s]===e[1]&&(n--,n<0))return s;return n>0?-2:-1}function ye(t,e,n,s,r){let l=e.href,i=e.title||null,a=t[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let o={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:l,title:i,text:a,tokens:s.inlineTokens(a)};return s.state.inLink=!1,o}function _t(t,e,n){let s=t.match(n.other.indentCodeCompensation);if(s===null)return e;let r=s[1];return e.split(`
|
|
96
96
|
`).map(l=>{let i=l.match(n.other.beginningSpace);if(i===null)return l;let[a]=i;return a.length>=r.length?l.slice(r.length):l}).join(`
|
|
97
|
-
`)}var
|
|
98
|
-
`)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],s=_t(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let s=
|
|
99
|
-
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=
|
|
97
|
+
`)}var V=class{options;rules;lexer;constructor(t){this.options=t||N}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:H(n,`
|
|
98
|
+
`)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],s=_t(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let s=H(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(n=s.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:H(e[0],`
|
|
99
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=H(e[0],`
|
|
100
100
|
`).split(`
|
|
101
101
|
`),s="",r="",l=[];for(;n.length>0;){let i=!1,a=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))a.push(n[o]),i=!0;else if(!i)a.push(n[o]);else break;n=n.slice(o);let c=a.join(`
|
|
102
|
-
`),
|
|
102
|
+
`),p=c.replace(this.rules.other.blockquoteSetextReplace,`
|
|
103
103
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
|
|
104
104
|
${c}`:c,r=r?`${r}
|
|
105
|
-
${
|
|
105
|
+
${p}`:p;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,l,!0),this.lexer.state.top=u,n.length===0)break;let h=l.at(-1);if(h?.type==="code")break;if(h?.type==="blockquote"){let m=h,f=m.raw+`
|
|
106
106
|
`+n.join(`
|
|
107
|
-
`),b=this.blockquote(
|
|
107
|
+
`),b=this.blockquote(f);l[l.length-1]=b,s=s.substring(0,s.length-m.raw.length)+b.raw,r=r.substring(0,r.length-m.text.length)+b.text;break}else if(h?.type==="list"){let m=h,f=m.raw+`
|
|
108
108
|
`+n.join(`
|
|
109
|
-
`),b=this.list(
|
|
110
|
-
`);continue}}return{type:"blockquote",raw:s,tokens:l,text:r}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let l=this.rules.other.listItemRegex(n),i=!1;for(;t;){let o=!1,c="",
|
|
111
|
-
`,1)[0].replace(this.rules.other.listReplaceTabs,L=>" ".repeat(3*L.length)),
|
|
112
|
-
`,1)[0],m=!
|
|
113
|
-
`,t=t.substring(
|
|
114
|
-
`,1)[0],R;if(
|
|
115
|
-
`+R.slice(
|
|
116
|
-
`+
|
|
117
|
-
`,t=t.substring($.length+1),
|
|
118
|
-
`):[],l={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let i of s)this.rules.other.tableAlignRight.test(i)?l.align.push("right"):this.rules.other.tableAlignCenter.test(i)?l.align.push("center"):this.rules.other.tableAlignLeft.test(i)?l.align.push("left"):l.align.push(null);for(let i=0;i<n.length;i++)l.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:!0,align:l.align[i]});for(let i of r)l.rows.push(
|
|
119
|
-
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);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(t){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let l=
|
|
109
|
+
`),b=this.list(f);l[l.length-1]=b,s=s.substring(0,s.length-h.raw.length)+b.raw,r=r.substring(0,r.length-m.raw.length)+b.raw,n=f.substring(l.at(-1).raw.length).split(`
|
|
110
|
+
`);continue}}return{type:"blockquote",raw:s,tokens:l,text:r}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let l=this.rules.other.listItemRegex(n),i=!1;for(;t;){let o=!1,c="",p="";if(!(e=l.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let u=e[2].split(`
|
|
111
|
+
`,1)[0].replace(this.rules.other.listReplaceTabs,L=>" ".repeat(3*L.length)),h=t.split(`
|
|
112
|
+
`,1)[0],m=!u.trim(),f=0;if(this.options.pedantic?(f=2,p=u.trimStart()):m?f=e[1].length+1:(f=e[2].search(this.rules.other.nonSpaceChar),f=f>4?1:f,p=u.slice(f),f+=e[1].length),m&&this.rules.other.blankLine.test(h)&&(c+=h+`
|
|
113
|
+
`,t=t.substring(h.length+1),o=!0),!o){let L=this.rules.other.nextBulletRegex(f),k=this.rules.other.hrRegex(f),y=this.rules.other.fencesBeginRegex(f),x=this.rules.other.headingBeginRegex(f),S=this.rules.other.htmlBeginRegex(f);for(;t;){let $=t.split(`
|
|
114
|
+
`,1)[0],R;if(h=$,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),R=h):R=h.replace(this.rules.other.tabCharGlobal," "),y.test(h)||x.test(h)||S.test(h)||L.test(h)||k.test(h))break;if(R.search(this.rules.other.nonSpaceChar)>=f||!h.trim())p+=`
|
|
115
|
+
`+R.slice(f);else{if(m||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||y.test(u)||x.test(u)||k.test(u))break;p+=`
|
|
116
|
+
`+h}!m&&!h.trim()&&(m=!0),c+=$+`
|
|
117
|
+
`,t=t.substring($.length+1),u=R.slice(f)}}r.loose||(i?r.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(i=!0));let b=null,M;this.options.gfm&&(b=this.rules.other.listIsTask.exec(p),b&&(M=b[0]!=="[ ] ",p=p.replace(this.rules.other.listReplaceTask,""))),r.items.push({type:"list_item",raw:c,task:!!b,checked:M,loose:!1,text:p,tokens:[]}),r.raw+=c}let a=r.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;r.raw=r.raw.trimEnd();for(let o=0;o<r.items.length;o++)if(this.lexer.state.top=!1,r.items[o].tokens=this.lexer.blockTokens(r.items[o].text,[]),!r.loose){let c=r.items[o].tokens.filter(u=>u.type==="space"),p=c.length>0&&c.some(u=>this.rules.other.anyLine.test(u.raw));r.loose=p}if(r.loose)for(let o=0;o<r.items.length;o++)r.items[o].loose=!0;return r}}html(t){let e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=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"):"",r=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:e[0],href:s,title:r}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=we(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
118
|
+
`):[],l={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let i of s)this.rules.other.tableAlignRight.test(i)?l.align.push("right"):this.rules.other.tableAlignCenter.test(i)?l.align.push("center"):this.rules.other.tableAlignLeft.test(i)?l.align.push("left"):l.align.push(null);for(let i=0;i<n.length;i++)l.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:!0,align:l.align[i]});for(let i of r)l.rows.push(we(i,l.header.length).map((a,o)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:l.align[o]})));return l}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
|
|
119
|
+
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);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(t){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let l=H(n.slice(0,-1),"\\");if((n.length-l.length)%2===0)return}else{let l=zt(e[2],"()");if(l===-2)return;if(l>-1){let i=(e[0].indexOf("!")===0?5:4)+e[1].length+l;e[2]=e[2].substring(0,l),e[0]=e[0].substring(0,i).trim(),e[3]=""}}let s=e[2],r="";if(this.options.pedantic){let l=this.rules.other.pedanticHrefTitle.exec(s);l&&(s=l[1],r=l[3])}else r=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(n)?s=s.slice(1):s=s.slice(1,-1)),ye(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let s=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=e[s.toLowerCase()];if(!r){let l=n[0].charAt(0);return{type:"text",raw:l,text:l}}return ye(n,r,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let s=this.rules.inline.emStrongLDelim.exec(t);if(!(!s||s[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[2])||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,l,i,a=r,o=0,c=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,e=e.slice(-1*t.length+r);(s=c.exec(e))!=null;){if(l=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!l)continue;if(i=[...l].length,s[3]||s[4]){a+=i;continue}else if((s[5]||s[6])&&r%3&&!((r+i)%3)){o+=i;continue}if(a-=i,a>0)continue;i=Math.min(i,i+a+o);let p=[...s[0]][0].length,u=t.slice(0,r+s.index+p+i);if(Math.min(r,i)%2){let m=u.slice(1,-1);return{type:"em",raw:u,text:m,tokens:this.lexer.inlineTokens(m)}}let h=u.slice(2,-2);return{type:"strong",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){let e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,s;return e[2]==="@"?(n=e[1],s="mailto:"+n):(n=e[1],s=n),{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,s;if(e[2]==="@")n=e[0],s="mailto:"+n;else{let r;do r=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(r!==e[0]);n=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},z=class ne{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||N,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 n={other:T,block:W.normal,inline:q.normal};this.options.pedantic?(n.block=W.pedantic,n.inline=q.pedantic):this.options.gfm&&(n.block=W.gfm,this.options.breaks?n.inline=q.breaks:n.inline=q.gfm),this.tokenizer.rules=n}static get rules(){return{block:W,inline:q}}static lex(e,n){return new ne(n).lex(e)}static lexInline(e,n){return new ne(n).inlineTokens(e)}lex(e){e=e.replace(T.carriageReturn,`
|
|
120
120
|
`),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let s=this.inlineQueue[n];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],s=!1){for(this.options.pedantic&&(e=e.replace(T.tabCharGlobal," ").replace(T.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some(i=>(r=i.call({lexer:this},e,n))?(e=e.substring(r.raw.length),n.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let i=n.at(-1);r.raw.length===1&&i!==void 0?i.raw+=`
|
|
121
121
|
`:n.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
|
|
122
122
|
`)?"":`
|
|
@@ -130,7 +130,7 @@ ${h}`:h;let g=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
|
|
|
130
130
|
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):n.push(r),s=l.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="text"?(i.raw+=(i.raw.endsWith(`
|
|
131
131
|
`)?"":`
|
|
132
132
|
`)+r.raw,i.text+=`
|
|
133
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):n.push(r);continue}if(e){let i="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(i);break}else throw new Error(i)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){let s=e,r=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)a.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let l=!1,i="";for(;e;){l||(i=""),l=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,s,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0,
|
|
133
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):n.push(r);continue}if(e){let i="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(i);break}else throw new Error(i)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){let s=e,r=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)a.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let l=!1,i="";for(;e;){l||(i=""),l=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,s,i)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0,p=e.slice(1),u;this.options.extensions.startInline.forEach(h=>{u=h.call({lexer:this},p),typeof u=="number"&&u>=0&&(c=Math.min(c,u))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(a=this.tokenizer.inlineText(o)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(i=a.raw.slice(-1)),l=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},X=class{options;parser;constructor(t){this.options=t||N}space(t){return""}code({text:t,lang:e,escaped:n}){let s=(e||"").match(T.notSpaceStart)?.[0],r=t.replace(T.endingNewline,"")+`
|
|
134
134
|
`;return s?'<pre><code class="language-'+A(s)+'">'+(n?r:A(r,!0))+`</code></pre>
|
|
135
135
|
`:"<pre><code>"+(n?r:A(r,!0))+`</code></pre>
|
|
136
136
|
`}blockquote({tokens:t}){return`<blockquote>
|
|
@@ -148,9 +148,9 @@ ${this.parser.parse(t)}</blockquote>
|
|
|
148
148
|
`}tablerow({text:t}){return`<tr>
|
|
149
149
|
${t}</tr>
|
|
150
150
|
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
|
|
151
|
-
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${A(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let s=this.parser.parseInline(n),r=
|
|
152
|
-
`+this.renderer.text(a);n?s+=this.renderer.paragraph({type:"paragraph",raw:o,text:o,tokens:[{type:"text",raw:o,text:o,escaped:!0}]}):s+=o;continue}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}parseInline(e,n=this.renderer){let s="";for(let r=0;r<e.length;r++){let l=e[r];if(this.options.extensions?.renderers?.[l.type]){let a=this.options.extensions.renderers[l.type].call({parser:this},l);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(l.type)){s+=a||"";continue}}let i=l;switch(i.type){case"escape":{s+=n.text(i);break}case"html":{s+=n.html(i);break}case"link":{s+=n.link(i);break}case"image":{s+=n.image(i);break}case"strong":{s+=n.strong(i);break}case"em":{s+=n.em(i);break}case"codespan":{s+=n.codespan(i);break}case"br":{s+=n.br(i);break}case"del":{s+=n.del(i);break}case"text":{s+=n.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}},U=class{options;block;constructor(t){this.options=t||N}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(){return this.block?z.lex:z.lexInline}provideParser(){return this.block?_.parse:_.parseInline}},It=class{defaults=
|
|
153
|
-
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+A(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}},v=new It;function u(t,e){return v.parse(t,e)}u.options=u.setOptions=function(t){return v.setOptions(t),u.defaults=v.defaults,ye(u.defaults),u};u.getDefaults=re;u.defaults=N;u.use=function(...t){return v.use(...t),u.defaults=v.defaults,ye(u.defaults),u};u.walkTokens=function(t,e){return v.walkTokens(t,e)};u.parseInline=v.parseInline;u.Parser=_;u.parser=_.parse;u.Renderer=V;u.TextRenderer=pe;u.Lexer=z;u.lexer=z.lex;u.Tokenizer=F;u.Hooks=U;u.parse=u;var Ft=u.options,Vt=u.setOptions,Xt=u.use,Jt=u.walkTokens,Yt=u.parseInline;var Kt=_.parse,en=z.lex;var vt="http://www.w3.org/2000/svg",I=(t,e={},n)=>{let s=document.createElementNS(vt,t);for(let[r,l]of Object.entries(e))s.setAttribute(r,String(l));return n!==void 0&&(s.textContent=n),s},ue="[\\p{L}\\p{N}_-]+",Nt=new RegExp("^("+ue+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$","u"),Lt=new RegExp("^("+ue+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?\\s*(-->|---|-.->|==>)\\s*(?:\\|[^|]{0,100}\\|\\s*)?("+ue+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$","u");function ve(t){if(typeof t!="string"||t.length>12e3)return null;let e=t.split(/\r?\n/).map(f=>f.trim()).filter(f=>f&&!f.startsWith("%%")),n=e.shift()?.match(/^(?:flowchart|graph)\s+(TB|TD|BT|LR|RL)$/i);if(!n)return null;let s=n[1]==="BT"||n[1]==="RL",r=n[1]==="LR"||n[1]==="RL",l=new Map,i=[],a=(f,y,x,S)=>{if(!l.has(f)&&l.size>=32)throw Error("MAX_NODES");l.set(f,String(y||x||S||l.get(f)||f).slice(0,120))};try{for(let f of e){if(/^(?:classDef|style|linkStyle)\s/.test(f))continue;let y=f.match(Lt);if(y){let[,S,$,R,E,C,M,G,Fe,Ve]=y;if(a(S,$,R,E),a(M,G,Fe,Ve),i.push({a:S,b:M,arrow:C}),i.length>64)throw Error("MAX_EDGES");continue}let x=f.match(Nt);if(x){a(x[1],x[2],x[3],x[4]);continue}return null}}catch{return null}if(!l.size)return null;let o=Math.min(r?4:3,l.size),c=Math.ceil(l.size/o),h=o*198+34,g=c*110+35,p=I("svg",{viewBox:"0 0 "+h+" "+g,role:"img","aria-label":"\u6D41\u7A0B\u56FE","data-diagram":"flowchart"}),m=I("marker",{id:"cl-doc-arrow",markerWidth:8,markerHeight:8,refX:6,refY:4,orient:"auto",markerUnits:"strokeWidth"});m.append(I("path",{d:"M 0 0 L 8 4 L 0 8 z",fill:"currentColor"}));let k=I("defs");k.append(m),p.append(k);let b=new Map,D=[...l.entries()];for(let[f,[y]]of D.entries()){let x=f%o;s&&(x=o-1-x),b.set(y,{x:24+x*198,y:23+Math.floor(f/o)*110})}let L=I("g");for(let f of i){let y=b.get(f.a),x=b.get(f.b);if(!y||!x)continue;let S=y.x+78,$=y.y+33,R=x.x+78,E=x.y+33,C=Math.hypot(R-S,E-$)||1;if(C<=1)continue;let M=(R-S)/C,G=(E-$)/C;L.append(I("line",{x1:S+M*52,y1:$+G*27,x2:R-M*52,y2:E-G*27,stroke:"currentColor","stroke-opacity":.65,"stroke-width":1.7,"stroke-dasharray":f.arrow==="-.->"?"5 5":"none","marker-end":f.arrow==="---"?"none":"url(#cl-doc-arrow)"}))}p.append(L);for(let[f,y]of D){let{x,y:S}=b.get(f);p.append(I("rect",{x,y:S,width:156,height:66,rx:12,fill:"var(--diagram-bg, #f5f8fc)",stroke:"var(--diagram-stroke, #9aafca)","stroke-width":1.2}));let $=I("text",{x:x+78,y:S+33,"text-anchor":"middle",fill:"var(--diagram-text, #1f334e)","font-size":12,"font-family":"system-ui, sans-serif"}),R=[...y].reduce((E,C)=>(E.at(-1).length>=19&&E.push(""),E[E.length-1]+=C,E),[""]).slice(0,3);R.forEach((E,C)=>$.append(I("tspan",{x:x+78,dy:C===0?-((R.length-1)*8):16},E))),p.append($)}return p}var Pt=new Set(["P","H1","H2","H3","H4","H5","H6","STRONG","B","EM","I","U","S","DEL","UL","OL","LI","BLOCKQUOTE","PRE","CODE","TABLE","THEAD","TBODY","TR","TH","TD","HR","BR","A","IMG","INPUT","SUP","SUB","DETAILS","SUMMARY","DIV","SPAN"]),Ot=new Set(["SCRIPT","STYLE","IFRAME","OBJECT","EMBED","FORM","BUTTON","TEXTAREA","SELECT","META","LINK","SVG","MATH","VIDEO","AUDIO","CANVAS"]);function Dt(t){try{let e=new URL(t,"https://document.invalid");return["http:","https:","mailto:"].includes(e.protocol)&&t.trim().match(/^(?:https?:|mailto:)/i)?e.href:null}catch{return null}}function Pe(t){if(t.nodeType===Node.TEXT_NODE)return document.createTextNode(t.textContent);if(t.nodeType!==Node.ELEMENT_NODE)return null;let e=t.tagName;if(Ot.has(e))return null;let n=Pt.has(e)?document.createElement(e.toLowerCase()):document.createDocumentFragment();if(e==="A"&&n.nodeType===Node.ELEMENT_NODE){let s=Dt(t.getAttribute("href")||"");s&&(n.setAttribute("href",s),n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"))}if(e==="CODE"){let s=(t.getAttribute("class")||"").match(/(?:^|\s)language-([a-z0-9_+-]{1,40})(?:\s|$)/i);s&&(n.dataset.language=s[1].toLowerCase())}if(e==="IMG"){let s=t.getAttribute("src")||"",r=t.getAttribute("alt")||"\u56FE\u7247";if(/^data:image\/(?:png|jpeg|webp|gif);base64,[a-z0-9+/=]+$/i.test(s)&&s.length<18e4)n.setAttribute("src",s),n.setAttribute("alt",r),n.setAttribute("loading","lazy"),n.setAttribute("referrerpolicy","no-referrer");else{let l=document.createElement("span");return l.className="external-image-blocked",l.textContent="[\u5916\u90E8\u56FE\u7247\u672A\u52A0\u8F7D] "+r,l}return n}if(e==="INPUT")return n.type="checkbox",n.disabled=!0,n.checked=t.hasAttribute("checked"),n;for(let s of t.childNodes){let r=Pe(s);r&&n.append(r)}return n}function de(t,e,n){let s=document.createElement("div");s.className="code-card";let r=document.createElement("div");r.className="code-toolbar";let l=document.createElement("span");l.textContent=e||"\u4EE3\u7801";let i=document.createElement("button");i.type="button",i.className="copy-block",i.textContent="\u590D\u5236\u4EE3\u7801",i.addEventListener("click",()=>{n(t,i)}),r.append(l,i);let a=document.createElement("pre"),o=document.createElement("code");return o.textContent=t,a.append(o),s.append(r,a),s}function Oe(t,e){let n=ve(t);if(!n){let i=de(t,"Mermaid \u63CF\u8FF0\uFF08\u539F\u6587\u4FDD\u7559\uFF09",e);return i.dataset.diagram="source-only",i}let s=document.createElement("figure");s.className="diagram-card",s.dataset.diagram="rendered";let r=document.createElement("figcaption");r.textContent="\u6D41\u7A0B\u56FE";let l=document.createElement("button");return l.type="button",l.className="copy-block",l.textContent="\u590D\u5236\u56FE\u5F62\u6E90\u7801",l.addEventListener("click",()=>{e(t,l)}),r.append(l),s.append(r,n),s}function Mt(t,e){for(let s of[...t.querySelectorAll("pre")]){let r=s.querySelector("code");if(!r)continue;let l=r.dataset.language||"",i=r.textContent;s.replaceWith(l==="mermaid"||l==="flowchart"?Oe(i,e):de(i,l,e))}let n=[...t.querySelectorAll("h1,h2,h3")];return n.forEach((s,r)=>s.id="doc-heading-"+r),n.map(s=>({id:s.id,level:Number(s.tagName[1]),text:s.textContent}))}function Ne(t,e,n){let s=u.parse(e,{gfm:!0,breaks:!1,async:!1}),r=new DOMParser().parseFromString(s,"text/html"),l=document.createDocumentFragment();for(let i of r.body.childNodes){let a=Pe(i);a&&l.append(a)}return t.replaceChildren(l),Mt(t,n)}function De(t,e){let n=document.createElement("pre");return n.className="plain-text",n.textContent=e,t.replaceChildren(n),[]}function Bt(t,e,n){let s=e;try{s=JSON.stringify(JSON.parse(e),null,2)}catch{}return t.replaceChildren(de(s,"JSON",n)),[]}function Le(t,e,n){return t.replaceChildren(Oe(e,n)),[]}var qt=new Map([["text/markdown",Ne],["text/x-markdown",Ne],["text/plain",De],["application/json",Bt],["text/mermaid",Le],["text/x-mermaid",Le]]);function Me(t,e,n,s){let r=qt.get(e.toLowerCase());return{headings:r?r(t,n,s):De(t,n),raw:!r}}var w=t=>document.getElementById(t),Ut=/^[A-Za-z0-9][A-Za-z0-9_.-]{7,127}$/,Ht=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,Zt=/^[a-f0-9]{64}$/,Ze=0,j=!1,je=!1,Y=null,Ge=null,Be=null,qe=0,Ue=0,P=new Map;function O(t,e="info"){w("status").textContent=t,w("status").dataset.state=e}function K(t){window.parent.postMessage({jsonrpc:"2.0",...t},"*")}function Qe(t,e={}){K({method:t,params:e})}function jt(t,e={}){if(!j)throw Error("DOCUMENT_APP_NOT_INITIALIZED");return new Promise((n,s)=>{let r=++Ze,l=setTimeout(()=>{P.delete(r),s(Error("DOCUMENT_APP_REPLY_UNKNOWN"))},3e4);P.set(r,{resolve:n,reject:s,timer:l}),K({id:r,method:t,params:e})})}function fe(t){if(t?.isError)throw Error("DOCUMENT_TOOL_REJECTED");if(t?.structuredContent?.status)return t.structuredContent;let e=t?.content?.find(n=>n.type==="text")?.text;if(typeof e!="string"||e.length>8e5)throw Error("DOCUMENT_RESULT_MISSING");return JSON.parse(e)}async function He(t,e){let n=!1;try{navigator.clipboard?.writeText&&(await navigator.clipboard.writeText(t),n=!0)}catch{}if(!n){let s=document.createElement("textarea");s.value=t,s.setAttribute("aria-hidden","true"),s.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0",document.body.append(s),s.focus(),s.select();try{n=document.execCommand("copy")===!0}catch{}s.remove()}return n?(e.textContent=e.id==="copy-all"?"\u5DF2\u590D\u5236\u5168\u6587":"\u5DF2\u590D\u5236",O("\u5DF2\u590D\u5236\u539F\u59CB\u5185\u5BB9\uFF0C\u53EF\u7C98\u8D34\u5230\u5176\u4ED6\u7F16\u8F91\u5668\u3002","ok"),!0):(e.textContent="\u590D\u5236\u4E0D\u53EF\u7528",O("\u5F53\u524D ChatGPT \u5BBF\u4E3B\u672A\u6388\u4E88\u526A\u8D34\u677F\u5199\u5165\u6743\u9650\uFF1B\u539F\u6587\u4FDD\u7559\uFF0C\u53EF\u5728\u6587\u6863\u533A\u624B\u52A8\u9009\u62E9\u590D\u5236\u3002","error"),!1)}function ge(){if(!j)return;let t=document.querySelector("main")?.getBoundingClientRect();if(!t||t.width<1||t.height<1)return;let e=parseFloat(getComputedStyle(document.body).paddingBottom)||0,n=Math.ceil(t.bottom+e),s=Math.ceil(document.documentElement.clientWidth);n<1||s<1||n===qe&&s===Ue||(qe=n,Ue=s,Qe("ui/notifications/size-changed",{width:s,height:n}))}function Gt(t){if(!j||!je||!Ge)return;let e=document.querySelector("main")?.getBoundingClientRect();if(!e||e.width<1||e.height<1){w("status").dataset.renderObservation="not-visible";return}let n=t.documentId+":"+t.traceRef;Be!==n&&(Be=n,w("status").dataset.renderObservation="pending",jt("tools/call",{name:"chat_loop_document__render",arguments:{documentId:t.documentId,traceRef:t.traceRef,contentHash:t.contentHash}}).then(fe).then(s=>{if(s.status!=="DOCUMENT_RENDERED"||s.documentId!==t.documentId||s.traceRef!==t.traceRef||s.contentHash!==t.contentHash)throw Error("DOCUMENT_RENDER_RECEIPT_INVALID");w("status").dataset.renderObservation="confirmed"}).catch(()=>{w("status").dataset.renderObservation="unverified"}))}function We(t){let e=t?.view;if(t?.status!=="DOCUMENT_READY"||typeof t.documentId!="string"||!Ut.test(t.documentId)||typeof t.traceRef!="string"||!Ht.test(t.traceRef)||typeof t.contentHash!="string"||!Zt.test(t.contentHash)||!e||e.template!=="chat-loop-document-v1"||typeof e.title!="string"||!e.title.trim()||typeof e.subtitle!="string"||typeof e.format!="string"||!e.format.trim()||typeof e.content!="string"||!e.content.trim())throw Error("DOCUMENT_VIEW_INVALID");Ge=t,w("title").textContent=e.title,w("subtitle").hidden=!e.subtitle,w("subtitle").textContent=e.subtitle;let n=w("content"),s=e.format,r=Me(n,s,e.content,He);w("copy-all").disabled=!1,w("copy-all").textContent="\u590D\u5236\u5168\u6587",w("copy-all").onclick=()=>{He(e.content,w("copy-all"))};let l=w("toc"),i=w("toc-links");i.replaceChildren(),l.hidden=!r.headings.length;for(let a of r.headings.slice(0,100)){let o=document.createElement("a");o.href="#"+a.id,o.textContent=a.text,o.addEventListener("click",c=>{c.preventDefault(),n.querySelector("#"+a.id)?.scrollIntoView({block:"nearest"})}),i.append(o)}O(r.raw?"\u5F53\u524D\u683C\u5F0F\u6682\u4EE5\u5B89\u5168\u539F\u6587\u6A21\u5F0F\u5C55\u793A\uFF0C\u5168\u6587\u4ECD\u53EF\u590D\u5236\u3002":"\u5B8C\u6574\u6587\u6863\u5DF2\u52A0\u8F7D\u3002","ok"),ge(),Gt(t)}function Qt(t){if(t.source!==window.parent)return;let e=t.data;if(!(!e||e.jsonrpc!=="2.0"||typeof e!="object")){if(Object.hasOwn(e,"id")&&!Object.hasOwn(e,"method")){let n=P.get(e.id);if(!n)return;P.delete(e.id),clearTimeout(n.timer),e.error?n.reject(Error("DOCUMENT_APP_REPLY_UNKNOWN")):n.resolve(e.result);return}if(e.method==="ui/notifications/tool-result"&&(Y=e.params,j))try{We(fe(Y))}catch{O("\u6587\u6863\u56DE\u6267\u65E0\u6548\uFF0C\u65E0\u6CD5\u5C55\u793A\u3002","error")}e.method==="ui/resource-teardown"&&e.id!==void 0&&K({id:e.id,result:{}})}}async function Wt(){if(window.parent===window){O("\u8BF7\u4ECE ChatGPT \u7684 MCP App \u6587\u6863\u5DE5\u5177\u6253\u5F00\u6B64\u9875\u9762\u3002","error");return}let t=++Ze,e=new Promise((n,s)=>{let r=setTimeout(()=>{P.delete(t),s(Error("DOCUMENT_APP_INIT_TIMEOUT"))},12e3);P.set(t,{resolve:n,reject:s,timer:r}),K({id:t,method:"ui/initialize",params:{appInfo:{name:"Chat Loop Document",version:"1.0.0"},appCapabilities:{},protocolVersion:"2026-01-26"}})});try{let n=await e;if(!n?.protocolVersion||!n.hostInfo||!n.hostCapabilities)throw Error("DOCUMENT_APP_INIT_INVALID");j=!0,je=!!n.hostCapabilities.serverTools,Qe("ui/notifications/initialized",{}),Y&&We(fe(Y)),ge(),typeof ResizeObserver=="function"&&new ResizeObserver(ge).observe(document.querySelector("main"))}catch{O("\u6587\u6863 App \u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5BBF\u4E3B\u8FDE\u63A5\u3002","error")}}window.addEventListener("message",Qt);Wt();})();
|
|
151
|
+
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${A(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let s=this.parser.parseInline(n),r=be(t);if(r===null)return s;t=r;let l='<a href="'+t+'"';return e&&(l+=' title="'+A(e)+'"'),l+=">"+s+"</a>",l}image({href:t,title:e,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=be(t);if(r===null)return A(n);t=r;let l=`<img src="${t}" alt="${n}"`;return e&&(l+=` title="${A(e)}"`),l+=">",l}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:A(t.text)}},ue=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}},_=class re{options;renderer;textRenderer;constructor(e){this.options=e||N,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ue}static parse(e,n){return new re(n).parse(e)}static parseInline(e,n){return new re(n).parseInline(e)}parse(e,n=!0){let s="";for(let r=0;r<e.length;r++){let l=e[r];if(this.options.extensions?.renderers?.[l.type]){let a=l,o=this.options.extensions.renderers[a.type].call({parser:this},a);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){s+=o||"";continue}}let i=l;switch(i.type){case"space":{s+=this.renderer.space(i);continue}case"hr":{s+=this.renderer.hr(i);continue}case"heading":{s+=this.renderer.heading(i);continue}case"code":{s+=this.renderer.code(i);continue}case"table":{s+=this.renderer.table(i);continue}case"blockquote":{s+=this.renderer.blockquote(i);continue}case"list":{s+=this.renderer.list(i);continue}case"html":{s+=this.renderer.html(i);continue}case"def":{s+=this.renderer.def(i);continue}case"paragraph":{s+=this.renderer.paragraph(i);continue}case"text":{let a=i,o=this.renderer.text(a);for(;r+1<e.length&&e[r+1].type==="text";)a=e[++r],o+=`
|
|
152
|
+
`+this.renderer.text(a);n?s+=this.renderer.paragraph({type:"paragraph",raw:o,text:o,tokens:[{type:"text",raw:o,text:o,escaped:!0}]}):s+=o;continue}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}parseInline(e,n=this.renderer){let s="";for(let r=0;r<e.length;r++){let l=e[r];if(this.options.extensions?.renderers?.[l.type]){let a=this.options.extensions.renderers[l.type].call({parser:this},l);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(l.type)){s+=a||"";continue}}let i=l;switch(i.type){case"escape":{s+=n.text(i);break}case"html":{s+=n.html(i);break}case"link":{s+=n.link(i);break}case"image":{s+=n.image(i);break}case"strong":{s+=n.strong(i);break}case"em":{s+=n.em(i);break}case"codespan":{s+=n.codespan(i);break}case"br":{s+=n.br(i);break}case"del":{s+=n.del(i);break}case"text":{s+=n.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}},U=class{options;block;constructor(t){this.options=t||N}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(){return this.block?z.lex:z.lexInline}provideParser(){return this.block?_.parse:_.parseInline}},It=class{defaults=se();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=_;Renderer=X;TextRenderer=ue;Lexer=z;Tokenizer=V;Hooks=U;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let s of t)switch(n=n.concat(e.call(this,s)),s.type){case"table":{let r=s;for(let l of r.header)n=n.concat(this.walkTokens(l.tokens,e));for(let l of r.rows)for(let i of l)n=n.concat(this.walkTokens(i.tokens,e));break}case"list":{let r=s;n=n.concat(this.walkTokens(r.items,e));break}default:{let r=s;this.defaults.extensions?.childTokens?.[r.type]?this.defaults.extensions.childTokens[r.type].forEach(l=>{let i=r[l].flat(1/0);n=n.concat(this.walkTokens(i,e))}):r.tokens&&(n=n.concat(this.walkTokens(r.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let l=e.renderers[r.name];l?e.renderers[r.name]=function(...i){let a=r.renderer.apply(this,i);return a===!1&&(a=l.apply(this,i)),a}:e.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let l=e[r.level];l?l.unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),s.extensions=e),n.renderer){let r=this.defaults.renderer||new X(this.defaults);for(let l in n.renderer){if(!(l in r))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let i=l,a=n.renderer[i],o=r[i];r[i]=(...c)=>{let p=a.apply(r,c);return p===!1&&(p=o.apply(r,c)),p||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new V(this.defaults);for(let l in n.tokenizer){if(!(l in r))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let i=l,a=n.tokenizer[i],o=r[i];r[i]=(...c)=>{let p=a.apply(r,c);return p===!1&&(p=o.apply(r,c)),p}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new U;for(let l in n.hooks){if(!(l in r))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let i=l,a=n.hooks[i],o=r[i];U.passThroughHooks.has(l)?r[i]=c=>{if(this.defaults.async&&U.passThroughHooksRespectAsync.has(l))return Promise.resolve(a.call(r,c)).then(u=>o.call(r,u));let p=a.call(r,c);return o.call(r,p)}:r[i]=(...c)=>{let p=a.apply(r,c);return p===!1&&(p=o.apply(r,c)),p}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,l=n.walkTokens;s.walkTokens=function(i){let a=[];return a.push(l.call(this,i)),r&&(a=a.concat(r.call(this,i))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return z.lex(t,e??this.defaults)}parser(t,e){return _.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let s={...n},r={...this.defaults,...s},l=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.async===!1)return l(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 l(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));r.hooks&&(r.hooks.options=r,r.hooks.block=t);let i=r.hooks?r.hooks.provideLexer():t?z.lex:z.lexInline,a=r.hooks?r.hooks.provideParser():t?_.parse:_.parseInline;if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(e):e).then(o=>i(o,r)).then(o=>r.hooks?r.hooks.processAllTokens(o):o).then(o=>r.walkTokens?Promise.all(this.walkTokens(o,r.walkTokens)).then(()=>o):o).then(o=>a(o,r)).then(o=>r.hooks?r.hooks.postprocess(o):o).catch(l);try{r.hooks&&(e=r.hooks.preprocess(e));let o=i(e,r);r.hooks&&(o=r.hooks.processAllTokens(o)),r.walkTokens&&this.walkTokens(o,r.walkTokens);let c=a(o,r);return r.hooks&&(c=r.hooks.postprocess(c)),c}catch(o){return l(o)}}}onError(t,e){return n=>{if(n.message+=`
|
|
153
|
+
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+A(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}},v=new It;function d(t,e){return v.parse(t,e)}d.options=d.setOptions=function(t){return v.setOptions(t),d.defaults=v.defaults,Te(d.defaults),d};d.getDefaults=se;d.defaults=N;d.use=function(...t){return v.use(...t),d.defaults=v.defaults,Te(d.defaults),d};d.walkTokens=function(t,e){return v.walkTokens(t,e)};d.parseInline=v.parseInline;d.Parser=_;d.parser=_.parse;d.Renderer=X;d.TextRenderer=ue;d.Lexer=z;d.lexer=z.lex;d.Tokenizer=V;d.Hooks=U;d.parse=d;var Ft=d.options,Vt=d.setOptions,Xt=d.use,Jt=d.walkTokens,Yt=d.parseInline;var Kt=_.parse,en=z.lex;var vt="http://www.w3.org/2000/svg",I=(t,e={},n)=>{let s=document.createElementNS(vt,t);for(let[r,l]of Object.entries(e))s.setAttribute(r,String(l));return n!==void 0&&(s.textContent=n),s},de="[\\p{L}\\p{N}_-]+",Nt=new RegExp("^("+de+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$","u"),Lt=new RegExp("^("+de+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?\\s*(-->|---|-.->|==>)\\s*(?:\\|[^|]{0,100}\\|\\s*)?("+de+")(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$","u");function Ne(t){if(typeof t!="string"||t.length>12e3)return null;let e=t.split(/\r?\n/).map(k=>k.trim()).filter(k=>k&&!k.startsWith("%%")),n=e.shift()?.match(/^(?:flowchart|graph)\s+(TB|TD|BT|LR|RL)$/i);if(!n)return null;let s=n[1]==="BT"||n[1]==="RL",r=n[1]==="LR"||n[1]==="RL",l=new Map,i=[],a=(k,y,x,S)=>{if(!l.has(k)&&l.size>=32)throw Error("MAX_NODES");l.set(k,String(y||x||S||l.get(k)||k).slice(0,120))};try{for(let k of e){if(/^(?:classDef|style|linkStyle)\s/.test(k))continue;let y=k.match(Lt);if(y){let[,S,$,R,E,C,B,Q,Fe,Ve]=y;if(a(S,$,R,E),a(B,Q,Fe,Ve),i.push({a:S,b:B,arrow:C}),i.length>64)throw Error("MAX_EDGES");continue}let x=k.match(Nt);if(x){a(x[1],x[2],x[3],x[4]);continue}return null}}catch{return null}if(!l.size)return null;let o=Math.min(r?4:3,l.size),c=Math.ceil(l.size/o),p=o*198+34,u=c*110+35,h=I("svg",{viewBox:"0 0 "+p+" "+u,role:"img","aria-label":"\u6D41\u7A0B\u56FE","data-diagram":"flowchart"}),m=I("marker",{id:"cl-doc-arrow",markerWidth:8,markerHeight:8,refX:6,refY:4,orient:"auto",markerUnits:"strokeWidth"});m.append(I("path",{d:"M 0 0 L 8 4 L 0 8 z",fill:"currentColor"}));let f=I("defs");f.append(m),h.append(f);let b=new Map,M=[...l.entries()];for(let[k,[y]]of M.entries()){let x=k%o;s&&(x=o-1-x),b.set(y,{x:24+x*198,y:23+Math.floor(k/o)*110})}let L=I("g");for(let k of i){let y=b.get(k.a),x=b.get(k.b);if(!y||!x)continue;let S=y.x+78,$=y.y+33,R=x.x+78,E=x.y+33,C=Math.hypot(R-S,E-$)||1;if(C<=1)continue;let B=(R-S)/C,Q=(E-$)/C;L.append(I("line",{x1:S+B*52,y1:$+Q*27,x2:R-B*52,y2:E-Q*27,stroke:"currentColor","stroke-opacity":.65,"stroke-width":1.7,"stroke-dasharray":k.arrow==="-.->"?"5 5":"none","marker-end":k.arrow==="---"?"none":"url(#cl-doc-arrow)"}))}h.append(L);for(let[k,y]of M){let{x,y:S}=b.get(k);h.append(I("rect",{x,y:S,width:156,height:66,rx:12,fill:"var(--diagram-bg, #f5f8fc)",stroke:"var(--diagram-stroke, #9aafca)","stroke-width":1.2}));let $=I("text",{x:x+78,y:S+33,"text-anchor":"middle",fill:"var(--diagram-text, #1f334e)","font-size":12,"font-family":"system-ui, sans-serif"}),R=[...y].reduce((E,C)=>(E.at(-1).length>=19&&E.push(""),E[E.length-1]+=C,E),[""]).slice(0,3);R.forEach((E,C)=>$.append(I("tspan",{x:x+78,dy:C===0?-((R.length-1)*8):16},E))),h.append($)}return h}var Pt=new Set(["P","H1","H2","H3","H4","H5","H6","STRONG","B","EM","I","U","S","DEL","UL","OL","LI","BLOCKQUOTE","PRE","CODE","TABLE","THEAD","TBODY","TR","TH","TD","HR","BR","A","IMG","INPUT","SUP","SUB","DETAILS","SUMMARY","DIV","SPAN"]),Ot=new Set(["SCRIPT","STYLE","IFRAME","OBJECT","EMBED","FORM","BUTTON","TEXTAREA","SELECT","META","LINK","SVG","MATH","VIDEO","AUDIO","CANVAS"]);function Dt(t){try{let e=new URL(t,"https://document.invalid");return["http:","https:","mailto:"].includes(e.protocol)&&t.trim().match(/^(?:https?:|mailto:)/i)?e.href:null}catch{return null}}function Pe(t){if(t.nodeType===Node.TEXT_NODE)return document.createTextNode(t.textContent);if(t.nodeType!==Node.ELEMENT_NODE)return null;let e=t.tagName;if(Ot.has(e))return null;let n=Pt.has(e)?document.createElement(e.toLowerCase()):document.createDocumentFragment();if(e==="A"&&n.nodeType===Node.ELEMENT_NODE){let s=Dt(t.getAttribute("href")||"");s&&(n.setAttribute("href",s),n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"))}if(e==="CODE"){let s=(t.getAttribute("class")||"").match(/(?:^|\s)language-([a-z0-9_+-]{1,40})(?:\s|$)/i);s&&(n.dataset.language=s[1].toLowerCase())}if(e==="IMG"){let s=t.getAttribute("src")||"",r=t.getAttribute("alt")||"\u56FE\u7247";if(/^data:image\/(?:png|jpeg|webp|gif);base64,[a-z0-9+/=]+$/i.test(s)&&s.length<18e4)n.setAttribute("src",s),n.setAttribute("alt",r),n.setAttribute("loading","lazy"),n.setAttribute("referrerpolicy","no-referrer");else{let l=document.createElement("span");return l.className="external-image-blocked",l.textContent="[\u5916\u90E8\u56FE\u7247\u672A\u52A0\u8F7D] "+r,l}return n}if(e==="INPUT")return n.type="checkbox",n.disabled=!0,n.checked=t.hasAttribute("checked"),n;for(let s of t.childNodes){let r=Pe(s);r&&n.append(r)}return n}function ge(t,e,n){let s=document.createElement("div");s.className="code-card";let r=document.createElement("div");r.className="code-toolbar";let l=document.createElement("span");l.textContent=e||"\u4EE3\u7801";let i=document.createElement("button");i.type="button",i.className="copy-block",i.textContent="\u590D\u5236\u4EE3\u7801",i.addEventListener("click",()=>{n(t,i)}),r.append(l,i);let a=document.createElement("pre"),o=document.createElement("code");return o.textContent=t,a.append(o),s.append(r,a),s}function Oe(t,e){let n=Ne(t);if(!n){let i=ge(t,"Mermaid \u63CF\u8FF0\uFF08\u539F\u6587\u4FDD\u7559\uFF09",e);return i.dataset.diagram="source-only",i}let s=document.createElement("figure");s.className="diagram-card",s.dataset.diagram="rendered";let r=document.createElement("figcaption");r.textContent="\u6D41\u7A0B\u56FE";let l=document.createElement("button");return l.type="button",l.className="copy-block",l.textContent="\u590D\u5236\u56FE\u5F62\u6E90\u7801",l.addEventListener("click",()=>{e(t,l)}),r.append(l),s.append(r,n),s}function Mt(t,e){for(let s of[...t.querySelectorAll("pre")]){let r=s.querySelector("code");if(!r)continue;let l=r.dataset.language||"",i=r.textContent;s.replaceWith(l==="mermaid"||l==="flowchart"?Oe(i,e):ge(i,l,e))}let n=[...t.querySelectorAll("h1,h2,h3")];return n.forEach((s,r)=>s.id="doc-heading-"+r),n.map(s=>({id:s.id,level:Number(s.tagName[1]),text:s.textContent}))}function P(t,e,n){let s=d.parse(e,{gfm:!0,breaks:!1,async:!1}),r=new DOMParser().parseFromString(s,"text/html"),l=document.createDocumentFragment();for(let i of r.body.childNodes){let a=Pe(i);a&&l.append(a)}return t.replaceChildren(l),Mt(t,n)}function De(t,e){let n=document.createElement("pre");return n.className="plain-text",n.textContent=e,t.replaceChildren(n),[]}function Bt(t,e,n){let s=e;try{s=JSON.stringify(JSON.parse(e),null,2)}catch{}return t.replaceChildren(ge(s,"JSON",n)),[]}function Le(t,e,n){return t.replaceChildren(Oe(e,n)),[]}var qt=new Map([["text/markdown",P],["text/x-markdown",P],["markdown",P],["md",P],["text/md",P],["application/markdown",P],["text/plain",De],["application/json",Bt],["text/mermaid",Le],["text/x-mermaid",Le]]);function Me(t,e,n,s){let r=qt.get(e.toLowerCase());return{headings:r?r(t,n,s):De(t,n),raw:!r}}var w=t=>document.getElementById(t),Ht=/^[A-Za-z0-9][A-Za-z0-9_.-]{7,127}$/,Ut=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,Zt=/^[a-f0-9]{64}$/,Ze=0,G=!1,je=!1,K=null,Ge=null,Be=null,qe=0,He=0,O=new Map;function D(t,e="info"){w("status").textContent=t,w("status").dataset.state=e}function ee(t){window.parent.postMessage({jsonrpc:"2.0",...t},"*")}function Qe(t,e={}){ee({method:t,params:e})}function jt(t,e={}){if(!G)throw Error("DOCUMENT_APP_NOT_INITIALIZED");return new Promise((n,s)=>{let r=++Ze,l=setTimeout(()=>{O.delete(r),s(Error("DOCUMENT_APP_REPLY_UNKNOWN"))},3e4);O.set(r,{resolve:n,reject:s,timer:l}),ee({id:r,method:t,params:e})})}function ke(t){if(t?.isError)throw Error("DOCUMENT_TOOL_REJECTED");if(t?.structuredContent?.status)return t.structuredContent;let e=t?.content?.find(n=>n.type==="text")?.text;if(typeof e!="string"||e.length>8e5)throw Error("DOCUMENT_RESULT_MISSING");return JSON.parse(e)}async function Ue(t,e){let n=!1;try{navigator.clipboard?.writeText&&(await navigator.clipboard.writeText(t),n=!0)}catch{}if(!n){let s=document.createElement("textarea");s.value=t,s.setAttribute("aria-hidden","true"),s.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0",document.body.append(s),s.focus(),s.select();try{n=document.execCommand("copy")===!0}catch{}s.remove()}return n?(e.textContent=e.id==="copy-all"?"\u5DF2\u590D\u5236\u5168\u6587":"\u5DF2\u590D\u5236",D("\u5DF2\u590D\u5236\u539F\u59CB\u5185\u5BB9\uFF0C\u53EF\u7C98\u8D34\u5230\u5176\u4ED6\u7F16\u8F91\u5668\u3002","ok"),!0):(e.textContent="\u590D\u5236\u4E0D\u53EF\u7528",D("\u5F53\u524D ChatGPT \u5BBF\u4E3B\u672A\u6388\u4E88\u526A\u8D34\u677F\u5199\u5165\u6743\u9650\uFF1B\u539F\u6587\u4FDD\u7559\uFF0C\u53EF\u5728\u6587\u6863\u533A\u624B\u52A8\u9009\u62E9\u590D\u5236\u3002","error"),!1)}function fe(){if(!G)return;let t=document.querySelector("main")?.getBoundingClientRect();if(!t||t.width<1||t.height<1)return;let e=parseFloat(getComputedStyle(document.body).paddingBottom)||0,n=Math.ceil(t.bottom+e),s=Math.ceil(document.documentElement.clientWidth);n<1||s<1||n===qe&&s===He||(qe=n,He=s,Qe("ui/notifications/size-changed",{width:s,height:n}))}function Gt(t){if(!G||!je||!Ge)return;let e=document.querySelector("main")?.getBoundingClientRect();if(!e||e.width<1||e.height<1){w("status").dataset.renderObservation="not-visible";return}let n=t.documentId+":"+t.traceRef;Be!==n&&(Be=n,w("status").dataset.renderObservation="pending",jt("tools/call",{name:"chat_loop_document__render",arguments:{documentId:t.documentId,traceRef:t.traceRef,contentHash:t.contentHash}}).then(ke).then(s=>{if(s.status!=="DOCUMENT_RENDERED"||s.documentId!==t.documentId||s.traceRef!==t.traceRef||s.contentHash!==t.contentHash)throw Error("DOCUMENT_RENDER_RECEIPT_INVALID");w("status").dataset.renderObservation="confirmed"}).catch(()=>{w("status").dataset.renderObservation="unverified"}))}function We(t){let e=t?.view;if(t?.status!=="DOCUMENT_READY"||typeof t.documentId!="string"||!Ht.test(t.documentId)||typeof t.traceRef!="string"||!Ut.test(t.traceRef)||typeof t.contentHash!="string"||!Zt.test(t.contentHash)||!e||e.template!=="chat-loop-document-v1"||typeof e.title!="string"||!e.title.trim()||typeof e.subtitle!="string"||typeof e.format!="string"||!e.format.trim()||typeof e.content!="string"||!e.content.trim())throw Error("DOCUMENT_VIEW_INVALID");Ge=t,w("title").textContent=e.title,w("subtitle").hidden=!e.subtitle,w("subtitle").textContent=e.subtitle;let n=w("content"),s=e.format,r=Me(n,s,e.content,Ue),l=n.querySelector(":scope > h1"),i=h=>h.replace(/\s+/g," ").trim(),a=l&&i(l.textContent)===i(e.title),o=a?l.id:null;a&&l.remove();let c=r.headings.filter(h=>h.id!==o);w("copy-all").disabled=!1,w("copy-all").textContent="\u590D\u5236\u5168\u6587",w("copy-all").onclick=()=>{Ue(e.content,w("copy-all"))};let p=w("toc"),u=w("toc-links");u.replaceChildren(),p.hidden=!c.length;for(let h of c.slice(0,100)){let m=document.createElement("a");m.href="#"+h.id,m.textContent=h.text,m.addEventListener("click",f=>{f.preventDefault(),n.querySelector("#"+h.id)?.scrollIntoView({block:"nearest"})}),u.append(m)}D(r.raw?"\u5F53\u524D\u683C\u5F0F\u6682\u4EE5\u5B89\u5168\u539F\u6587\u6A21\u5F0F\u5C55\u793A\uFF0C\u5168\u6587\u4ECD\u53EF\u590D\u5236\u3002":"\u5B8C\u6574\u6587\u6863\u5DF2\u52A0\u8F7D\u3002","ok"),fe(),Gt(t)}function Qt(t){if(t.source!==window.parent)return;let e=t.data;if(!(!e||e.jsonrpc!=="2.0"||typeof e!="object")){if(Object.hasOwn(e,"id")&&!Object.hasOwn(e,"method")){let n=O.get(e.id);if(!n)return;O.delete(e.id),clearTimeout(n.timer),e.error?n.reject(Error("DOCUMENT_APP_REPLY_UNKNOWN")):n.resolve(e.result);return}if(e.method==="ui/notifications/tool-result"&&(K=e.params,G))try{We(ke(K))}catch{D("\u6587\u6863\u56DE\u6267\u65E0\u6548\uFF0C\u65E0\u6CD5\u5C55\u793A\u3002","error")}e.method==="ui/resource-teardown"&&e.id!==void 0&&ee({id:e.id,result:{}})}}async function Wt(){if(window.parent===window){D("\u8BF7\u4ECE ChatGPT \u7684 MCP App \u6587\u6863\u5DE5\u5177\u6253\u5F00\u6B64\u9875\u9762\u3002","error");return}let t=++Ze,e=new Promise((n,s)=>{let r=setTimeout(()=>{O.delete(t),s(Error("DOCUMENT_APP_INIT_TIMEOUT"))},12e3);O.set(t,{resolve:n,reject:s,timer:r}),ee({id:t,method:"ui/initialize",params:{appInfo:{name:"Chat Loop Document",version:"1.0.0"},appCapabilities:{},protocolVersion:"2026-01-26"}})});try{let n=await e;if(!n?.protocolVersion||!n.hostInfo||!n.hostCapabilities)throw Error("DOCUMENT_APP_INIT_INVALID");G=!0,je=!!n.hostCapabilities.serverTools,Qe("ui/notifications/initialized",{}),K&&We(ke(K)),fe(),typeof ResizeObserver=="function"&&new ResizeObserver(fe).observe(document.querySelector("main"))}catch{D("\u6587\u6863 App \u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5BBF\u4E3B\u8FDE\u63A5\u3002","error")}}window.addEventListener("message",Qt);Wt();})();
|
|
154
154
|
</script>
|
|
155
155
|
</body>
|
|
156
156
|
</html>
|