@tomflow/chatloop-tools 0.9.38 → 0.9.39
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 +3 -2
- package/lib/release-health-checks.mjs +14 -1
- package/package.json +8 -4
- package/providers/document.mjs +95 -0
- package/providers.generated.mjs +3 -2
- package/scripts/build-document-app.mjs +29 -0
- package/ui/document/diagram.js +88 -0
- package/ui/document/render-content.js +146 -0
- package/ui/document/view-app.js +193 -0
- package/ui/document/view.html +157 -0
- package/ui/document/view.template.html +97 -0
package/README.md
CHANGED
|
@@ -59,14 +59,15 @@ Start all enabled tools or one.
|
|
|
59
59
|
`providers/<id>.mjs` owns each MCP Provider's tool names, schemas,
|
|
60
60
|
activation condition, scoped call adapter and optional CLI commands.
|
|
61
61
|
|
|
62
|
-
The
|
|
62
|
+
The seven built-in Providers are:
|
|
63
63
|
|
|
64
64
|
- `desktop`: allowlisted Desktop Commander tools and isolated fixtures
|
|
65
65
|
- `extension`: official pinned Extension CLI and nine scoped actions
|
|
66
66
|
- `runtime`: exact-request receipt lookup without replay
|
|
67
67
|
- `context`: independent Context SDK read/write schemas and fixed CLI
|
|
68
68
|
- `trace`: Project-scoped diagnosis and SOFT stage observations, plus a bearer-token-scoped Form Trace lookup using the Prepare `traceRef`
|
|
69
|
-
-
|
|
69
|
+
- Document: independent generic read-only MCP App (show/render). Caller controls title, content and open-ended format; reader safely renders supported formats and retains the original source for one-click copy, with a source fallback for other formats. It does not create a business template, approval, Form or new Chat message.
|
|
70
|
+
- Form: stateless, generic single-select MCP App. Prepare accepts only caller-defined options and optional conditional text input; it preserves or generates formId and returns a random traceRef. It never accepts, stores, renders or copies a business document: the caller presents R/P separately using the generic Document App. Render acknowledges the UI; Submit returns selected value/label and optional text. ui/update-model-context makes a result available to future model turns but does not trigger one or prove approval. Form does not send Chat messages, interpret decisions, call Context or impose expiry. Prepare/Render/Submit observations are correlated by formId and traceRef without altering results.
|
|
70
71
|
|
|
71
72
|
`npm run build:providers` generates `providers.generated.mjs`, the static
|
|
72
73
|
assembly and release fingerprint manifest. Both `tools/list` and `tools/call`
|
|
@@ -106,7 +106,20 @@ export async function verifyMcpTools(p,ports={}){
|
|
|
106
106
|
if(!html.includes('chat_loop_form__render')||!html.includes('ui/message'))
|
|
107
107
|
throw Object.assign(Error('MCP_PROBE_FORM_APP_OUTDATED'),{
|
|
108
108
|
code:'MCP_PROBE_FORM_APP_OUTDATED'});
|
|
109
|
-
|
|
109
|
+
for(const name of ['chat_loop_document__show','chat_loop_document__render'])
|
|
110
|
+
if(!names.includes(name))throw Object.assign(Error('MCP_PROBE_REQUIRED_TOOL_MISSING'),{
|
|
111
|
+
code:'MCP_PROBE_REQUIRED_TOOL_MISSING'});
|
|
112
|
+
const documentTool=listed.result.tools.find(x=>x.name==='chat_loop_document__show');
|
|
113
|
+
const docUri=documentTool?._meta?.ui?.resourceUri;
|
|
114
|
+
if(!resources.result.resources.some(x=>x.uri===docUri))
|
|
115
|
+
throw Object.assign(Error('MCP_PROBE_DOCUMENT_RESOURCE_MISSING'),{
|
|
116
|
+
code:'MCP_PROBE_DOCUMENT_RESOURCE_MISSING'});
|
|
117
|
+
const docView=await request('resources/read',{uri:docUri});
|
|
118
|
+
const docHtml=docView.result?.contents?.[0]?.text||'';
|
|
119
|
+
if(!docHtml.includes('chat_loop_document__render')||!docHtml.includes('复制全文'))
|
|
120
|
+
throw Object.assign(Error('MCP_PROBE_DOCUMENT_APP_OUTDATED'),{
|
|
121
|
+
code:'MCP_PROBE_DOCUMENT_APP_OUTDATED'});
|
|
122
|
+
return {ok:true,toolCount:names.length,formResource:uri,documentResource:docUri};
|
|
110
123
|
}finally{
|
|
111
124
|
try{child.stdin.end();child.kill('SIGTERM')}catch{}
|
|
112
125
|
await Promise.race([new Promise(resolve=>child.once('exit',resolve)),
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.39",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
"build:providers:check": "node ./scripts/build-providers.mjs --check",
|
|
28
28
|
"build:form": "node ./scripts/build-form-app.mjs",
|
|
29
29
|
"build:form:check": "node ./scripts/build-form-app.mjs --check",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"build:document": "node ./scripts/build-document-app.mjs",
|
|
31
|
+
"build:document:check": "node ./scripts/build-document-app.mjs --check",
|
|
32
|
+
"pretest": "node ./scripts/build-providers.mjs --check && node ./scripts/build-form-app.mjs --check && node ./scripts/build-document-app.mjs --check",
|
|
33
|
+
"prepack": "node ./scripts/build-providers.mjs --check && node ./scripts/build-form-app.mjs --check && node ./scripts/build-document-app.mjs --check"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"@tomflow/chatloop-context": "0.6.12",
|
|
@@ -55,6 +57,8 @@
|
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|
|
57
59
|
"@modelcontextprotocol/ext-apps": "1.7.5",
|
|
58
|
-
"esbuild": "0.28.2"
|
|
60
|
+
"esbuild": "0.28.2",
|
|
61
|
+
"happy-dom": "20.8.4",
|
|
62
|
+
"marked": "16.3.0"
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Generic read-only document presentation; R/P content remains owned by caller Skills.
|
|
2
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const URI='ui://chat-loop/document/v1';
|
|
6
|
+
const MIME='text/html;profile=mcp-app';
|
|
7
|
+
const IDENT=/^[A-Za-z0-9][A-Za-z0-9_.-]{7,127}$/;
|
|
8
|
+
const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
9
|
+
const DIGEST=/^[0-9a-f]{64}$/;
|
|
10
|
+
const TYPE=/^[a-zA-Z0-9][a-zA-Z0-9.+/-]{0,79}$/;
|
|
11
|
+
const err=code=>Object.assign(Error(code),{code});
|
|
12
|
+
const result=data=>({content:[{type:'text',text:JSON.stringify(data)}],
|
|
13
|
+
structuredContent:data});
|
|
14
|
+
const pure=(x,keys)=>x&&typeof x==='object'&&!Array.isArray(x)
|
|
15
|
+
&&Object.keys(x).every(k=>keys.includes(k));
|
|
16
|
+
const length=(x,n)=>typeof x==='string'&&x.trim().length>0&&x.length<=n;
|
|
17
|
+
const documentSchema={type:'object',additionalProperties:false,
|
|
18
|
+
required:['title','content'],properties:{
|
|
19
|
+
title:{type:'string',minLength:1,maxLength:180},
|
|
20
|
+
content:{type:'string',minLength:1,maxLength:262144},
|
|
21
|
+
format:{type:'string',minLength:1,maxLength:80},
|
|
22
|
+
subtitle:{type:'string',maxLength:500}
|
|
23
|
+
}};
|
|
24
|
+
const tools=[
|
|
25
|
+
{name:'chat_loop_document__show',
|
|
26
|
+
description:'Display an independent, general-purpose rich document App with full-source copy. The caller Skill owns document sections, content, format, versions and approval. Call this BEFORE the separate Form App for review flows; do not place Form controls inside the document.',
|
|
27
|
+
inputSchema:{type:'object',additionalProperties:false,required:['document'],
|
|
28
|
+
properties:{documentId:{type:'string',pattern:IDENT.source},
|
|
29
|
+
document:documentSchema}},
|
|
30
|
+
annotations:{readOnlyHint:true},
|
|
31
|
+
_meta:{ui:{resourceUri:URI,visibility:['model','app']},
|
|
32
|
+
'openai/outputTemplate':URI,'openai/widgetAccessible':true}},
|
|
33
|
+
{name:'chat_loop_document__render',
|
|
34
|
+
description:'Document App-only visual rendering acknowledgement; no document storage, review decision, approval, or Form behavior.',
|
|
35
|
+
inputSchema:{type:'object',additionalProperties:false,
|
|
36
|
+
required:['documentId','traceRef','contentHash'],
|
|
37
|
+
properties:{documentId:{type:'string',pattern:IDENT.source},
|
|
38
|
+
traceRef:{type:'string',pattern:UUID.source},
|
|
39
|
+
contentHash:{type:'string',pattern:DIGEST.source}}},
|
|
40
|
+
annotations:{readOnlyHint:false},
|
|
41
|
+
_meta:{ui:{visibility:['app']},'openai/widgetAccessible':true}}
|
|
42
|
+
];
|
|
43
|
+
function show(args){
|
|
44
|
+
if(!pure(args,['documentId','document'])
|
|
45
|
+
||args.documentId!==undefined
|
|
46
|
+
&&(typeof args.documentId!=='string'||!IDENT.test(args.documentId)))
|
|
47
|
+
throw err('DOCUMENT_INVALID_ARGUMENT');
|
|
48
|
+
const doc=args.document;
|
|
49
|
+
if(!pure(doc,['title','subtitle','content','format'])
|
|
50
|
+
||!length(doc.title,180)||!length(doc.content,262144)
|
|
51
|
+
||doc.subtitle!==undefined
|
|
52
|
+
&&(typeof doc.subtitle!=='string'||doc.subtitle.length>500)
|
|
53
|
+
||doc.format!==undefined
|
|
54
|
+
&&(typeof doc.format!=='string'||!TYPE.test(doc.format)))
|
|
55
|
+
throw err('DOCUMENT_INVALID_CONTENT');
|
|
56
|
+
const documentId=args.documentId??randomUUID(),traceRef=randomUUID();
|
|
57
|
+
const contentHash=createHash('sha256').update(doc.content).digest('hex');
|
|
58
|
+
return {status:'DOCUMENT_READY',documentId,traceRef,contentHash,
|
|
59
|
+
view:{template:'chat-loop-document-v1',title:doc.title,
|
|
60
|
+
subtitle:doc.subtitle??'',format:doc.format??'text/markdown',
|
|
61
|
+
content:doc.content}};
|
|
62
|
+
}
|
|
63
|
+
function rendered(args){
|
|
64
|
+
if(!pure(args,['documentId','traceRef','contentHash'])
|
|
65
|
+
||typeof args.documentId!=='string'||!IDENT.test(args.documentId)
|
|
66
|
+
||typeof args.traceRef!=='string'||!UUID.test(args.traceRef)
|
|
67
|
+
||typeof args.contentHash!=='string'||!DIGEST.test(args.contentHash))
|
|
68
|
+
throw err('DOCUMENT_RENDER_INVALID');
|
|
69
|
+
return {status:'DOCUMENT_RENDERED',documentId:args.documentId,
|
|
70
|
+
traceRef:args.traceRef,contentHash:args.contentHash};
|
|
71
|
+
}
|
|
72
|
+
export const provider=Object.freeze({
|
|
73
|
+
id:'document',order:6,names:tools.map(tool=>tool.name),
|
|
74
|
+
create(){
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
tools:()=>tools,
|
|
77
|
+
resources:()=>[{uri:URI,name:'Chat Loop Document',
|
|
78
|
+
description:'Generic rich document reader with one-click copy',
|
|
79
|
+
mimeType:MIME}],
|
|
80
|
+
async readResource(uri){
|
|
81
|
+
if(uri!==URI)throw err('MCP_RESOURCE_NOT_FOUND');
|
|
82
|
+
return {contents:[{uri,mimeType:MIME,
|
|
83
|
+
text:readFileSync(new URL('../ui/document/view.html',import.meta.url),'utf8'),
|
|
84
|
+
_meta:{ui:{availableDisplayModes:['inline'],
|
|
85
|
+
preferredDisplayMode:'inline',
|
|
86
|
+
permissions:{clipboardWrite:{}}}}}]};
|
|
87
|
+
},
|
|
88
|
+
async call(name,args){
|
|
89
|
+
if(name===tools[0].name)return result(show(args));
|
|
90
|
+
if(name===tools[1].name)return result(rendered(args));
|
|
91
|
+
throw err('UNKNOWN_TOOL');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
package/providers.generated.mjs
CHANGED
|
@@ -5,5 +5,6 @@ import {provider as p2} from './providers/runtime.mjs';
|
|
|
5
5
|
import {provider as p3} from './providers/context.mjs';
|
|
6
6
|
import {provider as p4} from './providers/trace.mjs';
|
|
7
7
|
import {provider as p5} from './providers/form.mjs';
|
|
8
|
-
|
|
9
|
-
export const
|
|
8
|
+
import {provider as p6} from './providers/document.mjs';
|
|
9
|
+
export const providerDefinitions=Object.freeze([p0,p1,p2,p3,p4,p5,p6]);
|
|
10
|
+
export const providerFiles=Object.freeze(["providers/desktop.mjs","providers/extension.mjs","providers/runtime.mjs","providers/context.mjs","providers/trace.mjs","providers/form.mjs","providers/document.mjs"]);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Deterministic, self-contained document MCP App. No external scripts at runtime.
|
|
2
|
+
import {build} from 'esbuild';
|
|
3
|
+
import {readFileSync,writeFileSync} from 'node:fs';
|
|
4
|
+
import {dirname,join} from 'node:path';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
6
|
+
|
|
7
|
+
const root=dirname(dirname(fileURLToPath(import.meta.url)));
|
|
8
|
+
const template=readFileSync(join(root,'ui/document/view.template.html'),'utf8');
|
|
9
|
+
const output=await build({
|
|
10
|
+
entryPoints:[join(root,'ui/document/view-app.js')],
|
|
11
|
+
bundle:true,platform:'browser',format:'iife',target:'es2022',
|
|
12
|
+
minify:true,write:false,legalComments:'none',logLevel:'silent'
|
|
13
|
+
});
|
|
14
|
+
if(output.outputFiles.length!==1)throw Error('DOCUMENT_BUNDLE_INVALID');
|
|
15
|
+
const script=output.outputFiles[0].text.replaceAll('</script','<'+String.fromCharCode(92)+'/script');
|
|
16
|
+
const marker='<!-- CHAT_LOOP_DOCUMENT_SCRIPT -->';
|
|
17
|
+
if(template.split(marker).length!==2)throw Error('DOCUMENT_TEMPLATE_INVALID');
|
|
18
|
+
const html=template.replace(marker,'<script>'+script+'</script>');
|
|
19
|
+
if(Buffer.byteLength(html,'utf8')>700000)
|
|
20
|
+
throw Error('DOCUMENT_APP_EXCEEDS_MCP_RESOURCE_BUDGET');
|
|
21
|
+
const file=join(root,'ui/document/view.html');
|
|
22
|
+
if(process.argv.includes('--check')){
|
|
23
|
+
let actual;try{actual=readFileSync(file,'utf8')}catch{}
|
|
24
|
+
if(actual!==html)throw Error('DOCUMENT_APP_BUILD_STALE');
|
|
25
|
+
console.log('MCP_DOCUMENT_APP_CURRENT bytes='+Buffer.byteLength(html));
|
|
26
|
+
}else{
|
|
27
|
+
writeFileSync(file,html);
|
|
28
|
+
console.log('MCP_DOCUMENT_APP_BUILT bytes='+Buffer.byteLength(html));
|
|
29
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Optional flowchart renderer. Unsupported diagram syntax is shown as source.
|
|
2
|
+
const ns='http://www.w3.org/2000/svg';
|
|
3
|
+
const svgNode=(tag,attrs={},text)=>{
|
|
4
|
+
const node=document.createElementNS(ns,tag);
|
|
5
|
+
for(const [k,v] of Object.entries(attrs))node.setAttribute(k,String(v));
|
|
6
|
+
if(text!==undefined)node.textContent=text;
|
|
7
|
+
return node;
|
|
8
|
+
};
|
|
9
|
+
const atom='[\\p{L}\\p{N}_-]+';
|
|
10
|
+
const nodeRe=new RegExp('^('+atom+')(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$','u');
|
|
11
|
+
const edgeRe=new RegExp('^('+atom+')(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?\\s*(-->|---|-.->|==>)\\s*(?:\\|[^|]{0,100}\\|\\s*)?('+atom+')(?:\\[([^\\]]*)\\]|\\(([^)]*)\\)|\\{([^}]*)\\})?$','u');
|
|
12
|
+
export function renderFlowchart(source){
|
|
13
|
+
if(typeof source!=='string'||source.length>12000)return null;
|
|
14
|
+
const lines=source.split(/\r?\n/).map(x=>x.trim())
|
|
15
|
+
.filter(x=>x&&!x.startsWith('%%'));
|
|
16
|
+
const head=lines.shift()?.match(/^(?:flowchart|graph)\s+(TB|TD|BT|LR|RL)$/i);
|
|
17
|
+
if(!head)return null;
|
|
18
|
+
const reverse=head[1]==='BT'||head[1]==='RL';
|
|
19
|
+
const horizontal=head[1]==='LR'||head[1]==='RL';
|
|
20
|
+
const nodes=new Map(),edges=[];
|
|
21
|
+
const add=(id,a,b,c)=>{
|
|
22
|
+
if(!nodes.has(id)&&nodes.size>=32)throw Error('MAX_NODES');
|
|
23
|
+
nodes.set(id,String(a||b||c||nodes.get(id)||id).slice(0,120));
|
|
24
|
+
};
|
|
25
|
+
try{
|
|
26
|
+
for(const line of lines){
|
|
27
|
+
if(/^(?:classDef|style|linkStyle)\s/.test(line))continue;
|
|
28
|
+
const edge=line.match(edgeRe);
|
|
29
|
+
if(edge){
|
|
30
|
+
const [,a,a1,a2,a3,arrow,b,b1,b2,b3]=edge;
|
|
31
|
+
add(a,a1,a2,a3);add(b,b1,b2,b3);
|
|
32
|
+
edges.push({a,b,arrow});
|
|
33
|
+
if(edges.length>64)throw Error('MAX_EDGES');
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const one=line.match(nodeRe);
|
|
37
|
+
if(one){add(one[1],one[2],one[3],one[4]);continue;}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}catch{return null;}
|
|
41
|
+
if(!nodes.size)return null;
|
|
42
|
+
const across=Math.min(horizontal?4:3,nodes.size);
|
|
43
|
+
const rows=Math.ceil(nodes.size/across),width=across*198+34,height=rows*110+35;
|
|
44
|
+
const svg=svgNode('svg',{viewBox:'0 0 '+width+' '+height,
|
|
45
|
+
role:'img','aria-label':'流程图','data-diagram':'flowchart'});
|
|
46
|
+
const marker=svgNode('marker',{id:'cl-doc-arrow',markerWidth:8,markerHeight:8,
|
|
47
|
+
refX:6,refY:4,orient:'auto',markerUnits:'strokeWidth'});
|
|
48
|
+
marker.append(svgNode('path',{d:'M 0 0 L 8 4 L 0 8 z',fill:'currentColor'}));
|
|
49
|
+
const defs=svgNode('defs');defs.append(marker);svg.append(defs);
|
|
50
|
+
const positions=new Map(),ordered=[...nodes.entries()];
|
|
51
|
+
for(const [i,[id]] of ordered.entries()){
|
|
52
|
+
let col=i%across;
|
|
53
|
+
if(reverse)col=across-1-col;
|
|
54
|
+
positions.set(id,{x:24+col*198,y:23+Math.floor(i/across)*110});
|
|
55
|
+
}
|
|
56
|
+
const links=svgNode('g');
|
|
57
|
+
for(const edge of edges){
|
|
58
|
+
const a=positions.get(edge.a),b=positions.get(edge.b);
|
|
59
|
+
if(!a||!b)continue;
|
|
60
|
+
const ax=a.x+78,ay=a.y+33,bx=b.x+78,by=b.y+33;
|
|
61
|
+
const distance=Math.hypot(bx-ax,by-ay)||1;
|
|
62
|
+
if(distance<=1)continue;
|
|
63
|
+
const ux=(bx-ax)/distance,uy=(by-ay)/distance;
|
|
64
|
+
links.append(svgNode('line',{x1:ax+ux*52,y1:ay+uy*27,
|
|
65
|
+
x2:bx-ux*52,y2:by-uy*27,stroke:'currentColor',
|
|
66
|
+
'stroke-opacity':0.65,'stroke-width':1.7,
|
|
67
|
+
'stroke-dasharray':edge.arrow==='-.->'?'5 5':'none',
|
|
68
|
+
'marker-end':edge.arrow==='---'?'none':'url(#cl-doc-arrow)'}));
|
|
69
|
+
}
|
|
70
|
+
svg.append(links);
|
|
71
|
+
for(const [id,label] of ordered){
|
|
72
|
+
const {x,y}=positions.get(id);
|
|
73
|
+
svg.append(svgNode('rect',{x,y,width:156,height:66,rx:12,
|
|
74
|
+
fill:'var(--diagram-bg, #f5f8fc)',
|
|
75
|
+
stroke:'var(--diagram-stroke, #9aafca)','stroke-width':1.2}));
|
|
76
|
+
const text=svgNode('text',{x:x+78,y:y+33,'text-anchor':'middle',
|
|
77
|
+
fill:'var(--diagram-text, #1f334e)',
|
|
78
|
+
'font-size':12,'font-family':'system-ui, sans-serif'});
|
|
79
|
+
const rows=[...label].reduce((a,ch)=>{
|
|
80
|
+
if(a.at(-1).length>=19)a.push('');
|
|
81
|
+
a[a.length-1]+=ch;return a;
|
|
82
|
+
},['']).slice(0,3);
|
|
83
|
+
rows.forEach((part,j)=>text.append(svgNode('tspan',
|
|
84
|
+
{x:x+78,dy:j===0?-((rows.length-1)*8):16},part)));
|
|
85
|
+
svg.append(text);
|
|
86
|
+
}
|
|
87
|
+
return svg;
|
|
88
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {marked} from 'marked';
|
|
2
|
+
import {renderFlowchart} from './diagram.js';
|
|
3
|
+
|
|
4
|
+
// Add new content renderers here without changing the document MCP contract.
|
|
5
|
+
// The source is always preserved separately for lossless full-text copying.
|
|
6
|
+
const permitted=new Set(['P','H1','H2','H3','H4','H5','H6','STRONG','B',
|
|
7
|
+
'EM','I','U','S','DEL','UL','OL','LI','BLOCKQUOTE','PRE','CODE','TABLE',
|
|
8
|
+
'THEAD','TBODY','TR','TH','TD','HR','BR','A','IMG','INPUT','SUP','SUB','DETAILS',
|
|
9
|
+
'SUMMARY','DIV','SPAN']);
|
|
10
|
+
const discard=new Set(['SCRIPT','STYLE','IFRAME','OBJECT','EMBED','FORM','BUTTON',
|
|
11
|
+
'TEXTAREA','SELECT','META','LINK','SVG','MATH','VIDEO','AUDIO','CANVAS']);
|
|
12
|
+
function safeUrl(raw){
|
|
13
|
+
try{
|
|
14
|
+
const u=new URL(raw,'https://document.invalid');
|
|
15
|
+
return ['http:','https:','mailto:'].includes(u.protocol)
|
|
16
|
+
&&raw.trim().match(/^(?:https?:|mailto:)/i)?u.href:null;
|
|
17
|
+
}catch{return null;}
|
|
18
|
+
}
|
|
19
|
+
function clean(node){
|
|
20
|
+
if(node.nodeType===Node.TEXT_NODE)return document.createTextNode(node.textContent);
|
|
21
|
+
if(node.nodeType!==Node.ELEMENT_NODE)return null;
|
|
22
|
+
const tag=node.tagName;
|
|
23
|
+
if(discard.has(tag))return null;
|
|
24
|
+
const target=permitted.has(tag)?document.createElement(tag.toLowerCase()):
|
|
25
|
+
document.createDocumentFragment();
|
|
26
|
+
if(tag==='A'&&target.nodeType===Node.ELEMENT_NODE){
|
|
27
|
+
const href=safeUrl(node.getAttribute('href')||'');
|
|
28
|
+
if(href){target.setAttribute('href',href);
|
|
29
|
+
target.setAttribute('target','_blank');
|
|
30
|
+
target.setAttribute('rel','noopener noreferrer');}
|
|
31
|
+
}
|
|
32
|
+
if(tag==='CODE'){
|
|
33
|
+
const lang=(node.getAttribute('class')||'').match(/(?:^|\s)language-([a-z0-9_+-]{1,40})(?:\s|$)/i);
|
|
34
|
+
if(lang)target.dataset.language=lang[1].toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
if(tag==='IMG'){
|
|
37
|
+
const src=node.getAttribute('src')||'',alt=node.getAttribute('alt')||'图片';
|
|
38
|
+
if(/^data:image\/(?:png|jpeg|webp|gif);base64,[a-z0-9+/=]+$/i.test(src)
|
|
39
|
+
&&src.length<180000){
|
|
40
|
+
target.setAttribute('src',src);target.setAttribute('alt',alt);
|
|
41
|
+
target.setAttribute('loading','lazy');target.setAttribute('referrerpolicy','no-referrer');
|
|
42
|
+
}else{
|
|
43
|
+
const label=document.createElement('span');
|
|
44
|
+
label.className='external-image-blocked';
|
|
45
|
+
label.textContent='[外部图片未加载] '+alt;
|
|
46
|
+
return label;
|
|
47
|
+
}
|
|
48
|
+
return target;
|
|
49
|
+
}
|
|
50
|
+
if(tag==='INPUT'){
|
|
51
|
+
target.type='checkbox';target.disabled=true;
|
|
52
|
+
target.checked=node.hasAttribute('checked');
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
for(const child of node.childNodes){
|
|
56
|
+
const safe=clean(child);
|
|
57
|
+
if(safe)target.append(safe);
|
|
58
|
+
}
|
|
59
|
+
return target;
|
|
60
|
+
}
|
|
61
|
+
function codeCard(source,language,copy){
|
|
62
|
+
const wrapper=document.createElement('div');
|
|
63
|
+
wrapper.className='code-card';
|
|
64
|
+
const toolbar=document.createElement('div');
|
|
65
|
+
toolbar.className='code-toolbar';
|
|
66
|
+
const name=document.createElement('span');
|
|
67
|
+
name.textContent=language||'代码';
|
|
68
|
+
const button=document.createElement('button');
|
|
69
|
+
button.type='button';button.className='copy-block';
|
|
70
|
+
button.textContent='复制代码';
|
|
71
|
+
button.addEventListener('click',()=>void copy(source,button));
|
|
72
|
+
toolbar.append(name,button);
|
|
73
|
+
const pre=document.createElement('pre');
|
|
74
|
+
const code=document.createElement('code');
|
|
75
|
+
code.textContent=source;pre.append(code);
|
|
76
|
+
wrapper.append(toolbar,pre);
|
|
77
|
+
return wrapper;
|
|
78
|
+
}
|
|
79
|
+
function diagramCard(source,copy){
|
|
80
|
+
const view=renderFlowchart(source);
|
|
81
|
+
if(!view){
|
|
82
|
+
const fallback=codeCard(source,'Mermaid 描述(原文保留)',copy);
|
|
83
|
+
fallback.dataset.diagram='source-only';
|
|
84
|
+
return fallback;
|
|
85
|
+
}
|
|
86
|
+
const wrapper=document.createElement('figure');
|
|
87
|
+
wrapper.className='diagram-card';
|
|
88
|
+
wrapper.dataset.diagram='rendered';
|
|
89
|
+
const toolbar=document.createElement('figcaption');
|
|
90
|
+
toolbar.textContent='流程图';
|
|
91
|
+
const button=document.createElement('button');
|
|
92
|
+
button.type='button';button.className='copy-block';
|
|
93
|
+
button.textContent='复制图形源码';
|
|
94
|
+
button.addEventListener('click',()=>void copy(source,button));
|
|
95
|
+
toolbar.append(button);
|
|
96
|
+
wrapper.append(toolbar,view);
|
|
97
|
+
return wrapper;
|
|
98
|
+
}
|
|
99
|
+
function enhance(root,copy){
|
|
100
|
+
for(const pre of [...root.querySelectorAll('pre')]){
|
|
101
|
+
const code=pre.querySelector('code');
|
|
102
|
+
if(!code)continue;
|
|
103
|
+
const language=code.dataset.language||'';
|
|
104
|
+
const source=code.textContent;
|
|
105
|
+
pre.replaceWith(language==='mermaid'||language==='flowchart'
|
|
106
|
+
?diagramCard(source,copy):codeCard(source,language,copy));
|
|
107
|
+
}
|
|
108
|
+
const headings=[...root.querySelectorAll('h1,h2,h3')];
|
|
109
|
+
headings.forEach((h,i)=>h.id='doc-heading-'+i);
|
|
110
|
+
return headings.map(h=>({id:h.id,level:Number(h.tagName[1]),text:h.textContent}));
|
|
111
|
+
}
|
|
112
|
+
function markdown(root,source,copy){
|
|
113
|
+
const html=marked.parse(source,{gfm:true,breaks:false,async:false});
|
|
114
|
+
const parsed=new DOMParser().parseFromString(html,'text/html');
|
|
115
|
+
const fragment=document.createDocumentFragment();
|
|
116
|
+
for(const item of parsed.body.childNodes){
|
|
117
|
+
const safe=clean(item);if(safe)fragment.append(safe);
|
|
118
|
+
}
|
|
119
|
+
root.replaceChildren(fragment);
|
|
120
|
+
return enhance(root,copy);
|
|
121
|
+
}
|
|
122
|
+
function plain(root,source){
|
|
123
|
+
const pre=document.createElement('pre');
|
|
124
|
+
pre.className='plain-text';pre.textContent=source;
|
|
125
|
+
root.replaceChildren(pre);
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
function json(root,source,copy){
|
|
129
|
+
let prettified=source;
|
|
130
|
+
try{prettified=JSON.stringify(JSON.parse(source),null,2)}catch{}
|
|
131
|
+
root.replaceChildren(codeCard(prettified,'JSON',copy));
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
function diagram(root,source,copy){
|
|
135
|
+
root.replaceChildren(diagramCard(source,copy));return [];
|
|
136
|
+
}
|
|
137
|
+
const renderers=new Map([
|
|
138
|
+
['text/markdown',markdown],['text/x-markdown',markdown],
|
|
139
|
+
['text/plain',plain],['application/json',json],
|
|
140
|
+
['text/mermaid',diagram],['text/x-mermaid',diagram]
|
|
141
|
+
]);
|
|
142
|
+
export function renderContent(root,format,source,copy){
|
|
143
|
+
const render=renderers.get(format.toLowerCase());
|
|
144
|
+
const headings=render?render(root,source,copy):plain(root,source);
|
|
145
|
+
return {headings,raw:!render};
|
|
146
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {renderContent} from './render-content.js';
|
|
2
|
+
|
|
3
|
+
const $=id=>document.getElementById(id);
|
|
4
|
+
const ident=/^[A-Za-z0-9][A-Za-z0-9_.-]{7,127}$/;
|
|
5
|
+
const uuid=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
6
|
+
const digest=/^[a-f0-9]{64}$/;
|
|
7
|
+
let seq=0,connected=false,serverTools=false,pendingResult=null,shown=null;
|
|
8
|
+
let observed=null,lastHeight=0,lastWidth=0;
|
|
9
|
+
const requests=new Map();
|
|
10
|
+
function status(text,state='info'){
|
|
11
|
+
$('status').textContent=text;$('status').dataset.state=state;
|
|
12
|
+
}
|
|
13
|
+
function send(message){
|
|
14
|
+
window.parent.postMessage({jsonrpc:'2.0',...message},'*');
|
|
15
|
+
}
|
|
16
|
+
function notify(method,params={}){
|
|
17
|
+
send({method,params});
|
|
18
|
+
}
|
|
19
|
+
function call(method,params={}){
|
|
20
|
+
if(!connected)throw Error('DOCUMENT_APP_NOT_INITIALIZED');
|
|
21
|
+
return new Promise((resolve,reject)=>{
|
|
22
|
+
const id=++seq;
|
|
23
|
+
const timer=setTimeout(()=>{
|
|
24
|
+
requests.delete(id);reject(Error('DOCUMENT_APP_REPLY_UNKNOWN'));
|
|
25
|
+
},30000);
|
|
26
|
+
requests.set(id,{resolve,reject,timer});
|
|
27
|
+
send({id,method,params});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function decode(result){
|
|
31
|
+
if(result?.isError)throw Error('DOCUMENT_TOOL_REJECTED');
|
|
32
|
+
if(result?.structuredContent?.status)return result.structuredContent;
|
|
33
|
+
const text=result?.content?.find(item=>item.type==='text')?.text;
|
|
34
|
+
if(typeof text!=='string'||text.length>800000)
|
|
35
|
+
throw Error('DOCUMENT_RESULT_MISSING');
|
|
36
|
+
return JSON.parse(text);
|
|
37
|
+
}
|
|
38
|
+
async function copyText(source,button){
|
|
39
|
+
let copied=false;
|
|
40
|
+
try{
|
|
41
|
+
if(navigator.clipboard?.writeText){
|
|
42
|
+
await navigator.clipboard.writeText(source);
|
|
43
|
+
copied=true;
|
|
44
|
+
}
|
|
45
|
+
}catch{/* sandbox may disallow direct clipboard despite a permission request */}
|
|
46
|
+
if(!copied){
|
|
47
|
+
const area=document.createElement('textarea');
|
|
48
|
+
area.value=source;
|
|
49
|
+
area.setAttribute('aria-hidden','true');
|
|
50
|
+
area.style.cssText='position:fixed;left:0;top:0;width:1px;height:1px;opacity:0';
|
|
51
|
+
document.body.append(area);
|
|
52
|
+
area.focus();area.select();
|
|
53
|
+
try{copied=document.execCommand('copy')===true}catch{}
|
|
54
|
+
area.remove();
|
|
55
|
+
}
|
|
56
|
+
if(copied){
|
|
57
|
+
button.textContent=button.id==='copy-all'?'已复制全文':'已复制';
|
|
58
|
+
status('已复制原始内容,可粘贴到其他编辑器。','ok');
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
button.textContent='复制不可用';
|
|
62
|
+
status('当前 ChatGPT 宿主未授予剪贴板写入权限;原文保留,可在文档区手动选择复制。','error');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function resize(){
|
|
66
|
+
if(!connected)return;
|
|
67
|
+
const bounds=document.querySelector('main')?.getBoundingClientRect();
|
|
68
|
+
if(!bounds||bounds.width<1||bounds.height<1)return;
|
|
69
|
+
const pad=parseFloat(getComputedStyle(document.body).paddingBottom)||0;
|
|
70
|
+
const height=Math.ceil(bounds.bottom+pad),width=Math.ceil(document.documentElement.clientWidth);
|
|
71
|
+
if(height<1||width<1||height===lastHeight&&width===lastWidth)return;
|
|
72
|
+
lastHeight=height;lastWidth=width;
|
|
73
|
+
notify('ui/notifications/size-changed',{width,height});
|
|
74
|
+
}
|
|
75
|
+
function reportRendered(result){
|
|
76
|
+
if(!connected||!serverTools||!shown)return;
|
|
77
|
+
const bounds=document.querySelector('main')?.getBoundingClientRect();
|
|
78
|
+
if(!bounds||bounds.width<1||bounds.height<1){
|
|
79
|
+
$('status').dataset.renderObservation='not-visible';
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const key=result.documentId+':'+result.traceRef;
|
|
83
|
+
if(observed===key)return;
|
|
84
|
+
observed=key;
|
|
85
|
+
$('status').dataset.renderObservation='pending';
|
|
86
|
+
void call('tools/call',{name:'chat_loop_document__render',arguments:{
|
|
87
|
+
documentId:result.documentId,traceRef:result.traceRef,
|
|
88
|
+
contentHash:result.contentHash
|
|
89
|
+
}}).then(decode).then(receipt=>{
|
|
90
|
+
if(receipt.status!=='DOCUMENT_RENDERED'
|
|
91
|
+
||receipt.documentId!==result.documentId
|
|
92
|
+
||receipt.traceRef!==result.traceRef
|
|
93
|
+
||receipt.contentHash!==result.contentHash)
|
|
94
|
+
throw Error('DOCUMENT_RENDER_RECEIPT_INVALID');
|
|
95
|
+
$('status').dataset.renderObservation='confirmed';
|
|
96
|
+
}).catch(()=>{
|
|
97
|
+
$('status').dataset.renderObservation='unverified';
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function render(result){
|
|
101
|
+
const view=result?.view;
|
|
102
|
+
if(result?.status!=='DOCUMENT_READY'
|
|
103
|
+
||typeof result.documentId!=='string'||!ident.test(result.documentId)
|
|
104
|
+
||typeof result.traceRef!=='string'||!uuid.test(result.traceRef)
|
|
105
|
+
||typeof result.contentHash!=='string'||!digest.test(result.contentHash)
|
|
106
|
+
||!view||view.template!=='chat-loop-document-v1'
|
|
107
|
+
||typeof view.title!=='string'||!view.title.trim()
|
|
108
|
+
||typeof view.subtitle!=='string'
|
|
109
|
+
||typeof view.format!=='string'||!view.format.trim()
|
|
110
|
+
||typeof view.content!=='string'||!view.content.trim())
|
|
111
|
+
throw Error('DOCUMENT_VIEW_INVALID');
|
|
112
|
+
shown=result;
|
|
113
|
+
$('title').textContent=view.title;
|
|
114
|
+
$('subtitle').hidden=!view.subtitle;
|
|
115
|
+
$('subtitle').textContent=view.subtitle;
|
|
116
|
+
const contents=$('content'),format=view.format;
|
|
117
|
+
const rendered=renderContent(contents,format,view.content,copyText);
|
|
118
|
+
$('copy-all').disabled=false;
|
|
119
|
+
$('copy-all').textContent='复制全文';
|
|
120
|
+
$('copy-all').onclick=()=>void copyText(view.content,$('copy-all'));
|
|
121
|
+
const toc=$('toc'),links=$('toc-links');
|
|
122
|
+
links.replaceChildren();
|
|
123
|
+
toc.hidden=!rendered.headings.length;
|
|
124
|
+
for(const heading of rendered.headings.slice(0,100)){
|
|
125
|
+
const a=document.createElement('a');
|
|
126
|
+
a.href='#'+heading.id;
|
|
127
|
+
a.textContent=heading.text;
|
|
128
|
+
a.addEventListener('click',event=>{
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
contents.querySelector('#'+heading.id)?.scrollIntoView({block:'nearest'});
|
|
131
|
+
});
|
|
132
|
+
links.append(a);
|
|
133
|
+
}
|
|
134
|
+
status(rendered.raw?'当前格式暂以安全原文模式展示,全文仍可复制。':
|
|
135
|
+
'完整文档已加载。','ok');
|
|
136
|
+
resize();
|
|
137
|
+
reportRendered(result);
|
|
138
|
+
}
|
|
139
|
+
function receive(event){
|
|
140
|
+
if(event.source!==window.parent)return;
|
|
141
|
+
const message=event.data;
|
|
142
|
+
if(!message||message.jsonrpc!=='2.0'||typeof message!=='object')return;
|
|
143
|
+
if(Object.hasOwn(message,'id')&&!Object.hasOwn(message,'method')){
|
|
144
|
+
const request=requests.get(message.id);
|
|
145
|
+
if(!request)return;
|
|
146
|
+
requests.delete(message.id);clearTimeout(request.timer);
|
|
147
|
+
if(message.error)request.reject(Error('DOCUMENT_APP_REPLY_UNKNOWN'));
|
|
148
|
+
else request.resolve(message.result);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if(message.method==='ui/notifications/tool-result'){
|
|
152
|
+
pendingResult=message.params;
|
|
153
|
+
if(connected){
|
|
154
|
+
try{render(decode(pendingResult))}
|
|
155
|
+
catch{status('文档回执无效,无法展示。','error');}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if(message.method==='ui/resource-teardown'&&message.id!==undefined)
|
|
159
|
+
send({id:message.id,result:{}});
|
|
160
|
+
}
|
|
161
|
+
async function initialize(){
|
|
162
|
+
if(window.parent===window){
|
|
163
|
+
status('请从 ChatGPT 的 MCP App 文档工具打开此页面。','error');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const id=++seq;
|
|
167
|
+
const prepared=new Promise((resolve,reject)=>{
|
|
168
|
+
const timer=setTimeout(()=>{
|
|
169
|
+
requests.delete(id);reject(Error('DOCUMENT_APP_INIT_TIMEOUT'));
|
|
170
|
+
},12000);
|
|
171
|
+
requests.set(id,{resolve,reject,timer});
|
|
172
|
+
send({id,method:'ui/initialize',params:{
|
|
173
|
+
appInfo:{name:'Chat Loop Document',version:'1.0.0'},
|
|
174
|
+
appCapabilities:{},protocolVersion:'2026-01-26'
|
|
175
|
+
}});
|
|
176
|
+
});
|
|
177
|
+
try{
|
|
178
|
+
const info=await prepared;
|
|
179
|
+
if(!info?.protocolVersion||!info.hostInfo||!info.hostCapabilities)
|
|
180
|
+
throw Error('DOCUMENT_APP_INIT_INVALID');
|
|
181
|
+
connected=true;
|
|
182
|
+
serverTools=Boolean(info.hostCapabilities.serverTools);
|
|
183
|
+
notify('ui/notifications/initialized',{});
|
|
184
|
+
if(pendingResult)render(decode(pendingResult));
|
|
185
|
+
resize();
|
|
186
|
+
if(typeof ResizeObserver==='function')
|
|
187
|
+
new ResizeObserver(resize).observe(document.querySelector('main'));
|
|
188
|
+
}catch{
|
|
189
|
+
status('文档 App 初始化失败,请检查宿主连接。','error');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
window.addEventListener('message',receive);
|
|
193
|
+
void initialize();
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Chat Loop 文档</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root{color-scheme:light dark;font:14px/1.6 system-ui,-apple-system,Segoe UI,sans-serif;
|
|
9
|
+
--ink:#20242b;--muted:#697488;--line:#d7dce5;--surface:#fff;--pane:#f6f8fb;--link:#1769b6;
|
|
10
|
+
--diagram-bg:#f5f8fc;--diagram-stroke:#9aafca;--diagram-text:#1f334e}
|
|
11
|
+
*{box-sizing:border-box}
|
|
12
|
+
body{padding:12px;margin:0;background:transparent;color:var(--ink)}
|
|
13
|
+
[hidden]{display:none!important}
|
|
14
|
+
.document{max-width:900px;margin:0 auto;border:1px solid var(--line);border-radius:14px;
|
|
15
|
+
overflow:hidden;background:var(--surface)}
|
|
16
|
+
header{padding:18px 20px 14px;display:flex;align-items:flex-start;justify-content:space-between;
|
|
17
|
+
gap:18px;border-bottom:1px solid var(--line)}
|
|
18
|
+
.heading{min-width:0;flex:1}
|
|
19
|
+
#title{font-size:19px;font-weight:700;line-height:1.35;margin:0;overflow-wrap:anywhere}
|
|
20
|
+
#subtitle{margin:5px 0 0;font-size:12px;color:var(--muted);overflow-wrap:anywhere}
|
|
21
|
+
.actions{display:flex;gap:8px;flex-shrink:0}
|
|
22
|
+
button{font:inherit;cursor:pointer;border:1px solid var(--line);border-radius:8px;
|
|
23
|
+
background:var(--pane);color:var(--ink);padding:6px 12px}
|
|
24
|
+
button:disabled{opacity:.45;cursor:not-allowed}
|
|
25
|
+
button:focus-visible,a:focus-visible{outline:2px solid var(--link);outline-offset:2px}
|
|
26
|
+
#copy-all{font-weight:600;white-space:nowrap}
|
|
27
|
+
#toc{padding:10px 20px 8px;border-bottom:1px solid var(--line)}
|
|
28
|
+
#toc summary{font-size:12px;color:var(--muted);cursor:pointer}
|
|
29
|
+
#toc nav{display:flex;flex-wrap:wrap;gap:6px 16px;margin-top:8px}
|
|
30
|
+
#toc nav a{font-size:12px;text-decoration:none;color:var(--link)}
|
|
31
|
+
#content{padding:16px 20px;max-height:min(75vh,920px);overflow-y:auto;overflow-x:auto;
|
|
32
|
+
overflow-wrap:anywhere;overscroll-behavior:contain}
|
|
33
|
+
#content>:first-child{margin-top:0}
|
|
34
|
+
#content h1{font-size:21px;margin:22px 0 12px}
|
|
35
|
+
#content h2{font-size:18px;margin:19px 0 10px}
|
|
36
|
+
#content h3{font-size:16px;margin:16px 0 8px}
|
|
37
|
+
#content h4,#content h5,#content h6{font-size:14px;margin:14px 0 7px}
|
|
38
|
+
#content p{margin:10px 0}
|
|
39
|
+
#content ul,#content ol{padding-left:24px}
|
|
40
|
+
#content li{margin:4px 0}
|
|
41
|
+
#content a{color:var(--link)}
|
|
42
|
+
#content blockquote{margin:12px 0;padding:4px 15px;border-left:3px solid var(--line);
|
|
43
|
+
color:var(--muted);background:var(--pane)}
|
|
44
|
+
#content table{border-collapse:collapse;width:100%;margin:12px 0;min-width:320px;
|
|
45
|
+
font-size:13px}
|
|
46
|
+
#content th,#content td{border:1px solid var(--line);padding:7px 10px;text-align:left;
|
|
47
|
+
vertical-align:top}
|
|
48
|
+
#content th{background:var(--pane)}
|
|
49
|
+
#content hr{border:0;border-top:1px solid var(--line);margin:20px 0}
|
|
50
|
+
#content code{font:12px/1.55 ui-monospace,SFMono-Regular,Consolas,monospace}
|
|
51
|
+
#content :not(pre)>code{padding:1px 5px;background:var(--pane);border-radius:4px}
|
|
52
|
+
#content .plain-text,#content .code-card pre{white-space:pre;overflow:auto;
|
|
53
|
+
tab-size:2;margin:0;padding:12px 15px;font:12px/1.6 ui-monospace,monospace}
|
|
54
|
+
.code-card,.diagram-card{border:1px solid var(--line);border-radius:9px;margin:13px 0;
|
|
55
|
+
background:var(--pane);overflow:hidden}
|
|
56
|
+
.code-toolbar,.diagram-card figcaption{display:flex;align-items:center;
|
|
57
|
+
justify-content:space-between;gap:12px;padding:7px 12px;border-bottom:1px solid var(--line);
|
|
58
|
+
color:var(--muted);font-size:12px}
|
|
59
|
+
.copy-block{font-size:12px;padding:3px 8px}
|
|
60
|
+
.diagram-card{padding-bottom:12px}
|
|
61
|
+
.diagram-card svg{display:block;width:100%;height:auto;max-height:520px;min-width:260px;
|
|
62
|
+
padding:12px;overflow:visible}
|
|
63
|
+
.external-image-blocked{font-size:12px;color:var(--muted);background:var(--pane);
|
|
64
|
+
border:1px dashed var(--line);padding:5px 8px}
|
|
65
|
+
#status{display:block;padding:8px 20px 12px;min-height:20px;font-size:12px;color:var(--muted)}
|
|
66
|
+
#status[data-state=error]{color:#b63939}
|
|
67
|
+
#status[data-state=ok]{color:#277349}
|
|
68
|
+
@media(prefers-color-scheme:dark){
|
|
69
|
+
:root{--ink:#e5e8ef;--muted:#a6afbc;--line:#474d58;--surface:#24282f;
|
|
70
|
+
--pane:#303640;--link:#90bff7;--diagram-bg:#303a4a;--diagram-stroke:#8c9cb4;
|
|
71
|
+
--diagram-text:#edf1f8}}
|
|
72
|
+
@media(max-width:480px){header{padding:12px;gap:8px;flex-wrap:wrap}
|
|
73
|
+
#content{padding:12px}#toc{padding:8px 12px}#status{padding:7px 12px}
|
|
74
|
+
#title{font-size:17px}}
|
|
75
|
+
</style>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
<main class="document" aria-label="通用文档阅读器">
|
|
79
|
+
<header>
|
|
80
|
+
<div class="heading">
|
|
81
|
+
<h1 id="title">正在加载文档…</h1>
|
|
82
|
+
<p id="subtitle" hidden></p>
|
|
83
|
+
</div>
|
|
84
|
+
<div class="actions">
|
|
85
|
+
<button id="copy-all" type="button" disabled aria-label="一键复制文档全文">复制全文</button>
|
|
86
|
+
</div>
|
|
87
|
+
</header>
|
|
88
|
+
<details id="toc" hidden>
|
|
89
|
+
<summary>文档目录</summary>
|
|
90
|
+
<nav id="toc-links" aria-label="文档章节导航"></nav>
|
|
91
|
+
</details>
|
|
92
|
+
<article id="content" aria-label="文档内容"></article>
|
|
93
|
+
<span id="status" role="status" aria-live="polite">正在连接文档服务…</span>
|
|
94
|
+
</main>
|
|
95
|
+
<script>(()=>{function re(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var N=re();function ye(t){N=t}var H={exec:()=>null};function d(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|$)|$)/,Z=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ke=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,se=/(?:[*+-]|\d{1,9}[.)])/,Te=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Re=d(Te).replace(/bull/g,se).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=d(Te).replace(/bull/g,se).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(),ie=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,tt=/^[^\n]+/,le=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,nt=d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",le).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),rt=d(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,se).getRegex(),X="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",ae=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,st=d("^ {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",ae).replace("tag",X).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Se=d(ie).replace("hr",Z).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",X).getRegex(),it=d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Se).getRegex(),oe={blockquote:it,code:Je,def:nt,fences:Ye,heading:Ke,hr:Z,html:st,lheading:Re,list:rt,newline:Xe,paragraph:Se,table:H,text:tt},ke=d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Z).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",X).getRegex(),lt={...oe,lheading:et,table:ke,paragraph:d(ie).replace("hr",Z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ke).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",X).getRegex()},at={...oe,html:d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ae).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:H,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:d(ie).replace("hr",Z).replace("heading",` *#{1,6} *[^
|
|
96
|
+
]`).replace("lheading",Re).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},ot=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ct=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Ee=/^( {2,}|\\)\n(?!\s*$)/,ht=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,J=/[\p{P}\p{S}]/u,ce=/[\s\p{P}\p{S}]/u,$e=/[^\s\p{P}\p{S}]/u,pt=d(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,ce).getRegex(),Ae=/(?!~)[\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,Ce=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,ft=d(Ce,"u").replace(/punct/g,J).getRegex(),kt=d(Ce,"u").replace(/punct/g,Ae).getRegex(),ze="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",xt=d(ze,"gu").replace(/notPunctSpace/g,$e).replace(/punctSpace/g,ce).replace(/punct/g,J).getRegex(),mt=d(ze,"gu").replace(/notPunctSpace/g,dt).replace(/punctSpace/g,ut).replace(/punct/g,Ae).getRegex(),bt=d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,$e).replace(/punctSpace/g,ce).replace(/punct/g,J).getRegex(),wt=d(/\\(punct)/,"gu").replace(/punct/g,J).getRegex(),yt=d(/^<(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=d(ae).replace("(?:-->|$)","-->").getRegex(),Rt=d("^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(),W=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/,St=d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",W).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),_e=d(/^!?\[(label)\]\[(ref)\]/).replace("label",W).replace("ref",le).getRegex(),Ie=d(/^!?\[(ref)\](?:\[\])?/).replace("ref",le).getRegex(),Et=d("reflink|nolink(?!\\()","g").replace("reflink",_e).replace("nolink",Ie).getRegex(),he={_backpedal:H,anyPunctuation:wt,autolink:yt,blockSkip:gt,br:Ee,code:ct,del:H,emStrongLDelim:ft,emStrongRDelimAst:xt,emStrongRDelimUnd:bt,escape:ot,link:St,nolink:Ie,punctuation:pt,reflink:_e,reflinkSearch:Et,tag:Rt,text:ht,url:H},$t={...he,link:d(/^!?\[(label)\]\((.*?)\)/).replace("label",W).getRegex(),reflink:d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",W).getRegex()},ee={...he,emStrongRDelimAst:mt,emStrongLDelim:kt,url:d(/^((?: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={...ee,br:d(Ee).replace("{2,}","*").getRegex(),text:d(ee.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Q={normal:oe,gfm:lt,pedantic:at},B={normal:he,gfm:ee,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 me(t){try{t=encodeURI(t).replace(T.percentDecode,"%")}catch{return null}return t}function be(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 q(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 we(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(`
|
|
97
|
+
`).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(`
|
|
98
|
+
`)}var F=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:q(n,`
|
|
99
|
+
`)}}}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=q(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:q(e[0],`
|
|
100
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=q(e[0],`
|
|
101
|
+
`).split(`
|
|
102
|
+
`),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(`
|
|
103
|
+
`),h=c.replace(this.rules.other.blockquoteSetextReplace,`
|
|
104
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
|
|
105
|
+
${c}`:c,r=r?`${r}
|
|
106
|
+
${h}`:h;let g=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(h,l,!0),this.lexer.state.top=g,n.length===0)break;let p=l.at(-1);if(p?.type==="code")break;if(p?.type==="blockquote"){let m=p,k=m.raw+`
|
|
107
|
+
`+n.join(`
|
|
108
|
+
`),b=this.blockquote(k);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(p?.type==="list"){let m=p,k=m.raw+`
|
|
109
|
+
`+n.join(`
|
|
110
|
+
`),b=this.list(k);l[l.length-1]=b,s=s.substring(0,s.length-p.raw.length)+b.raw,r=r.substring(0,r.length-m.raw.length)+b.raw,n=k.substring(l.at(-1).raw.length).split(`
|
|
111
|
+
`);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="",h="";if(!(e=l.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let g=e[2].split(`
|
|
112
|
+
`,1)[0].replace(this.rules.other.listReplaceTabs,L=>" ".repeat(3*L.length)),p=t.split(`
|
|
113
|
+
`,1)[0],m=!g.trim(),k=0;if(this.options.pedantic?(k=2,h=g.trimStart()):m?k=e[1].length+1:(k=e[2].search(this.rules.other.nonSpaceChar),k=k>4?1:k,h=g.slice(k),k+=e[1].length),m&&this.rules.other.blankLine.test(p)&&(c+=p+`
|
|
114
|
+
`,t=t.substring(p.length+1),o=!0),!o){let L=this.rules.other.nextBulletRegex(k),f=this.rules.other.hrRegex(k),y=this.rules.other.fencesBeginRegex(k),x=this.rules.other.headingBeginRegex(k),S=this.rules.other.htmlBeginRegex(k);for(;t;){let $=t.split(`
|
|
115
|
+
`,1)[0],R;if(p=$,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),R=p):R=p.replace(this.rules.other.tabCharGlobal," "),y.test(p)||x.test(p)||S.test(p)||L.test(p)||f.test(p))break;if(R.search(this.rules.other.nonSpaceChar)>=k||!p.trim())h+=`
|
|
116
|
+
`+R.slice(k);else{if(m||g.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||y.test(g)||x.test(g)||f.test(g))break;h+=`
|
|
117
|
+
`+p}!m&&!p.trim()&&(m=!0),c+=$+`
|
|
118
|
+
`,t=t.substring($.length+1),g=R.slice(k)}}r.loose||(i?r.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(i=!0));let b=null,D;this.options.gfm&&(b=this.rules.other.listIsTask.exec(h),b&&(D=b[0]!=="[ ] ",h=h.replace(this.rules.other.listReplaceTask,""))),r.items.push({type:"list_item",raw:c,task:!!b,checked:D,loose:!1,text:h,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(g=>g.type==="space"),h=c.length>0&&c.some(g=>this.rules.other.anyLine.test(g.raw));r.loose=h}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=be(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
119
|
+
`):[],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(be(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)===`
|
|
120
|
+
`?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=q(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)),we(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 we(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 h=[...s[0]][0].length,g=t.slice(0,r+s.index+h+i);if(Math.min(r,i)%2){let m=g.slice(1,-1);return{type:"em",raw:g,text:m,tokens:this.lexer.inlineTokens(m)}}let p=g.slice(2,-2);return{type:"strong",raw:g,text:p,tokens:this.lexer.inlineTokens(p)}}}}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 te{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 F,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:Q.normal,inline:B.normal};this.options.pedantic?(n.block=Q.pedantic,n.inline=B.pedantic):this.options.gfm&&(n.block=Q.gfm,this.options.breaks?n.inline=B.breaks:n.inline=B.gfm),this.tokenizer.rules=n}static get rules(){return{block:Q,inline:B}}static lex(e,n){return new te(n).lex(e)}static lexInline(e,n){return new te(n).inlineTokens(e)}lex(e){e=e.replace(T.carriageReturn,`
|
|
121
|
+
`),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+=`
|
|
122
|
+
`: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(`
|
|
123
|
+
`)?"":`
|
|
124
|
+
`)+r.raw,i.text+=`
|
|
125
|
+
`+r.text,this.inlineQueue.at(-1).src=i.text):n.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
|
|
126
|
+
`)?"":`
|
|
127
|
+
`)+r.raw,i.text+=`
|
|
128
|
+
`+r.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},n.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),n.push(r);continue}let l=e;if(this.options.extensions?.startBlock){let i=1/0,a=e.slice(1),o;this.options.extensions.startBlock.forEach(c=>{o=c.call({lexer:this},a),typeof o=="number"&&o>=0&&(i=Math.min(i,o))}),i<1/0&&i>=0&&(l=e.substring(0,i+1))}if(this.state.top&&(r=this.tokenizer.paragraph(l))){let i=n.at(-1);s&&i?.type==="paragraph"?(i.raw+=(i.raw.endsWith(`
|
|
129
|
+
`)?"":`
|
|
130
|
+
`)+r.raw,i.text+=`
|
|
131
|
+
`+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(`
|
|
132
|
+
`)?"":`
|
|
133
|
+
`)+r.raw,i.text+=`
|
|
134
|
+
`+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,h=e.slice(1),g;this.options.extensions.startInline.forEach(p=>{g=p.call({lexer:this},h),typeof g=="number"&&g>=0&&(c=Math.min(c,g))}),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}},V=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,"")+`
|
|
135
|
+
`;return s?'<pre><code class="language-'+A(s)+'">'+(n?r:A(r,!0))+`</code></pre>
|
|
136
|
+
`:"<pre><code>"+(n?r:A(r,!0))+`</code></pre>
|
|
137
|
+
`}blockquote({tokens:t}){return`<blockquote>
|
|
138
|
+
${this.parser.parse(t)}</blockquote>
|
|
139
|
+
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
|
140
|
+
`}hr(t){return`<hr>
|
|
141
|
+
`}list(t){let e=t.ordered,n=t.start,s="";for(let i=0;i<t.items.length;i++){let a=t.items[i];s+=this.listitem(a)}let r=e?"ol":"ul",l=e&&n!==1?' start="'+n+'"':"";return"<"+r+l+`>
|
|
142
|
+
`+s+"</"+r+`>
|
|
143
|
+
`}listitem(t){let e="";if(t.task){let n=this.checkbox({checked:!!t.checked});t.loose?t.tokens[0]?.type==="paragraph"?(t.tokens[0].text=n+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&t.tokens[0].tokens[0].type==="text"&&(t.tokens[0].tokens[0].text=n+" "+A(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):e+=n+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`<li>${e}</li>
|
|
144
|
+
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
|
145
|
+
`}table(t){let e="",n="";for(let r=0;r<t.header.length;r++)n+=this.tablecell(t.header[r]);e+=this.tablerow({text:n});let s="";for(let r=0;r<t.rows.length;r++){let l=t.rows[r];n="";for(let i=0;i<l.length;i++)n+=this.tablecell(l[i]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
|
|
146
|
+
<thead>
|
|
147
|
+
`+e+`</thead>
|
|
148
|
+
`+s+`</table>
|
|
149
|
+
`}tablerow({text:t}){return`<tr>
|
|
150
|
+
${t}</tr>
|
|
151
|
+
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
|
|
152
|
+
`}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=me(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=me(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)}},pe=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 ne{options;renderer;textRenderer;constructor(e){this.options=e||N,this.options.renderer=this.options.renderer||new V,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new pe}static parse(e,n){return new ne(n).parse(e)}static parseInline(e,n){return new ne(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+=`
|
|
153
|
+
`+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=re();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=_;Renderer=V;TextRenderer=pe;Lexer=z;Tokenizer=F;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 V(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 h=a.apply(r,c);return h===!1&&(h=o.apply(r,c)),h||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new F(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 h=a.apply(r,c);return h===!1&&(h=o.apply(r,c)),h}}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(g=>o.call(r,g));let h=a.call(r,c);return o.call(r,h)}:r[i]=(...c)=>{let h=a.apply(r,c);return h===!1&&(h=o.apply(r,c)),h}}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+=`
|
|
154
|
+
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();})();
|
|
155
|
+
</script>
|
|
156
|
+
</body>
|
|
157
|
+
</html>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Chat Loop 文档</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root{color-scheme:light dark;font:14px/1.6 system-ui,-apple-system,Segoe UI,sans-serif;
|
|
9
|
+
--ink:#20242b;--muted:#697488;--line:#d7dce5;--surface:#fff;--pane:#f6f8fb;--link:#1769b6;
|
|
10
|
+
--diagram-bg:#f5f8fc;--diagram-stroke:#9aafca;--diagram-text:#1f334e}
|
|
11
|
+
*{box-sizing:border-box}
|
|
12
|
+
body{padding:12px;margin:0;background:transparent;color:var(--ink)}
|
|
13
|
+
[hidden]{display:none!important}
|
|
14
|
+
.document{max-width:900px;margin:0 auto;border:1px solid var(--line);border-radius:14px;
|
|
15
|
+
overflow:hidden;background:var(--surface)}
|
|
16
|
+
header{padding:18px 20px 14px;display:flex;align-items:flex-start;justify-content:space-between;
|
|
17
|
+
gap:18px;border-bottom:1px solid var(--line)}
|
|
18
|
+
.heading{min-width:0;flex:1}
|
|
19
|
+
#title{font-size:19px;font-weight:700;line-height:1.35;margin:0;overflow-wrap:anywhere}
|
|
20
|
+
#subtitle{margin:5px 0 0;font-size:12px;color:var(--muted);overflow-wrap:anywhere}
|
|
21
|
+
.actions{display:flex;gap:8px;flex-shrink:0}
|
|
22
|
+
button{font:inherit;cursor:pointer;border:1px solid var(--line);border-radius:8px;
|
|
23
|
+
background:var(--pane);color:var(--ink);padding:6px 12px}
|
|
24
|
+
button:disabled{opacity:.45;cursor:not-allowed}
|
|
25
|
+
button:focus-visible,a:focus-visible{outline:2px solid var(--link);outline-offset:2px}
|
|
26
|
+
#copy-all{font-weight:600;white-space:nowrap}
|
|
27
|
+
#toc{padding:10px 20px 8px;border-bottom:1px solid var(--line)}
|
|
28
|
+
#toc summary{font-size:12px;color:var(--muted);cursor:pointer}
|
|
29
|
+
#toc nav{display:flex;flex-wrap:wrap;gap:6px 16px;margin-top:8px}
|
|
30
|
+
#toc nav a{font-size:12px;text-decoration:none;color:var(--link)}
|
|
31
|
+
#content{padding:16px 20px;max-height:min(75vh,920px);overflow-y:auto;overflow-x:auto;
|
|
32
|
+
overflow-wrap:anywhere;overscroll-behavior:contain}
|
|
33
|
+
#content>:first-child{margin-top:0}
|
|
34
|
+
#content h1{font-size:21px;margin:22px 0 12px}
|
|
35
|
+
#content h2{font-size:18px;margin:19px 0 10px}
|
|
36
|
+
#content h3{font-size:16px;margin:16px 0 8px}
|
|
37
|
+
#content h4,#content h5,#content h6{font-size:14px;margin:14px 0 7px}
|
|
38
|
+
#content p{margin:10px 0}
|
|
39
|
+
#content ul,#content ol{padding-left:24px}
|
|
40
|
+
#content li{margin:4px 0}
|
|
41
|
+
#content a{color:var(--link)}
|
|
42
|
+
#content blockquote{margin:12px 0;padding:4px 15px;border-left:3px solid var(--line);
|
|
43
|
+
color:var(--muted);background:var(--pane)}
|
|
44
|
+
#content table{border-collapse:collapse;width:100%;margin:12px 0;min-width:320px;
|
|
45
|
+
font-size:13px}
|
|
46
|
+
#content th,#content td{border:1px solid var(--line);padding:7px 10px;text-align:left;
|
|
47
|
+
vertical-align:top}
|
|
48
|
+
#content th{background:var(--pane)}
|
|
49
|
+
#content hr{border:0;border-top:1px solid var(--line);margin:20px 0}
|
|
50
|
+
#content code{font:12px/1.55 ui-monospace,SFMono-Regular,Consolas,monospace}
|
|
51
|
+
#content :not(pre)>code{padding:1px 5px;background:var(--pane);border-radius:4px}
|
|
52
|
+
#content .plain-text,#content .code-card pre{white-space:pre;overflow:auto;
|
|
53
|
+
tab-size:2;margin:0;padding:12px 15px;font:12px/1.6 ui-monospace,monospace}
|
|
54
|
+
.code-card,.diagram-card{border:1px solid var(--line);border-radius:9px;margin:13px 0;
|
|
55
|
+
background:var(--pane);overflow:hidden}
|
|
56
|
+
.code-toolbar,.diagram-card figcaption{display:flex;align-items:center;
|
|
57
|
+
justify-content:space-between;gap:12px;padding:7px 12px;border-bottom:1px solid var(--line);
|
|
58
|
+
color:var(--muted);font-size:12px}
|
|
59
|
+
.copy-block{font-size:12px;padding:3px 8px}
|
|
60
|
+
.diagram-card{padding-bottom:12px}
|
|
61
|
+
.diagram-card svg{display:block;width:100%;height:auto;max-height:520px;min-width:260px;
|
|
62
|
+
padding:12px;overflow:visible}
|
|
63
|
+
.external-image-blocked{font-size:12px;color:var(--muted);background:var(--pane);
|
|
64
|
+
border:1px dashed var(--line);padding:5px 8px}
|
|
65
|
+
#status{display:block;padding:8px 20px 12px;min-height:20px;font-size:12px;color:var(--muted)}
|
|
66
|
+
#status[data-state=error]{color:#b63939}
|
|
67
|
+
#status[data-state=ok]{color:#277349}
|
|
68
|
+
@media(prefers-color-scheme:dark){
|
|
69
|
+
:root{--ink:#e5e8ef;--muted:#a6afbc;--line:#474d58;--surface:#24282f;
|
|
70
|
+
--pane:#303640;--link:#90bff7;--diagram-bg:#303a4a;--diagram-stroke:#8c9cb4;
|
|
71
|
+
--diagram-text:#edf1f8}}
|
|
72
|
+
@media(max-width:480px){header{padding:12px;gap:8px;flex-wrap:wrap}
|
|
73
|
+
#content{padding:12px}#toc{padding:8px 12px}#status{padding:7px 12px}
|
|
74
|
+
#title{font-size:17px}}
|
|
75
|
+
</style>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
<main class="document" aria-label="通用文档阅读器">
|
|
79
|
+
<header>
|
|
80
|
+
<div class="heading">
|
|
81
|
+
<h1 id="title">正在加载文档…</h1>
|
|
82
|
+
<p id="subtitle" hidden></p>
|
|
83
|
+
</div>
|
|
84
|
+
<div class="actions">
|
|
85
|
+
<button id="copy-all" type="button" disabled aria-label="一键复制文档全文">复制全文</button>
|
|
86
|
+
</div>
|
|
87
|
+
</header>
|
|
88
|
+
<details id="toc" hidden>
|
|
89
|
+
<summary>文档目录</summary>
|
|
90
|
+
<nav id="toc-links" aria-label="文档章节导航"></nav>
|
|
91
|
+
</details>
|
|
92
|
+
<article id="content" aria-label="文档内容"></article>
|
|
93
|
+
<span id="status" role="status" aria-live="polite">正在连接文档服务…</span>
|
|
94
|
+
</main>
|
|
95
|
+
<!-- CHAT_LOOP_DOCUMENT_SCRIPT -->
|
|
96
|
+
</body>
|
|
97
|
+
</html>
|