miki-moni 0.3.1
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/LICENSE +21 -0
- package/README.md +283 -0
- package/README.zh-CN.md +275 -0
- package/README.zh-TW.md +275 -0
- package/bin/miki.mjs +49 -0
- package/dist/web/assets/favicon-DFpLtP36.svg +13 -0
- package/dist/web/assets/index--89DkyV1.css +1 -0
- package/dist/web/assets/index-CyPlxvOn.js +64 -0
- package/dist/web/index.html +20 -0
- package/dist/web/pair-info.html +138 -0
- package/dist/web-phone/assets/app-CyQWCdKZ.js +64 -0
- package/dist/web-phone/assets/index-D5BUh7Uf.js +1 -0
- package/dist/web-phone/assets/index-D8vY_9ld.css +1 -0
- package/dist/web-phone/index.html +20 -0
- package/hooks/miki-emit.ps1 +56 -0
- package/package.json +89 -0
- package/shared/i18n.ts +915 -0
- package/src/cli/i18n-cli.ts +149 -0
- package/src/cli/miki.ts +168 -0
- package/src/cli/pair.ts +534 -0
- package/src/cli/prompt.ts +6 -0
- package/src/cli/pushable-iter.ts +45 -0
- package/src/cli/setup-self-host.ts +292 -0
- package/src/cli/setup-wizard.ts +130 -0
- package/src/cli/wrap.ts +742 -0
- package/src/config.ts +121 -0
- package/src/crypto.ts +66 -0
- package/src/data-dir.ts +31 -0
- package/src/ext-registry.ts +47 -0
- package/src/hook-handler.ts +86 -0
- package/src/index.ts +279 -0
- package/src/install-hooks.ts +107 -0
- package/src/notifier.ts +21 -0
- package/src/pairing.ts +100 -0
- package/src/protocol-ext.ts +46 -0
- package/src/relay-client.ts +468 -0
- package/src/relay-protocol.ts +57 -0
- package/src/server.ts +1134 -0
- package/src/session-resolver.ts +437 -0
- package/src/session-store.ts +131 -0
- package/src/types.ts +33 -0
- package/src/vscode-bridge.ts +407 -0
- package/src/wrap-process.ts +183 -0
- package/tools/tray.ps1 +286 -0
- package/worker/package.json +24 -0
- package/worker/src/daemon-relay.ts +348 -0
- package/worker/src/env.ts +11 -0
- package/worker/src/handshake.ts +63 -0
- package/worker/src/index.ts +81 -0
- package/worker/src/pairing-code.ts +39 -0
- package/worker/src/pairing-coordinator.ts +145 -0
- package/worker/wrangler-selfhost.toml +36 -0
- package/worker/wrangler.toml +29 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-Hant-TW">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<title>miki-moni · 配對</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
9
|
+
html, body { height: 100%; }
|
|
10
|
+
body {
|
|
11
|
+
background: #0b1020; color: #d4d4d4;
|
|
12
|
+
font-family: "Inter", "Noto Sans TC", system-ui, sans-serif;
|
|
13
|
+
display: flex; align-items: center; justify-content: center;
|
|
14
|
+
padding: 24px;
|
|
15
|
+
}
|
|
16
|
+
.card {
|
|
17
|
+
background: #12172a;
|
|
18
|
+
border: 1px solid #2a3050;
|
|
19
|
+
border-radius: 14px;
|
|
20
|
+
padding: 32px 40px;
|
|
21
|
+
max-width: 520px;
|
|
22
|
+
width: 100%;
|
|
23
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
|
|
24
|
+
}
|
|
25
|
+
h1 { font-size: 18px; font-weight: 600; margin-bottom: 4px; color: #f472b6; }
|
|
26
|
+
.sub { font-size: 13px; color: #94a3b8; margin-bottom: 24px; }
|
|
27
|
+
.qr-wrap {
|
|
28
|
+
background: white;
|
|
29
|
+
padding: 16px;
|
|
30
|
+
border-radius: 8px;
|
|
31
|
+
display: flex;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
margin-bottom: 24px;
|
|
34
|
+
}
|
|
35
|
+
#qr { display: block; line-height: 0; }
|
|
36
|
+
#qr svg { display: block; width: 280px; height: 280px; }
|
|
37
|
+
.row { margin-bottom: 14px; }
|
|
38
|
+
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; margin-bottom: 4px; }
|
|
39
|
+
.value {
|
|
40
|
+
background: #1a2138;
|
|
41
|
+
border: 1px solid #2a3050;
|
|
42
|
+
border-radius: 6px;
|
|
43
|
+
padding: 10px 12px;
|
|
44
|
+
font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
|
|
45
|
+
font-size: 14px;
|
|
46
|
+
color: #e6e9ef;
|
|
47
|
+
word-break: break-all;
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
}
|
|
52
|
+
.code { font-size: 20px; font-weight: 600; letter-spacing: 0.1em; color: #fde68a; }
|
|
53
|
+
.copy {
|
|
54
|
+
background: #2a3050; border: none; color: #d4d4d4;
|
|
55
|
+
border-radius: 4px; padding: 4px 10px; font-size: 11px;
|
|
56
|
+
cursor: pointer; transition: background 0.15s;
|
|
57
|
+
flex-shrink: 0;
|
|
58
|
+
}
|
|
59
|
+
.copy:hover { background: #3a4060; }
|
|
60
|
+
.copy.done { background: #16a34a; color: white; }
|
|
61
|
+
.hint { font-size: 12px; color: #64748b; margin-top: 20px; line-height: 1.6; }
|
|
62
|
+
.err { color: #f87171; padding: 20px; text-align: center; }
|
|
63
|
+
</style>
|
|
64
|
+
</head>
|
|
65
|
+
<body>
|
|
66
|
+
<div class="card">
|
|
67
|
+
<h1>📱 miki-moni 配對</h1>
|
|
68
|
+
<div class="sub">手機掃 QR、開 URL,或輸入 16 碼 — 三選一</div>
|
|
69
|
+
|
|
70
|
+
<div id="content"></div>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<script src="https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js"></script>
|
|
74
|
+
<script>
|
|
75
|
+
const params = new URLSearchParams(location.search);
|
|
76
|
+
const token = params.get("t");
|
|
77
|
+
const relay = params.get("r");
|
|
78
|
+
const pwa = params.get("pwa") || "https://miki-moni.pages.dev/";
|
|
79
|
+
const content = document.getElementById("content");
|
|
80
|
+
|
|
81
|
+
if (!token || !relay) {
|
|
82
|
+
content.innerHTML = '<div class="err">缺少 token / relay 參數。從 tray 圖示重開這個頁面,或跑 <code>miki pair</code> 看 banner。</div>';
|
|
83
|
+
} else {
|
|
84
|
+
const url = pwa + "#t=" + encodeURIComponent(token) + "&r=" + encodeURIComponent(relay);
|
|
85
|
+
const grouped = token.match(/.{1,4}/g).join("-");
|
|
86
|
+
|
|
87
|
+
content.innerHTML = `
|
|
88
|
+
<div class="qr-wrap"><div id="qr"></div></div>
|
|
89
|
+
|
|
90
|
+
<div class="row">
|
|
91
|
+
<div class="label">配對碼(16 碼,case-insensitive,dash 可省)</div>
|
|
92
|
+
<div class="value"><span class="code">${grouped}</span>
|
|
93
|
+
<button class="copy" data-copy="${token}">copy</button>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="row">
|
|
98
|
+
<div class="label">URL(手機直接開)</div>
|
|
99
|
+
<div class="value"><span style="flex:1;">${url}</span>
|
|
100
|
+
<button class="copy" data-copy="${url.replace(/"/g, """)}">copy</button>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div class="hint">
|
|
105
|
+
QR 跟 URL / 16 碼是<strong>永久</strong>有效,rotate 才會換。<br />
|
|
106
|
+
被截圖外洩 → 終端機跑 <code style="background:#2a3050;padding:2px 6px;border-radius:3px;">miki pair --rotate</code> 換新的。
|
|
107
|
+
</div>
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
// qrcode-generator API: typeNumber=0 (auto), errorCorrectionLevel='M'
|
|
111
|
+
try {
|
|
112
|
+
const qr = qrcode(0, "M");
|
|
113
|
+
qr.addData(url);
|
|
114
|
+
qr.make();
|
|
115
|
+
document.getElementById("qr").innerHTML = qr.createSvgTag({ cellSize: 6, margin: 2 });
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.error("QR render failed", e);
|
|
118
|
+
document.getElementById("qr").innerHTML = '<div style="color:#f87171;padding:40px;">QR generation failed: ' + e.message + '</div>';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
document.querySelectorAll(".copy").forEach((btn) => {
|
|
122
|
+
btn.addEventListener("click", async () => {
|
|
123
|
+
try {
|
|
124
|
+
await navigator.clipboard.writeText(btn.dataset.copy);
|
|
125
|
+
const orig = btn.textContent;
|
|
126
|
+
btn.textContent = "✓ copied";
|
|
127
|
+
btn.classList.add("done");
|
|
128
|
+
setTimeout(() => { btn.textContent = orig; btn.classList.remove("done"); }, 1500);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
btn.textContent = "fail";
|
|
131
|
+
setTimeout(() => { btn.textContent = "copy"; }, 1500);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
</script>
|
|
137
|
+
</body>
|
|
138
|
+
</html>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var Cn=Object.defineProperty;var Rn=(t,e,s)=>e in t?Cn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var F=(t,e,s)=>Rn(t,typeof e!="symbol"?e+"":e,s);import{f as zn,d as y,A as G,y as K,b as le,t as c,c as Ln,T as We,u as n,L as $n,a as It,s as In,R as An,S as Ke,g as Pn,e as En}from"./index-D5BUh7Uf.js";function ht(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ae=ht();function Yt(t){Ae=t}var $e={exec:()=>null};function j(t,e=""){let s=typeof t=="string"?t:t.source,r={replace:(i,o)=>{let u=typeof o=="string"?o:o.source;return u=u.replace(re.caret,"$1"),s=s.replace(i,u),r},getRegex:()=>new RegExp(s,e)};return r}var Bn=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),re={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex: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"),blockquoteBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}>`)},Dn=/^(?:[ \t]*(?:\n|$))+/,Mn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Wn=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ne=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,On=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ft=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Vt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Xt=j(Vt).replace(/bull/g,ft).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(),jn=j(Vt).replace(/bull/g,ft).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(),gt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Hn=/^[^\n]+/,mt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,qn=j(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",mt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Fn=j(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ft).getRegex(),nt="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",kt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Kn=j("^ {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",kt).replace("tag",nt).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Gt=j(gt).replace("hr",Ne).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[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",nt).getRegex(),Nn=j(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Gt).getRegex(),bt={blockquote:Nn,code:Mn,def:qn,fences:Wn,heading:On,hr:Ne,html:Kn,lheading:Xt,list:Fn,newline:Dn,paragraph:Gt,table:$e,text:Hn},At=j("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",nt).getRegex(),Un={...bt,lheading:jn,table:At,paragraph:j(gt).replace("hr",Ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",At).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",nt).getRegex()},Zn={...bt,html:j(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",kt).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:$e,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:j(gt).replace("hr",Ne).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",Xt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Qn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Yn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Jt=/^( {2,}|\\)\n(?!\s*$)/,Vn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Oe=/[\p{P}\p{S}]/u,st=/[\s\p{P}\p{S}]/u,yt=/[^\s\p{P}\p{S}]/u,Xn=j(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,st).getRegex(),en=/(?!~)[\p{P}\p{S}]/u,Gn=/(?!~)[\s\p{P}\p{S}]/u,Jn=/(?:[^\s\p{P}\p{S}]|~)/u,es=j(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Bn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),tn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ts=j(tn,"u").replace(/punct/g,Oe).getRegex(),ns=j(tn,"u").replace(/punct/g,en).getRegex(),nn="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",ss=j(nn,"gu").replace(/notPunctSpace/g,yt).replace(/punctSpace/g,st).replace(/punct/g,Oe).getRegex(),is=j(nn,"gu").replace(/notPunctSpace/g,Jn).replace(/punctSpace/g,Gn).replace(/punct/g,en).getRegex(),rs=j("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,yt).replace(/punctSpace/g,st).replace(/punct/g,Oe).getRegex(),os=j(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,Oe).getRegex(),ls="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",as=j(ls,"gu").replace(/notPunctSpace/g,yt).replace(/punctSpace/g,st).replace(/punct/g,Oe).getRegex(),cs=j(/\\(punct)/,"gu").replace(/punct/g,Oe).getRegex(),us=j(/^<(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(),ds=j(kt).replace("(?:-->|$)","-->").getRegex(),ps=j("^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",ds).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Je=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,hs=j(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Je).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),sn=j(/^!?\[(label)\]\[(ref)\]/).replace("label",Je).replace("ref",mt).getRegex(),rn=j(/^!?\[(ref)\](?:\[\])?/).replace("ref",mt).getRegex(),fs=j("reflink|nolink(?!\\()","g").replace("reflink",sn).replace("nolink",rn).getRegex(),Pt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,xt={_backpedal:$e,anyPunctuation:cs,autolink:us,blockSkip:es,br:Jt,code:Yn,del:$e,delLDelim:$e,delRDelim:$e,emStrongLDelim:ts,emStrongRDelimAst:ss,emStrongRDelimUnd:rs,escape:Qn,link:hs,nolink:rn,punctuation:Xn,reflink:sn,reflinkSearch:fs,tag:ps,text:Vn,url:$e},gs={...xt,link:j(/^!?\[(label)\]\((.*?)\)/).replace("label",Je).getRegex(),reflink:j(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Je).getRegex()},ct={...xt,emStrongRDelimAst:is,emStrongLDelim:ns,delLDelim:os,delRDelim:as,url:j(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Pt).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:j(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Pt).getRegex()},ms={...ct,br:j(Jt).replace("{2,}","*").getRegex(),text:j(ct.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ye={normal:bt,gfm:Un,pedantic:Zn},He={normal:xt,gfm:ct,breaks:ms,pedantic:gs},ks={"&":"&","<":"<",">":">",'"':""","'":"'"},Et=t=>ks[t];function ke(t,e){if(e){if(re.escapeTest.test(t))return t.replace(re.escapeReplace,Et)}else if(re.escapeTestNoEncode.test(t))return t.replace(re.escapeReplaceNoEncode,Et);return t}function Bt(t){try{t=encodeURI(t).replace(re.percentDecode,"%")}catch{return null}return t}function Dt(t,e){var o;let s=t.replace(re.findPipe,(u,a,l)=>{let f=!1,p=a;for(;--p>=0&&l[p]==="\\";)f=!f;return f?"|":" |"}),r=s.split(re.splitPipe),i=0;if(r[0].trim()||r.shift(),r.length>0&&!((o=r.at(-1))!=null&&o.trim())&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;i<r.length;i++)r[i]=r[i].trim().replace(re.slashPipe,"|");return r}function Se(t,e,s){let r=t.length;if(r===0)return"";let i=0;for(;i<r&&t.charAt(r-i-1)===e;)i++;return t.slice(0,r-i)}function Mt(t){let e=t.split(`
|
|
3
|
+
`),s=e.length-1;for(;s>=0&&re.blankLine.test(e[s]);)s--;return e.length-s<=2?t:e.slice(0,s+1).join(`
|
|
4
|
+
`)}function bs(t,e){if(t.indexOf(e[1])===-1)return-1;let s=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])s++;else if(t[r]===e[1]&&(s--,s<0))return r;return s>0?-2:-1}function ys(t,e=0){let s=e,r="";for(let i of t)if(i===" "){let o=4-s%4;r+=" ".repeat(o),s+=o}else r+=i,s++;return r}function Wt(t,e,s,r,i){let o=e.href,u=e.title||null,a=t[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:t[0].charAt(0)==="!"?"image":"link",raw:s,href:o,title:u,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}function xs(t,e,s){let r=t.match(s.other.indentCodeCompensation);if(r===null)return e;let i=r[1];return e.split(`
|
|
5
|
+
`).map(o=>{let u=o.match(s.other.beginningSpace);if(u===null)return o;let[a]=u;return a.length>=i.length?o.slice(i.length):o}).join(`
|
|
6
|
+
`)}var et=class{constructor(t){F(this,"options");F(this,"rules");F(this,"lexer");this.options=t||Ae}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 s=this.options.pedantic?e[0]:Mt(e[0]),r=s.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:s,codeBlockStyle:"indented",text:r}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let s=e[0],r=xs(s,e[3]||"",this.rules);return{type:"code",raw:s,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let s=e[2].trim();if(this.rules.other.endingHash.test(s)){let r=Se(s,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(s=r.trim())}return{type:"heading",raw:Se(e[0],`
|
|
7
|
+
`),depth:e[1].length,text:s,tokens:this.lexer.inline(s)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Se(e[0],`
|
|
8
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let s=Se(e[0],`
|
|
9
|
+
`).split(`
|
|
10
|
+
`),r="",i="",o=[];for(;s.length>0;){let u=!1,a=[],l;for(l=0;l<s.length;l++)if(this.rules.other.blockquoteStart.test(s[l]))a.push(s[l]),u=!0;else if(!u)a.push(s[l]);else break;s=s.slice(l);let f=a.join(`
|
|
11
|
+
`),p=f.replace(this.rules.other.blockquoteSetextReplace,`
|
|
12
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
13
|
+
${f}`:f,i=i?`${i}
|
|
14
|
+
${p}`:p;let g=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,o,!0),this.lexer.state.top=g,s.length===0)break;let m=o.at(-1);if((m==null?void 0:m.type)==="code")break;if((m==null?void 0:m.type)==="blockquote"){let x=m,d=x.raw+`
|
|
15
|
+
`+s.join(`
|
|
16
|
+
`),P=this.blockquote(d);o[o.length-1]=P,r=r.substring(0,r.length-x.raw.length)+P.raw,i=i.substring(0,i.length-x.text.length)+P.text;break}else if((m==null?void 0:m.type)==="list"){let x=m,d=x.raw+`
|
|
17
|
+
`+s.join(`
|
|
18
|
+
`),P=this.list(d);o[o.length-1]=P,r=r.substring(0,r.length-m.raw.length)+P.raw,i=i.substring(0,i.length-x.raw.length)+P.raw,s=d.substring(o.at(-1).raw.length).split(`
|
|
19
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:o,text:i}}}list(t){let e=this.rules.block.list.exec(t);if(e){let s=e[1].trim(),r=s.length>1,i={type:"list",raw:"",ordered:r,start:r?+s.slice(0,-1):"",loose:!1,items:[]};s=r?`\\d{1,9}\\${s.slice(-1)}`:`\\${s}`,this.options.pedantic&&(s=r?s:"[*+-]");let o=this.rules.other.listItemRegex(s),u=!1;for(;t;){let l=!1,f="",p="";if(!(e=o.exec(t))||this.rules.block.hr.test(t))break;f=e[0],t=t.substring(f.length);let g=ys(e[2].split(`
|
|
20
|
+
`,1)[0],e[1].length),m=t.split(`
|
|
21
|
+
`,1)[0],x=!g.trim(),d=0;if(this.options.pedantic?(d=2,p=g.trimStart()):x?d=e[1].length+1:(d=g.search(this.rules.other.nonSpaceChar),d=d>4?1:d,p=g.slice(d),d+=e[1].length),x&&this.rules.other.blankLine.test(m)&&(f+=m+`
|
|
22
|
+
`,t=t.substring(m.length+1),l=!0),!l){let P=this.rules.other.nextBulletRegex(d),R=this.rules.other.hrRegex(d),b=this.rules.other.fencesBeginRegex(d),w=this.rules.other.headingBeginRegex(d),E=this.rules.other.htmlBeginRegex(d),_=this.rules.other.blockquoteBeginRegex(d);for(;t;){let C=t.split(`
|
|
23
|
+
`,1)[0],B;if(m=C,this.options.pedantic?(m=m.replace(this.rules.other.listReplaceNesting," "),B=m):B=m.replace(this.rules.other.tabCharGlobal," "),b.test(m)||w.test(m)||E.test(m)||_.test(m)||P.test(m)||R.test(m))break;if(B.search(this.rules.other.nonSpaceChar)>=d||!m.trim())p+=`
|
|
24
|
+
`+B.slice(d);else{if(x||g.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||b.test(g)||w.test(g)||R.test(g))break;p+=`
|
|
25
|
+
`+m}x=!m.trim(),f+=C+`
|
|
26
|
+
`,t=t.substring(C.length+1),g=B.slice(d)}}i.loose||(u?i.loose=!0:this.rules.other.doubleBlankLine.test(f)&&(u=!0)),i.items.push({type:"list_item",raw:f,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),i.raw+=f}let a=i.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let l of i.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let f=l.tokens[0];if(l.task&&((f==null?void 0:f.type)==="text"||(f==null?void 0:f.type)==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),f.raw=f.raw.replace(this.rules.other.listReplaceTask,""),f.text=f.text.replace(this.rules.other.listReplaceTask,"");for(let g=this.lexer.inlineQueue.length-1;g>=0;g--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[g].src)){this.lexer.inlineQueue[g].src=this.lexer.inlineQueue[g].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(l.raw);if(p){let g={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};l.checked=g.checked,i.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=g.raw+l.tokens[0].raw,l.tokens[0].text=g.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(g)):l.tokens.unshift({type:"paragraph",raw:g.raw,text:g.raw,tokens:[g]}):l.tokens.unshift(g)}}else l.task&&(l.task=!1);if(!i.loose){let p=l.tokens.filter(m=>m.type==="space"),g=p.length>0&&p.some(m=>this.rules.other.anyLine.test(m.raw));i.loose=g}}if(i.loose)for(let l of i.items){l.loose=!0;for(let f of l.tokens)f.type==="text"&&(f.type="paragraph")}return i}}html(t){let e=this.rules.block.html.exec(t);if(e){let s=Mt(e[0]);return{type:"html",block:!0,raw:s,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:s}}}def(t){let e=this.rules.block.def.exec(t);if(e){let s=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",i=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:s,raw:Se(e[0],`
|
|
27
|
+
`),href:r,title:i}}}table(t){var u;let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let s=Dt(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=(u=e[3])!=null&&u.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
28
|
+
`):[],o={type:"table",raw:Se(e[0],`
|
|
29
|
+
`),header:[],align:[],rows:[]};if(s.length===r.length){for(let a of r)this.rules.other.tableAlignRight.test(a)?o.align.push("right"):this.rules.other.tableAlignCenter.test(a)?o.align.push("center"):this.rules.other.tableAlignLeft.test(a)?o.align.push("left"):o.align.push(null);for(let a=0;a<s.length;a++)o.header.push({text:s[a],tokens:this.lexer.inline(s[a]),header:!0,align:o.align[a]});for(let a of i)o.rows.push(Dt(a,o.header.length).map((l,f)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:o.align[f]})));return o}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let s=e[1].trim();return{type:"heading",raw:Se(e[0],`
|
|
30
|
+
`),depth:e[2].charAt(0)==="="?1:2,text:s,tokens:this.lexer.inline(s)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let s=e[1].charAt(e[1].length-1)===`
|
|
31
|
+
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:s,tokens:this.lexer.inline(s)}}}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 s=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let o=Se(s.slice(0,-1),"\\");if((s.length-o.length)%2===0)return}else{let o=bs(e[2],"()");if(o===-2)return;if(o>-1){let u=(e[0].indexOf("!")===0?5:4)+e[1].length+o;e[2]=e[2].substring(0,o),e[0]=e[0].substring(0,u).trim(),e[3]=""}}let r=e[2],i="";if(this.options.pedantic){let o=this.rules.other.pedanticHrefTitle.exec(r);o&&(r=o[1],i=o[3])}else i=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?r=r.slice(1):r=r.slice(1,-1)),Wt(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let s;if((s=this.rules.inline.reflink.exec(t))||(s=this.rules.inline.nolink.exec(t))){let r=(s[2]||s[1]).replace(this.rules.other.multipleSpaceGlobal," "),i=e[r.toLowerCase()];if(!i){let o=s[0].charAt(0);return{type:"text",raw:o,text:o}}return Wt(s,i,s[0],this.lexer,this.rules)}}emStrong(t,e,s=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&s.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!s||this.rules.inline.punctuation.exec(s))){let i=[...r[0]].length-1,o,u,a=i,l=0,f=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(f.lastIndex=0,e=e.slice(-1*t.length+i);(r=f.exec(e))!==null;){if(o=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!o)continue;if(u=[...o].length,r[3]||r[4]){a+=u;continue}else if((r[5]||r[6])&&i%3&&!((i+u)%3)){l+=u;continue}if(a-=u,a>0)continue;u=Math.min(u,u+a+l);let p=[...r[0]][0].length,g=t.slice(0,i+r.index+p+u);if(Math.min(i,u)%2){let x=g.slice(1,-1);return{type:"em",raw:g,text:x,tokens:this.lexer.inlineTokens(x)}}let m=g.slice(2,-2);return{type:"strong",raw:g,text:m,tokens:this.lexer.inlineTokens(m)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let s=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(s),i=this.rules.other.startingSpaceChar.test(s)&&this.rules.other.endingSpaceChar.test(s);return r&&i&&(s=s.substring(1,s.length-1)),{type:"codespan",raw:e[0],text:s}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,s=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!s||this.rules.inline.punctuation.exec(s))){let i=[...r[0]].length-1,o,u,a=i,l=this.rules.inline.delRDelim;for(l.lastIndex=0,e=e.slice(-1*t.length+i);(r=l.exec(e))!==null;){if(o=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!o||(u=[...o].length,u!==i))continue;if(r[3]||r[4]){a+=u;continue}if(a-=u,a>0)continue;u=Math.min(u,u+a);let f=[...r[0]][0].length,p=t.slice(0,i+r.index+f+u),g=p.slice(i,-i);return{type:"del",raw:p,text:g,tokens:this.lexer.inlineTokens(g)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let s,r;return e[2]==="@"?(s=e[1],r="mailto:"+s):(s=e[1],r=s),{type:"link",raw:e[0],text:s,href:r,tokens:[{type:"text",raw:s,text:s}]}}}url(t){var s;let e;if(e=this.rules.inline.url.exec(t)){let r,i;if(e[2]==="@")r=e[0],i="mailto:"+r;else{let o;do o=e[0],e[0]=((s=this.rules.inline._backpedal.exec(e[0]))==null?void 0:s[0])??"";while(o!==e[0]);r=e[0],e[1]==="www."?i="http://"+e[0]:i=e[0]}return{type:"link",raw:e[0],text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let s=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:s}}}},he=class ut{constructor(e){F(this,"tokens");F(this,"options");F(this,"state");F(this,"inlineQueue");F(this,"tokenizer");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ae,this.options.tokenizer=this.options.tokenizer||new et,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 s={other:re,block:Ye.normal,inline:He.normal};this.options.pedantic?(s.block=Ye.pedantic,s.inline=He.pedantic):this.options.gfm&&(s.block=Ye.gfm,this.options.breaks?s.inline=He.breaks:s.inline=He.gfm),this.tokenizer.rules=s}static get rules(){return{block:Ye,inline:He}}static lex(e,s){return new ut(s).lex(e)}static lexInline(e,s){return new ut(s).inlineTokens(e)}lex(e){e=e.replace(re.carriageReturn,`
|
|
32
|
+
`),this.blockTokens(e,this.tokens);for(let s=0;s<this.inlineQueue.length;s++){let r=this.inlineQueue[s];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,s=[],r=!1){var o,u,a;this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(re.tabCharGlobal," ").replace(re.spaceLine,""));let i=1/0;for(;e;){if(e.length<i)i=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let l;if((u=(o=this.options.extensions)==null?void 0:o.block)!=null&&u.some(p=>(l=p.call({lexer:this},e,s))?(e=e.substring(l.raw.length),s.push(l),!0):!1))continue;if(l=this.tokenizer.space(e)){e=e.substring(l.raw.length);let p=s.at(-1);l.raw.length===1&&p!==void 0?p.raw+=`
|
|
33
|
+
`:s.push(l);continue}if(l=this.tokenizer.code(e)){e=e.substring(l.raw.length);let p=s.at(-1);(p==null?void 0:p.type)==="paragraph"||(p==null?void 0:p.type)==="text"?(p.raw+=(p.raw.endsWith(`
|
|
34
|
+
`)?"":`
|
|
35
|
+
`)+l.raw,p.text+=`
|
|
36
|
+
`+l.text,this.inlineQueue.at(-1).src=p.text):s.push(l);continue}if(l=this.tokenizer.fences(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.heading(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.hr(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.blockquote(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.list(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.html(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.def(e)){e=e.substring(l.raw.length);let p=s.at(-1);(p==null?void 0:p.type)==="paragraph"||(p==null?void 0:p.type)==="text"?(p.raw+=(p.raw.endsWith(`
|
|
37
|
+
`)?"":`
|
|
38
|
+
`)+l.raw,p.text+=`
|
|
39
|
+
`+l.raw,this.inlineQueue.at(-1).src=p.text):this.tokens.links[l.tag]||(this.tokens.links[l.tag]={href:l.href,title:l.title},s.push(l));continue}if(l=this.tokenizer.table(e)){e=e.substring(l.raw.length),s.push(l);continue}if(l=this.tokenizer.lheading(e)){e=e.substring(l.raw.length),s.push(l);continue}let f=e;if((a=this.options.extensions)!=null&&a.startBlock){let p=1/0,g=e.slice(1),m;this.options.extensions.startBlock.forEach(x=>{m=x.call({lexer:this},g),typeof m=="number"&&m>=0&&(p=Math.min(p,m))}),p<1/0&&p>=0&&(f=e.substring(0,p+1))}if(this.state.top&&(l=this.tokenizer.paragraph(f))){let p=s.at(-1);r&&(p==null?void 0:p.type)==="paragraph"?(p.raw+=(p.raw.endsWith(`
|
|
40
|
+
`)?"":`
|
|
41
|
+
`)+l.raw,p.text+=`
|
|
42
|
+
`+l.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=p.text):s.push(l),r=f.length!==e.length,e=e.substring(l.raw.length);continue}if(l=this.tokenizer.text(e)){e=e.substring(l.raw.length);let p=s.at(-1);(p==null?void 0:p.type)==="text"?(p.raw+=(p.raw.endsWith(`
|
|
43
|
+
`)?"":`
|
|
44
|
+
`)+l.raw,p.text+=`
|
|
45
|
+
`+l.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=p.text):s.push(l);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,s}inline(e,s=[]){return this.inlineQueue.push({src:e,tokens:s}),s}inlineTokens(e,s=[]){var f,p,g,m,x;this.tokenizer.lexer=this;let r=e,i=null;if(this.tokens.links){let d=Object.keys(this.tokens.links);if(d.length>0)for(;(i=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)d.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(i=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,i.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let o;for(;(i=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)o=i[2]?i[2].length:0,r=r.slice(0,i.index+o)+"["+"a".repeat(i[0].length-o-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=((p=(f=this.options.hooks)==null?void 0:f.emStrongMask)==null?void 0:p.call({lexer:this},r))??r;let u=!1,a="",l=1/0;for(;e;){if(e.length<l)l=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}u||(a=""),u=!1;let d;if((m=(g=this.options.extensions)==null?void 0:g.inline)!=null&&m.some(R=>(d=R.call({lexer:this},e,s))?(e=e.substring(d.raw.length),s.push(d),!0):!1))continue;if(d=this.tokenizer.escape(e)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.tag(e)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.link(e)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(d.raw.length);let R=s.at(-1);d.type==="text"&&(R==null?void 0:R.type)==="text"?(R.raw+=d.raw,R.text+=d.text):s.push(d);continue}if(d=this.tokenizer.emStrong(e,r,a)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.codespan(e)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.br(e)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.del(e,r,a)){e=e.substring(d.raw.length),s.push(d);continue}if(d=this.tokenizer.autolink(e)){e=e.substring(d.raw.length),s.push(d);continue}if(!this.state.inLink&&(d=this.tokenizer.url(e))){e=e.substring(d.raw.length),s.push(d);continue}let P=e;if((x=this.options.extensions)!=null&&x.startInline){let R=1/0,b=e.slice(1),w;this.options.extensions.startInline.forEach(E=>{w=E.call({lexer:this},b),typeof w=="number"&&w>=0&&(R=Math.min(R,w))}),R<1/0&&R>=0&&(P=e.substring(0,R+1))}if(d=this.tokenizer.inlineText(P)){e=e.substring(d.raw.length),d.raw.slice(-1)!=="_"&&(a=d.raw.slice(-1)),u=!0;let R=s.at(-1);(R==null?void 0:R.type)==="text"?(R.raw+=d.raw,R.text+=d.text):s.push(d);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return s}infiniteLoopError(e){let s="Infinite loop on byte: "+e;if(this.options.silent)console.error(s);else throw new Error(s)}},tt=class{constructor(t){F(this,"options");F(this,"parser");this.options=t||Ae}space(t){return""}code({text:t,lang:e,escaped:s}){var o;let r=(o=(e||"").match(re.notSpaceStart))==null?void 0:o[0],i=t.replace(re.endingNewline,"")+`
|
|
46
|
+
`;return r?'<pre><code class="language-'+ke(r)+'">'+(s?i:ke(i,!0))+`</code></pre>
|
|
47
|
+
`:"<pre><code>"+(s?i:ke(i,!0))+`</code></pre>
|
|
48
|
+
`}blockquote({tokens:t}){return`<blockquote>
|
|
49
|
+
${this.parser.parse(t)}</blockquote>
|
|
50
|
+
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
|
51
|
+
`}hr(t){return`<hr>
|
|
52
|
+
`}list(t){let e=t.ordered,s=t.start,r="";for(let u=0;u<t.items.length;u++){let a=t.items[u];r+=this.listitem(a)}let i=e?"ol":"ul",o=e&&s!==1?' start="'+s+'"':"";return"<"+i+o+`>
|
|
53
|
+
`+r+"</"+i+`>
|
|
54
|
+
`}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
|
|
55
|
+
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
|
56
|
+
`}table(t){let e="",s="";for(let i=0;i<t.header.length;i++)s+=this.tablecell(t.header[i]);e+=this.tablerow({text:s});let r="";for(let i=0;i<t.rows.length;i++){let o=t.rows[i];s="";for(let u=0;u<o.length;u++)s+=this.tablecell(o[u]);r+=this.tablerow({text:s})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
57
|
+
<thead>
|
|
58
|
+
`+e+`</thead>
|
|
59
|
+
`+r+`</table>
|
|
60
|
+
`}tablerow({text:t}){return`<tr>
|
|
61
|
+
${t}</tr>
|
|
62
|
+
`}tablecell(t){let e=this.parser.parseInline(t.tokens),s=t.header?"th":"td";return(t.align?`<${s} align="${t.align}">`:`<${s}>`)+e+`</${s}>
|
|
63
|
+
`}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>${ke(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:s}){let r=this.parser.parseInline(s),i=Bt(t);if(i===null)return r;t=i;let o='<a href="'+t+'"';return e&&(o+=' title="'+ke(e)+'"'),o+=">"+r+"</a>",o}image({href:t,title:e,text:s,tokens:r}){r&&(s=this.parser.parseInline(r,this.parser.textRenderer));let i=Bt(t);if(i===null)return ke(s);t=i;let o=`<img src="${t}" alt="${ke(s)}"`;return e&&(o+=` title="${ke(e)}"`),o+=">",o}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:ke(t.text)}},wt=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""}checkbox({raw:t}){return t}},fe=class dt{constructor(e){F(this,"options");F(this,"renderer");F(this,"textRenderer");this.options=e||Ae,this.options.renderer=this.options.renderer||new tt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new wt}static parse(e,s){return new dt(s).parse(e)}static parseInline(e,s){return new dt(s).parseInline(e)}parse(e){var r,i;this.renderer.parser=this;let s="";for(let o=0;o<e.length;o++){let u=e[o];if((i=(r=this.options.extensions)==null?void 0:r.renderers)!=null&&i[u.type]){let l=u,f=this.options.extensions.renderers[l.type].call({parser:this},l);if(f!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(l.type)){s+=f||"";continue}}let a=u;switch(a.type){case"space":{s+=this.renderer.space(a);break}case"hr":{s+=this.renderer.hr(a);break}case"heading":{s+=this.renderer.heading(a);break}case"code":{s+=this.renderer.code(a);break}case"table":{s+=this.renderer.table(a);break}case"blockquote":{s+=this.renderer.blockquote(a);break}case"list":{s+=this.renderer.list(a);break}case"checkbox":{s+=this.renderer.checkbox(a);break}case"html":{s+=this.renderer.html(a);break}case"def":{s+=this.renderer.def(a);break}case"paragraph":{s+=this.renderer.paragraph(a);break}case"text":{s+=this.renderer.text(a);break}default:{let l='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}parseInline(e,s=this.renderer){var i,o;this.renderer.parser=this;let r="";for(let u=0;u<e.length;u++){let a=e[u];if((o=(i=this.options.extensions)==null?void 0:i.renderers)!=null&&o[a.type]){let f=this.options.extensions.renderers[a.type].call({parser:this},a);if(f!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){r+=f||"";continue}}let l=a;switch(l.type){case"escape":{r+=s.text(l);break}case"html":{r+=s.html(l);break}case"link":{r+=s.link(l);break}case"image":{r+=s.image(l);break}case"checkbox":{r+=s.checkbox(l);break}case"strong":{r+=s.strong(l);break}case"em":{r+=s.em(l);break}case"codespan":{r+=s.codespan(l);break}case"br":{r+=s.br(l);break}case"del":{r+=s.del(l);break}case"text":{r+=s.text(l);break}default:{let f='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(f),"";throw new Error(f)}}}return r}},Ve,qe=(Ve=class{constructor(t){F(this,"options");F(this,"block");this.options=t||Ae}preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?he.lex:he.lexInline}provideParser(t=this.block){return t?fe.parse:fe.parseInline}},F(Ve,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),F(Ve,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),Ve),ws=class{constructor(...t){F(this,"defaults",ht());F(this,"options",this.setOptions);F(this,"parse",this.parseMarkdown(!0));F(this,"parseInline",this.parseMarkdown(!1));F(this,"Parser",fe);F(this,"Renderer",tt);F(this,"TextRenderer",wt);F(this,"Lexer",he);F(this,"Tokenizer",et);F(this,"Hooks",qe);this.use(...t)}walkTokens(t,e){var r,i;let s=[];for(let o of t)switch(s=s.concat(e.call(this,o)),o.type){case"table":{let u=o;for(let a of u.header)s=s.concat(this.walkTokens(a.tokens,e));for(let a of u.rows)for(let l of a)s=s.concat(this.walkTokens(l.tokens,e));break}case"list":{let u=o;s=s.concat(this.walkTokens(u.items,e));break}default:{let u=o;(i=(r=this.defaults.extensions)==null?void 0:r.childTokens)!=null&&i[u.type]?this.defaults.extensions.childTokens[u.type].forEach(a=>{let l=u[a].flat(1/0);s=s.concat(this.walkTokens(l,e))}):u.tokens&&(s=s.concat(this.walkTokens(u.tokens,e)))}}return s}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(s=>{let r={...s};if(r.async=this.defaults.async||r.async||!1,s.extensions&&(s.extensions.forEach(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){let o=e.renderers[i.name];o?e.renderers[i.name]=function(...u){let a=i.renderer.apply(this,u);return a===!1&&(a=o.apply(this,u)),a}:e.renderers[i.name]=i.renderer}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let o=e[i.level];o?o.unshift(i.tokenizer):e[i.level]=[i.tokenizer],i.start&&(i.level==="block"?e.startBlock?e.startBlock.push(i.start):e.startBlock=[i.start]:i.level==="inline"&&(e.startInline?e.startInline.push(i.start):e.startInline=[i.start]))}"childTokens"in i&&i.childTokens&&(e.childTokens[i.name]=i.childTokens)}),r.extensions=e),s.renderer){let i=this.defaults.renderer||new tt(this.defaults);for(let o in s.renderer){if(!(o in i))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;let u=o,a=s.renderer[u],l=i[u];i[u]=(...f)=>{let p=a.apply(i,f);return p===!1&&(p=l.apply(i,f)),p||""}}r.renderer=i}if(s.tokenizer){let i=this.defaults.tokenizer||new et(this.defaults);for(let o in s.tokenizer){if(!(o in i))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;let u=o,a=s.tokenizer[u],l=i[u];i[u]=(...f)=>{let p=a.apply(i,f);return p===!1&&(p=l.apply(i,f)),p}}r.tokenizer=i}if(s.hooks){let i=this.defaults.hooks||new qe;for(let o in s.hooks){if(!(o in i))throw new Error(`hook '${o}' does not exist`);if(["options","block"].includes(o))continue;let u=o,a=s.hooks[u],l=i[u];qe.passThroughHooks.has(o)?i[u]=f=>{if(this.defaults.async&&qe.passThroughHooksRespectAsync.has(o))return(async()=>{let g=await a.call(i,f);return l.call(i,g)})();let p=a.call(i,f);return l.call(i,p)}:i[u]=(...f)=>{if(this.defaults.async)return(async()=>{let g=await a.apply(i,f);return g===!1&&(g=await l.apply(i,f)),g})();let p=a.apply(i,f);return p===!1&&(p=l.apply(i,f)),p}}r.hooks=i}if(s.walkTokens){let i=this.defaults.walkTokens,o=s.walkTokens;r.walkTokens=function(u){let a=[];return a.push(o.call(this,u)),i&&(a=a.concat(i.call(this,u))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return he.lex(t,e??this.defaults)}parser(t,e){return fe.parse(t,e??this.defaults)}parseMarkdown(t){return(e,s)=>{let r={...s},i={...this.defaults,...r},o=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return o(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 o(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(i.hooks&&(i.hooks.options=i,i.hooks.block=t),i.async)return(async()=>{let u=i.hooks?await i.hooks.preprocess(e):e,a=await(i.hooks?await i.hooks.provideLexer(t):t?he.lex:he.lexInline)(u,i),l=i.hooks?await i.hooks.processAllTokens(a):a;i.walkTokens&&await Promise.all(this.walkTokens(l,i.walkTokens));let f=await(i.hooks?await i.hooks.provideParser(t):t?fe.parse:fe.parseInline)(l,i);return i.hooks?await i.hooks.postprocess(f):f})().catch(o);try{i.hooks&&(e=i.hooks.preprocess(e));let u=(i.hooks?i.hooks.provideLexer(t):t?he.lex:he.lexInline)(e,i);i.hooks&&(u=i.hooks.processAllTokens(u)),i.walkTokens&&this.walkTokens(u,i.walkTokens);let a=(i.hooks?i.hooks.provideParser(t):t?fe.parse:fe.parseInline)(u,i);return i.hooks&&(a=i.hooks.postprocess(a)),a}catch(u){return o(u)}}}onError(t,e){return s=>{if(s.message+=`
|
|
64
|
+
Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+ke(s.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(s);throw s}}},Ie=new ws;function q(t,e){return Ie.parse(t,e)}q.options=q.setOptions=function(t){return Ie.setOptions(t),q.defaults=Ie.defaults,Yt(q.defaults),q};q.getDefaults=ht;q.defaults=Ae;q.use=function(...t){return Ie.use(...t),q.defaults=Ie.defaults,Yt(q.defaults),q};q.walkTokens=function(t,e){return Ie.walkTokens(t,e)};q.parseInline=Ie.parseInline;q.Parser=fe;q.parser=fe.parse;q.Renderer=tt;q.TextRenderer=wt;q.Lexer=he;q.lexer=he.lex;q.Tokenizer=et;q.Hooks=qe;q.parse=q;q.options;q.setOptions;q.use;q.walkTokens;q.parseInline;fe.parse;he.lex;class vs{constructor(){F(this,"mode","local")}fetch(e,s){return window.fetch(e,s)}openWebSocket(e){const s=window.location.origin.replace(/^http/,"ws");return new window.WebSocket(s+e)}}const Xe={active:"dot dot-active",waiting:"dot dot-waiting",idle:"dot dot-idle",stale:"dot dot-stale"},Ss={active:"var(--pass)",waiting:"var(--warn)",idle:"var(--neutral)",stale:"var(--accent)"};function Ge(t){return c(`status.${t}`)}const _s=50,vt="%c[miki-moni]",St="color:#4b556a;font-weight:600";function Ot(t,e){console.log(vt,St,t,e??"")}function jt(t,e){console.warn(vt,St,t,e??"")}function Ts(t,e){console.error(vt,St,t,e??"")}function Cs(t){const e=typeof t=="number"?new Date(t):new Date(t);return isNaN(e.getTime())?"":e.toLocaleString("zh-TW",{hour12:!1})}function Fe(t){const e=Math.max(0,Date.now()-t);return e<6e4?c("time.secondsAgo",{n:Math.floor(e/1e3)}):e<36e5?c("time.minutesAgo",{n:Math.floor(e/6e4)}):e<864e5?c("time.hoursAgo",{n:Math.floor(e/36e5)}):c("time.daysAgo",{n:Math.floor(e/864e5)})}function lt(t){if(!t)return"";const e=Date.parse(t);return Number.isFinite(e)?Fe(e):""}function Rs({size:t=22}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.6","stroke-linecap":"round","stroke-linejoin":"round","aria-label":"miki-moni",children:[n("path",{d:"M4.5 13.2 L6 10 L7.6 13 L9.6 11 L11.4 13 C14.5 13 18.5 13.6 20 15.8 C20.8 17 20.4 18.3 18.6 18.7 C16 19.2 7 19.2 5.4 18.4 C3.8 17.5 3.6 14.5 4.5 13.2 Z"}),n("path",{d:"M6.8 15.2 q0.9 0.7 1.8 0","stroke-width":"1.3"}),n("path",{d:"M15 7 h2.4 l-2.4 2.6 h2.4","stroke-width":"1.3"}),n("path",{d:"M18.4 4.5 h1.6 l-1.6 1.8 h1.6","stroke-width":"1.1"})]})}function zs({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),n("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function Ls({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round",children:n("polyline",{points:"20 6 9 17 4 12"})})}function on({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("path",{d:"m22 2-7 20-4-9-9-4Z"}),n("path",{d:"M22 2 11 13"})]})}function ln({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:n("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}function $s({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:n("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})})}function Is({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("rect",{x:"6",y:"4",width:"4",height:"16"}),n("rect",{x:"14",y:"4",width:"4",height:"16"})]})}function As({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("path",{d:"M12 22v-5"}),n("path",{d:"M9 8V2"}),n("path",{d:"M15 8V2"}),n("path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"}),n("line",{x1:"2",y1:"2",x2:"22",y2:"22"})]})}function Ps({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("circle",{cx:"12",cy:"12",r:"3"}),n("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Es({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("path",{d:"M3 5a2 2 0 0 1 2-2h11"}),n("path",{d:"M21 11v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5"}),n("polyline",{points:"7 10 10 13 7 16"}),n("line",{x1:"13",y1:"16",x2:"17",y2:"16"}),n("line",{x1:"19",y1:"3",x2:"19",y2:"7"}),n("line",{x1:"17",y1:"5",x2:"21",y2:"5"})]})}function Bs({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),n("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),n("line",{x1:"4",y1:"18",x2:"20",y2:"18"}),n("circle",{cx:"9",cy:"6",r:"2",fill:"var(--bg)"}),n("circle",{cx:"15",cy:"12",r:"2",fill:"var(--bg)"}),n("circle",{cx:"7",cy:"18",r:"2",fill:"var(--bg)"})]})}function an({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("rect",{x:"3",y:"3",width:"14",height:"14",rx:"2"}),n("circle",{cx:"8",cy:"8",r:"1.5"}),n("polyline",{points:"3 14 8 10 13 14 17 11"}),n("line",{x1:"19",y1:"15",x2:"19",y2:"21"}),n("line",{x1:"16",y1:"18",x2:"22",y2:"18"})]})}function Ht({size:t=13}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[n("polygon",{points:"12 2 2 7 12 12 22 7 12 2"}),n("polyline",{points:"2 17 12 22 22 17"}),n("polyline",{points:"2 12 12 17 22 12"})]})}function qt({size:t=13,spinning:e=!1}){return n("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",style:e?{animation:"mm-spin 0.9s linear infinite"}:void 0,children:[n("polyline",{points:"23 4 23 10 17 10"}),n("polyline",{points:"1 20 1 14 7 14"}),n("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10"}),n("path",{d:"M20.49 15a9 9 0 0 1-14.85 3.36L1 14"})]})}q.setOptions({gfm:!0,breaks:!0});function cn({text:t}){const e=We(()=>{try{return q.parse(t,{async:!1})}catch{return`<pre>${Ds(t)}</pre>`}},[t]);return n("div",{class:"md",dangerouslySetInnerHTML:{__html:e}})}function Ds(t){return t.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function Ft(t){try{return q.parse(t,{async:!1}).replace(/<pre[^>]*>[\s\S]*?<\/pre>/gi," ").replace(/<hr\s*\/?\s*>/gi," ").replace(/<\/(td|th|li)>/gi," · ").replace(/<\/(p|div|tr|thead|tbody|h[1-6]|blockquote)>/gi," ").replace(/<br\s*\/?\s*>/gi," ").replace(/<[^>]+>/g,"").replace(/ /g," ").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/(\s*·\s*){2,}/g," · ").replace(/\s+/g," ").trim().replace(/^·\s*/,"").replace(/\s*·\s*$/,"")}catch{return t.replace(/\s+/g," ").trim()}}async function un(t){var o;const e=await new Promise((u,a)=>{const l=new FileReader;l.onerror=()=>a(l.error),l.onload=()=>u(l.result),l.readAsDataURL(t)}),[s,r]=e.split(",");return{media_type:((o=s==null?void 0:s.match(/^data:([^;]+);/))==null?void 0:o[1])??"image/png",data:r??"",preview:e,bytes:t.size}}async function dn(t){var r;const e=(r=t.clipboardData)==null?void 0:r.items;if(!e)return[];const s=[];for(let i=0;i<e.length;i++){const o=e[i];if(!o.type.startsWith("image/"))continue;const u=o.getAsFile();u&&s.push(await un(u))}return s}async function pn(t){if(!t)return[];const e=Array.from(t),s=[];for(const r of e)r.type.startsWith("image/")&&s.push(await un(r));return s}function Ms(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function Ws({sessionUuid:t,ask:e,onSubmitted:s,onDismiss:r}){const[i,o]=y(0),[u,a]=y({}),[l,f]=y({}),[p,g]=y(!1),[m,x]=y(null),d=e.questions[i];if(!d)return null;function P(b,w,E){a(_=>{const C=new Set(_[b]??[]);return E?C.has(w)?C.delete(w):C.add(w):(C.clear(),C.add(w)),{..._,[b]:C}})}async function R(){const b=e.questions.map((w,E)=>{const C=Array.from(u[E]??[]).map(U=>{var v;return((v=w.options[U])==null?void 0:v.label)??""}).filter(Boolean),B=(l[E]??"").trim();return B?[...C,B]:C});if(b.every(w=>w.length===0)){x(c("ask.atLeastOne"));return}g(!0),x(null);try{const w=await le("/wrap/answer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:t,question_id:e.question_id,answers:b})});if(!w.ok){x(`HTTP ${w.status}`);return}s()}catch(w){x(String(w))}finally{g(!1)}}return n(Ke,{children:[n("div",{class:"ask-modal-backdrop",onClick:b=>{b.stopPropagation(),r()}}),n("div",{class:"ask-modal",onClick:b=>b.stopPropagation(),children:[n("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[n("strong",{style:{fontSize:14},children:c("ask.claudeAsking")}),n("span",{style:{color:"var(--fg-subtle)",fontSize:11,marginLeft:"auto"},children:e.questions.length>1?`${i+1} / ${e.questions.length}`:""}),n("button",{class:"btn-ghost",style:{padding:"2px 8px"},onClick:r,children:"×"})]}),e.questions.length>1&&n("div",{style:{display:"flex",gap:4,marginBottom:10,flexWrap:"wrap"},children:e.questions.map((b,w)=>{var _,C,B;const E=(((_=u[w])==null?void 0:_.size)??0)>0||(((B=(C=l[w])==null?void 0:C.trim())==null?void 0:B.length)??0)>0;return n("button",{class:"ask-tab"+(w===i?" ask-tab-active":"")+(E?" ask-tab-done":""),onClick:()=>o(w),children:[E?"✓ ":"",b.header]},w)})}),n("div",{style:{fontSize:13,fontWeight:500,marginBottom:10},children:d.question}),n("div",{style:{display:"flex",flexDirection:"column",gap:6},children:d.options.map((b,w)=>{var C;const E=((C=u[i])==null?void 0:C.has(w))??!1,_=!!d.multiSelect;return n("label",{class:"ask-option"+(E?" ask-option-checked":""),children:[n("input",{type:_?"checkbox":"radio",name:`q-${i}`,checked:E,onChange:()=>P(i,w,_)}),n("div",{children:[n("div",{style:{fontWeight:500},children:b.label}),b.description&&n("div",{style:{fontSize:11,color:"var(--fg-subtle)"},children:b.description})]})]},w)})}),n("input",{type:"text",placeholder:c("ask.placeholder"),value:l[i]??"",onInput:b=>f(w=>({...w,[i]:b.currentTarget.value})),style:{width:"100%",marginTop:10}}),m&&n("div",{style:{marginTop:8,fontSize:12,color:"var(--accent)"},children:m}),n("div",{style:{display:"flex",gap:8,marginTop:12},children:[e.questions.length>1&&i>0&&n("button",{class:"btn-outline",onClick:()=>o(b=>b-1),children:c("ask.prev")}),e.questions.length>1&&i<e.questions.length-1&&n("button",{class:"btn-outline",onClick:()=>o(b=>b+1),children:c("ask.next")}),n("button",{class:"btn-primary",style:{marginLeft:"auto"},onClick:R,disabled:p,children:p?c("ask.submitting"):c("ask.submit")})]})]})]})}function hn({images:t,onRemove:e,dimmed:s}){return t.length===0?null:n("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:6,opacity:s?.5:1},children:t.map((r,i)=>n("div",{style:{position:"relative",border:"1px solid var(--border)",borderRadius:4,padding:2},children:[n("img",{src:r.preview,alt:"",style:{display:"block",maxHeight:72,maxWidth:120,borderRadius:2}}),n("div",{style:{fontSize:9,color:"var(--fg-subtle)",textAlign:"center",marginTop:2},children:[r.media_type.replace("image/","")," · ",Ms(r.bytes)]}),n("button",{type:"button",onClick:o=>{o.stopPropagation(),e(i)},style:{position:"absolute",top:-6,right:-6,background:"rgba(20,20,20,0.85)",color:"white",border:"1px solid white",borderRadius:"50%",width:18,height:18,padding:0,cursor:"pointer",fontSize:10,lineHeight:"16px"},title:c("ask.removeThis"),children:"×"})]},i))})}function Os({turn:t}){const e=t.tool_use,[s,r]=y(!1),i=typeof e.input=="string"?e.input:JSON.stringify(e.input,null,2);return n("div",{class:"toolbox",style:{marginTop:4},children:[n("div",{class:"toolbox-head",style:{cursor:"pointer",userSelect:"none"},onClick:()=>r(o=>!o),title:s?c("expand.collapse"):c("expand.expandIn"),children:[n("span",{style:{color:"var(--fg-subtle)",fontSize:10,width:10,display:"inline-block"},children:s?"▾":"▸"}),n("span",{class:"dot dot-active",style:{width:6,height:6}}),n("span",{children:e.name}),e.description&&n("span",{style:{color:"var(--fg-subtle)"},children:e.description})]}),s&&n("div",{class:"toolbox-row",children:[n("div",{class:"toolbox-label",children:"IN"}),n("pre",{class:"toolbox-content",style:{margin:0},children:i})]})]})}function js({turn:t}){const e=t.tool_result,[s,r]=y(!1),i=e.content||"(empty)",o=i.replace(/\s+/g," ").slice(0,120);return n("div",{class:"toolbox",style:{marginTop:4},children:[n("div",{class:"toolbox-head",style:{cursor:"pointer",userSelect:"none"},onClick:()=>r(u=>!u),title:s?c("expand.collapse"):c("expand.expandOut"),children:[n("span",{style:{color:"var(--fg-subtle)",fontSize:10,width:10,display:"inline-block"},children:s?"▾":"▸"}),n("span",{class:"toolbox-label"+(e.is_error?" is-error":""),style:{margin:0},children:"OUT"}),!s&&n("span",{style:{color:"var(--fg-subtle)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:[o,i.length>120?"…":""]})]}),s&&n("div",{class:"toolbox-row",children:[n("div",{class:"toolbox-label",children:" "}),n("pre",{class:"toolbox-content"+(e.is_error?" is-error":""),style:{margin:0},children:[i,e.truncated&&n("div",{style:{color:"var(--fg-subtle)",fontSize:10,marginTop:4},children:"…[truncated]"})]})]})]})}function Hs({turn:t}){const e=t.role==="user"&&!t.tool_result,s=t.role==="system",r=!!(t.tool_use||t.tool_result),i=s?"system":e?"user":"claude",o=r||s?"var(--fg-subtle)":e?"var(--neutral)":"var(--pass)",u=r||s?"turn-bg-tool":e?"turn-bg-user":"turn-bg-assistant",a=r?3:6,l=r?11:12;return n("div",{class:`turn-row ${e?"turn-row-user":"turn-row-other"}`,children:n("div",{class:`turn-bubble ${u}${r?" turn-bubble-tool":""}`,children:[n("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:a,flexWrap:"wrap"},children:[n("span",{style:{color:o,fontWeight:600,fontSize:l},children:i}),n("span",{style:{color:"var(--fg-subtle)",fontSize:10},children:Cs(t.ts)}),t.tool_use&&n("span",{style:{color:"var(--fg-subtle)",fontSize:10},children:["· 🔧 ",t.tool_use.name]}),t.tool_result&&n("span",{style:{color:"var(--fg-subtle)",fontSize:10},children:"· 📤 tool result"})]}),t.text&&n(cn,{text:t.text}),t.tool_use&&n(Os,{turn:t}),t.tool_result&&n(js,{turn:t})]})})}function qs({turns:t}){const e=G(null),s=G(!0),r=t.length===0?"0":`${t.length}|${t[t.length-1].ts}|${t[t.length-1].text.length}`;K(()=>{s.current&&e.current&&(e.current.scrollTop=e.current.scrollHeight)},[r]);const i=64;function o(u){const a=u.currentTarget;s.current=a.scrollHeight-a.scrollTop-a.clientHeight<i}return t.length===0?n("div",{style:{padding:"12px 14px",color:"var(--fg-subtle)",fontSize:12},children:c("transcript.empty")}):n("div",{ref:e,onScroll:o,style:{overflowY:"auto",height:"100%",minHeight:0,overscrollBehavior:"contain",WebkitOverflowScrolling:"touch"},children:[n("div",{style:{position:"sticky",top:0,zIndex:1,padding:"6px 14px",fontSize:10,fontWeight:600,color:"var(--fg-subtle)",textTransform:"uppercase",letterSpacing:"0.08em",background:"var(--sl2)",borderBottom:"1px solid var(--border)"},children:[c("transcript.conversation")," · ",t.length]}),t.map((u,a)=>n(Hs,{turn:u},a))]})}function Fs({s:t,defaultExpanded:e,clientType:s,onSetClientType:r,onFocus:i,onSend:o,sendKey:u,modalMode:a,onAfterSend:l,activity:f,transcript:p,transcriptLoading:g,transcriptError:m,transcriptLimit:x,onSetTranscriptLimit:d,onReloadTranscript:P,showTools:R,onSetShowTools:b,streamingText:w,streamingStartTs:E,userOverlayText:_,userOverlayTs:C}){const B=s==="cli",U=!!t.wrapped,v=!U,[Z,J]=y(!e),[te,se]=y(""),[L,ee]=y([]),de=G(null);K(()=>{const $=de.current;if($){if(te===""){$.style.height="";return}requestAnimationFrame(()=>{$.style.height="auto",$.style.height=`${Math.min($.scrollHeight,a?160:260)}px`})}},[te,a]);const[ie,oe]=y(!1),D=G(null);K(()=>{if(!ie)return;function $(ne){var ue;(ue=D.current)!=null&&ue.contains(ne.target)||oe(!1)}return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[ie]);const W=U,[O,V]=y(!1),[be,Te]=y(!1),[ye,Pe]=y(!1),[Ee,Ce]=y(null),[xe,Re]=y(null),ae=t.session_uuid??"";async function Be(){Ot("click focus",{cwd:t.cwd,uuid:ae}),Ce(null);const $=await i(ae);Ce({ok:$.ok,label:$.ok?c("send.httpOk",{status:$.status}):c("send.httpFail",{status:$.status}),url:$.url,ts:Date.now()}),setTimeout(()=>Ce(null),15e3)}async function Ue(){const $=te.trim(),ne=L.length>0;if(!(!$&&!ne)){Ot("click send",{cwd:t.cwd,uuid:ae,mode:O?"submit":"prefill+enter",len:$.length,images:ne?L.length:0}),Re(null),Pe(!0);try{const N=await o(ae,$,O,W?L:void 0),ge=N.ok?O?c("send.claudeReplied",{ms:N.duration_ms??"?"}):c("send.sentToVSCode"):c("send.httpFail",{status:N.status});Re({ok:N.ok,label:ge,url:N.url,reply:N.reply,durationMs:N.duration_ms,diag:N.diag,error:N.error,ts:Date.now()}),N.ok&&(se(""),ee([])),N.ok&&l&&l()}finally{Pe(!1)}setTimeout(()=>Re(null),6e4)}}async function it($){const ne=await dn($);ne.length>0&&($.preventDefault(),ee(ue=>[...ue,...ne]))}if(Z)return n("div",{class:"card",style:{display:"flex",alignItems:"center",gap:12,padding:"10px 14px"},children:[n("span",{class:Xe[t.status]}),n("span",{style:{fontWeight:500,minWidth:120},children:t.project_name}),n("span",{style:{color:"var(--fg-subtle)",fontSize:11,fontFamily:"ui-monospace, monospace"},children:t.cwd}),n("span",{style:{color:"var(--fg-muted)",fontSize:12,marginLeft:"auto"},children:Ge(t.status)}),n("span",{style:{color:"var(--fg-subtle)",fontSize:11},children:Fe(t.last_event_at)}),n("button",{class:"btn-ghost",onClick:()=>J(!1),title:c("expand.expand"),children:"▾"})]});const we=e;return n("div",{class:"card",style:a?{display:"flex",flexDirection:"column",height:"100%",minHeight:0,border:"none",borderRadius:0}:we?{display:"flex",flexDirection:"column",height:"calc(100vh - 220px)",minHeight:480}:void 0,children:[n("div",{style:{display:"flex",alignItems:"center",gap:a?8:10,padding:a?"6px 12px":"12px 14px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[n("span",{class:Xe[t.status]}),n("button",{class:"btn-ghost",style:{fontWeight:600,fontSize:a?14:15,padding:a?"0 4px":"2px 6px"},onClick:Be,title:B?c("focus.cliNotSupported"):c("focus.bringVSCode"),disabled:B,children:t.project_name}),t.wrapped?n("span",{class:"client-badge client-badge-wrap client-badge-md",title:c("focus.wrappedTitle"),children:c("focus.wrappedBadge")}):n(_t,{type:s,onToggle:()=>r(ae,B?"vscode":"cli"),size:"md"}),!a&&n(Ke,{children:[n("span",{style:{color:"var(--fg-muted)",fontSize:12},children:Ge(t.status)}),f&&n("span",{class:"cell-activity",title:c("focus.wrapperRunning",{activity:f}),children:[f,"…"]}),n("span",{style:{color:"var(--fg-subtle)",fontSize:11,marginLeft:8},children:Fe(t.last_event_at)}),t.wrapped&&n(pt,{sessionUuid:t.session_uuid,mode:t.permission_mode??"default"})]}),!a&&n("button",{class:"btn-ghost",style:{marginLeft:"auto"},onClick:()=>J(!0),title:c("expand.collapse"),children:"▴"}),a&&n("div",{ref:D,style:{marginLeft:"auto",marginRight:36,position:"relative"},children:[n("button",{class:"btn-ghost icon-btn",style:{padding:"4px 6px"},onClick:()=>oe($=>!$),title:c("transcript.viewOptions"),"aria-label":c("transcript.viewOptions"),"aria-expanded":ie,children:n(Bs,{size:15})}),ie&&n("div",{style:{position:"absolute",top:"calc(100% + 6px)",right:0,zIndex:50,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"10px 12px",boxShadow:"0 6px 24px rgba(0,0,0,0.18)",minWidth:200,display:"flex",flexDirection:"column",gap:8},children:[n("label",{style:{display:"inline-flex",alignItems:"center",gap:8,fontSize:12,color:"var(--fg-muted)",cursor:"pointer",userSelect:"none"},children:[n("input",{type:"checkbox",checked:R,onChange:$=>b($.currentTarget.checked),style:{margin:0}}),c("transcript.showTool")]}),n("select",{value:x,onChange:$=>d(parseInt($.currentTarget.value,10)),style:{width:"100%"},children:[n("option",{value:10,children:c("transcript.items10")}),n("option",{value:20,children:c("transcript.items20")}),n("option",{value:50,children:c("transcript.items50")}),n("option",{value:100,children:c("transcript.items100")}),n("option",{value:200,children:c("transcript.items200")}),n("option",{value:500,children:c("transcript.items500")}),n("option",{value:1e4,children:c("transcript.itemsAll")})]}),n("div",{style:{display:"flex",gap:6},children:[n("button",{class:"btn-outline",style:{flex:1,height:30,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12},onClick:()=>{d(1e4),oe(!1)},disabled:g,title:c("transcript.loadAllTitle"),children:[n(Ht,{size:13})," ",c("transcript.loadAll")]}),n("button",{class:"btn-outline",style:{height:30,padding:"0 10px",display:"inline-flex",alignItems:"center",justifyContent:"center"},onClick:()=>{P(),oe(!1)},disabled:g,title:g?c("transcript.loading"):c("transcript.reload"),"aria-label":g?c("transcript.loading"):c("transcript.reload"),children:n(qt,{size:13,spinning:g})})]})]})]})]}),n("div",{style:we?{display:"flex",flexDirection:"column",flex:1,minHeight:0,borderBottom:"1px solid var(--border)"}:{borderBottom:"1px solid var(--border)"},children:[!a&&n("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 14px",flexShrink:0},children:[n("label",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--fg-subtle)",cursor:"pointer",userSelect:"none"},children:[n("input",{type:"checkbox",checked:R,onChange:$=>b($.currentTarget.checked),style:{margin:0}}),c("transcript.showTool")]}),n("select",{value:x,onChange:$=>d(parseInt($.currentTarget.value,10)),children:[n("option",{value:10,children:c("transcript.items10")}),n("option",{value:20,children:c("transcript.items20")}),n("option",{value:50,children:c("transcript.items50")}),n("option",{value:100,children:c("transcript.items100")}),n("option",{value:200,children:c("transcript.items200")}),n("option",{value:500,children:c("transcript.items500")}),n("option",{value:1e4,children:c("transcript.itemsAll")})]}),n("button",{class:"btn-outline",style:{height:28,padding:"0 8px",display:"inline-flex",alignItems:"center",justifyContent:"center"},onClick:()=>d(1e4),disabled:g,title:c("transcript.loadAllTitle"),"aria-label":c("transcript.loadAll"),children:n(Ht,{size:14})}),n("button",{class:"btn-outline",style:{height:28,padding:"0 8px",display:"inline-flex",alignItems:"center",justifyContent:"center"},onClick:P,disabled:g,title:g?c("transcript.loading"):c("transcript.reload"),"aria-label":g?c("transcript.loading"):c("transcript.reload"),children:n(qt,{size:14,spinning:g})})]}),m&&n("div",{style:{padding:"8px 14px",color:"var(--accent)",fontSize:12},children:m}),p&&(()=>{const $=R?p.turns:p.turns.filter(N=>!N.tool_use&&!N.tool_result).slice(-x),ne=[];if(_&&C){let N=0;for(const ge of p.turns){if(ge.role!=="user"||ge.tool_result)continue;const ze=Date.parse(ge.ts)||0;ze>N&&(N=ze)}N<C&&ne.push({ts:new Date(C).toISOString(),role:"user",text:_,raw_type:"synthetic-user-overlay"})}if(w&&w.length>0){let N=0;for(const Le of p.turns){if(Le.role!=="assistant"||Le.tool_use)continue;const ve=Date.parse(Le.ts)||0;ve>N&&(N=ve)}const ge=E??0;ge>0&&N>=ge||ne.push({ts:new Date().toISOString(),role:"assistant",text:w,raw_type:"synthetic-streaming"})}const ue=ne.length>0?$.concat(ne):$;return n("div",{style:we?{flex:1,minHeight:0,display:"flex"}:{maxHeight:480,overflow:"hidden",display:"flex"},children:n("div",{style:{flex:1,minWidth:0},children:n(qs,{turns:ue})})})})()]}),n("div",{style:{flexShrink:0},children:[Ee&&n("div",{style:{padding:"0 14px 8px",fontSize:12,color:Ee.ok?"var(--pass)":"var(--accent)"},children:c("send.focusing",{label:Ee.label})}),n("div",{style:{padding:"8px 14px 12px",display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid var(--border)"},children:[a&&n("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",fontSize:11,color:"var(--fg-subtle)",marginBottom:2},children:[n("span",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[n("span",{class:Xe[t.status],style:{width:7,height:7}}),n("span",{style:{color:"var(--fg-muted)"},children:Ge(t.status)})]}),t.wrapped&&n(Ke,{children:[n(Ys,{sessionUuid:t.session_uuid,current:t.current_model}),n(pt,{sessionUuid:t.session_uuid,mode:t.permission_mode??"default"})]}),n("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:8},children:[f&&n("span",{class:"cell-activity",title:c("focus.wrapperRunning",{activity:f}),children:[f,"…"]}),n("span",{children:Fe(t.last_event_at)})]})]}),n(hn,{images:L,onRemove:$=>ee(ne=>ne.filter((ue,N)=>N!==$)),dimmed:!W&&L.length>0}),!W&&L.length>0&&n("div",{style:{fontSize:10,color:"var(--warn)"},children:c("composer.imageIgnored")}),n("div",{style:{display:"flex",gap:8},children:[n("textarea",{ref:de,autoFocus:a,style:{flex:1,minWidth:0,minHeight:a?20:38,maxHeight:a?160:260,fontSize:13,overflow:"hidden",resize:"none"},rows:a?1:2,placeholder:v?B?c(a?"composer.cliNotWrappedShort":"composer.cliNotWrapped",{short:ae.slice(0,8)}):c(a?"composer.vscodeDisabledShort":"composer.vscodeDisabledWrap",{short:ae.slice(0,8)}):c(a?"composer.inputPromptShort":"composer.inputPrompt"),value:te,onInput:$=>se($.currentTarget.value),onPaste:$=>{it($)},onKeyDown:$=>{xn($,u)&&($.preventDefault(),!ye&&!v&&(te.trim()||L.length>0)&&Ue())},disabled:ye||v}),n("label",{class:"btn-ghost icon-btn",style:{height:34,width:34,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:W&&!ye?"pointer":"not-allowed",opacity:W&&!ye?1:.5},title:c("composer.uploadImage"),"aria-label":c("composer.uploadImage"),children:[n(an,{size:14}),n("input",{type:"file",accept:"image/*",multiple:!0,style:{display:"none"},disabled:!W||ye,onChange:async $=>{const ne=$.currentTarget,ue=await pn(ne.files);ue.length>0&&ee(N=>[...N,...ue]),ne.value=""}})]}),U&&n("button",{class:"btn-ghost icon-btn",style:{height:34,width:34,padding:0,fontSize:16,lineHeight:1,display:"inline-flex",alignItems:"center",justifyContent:"center"},onClick:()=>{le("/wrap/interrupt",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:ae})})},title:c("composer.interruptLong"),children:n(ln,{size:14})}),n("button",{class:U?"btn-primary icon-btn":"btn-ghost icon-btn",style:{height:34,width:34,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center"},disabled:!te.trim()&&L.length===0||ye||v,onClick:Ue,title:v?c("composer.needWrapHint"):U?c("composer.wrapWSHint"):c("composer.needWrapBadge"),children:ye?"⌛":n(on,{size:14})})]}),v&&B&&n("div",{style:{fontSize:10,color:"var(--fg-subtle)",lineHeight:1.5},children:["📟 ",n("strong",{style:{color:"#a8740d"},children:c("composer.cliNotWrappedStrong")}),c("composer.pleaseUse")," ",n("code",{children:["miki claude -r ",ae.slice(0,8),"…"]}),c("composer.toTakeOver")]}),!1,xe&&!xe.ok&&n("div",{style:{marginTop:4},children:[n("div",{style:{fontSize:12,color:"var(--accent)"},children:c("send.sendFailed",{label:xe.label})}),xe.error&&n("div",{style:{marginTop:6,fontSize:12,color:"var(--accent)",padding:8,background:"var(--bg-subtle)",borderRadius:4},children:["⚠️ ",xe.error]})]})]})]})]})}function Ks({sessions:t,filter:e,onFilter:s}){const r=t.reduce((u,a)=>(u[a.status]=(u[a.status]??0)+1,u),{}),i=(r.active??0)+(r.waiting??0),o=u=>s(e===u?"all":u);return n("div",{style:{display:"inline-flex",alignItems:"center",gap:2,marginLeft:4},children:[n(at,{n:i,label:c("header.live"),icon:n($s,{}),dot:"dot-active",active:e==="live",onClick:()=>o("live")}),n(at,{n:r.idle??0,label:c("header.idle"),icon:n(Is,{}),dot:"dot-idle",active:e==="idle",onClick:()=>o("idle")}),n(at,{n:r.stale??0,label:c("header.stale"),icon:n(As,{}),dot:"dot-stale",active:e==="stale",onClick:()=>o("stale")})]})}function at({n:t,label:e,icon:s,dot:r,active:i,onClick:o}){return n("button",{type:"button",onClick:o,class:"header-stat"+(i?" is-active":""),title:c("header.onlyShow",{label:e}),"aria-label":c("header.onlyShow",{label:e}),children:[n("strong",{children:t}),r&&n("span",{class:`dot ${r}`}),s??n("span",{children:e})]})}const Kt=[{bg:"#fef3e2",border:"#f3d4a8",label:"#7c4a08"},{bg:"#fde6d3",border:"#f4c8a2",label:"#7d3f06"},{bg:"#fdedd3",border:"#f1d39c",label:"#76551a"},{bg:"#fce7e6",border:"#f0bdba",label:"#7e2924"},{bg:"#f9e3df",border:"#e9b6ae",label:"#75342a"},{bg:"#fbe6cc",border:"#eecca0",label:"#74471a"},{bg:"#fff4dc",border:"#f0d9a4",label:"#6f4f12"},{bg:"#f7ede4",border:"#dec9b4",label:"#5a4838"}];function Ns(t){let e=0;for(let s=0;s<t.length;s++)e=e*31+t.charCodeAt(s)>>>0;return Kt[e%Kt.length]}function Us({sessionUuid:t,compact:e}){const[s,r]=y(!1);function i(u){if(u.stopPropagation(),!t)return;const a=`pnpm --dir D:\\code\\cc-hub miki claude -r ${t}`;navigator.clipboard.writeText(a).then(()=>{r(!0),window.setTimeout(()=>r(!1),1500)},()=>{})}const o=e?11:13;return n("button",{class:"btn-ghost icon-btn",style:{padding:e?"3px 6px":"4px 8px"},onClick:i,title:c("session.copyRestart",{uuid:t}),disabled:!t,children:s?n(Ls,{size:o}):n(zs,{size:o})})}function _t({type:t,onToggle:e,size:s="sm"}){const r=t==="cli",i=r?"📟 CLI":"🖥️ VSCode",o=r?c("session.cliMarkTooltip"):c("session.vscodeMarkTooltip");return n("button",{class:"client-badge"+(r?" client-badge-cli":" client-badge-vscode")+(s==="md"?" client-badge-md":""),onClick:u=>{u.stopPropagation(),e()},title:o,children:i})}function Nt({mode:t}){const e={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};switch(t){case"default":return n("svg",{...e,children:[n("path",{d:"M11 12.5V5a1.7 1.7 0 0 0-3.4 0v8.5"}),n("path",{d:"M11 14V3.5a1.7 1.7 0 0 1 3.4 0V14"}),n("path",{d:"M14.4 13V6a1.7 1.7 0 0 1 3.4 0v8"}),n("path",{d:"M17.8 11.5a1.7 1.7 0 1 1 3.4 0V15a8 8 0 0 1-8 8h-2a4 4 0 0 1-4-4v-2.5a2 2 0 0 1 1.4-1.9"})]});case"acceptEdits":return n("svg",{...e,children:[n("polyline",{points:"9 6 3 12 9 18"}),n("polyline",{points:"15 6 21 12 15 18"})]});case"plan":return n("svg",{...e,children:[n("rect",{x:"5",y:"3",width:"14",height:"18",rx:"2"}),n("line",{x1:"9",y1:"8",x2:"15",y2:"8"}),n("line",{x1:"9",y1:"12",x2:"15",y2:"12"}),n("line",{x1:"9",y1:"16",x2:"13",y2:"16"})]});case"auto":return n("svg",{...e,children:n("polygon",{points:"13 2 4 14 11 14 10 22 20 10 13 10 13 2"})});case"bypassPermissions":return n("svg",{...e,children:[n("path",{d:"M10 14a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1 1"}),n("path",{d:"M14 10a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1-1"})]})}}const Zs={default:{borderColor:"rgba(120,130,150,0.45)",color:"#60646c",background:"rgba(120,130,150,0.10)"},acceptEdits:{borderColor:"rgba(40,140,100,0.45)",color:"#1f7a4d",background:"rgba(40,140,100,0.12)"},plan:{borderColor:"rgba(40,110,200,0.45)",color:"#2c5fa8",background:"rgba(40,110,200,0.12)"},auto:{borderColor:"rgba(170,110,220,0.45)",color:"#7b3fb8",background:"rgba(170,110,220,0.12)"},bypassPermissions:{borderColor:"rgba(200,50,40,0.50)",color:"#b3261e",background:"rgba(200,50,40,0.12)"}},_e={default:{short:"ask",cls:"pmode-chip-default",menuLabel:"Ask before edits",descKey:"mode.defaultDesc",titleKey:"mode.defaultTitle"},acceptEdits:{short:"edit auto",cls:"pmode-chip-auto",menuLabel:"Edit automatically",descKey:"mode.acceptDesc",titleKey:"mode.acceptTitle"},plan:{short:"plan",cls:"pmode-chip-plan",menuLabel:"Plan mode",descKey:"mode.planDesc",titleKey:"mode.planTitle"},auto:{short:"auto",cls:"pmode-chip-autopick",menuLabel:"Auto mode",descKey:"mode.autoDesc",titleKey:"mode.autoTitle"},bypassPermissions:{short:"bypass",cls:"pmode-chip-bypass",menuLabel:"Bypass permissions",descKey:"mode.bypassDesc",titleKey:"mode.bypassTitle"}};function Qs(t){const e=_e[t]??_e.default;return{short:e.short,cls:e.cls,menuLabel:e.menuLabel,menuDesc:c(e.descKey),title:c(e.titleKey)}}function pt({sessionUuid:t,mode:e}){const[s,r]=y(!1),[i,o]=y(null),[u,a]=y(null),l=G(null),f=Qs(e);K(()=>{if(!s)return;function m(x){var d;(d=l.current)!=null&&d.contains(x.target)||r(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[s]);async function p(m){if(!t||i||m===e){r(!1);return}o(m),a(null);try{const x=await le("/wrap/permission-mode",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:t,mode:m})});if(x.ok)r(!1);else{const d=await x.json().catch(()=>({}));a((d==null?void 0:d.error)??`HTTP ${x.status}`)}}catch(x){a(String(x))}finally{o(null)}}const g=m=>m.stopPropagation();return n("div",{ref:l,class:"pmode-chip-wrap",onClick:g,onMouseDown:g,children:[n("button",{class:`pmode-chip ${_e[i??e].cls}`,title:f.title+c("mode.switchHint"),onClick:m=>{m.stopPropagation(),r(x=>!x)},onMouseDown:g,disabled:!t,children:[n(Nt,{mode:i??e}),n("span",{children:i?`${_e[i].short}…`:f.short})]}),s&&n("div",{class:"pmode-menu",onClick:g,onMouseDown:g,children:[n("div",{class:"pmode-menu-head",children:"Modes"}),["default","acceptEdits","plan","auto","bypassPermissions"].map(m=>n("button",{class:"pmode-menu-item "+(m===e?"is-current":"")+" "+_e[m].cls,onClick:x=>{x.stopPropagation(),p(m)},onMouseDown:g,disabled:!!i,title:c(_e[m].titleKey),children:[n("span",{class:"pmode-menu-icon",children:n(Nt,{mode:m})}),n("div",{class:"pmode-menu-text",children:[n("div",{class:"pmode-menu-label",children:_e[m].menuLabel}),n("div",{class:"pmode-menu-desc",children:c(_e[m].descKey)})]}),m===e&&n("span",{class:"pmode-check",children:"✓"})]},m)),u&&n("div",{class:"pmode-err",children:u})]})]})}const fn=[{key:"default",label:"default",aliasFor:""},{key:"sonnet",label:"Sonnet",aliasFor:"sonnet"},{key:"opus",label:"Opus",aliasFor:"opus"},{key:"haiku",label:"Haiku",aliasFor:"haiku"}];function Ut(t){if(!t)return"default";const e=fn.find(s=>s.aliasFor===t);return e?e.label:t.replace(/^claude-/,"").replace(/-\d{8}$/,"")}function Ys({sessionUuid:t,current:e}){const[s,r]=y(!1),[i,o]=y(null),[u,a]=y(null),[l,f]=y(""),p=G(null),g=G(null),[m,x]=y(null);K(()=>{if(!s)return;function b(w){var E;(E=p.current)!=null&&E.contains(w.target)||r(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s]),K(()=>{if(!s){x(null);return}function b(){var J;const w=(J=g.current)==null?void 0:J.getBoundingClientRect();if(!w)return;const E=window.innerWidth,_=window.innerHeight,C=Math.min(300,E-16),B=w.left,U=E-C-8,v=Math.max(8,Math.min(B,U)),Z=_-w.top+6;x({left:v,bottom:Z,width:C})}return b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}},[s]);async function d(b){if(!(!t||i!==null)){o(b),a(null);try{const w=await le("/wrap/model",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:t,model:b})});if(w.ok)r(!1),f("");else{const E=await w.json().catch(()=>({}));a((E==null?void 0:E.error)??`HTTP ${w.status}`)}}catch(w){a(String(w))}finally{o(null)}}}const P=i!==null?`${Ut(i||null)}…`:Ut(e),R=b=>b.stopPropagation();return n("div",{ref:p,class:"pmode-chip-wrap",onClick:R,onMouseDown:R,children:[n("button",{ref:g,class:"pmode-chip pmode-chip-neutral",title:c("model.switchHint"),onClick:b=>{b.stopPropagation(),r(w=>!w)},onMouseDown:R,disabled:!t,children:n("span",{children:P})}),s&&m&&n("div",{class:"pmode-menu",onClick:R,onMouseDown:R,style:{position:"fixed",left:m.left,bottom:m.bottom,top:"auto",right:"auto",width:m.width,maxWidth:"none",minWidth:0},children:[n("div",{class:"pmode-menu-head",children:c("model.menuTitle")}),fn.map(b=>{const w=(e??"")===b.aliasFor;return n("button",{class:"pmode-menu-item "+(w?"is-current":""),onClick:E=>{E.stopPropagation(),d(b.aliasFor)},onMouseDown:R,disabled:i!==null,title:b.label,children:[n("div",{class:"pmode-menu-text",children:[n("div",{class:"pmode-menu-label",children:b.label}),n("div",{class:"pmode-menu-desc",children:b.aliasFor===""?c("model.defaultDesc"):c("model.aliasDesc",{id:b.aliasFor})})]}),w&&n("span",{class:"pmode-check",children:"✓"})]},b.key)}),n("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",display:"flex",gap:6},children:[n("input",{type:"text",placeholder:c("model.customPlaceholder"),value:l,onInput:b=>f(b.currentTarget.value),onKeyDown:b=>{b.key==="Enter"&&l.trim()&&(b.preventDefault(),d(l.trim()))},style:{flex:1,minWidth:0,fontSize:12,fontFamily:"ui-monospace, monospace"}}),n("button",{class:"btn-primary",style:{height:28,padding:"0 10px",fontSize:11},disabled:!l.trim()||i!==null,onClick:b=>{b.stopPropagation(),l.trim()&&d(l.trim())},children:c("model.applyCustom")})]}),u&&n("div",{class:"pmode-err",children:u})]})]})}function Vs({sessionUuid:t}){function e(s){s.stopPropagation(),window.dispatchEvent(new CustomEvent("miki-moni:wrap-request",{detail:{sessionUuid:t}}))}return n("button",{class:"cell-wrap-btn cell-wrap-btn-icon",onClick:e,onMouseDown:s=>s.stopPropagation(),title:c("session.openCliTooltip"),"aria-label":c("session.openCli"),children:"🔌"})}function Xs({sessionByUuid:t}){const[e,s]=y(null),[r,i]=y(!1),[o,u]=y(!1),[a,l]=y(null);K(()=>{function g(m){var b;const d=(b=m.detail)==null?void 0:b.sessionUuid;if(!d)return;const P=t.get(d),R=(P==null?void 0:P.project_name)??d.slice(0,8);s({sessionUuid:d,project:R}),i(!1),l(null)}return window.addEventListener("miki-moni:wrap-request",g),()=>window.removeEventListener("miki-moni:wrap-request",g)},[t]);function f(){s(null),i(!1),l(null)}async function p(){if(!(!e||!r||o)){u(!0),l(null);try{const g=await le("/wrap/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:e.sessionUuid})});if(g.ok)f();else{const m=await g.json().catch(()=>({}));l((m==null?void 0:m.error)??`HTTP ${g.status}`)}}catch(g){l(String(g))}finally{u(!1)}}}return K(()=>{if(!e)return;function g(m){m.key==="Escape"&&!o&&f()}return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[e,o]),e?n("div",{role:"alertdialog","aria-modal":"false",style:{position:"fixed",top:16,left:"50%",transform:"translateX(-50%)",zIndex:70,maxWidth:540,minWidth:360,padding:"12px 14px",background:"var(--bg)",border:"1px solid var(--warn)",borderLeft:"3px solid var(--warn)",borderRadius:6,boxShadow:"0 6px 24px rgba(0,0,0,0.22)",fontSize:12,lineHeight:1.5,color:"var(--fg)",animation:"miki-toast-in 0.18s ease-out"},children:n("div",{style:{display:"flex",alignItems:"flex-start",gap:10},children:[n("span",{style:{fontSize:16,lineHeight:1,marginTop:1},children:"⚠️"}),n("div",{style:{flex:1,minWidth:0},children:[n("div",{style:{fontWeight:600,marginBottom:4},children:c("wrapNotice.title")}),n("div",{style:{color:"var(--fg-muted)",marginBottom:10},children:c("wrapNotice.body",{project:e.project})}),n("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:o?"not-allowed":"pointer",marginBottom:10},children:[n("input",{type:"checkbox",checked:r,disabled:o,onInput:g=>i(g.target.checked),style:{margin:0}}),n("span",{children:c("wrapNotice.confirmCheck")})]}),a&&n("div",{style:{fontSize:11,color:"var(--accent)",marginBottom:8},children:a}),n("div",{style:{display:"flex",gap:8},children:[n("button",{class:"btn-primary",style:{height:28,padding:"0 12px",fontSize:12},disabled:!r||o,onClick:()=>void p(),children:o?c("session.openCliPending"):c("wrapNotice.confirm")}),n("button",{class:"btn-ghost",style:{height:28,padding:"0 10px",fontSize:12},disabled:o,onClick:f,children:c("wrapNotice.later")})]})]})]})}):null}function Gs({sessions:t}){const[e,s]=y([]);K(()=>{function i(o){var l;const a=(l=o.detail)==null?void 0:l.cwd;a&&s(f=>[...f.filter(g=>g.cwd.toLowerCase()!==a.toLowerCase()),{cwd:a,startedAt:Date.now(),timedOut:!1}])}return window.addEventListener("miki-moni:spawn-pending",i),()=>window.removeEventListener("miki-moni:spawn-pending",i)},[]),K(()=>{if(e.length===0)return;const i=window.setInterval(()=>{const o=Date.now();s(u=>u.map(a=>a.timedOut?a:o-a.startedAt>3e4?{...a,timedOut:!0}:a))},1e3);return()=>window.clearInterval(i)},[e.length]),K(()=>{e.length!==0&&s(i=>i.filter(o=>!t.find(a=>a.cwd.toLowerCase()===o.cwd.toLowerCase()&&a.last_event_at>=o.startedAt)))},[t,e.length]);function r(i){s(o=>o.filter(u=>u.cwd!==i))}return e.length===0?null:n("div",{style:{position:"fixed",bottom:16,left:"50%",transform:"translateX(-50%)",zIndex:65,display:"flex",flexDirection:"column",gap:8,maxWidth:"min(520px, calc(100vw - 24px))",width:"100%"},children:e.map(i=>n("div",{role:"status",style:{padding:"10px 14px",background:"var(--bg)",border:"1px solid var(--border)",borderLeft:`3px solid var(${i.timedOut?"--accent":"--pass"})`,borderRadius:6,boxShadow:"0 6px 24px rgba(0,0,0,0.18)",fontSize:12,lineHeight:1.5,color:"var(--fg)",display:"flex",alignItems:"flex-start",gap:10},children:[i.timedOut?n("span",{style:{fontSize:14,marginTop:1},children:"⚠️"}):n("span",{class:"spawn-pending-spinner","aria-hidden":"true",children:"⟳"}),n("div",{style:{flex:1,minWidth:0},children:[n("div",{style:{fontWeight:600,marginBottom:2},children:c("spawnPending.title")}),n("div",{style:{color:"var(--fg-muted)",overflowWrap:"anywhere"},children:i.timedOut?c("spawnPending.timeout"):c("spawnPending.body",{cwd:i.cwd})})]}),n("button",{class:"btn-ghost",style:{fontSize:11,padding:"2px 8px",flexShrink:0},onClick:()=>r(i.cwd),children:c("spawnPending.dismiss")})]},i.cwd))})}function Js({recentCwds:t}){const[e,s]=y(!1),[r,i]=y(""),[o,u]=y(!1),[a,l]=y(null),[f,p]=y(!1),g=G(null),m=G(null),x=G(null),[d,P]=y(0),[R,b]=y(8);K(()=>{if(!e)return;function _(C){var B;(B=g.current)!=null&&B.contains(C.target)||s(!1)}return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[e]),K(()=>{e&&(l(null),p(!1),queueMicrotask(()=>{var _;return(_=x.current)==null?void 0:_.focus()}))},[e]),K(()=>{if(!e)return;function _(){var B;const C=(B=m.current)==null?void 0:B.getBoundingClientRect();C&&(P(C.bottom+6),b(Math.max(8,window.innerWidth-C.right)))}return _(),window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[e]);async function w(){const _=r.trim();if(!(!_||o)){u(!0),l(null),p(!1);try{const C=await le("/wrap/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({cwd:_})});if(C.ok)p(!0),window.dispatchEvent(new CustomEvent("miki-moni:spawn-pending",{detail:{cwd:_}})),window.setTimeout(()=>{s(!1),i("")},800);else{const B=await C.json().catch(()=>({}));l((B==null?void 0:B.error)??`HTTP ${C.status}`)}}catch(C){l(String(C))}finally{u(!1)}}}function E(_){_.key==="Enter"&&!_.shiftKey?(_.preventDefault(),w()):_.key==="Escape"&&s(!1)}return n("div",{ref:g,style:{position:"relative",display:"inline-flex"},children:[n("button",{ref:m,class:"btn-ghost",style:{padding:"4px 6px",display:"inline-flex",alignItems:"center"},onClick:()=>s(_=>!_),title:c("header.newCliTitle"),"aria-label":c("header.newCli"),children:n(Es,{size:15})}),e&&n("div",{style:{position:"fixed",top:d,right:R,zIndex:50,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"12px 14px",width:"min(360px, calc(100vw - 16px))",maxWidth:"calc(100vw - 16px)",boxSizing:"border-box",boxShadow:"0 6px 24px rgba(0,0,0,0.18)"},children:[n("div",{style:{fontSize:12,fontWeight:600,marginBottom:8},children:c("newCli.heading")}),n("label",{style:{fontSize:11,color:"var(--fg-muted)",display:"block",marginBottom:4},children:c("newCli.cwdLabel")}),n("input",{ref:x,type:"text",list:"newcli-cwd-suggestions",value:r,onInput:_=>i(_.target.value),onKeyDown:E,placeholder:c("newCli.cwdPlaceholder"),spellcheck:!1,autoComplete:"off",style:{width:"100%",fontFamily:"ui-monospace, Consolas, monospace",fontSize:12}}),t.length>0&&n("datalist",{id:"newcli-cwd-suggestions",children:t.map(_=>n("option",{value:_},_))}),t.length>0&&n("select",{value:"",onChange:_=>{const C=_.currentTarget.value;C&&(i(C),_.currentTarget.value="",queueMicrotask(()=>{var B;return(B=x.current)==null?void 0:B.focus()}))},"aria-label":c("newCli.recentCwds"),style:{width:"100%",marginTop:6,fontFamily:"ui-monospace, Consolas, monospace",fontSize:12},children:[n("option",{value:"",children:[c("newCli.recentCwds"),"…"]}),t.map(_=>n("option",{value:_,children:_},_))]}),n("div",{style:{fontSize:10,color:"var(--fg-subtle)",marginTop:6,lineHeight:1.45},children:c("newCli.hint")}),n("div",{style:{display:"flex",gap:6,marginTop:10,alignItems:"center"},children:[n("button",{class:"btn-primary",style:{height:28,padding:"0 10px",fontSize:11},disabled:o||!r.trim(),onClick:()=>void w(),children:o?c("newCli.submitting"):c("newCli.submit")}),a&&n("span",{style:{fontSize:10,color:"var(--accent)"},children:c("newCli.error",{err:a})}),f&&n("span",{style:{fontSize:10,color:"var(--pass)"},children:["✓ ",c("newCli.success")]})]})]})]})}function ei({s:t,preview:e,activity:s,streamingText:r,userOverlayText:i,pendingAsk:o,askDismissed:u,onReopenAsk:a,clientType:l,onSetClientType:f,onQuickSend:p,onOpenModal:g}){const m=(e==null?void 0:e.ai_title)??t.project_name,x=i&&i.length>0?i:e==null?void 0:e.last_user_text,d=r&&r.length>0?r:e==null?void 0:e.last_assistant_text,P=(e==null?void 0:e.last_tool_use)??null,R=We(()=>x?Ft(x):"",[x]),b=We(()=>d?Ft(d):"",[d]),w=!!r&&r.length>0,E=Ns(t.cwd),[_,C]=y(!1),B=G(t.status),U=G(void 0),v=G(void 0);K(()=>{const D=B.current;B.current=t.status;function W(){U.current&&(window.clearTimeout(U.current),U.current=void 0),v.current&&(window.clearTimeout(v.current),v.current=void 0)}if(D==="waiting"&&t.status!=="waiting"){W(),C(!1);return}D!=="waiting"&&t.status==="waiting"&&(W(),U.current=window.setTimeout(()=>{U.current=void 0,C(!0),v.current=window.setTimeout(()=>{v.current=void 0,C(!1)},1e4)},1e4))},[t.status]),K(()=>()=>{U.current&&window.clearTimeout(U.current),v.current&&window.clearTimeout(v.current)},[]);const[Z,J]=y(!1);K(()=>{if(t.status!=="waiting"){J(!1);return}if((e!=null&&e.last_user_ts?Date.parse(e.last_user_ts):0)>t.last_event_at){J(!1);return}const W=Date.now()-t.last_event_at;if(W>=6e4){J(!0);return}J(!1);const O=window.setTimeout(()=>J(!0),6e4-W);return()=>window.clearTimeout(O)},[t.status,t.last_event_at,e==null?void 0:e.last_user_ts]);const[te,se]=y(!1),L=G(null),ee=G(void 0),de=`${(e==null?void 0:e.last_user_ts)??""}|${(e==null?void 0:e.last_assistant_ts)??""}|${(e==null?void 0:e.last_tool_use_ts)??""}`;K(()=>{const D=L.current;L.current=de,D!==null&&D!==de&&(ee.current&&window.clearTimeout(ee.current),se(!0),ee.current=window.setTimeout(()=>{se(!1),ee.current=void 0},1200))},[de]),K(()=>()=>{ee.current&&window.clearTimeout(ee.current)},[]);const ie=140,oe=260;return n("div",{class:"cell cell-clickable"+(_?" cell-flash":"")+(te?" cell-flash-update":"")+(o&&u?" cell-ask-pending":""),style:{borderTop:`3px solid ${Ss[t.status]}`},onClick:()=>g(t),children:[n("div",{class:"cell-head",children:[n("span",{class:"cell-title",title:m,children:m}),o&&u&&n("button",{class:"cell-ask-bell",onClick:D=>{D.stopPropagation(),t.session_uuid&&a&&a(t.session_uuid)},title:c("session.waitingTooltip"),children:c("session.waitingBadge")}),s&&n("span",{class:"cell-activity",title:c("focus.wrapperRunning",{activity:s}),children:[n("span",{class:"cell-activity-dot"})," ",s,"…"]}),!t.wrapped&&t.session_uuid&&n(Vs,{sessionUuid:t.session_uuid}),n(Us,{sessionUuid:t.session_uuid??"",compact:!0})]}),n("div",{class:"cell-cwd",style:{color:E.label,display:"flex",alignItems:"center",gap:6},title:t.cwd,children:[n("strong",{style:{fontWeight:600},children:t.project_name}),t.wrapped?n("span",{class:"client-badge client-badge-wrap",title:c("session.wrappedDetailed"),children:c("focus.wrappedBadge")}):n(_t,{type:l,onToggle:()=>f(t.session_uuid??"",l==="cli"?"vscode":"cli")}),P&&n("span",{class:"cell-tool-inline",title:P.description||P.name,children:[n("span",{class:"cell-tool-icon",children:"🔧"}),n("strong",{children:P.name}),P.description&&n("span",{class:"cell-tool-desc",children:[" · ",P.description]}),(e==null?void 0:e.last_tool_use_ts)&&n("span",{class:"cell-tool-ts",title:e.last_tool_use_ts,children:[" · ",lt(e.last_tool_use_ts)]})]})]}),n("div",{class:"cell-preview cell-convo",children:!R&&!b?n("span",{class:"cell-empty",children:c("session.empty")}):n(Ke,{children:[b&&n("div",{class:"cell-turn cell-turn-assistant",children:[n("div",{class:"cell-turn-role",children:[n("span",{children:"claude"}),w?n("span",{class:"cell-turn-ts",style:{color:"var(--pass)"},children:"streaming…"}):(e==null?void 0:e.last_assistant_ts)&&n("span",{class:"cell-turn-ts",title:e.last_assistant_ts,children:lt(e.last_assistant_ts)})]}),n("div",{class:"cell-turn-body",children:[b.slice(0,oe),b.length>oe?"…":"",w&&n("span",{class:"streaming-cursor",children:"▌"})]})]}),R&&n("div",{class:"cell-turn cell-turn-user",children:[n("div",{class:"cell-turn-role",children:[n("span",{children:"user"}),(e==null?void 0:e.last_user_ts)&&n("span",{class:"cell-turn-ts",title:e.last_user_ts,children:lt(e.last_user_ts)})]}),n("div",{class:"cell-turn-body",children:[R.slice(0,ie),R.length>ie?"…":""]})]})]})}),n("div",{class:"cell-foot cell-foot-"+t.status,children:[n("span",{class:"cell-status",children:Ge(t.status)}),n("span",{children:"·"}),n("span",{children:Fe(t.last_event_at)}),t.wrapped&&n(pt,{sessionUuid:t.session_uuid,mode:t.permission_mode??"default"}),n("button",{class:"cell-send-btn icon-btn",style:t.wrapped?Zs[t.permission_mode??"default"]:void 0,onClick:D=>{D.stopPropagation(),p(t,D.clientX,D.clientY)},title:c("session.quickSend"),children:n(on,{size:12})})]})]})}function ti({sessions:t,sortMode:e,previews:s,activities:r,streaming:i,userOverlay:o,pendingAsks:u,dismissedAsks:a,onReopenAsk:l,getClientType:f,onSetClientType:p,onQuickSend:g,onOpenModal:m}){const x=We(()=>t.slice().sort(bi(e)),[t,e]);return n("div",{class:"cwd-group-grid",children:x.map(d=>{var P;return n(ei,{s:d,preview:d.session_uuid?s[d.session_uuid]:void 0,activity:d.session_uuid?r[d.session_uuid]:void 0,streamingText:d.session_uuid?i[d.session_uuid]:void 0,userOverlayText:d.session_uuid?(P=o[d.session_uuid])==null?void 0:P.text:void 0,pendingAsk:d.session_uuid?u[d.session_uuid]:void 0,askDismissed:d.session_uuid?a.has(d.session_uuid):!1,onReopenAsk:l,clientType:f(d.session_uuid),onSetClientType:p,onQuickSend:g,onOpenModal:m},d.session_uuid??d.cwd)})})}function ni({s:t,x:e,y:s,clientType:r,onSetClientType:i,onClose:o,onSend:u,sendKey:a}){var ie,oe;const l=r==="cli",f=!!t.wrapped,p=!f,[g,m]=y(""),[x,d]=y([]),[P,R]=y(!1),[b,w]=y(!1),[E,_]=y(!1),[C,B]=y(null),U=G(null),v=f,Z=360,J=280,te=typeof window<"u"&&window.innerWidth<560,se=te?Math.max(8,(window.innerWidth-Z)/2):Math.min(e+12,window.innerWidth-Z-16),L=te?Math.max(16,(window.innerHeight-J)/2):Math.min(s+12,window.innerHeight-J-16);K(()=>{function D(W){W.key==="Escape"&&o()}return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[o]);async function ee(){const D=!!g.trim(),W=x.length>0;if(!(!D&&!W||!t.session_uuid)){_(!0),B(null);try{const O=v?x:void 0,V=await u(t.session_uuid,g.trim(),P,O);if(V.ok){m(""),d([]),o();return}const be=c("send.httpFail",{status:V.status});B({ok:V.ok,label:be,reply:V.reply})}finally{_(!1)}}}async function de(D){const W=await dn(D);W.length>0&&(D.preventDefault(),d(O=>[...O,...W]))}return n(Ke,{children:[n("div",{class:"popover-backdrop",onClick:o}),n("div",{ref:U,class:"popover",style:{left:se,top:L},onClick:D=>D.stopPropagation(),children:[n("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[n("span",{class:Xe[t.status]}),n("strong",{style:{fontSize:13},children:t.project_name}),t.wrapped?n("span",{class:"client-badge client-badge-wrap",title:c("focus.wrappedTitle"),children:c("focus.wrappedBadge")}):n(_t,{type:r,onToggle:()=>i(t.session_uuid??"",l?"vscode":"cli")}),n("button",{class:"btn-ghost",style:{marginLeft:"auto",padding:"2px 8px"},onClick:o,title:c("session.closeKey"),children:"×"})]}),n("div",{style:{fontSize:10,color:"var(--fg-subtle)",fontFamily:"ui-monospace, monospace",marginBottom:8,wordBreak:"break-all"},children:[t.cwd,n("br",{}),t.session_uuid]}),n(hn,{images:x,onRemove:D=>d(W=>W.filter((O,V)=>V!==D)),dimmed:!v&&x.length>0}),!v&&x.length>0&&n("div",{style:{fontSize:10,color:"var(--warn)",marginBottom:4},children:c("composer.imageIgnored")}),n("textarea",{autoFocus:!0,placeholder:p?l?c("composer.cliNotWrapped",{short:((ie=t.session_uuid)==null?void 0:ie.slice(0,8))??""}):c("composer.vscodeDisabledWrap2",{short:((oe=t.session_uuid)==null?void 0:oe.slice(0,8))??""}):c("composer.inputPrompt"),value:g,onInput:D=>m(D.currentTarget.value),onPaste:D=>{de(D)},onKeyDown:D=>{xn(D,a)&&(D.preventDefault(),!E&&!p&&g.trim()&&ee())},disabled:E||p,style:{width:"100%",minHeight:80,fontSize:13,fontFamily:"inherit",marginBottom:8}}),n("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n("label",{class:"btn-ghost",style:{height:32,padding:"0 10px",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:v&&!E?"pointer":"not-allowed",opacity:v&&!E?1:.5},title:c("composer.uploadImage"),"aria-label":c("composer.uploadImage"),children:[n(an,{size:14}),n("input",{type:"file",accept:"image/*",multiple:!0,style:{display:"none"},disabled:!v||E,onChange:async D=>{const W=D.currentTarget,O=await pn(W.files);O.length>0&&d(V=>[...V,...O]),W.value=""}})]}),f&&n("button",{class:"btn-ghost",style:{marginLeft:"auto",height:32,padding:"0 10px",fontSize:14,lineHeight:1},onClick:()=>{t.session_uuid&&le("/wrap/interrupt",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:t.session_uuid})})},title:c("composer.interruptShort"),children:n(ln,{size:14})}),n("button",{class:f?"btn-primary":"btn-ghost",disabled:!g.trim()||E||p,onClick:ee,style:f?void 0:{marginLeft:"auto"},title:p?c("composer.needWrapHint2"):c("composer.wrapWSShort"),children:E?c("composer.sendBusy"):f?c("composer.sendWrapped"):c("composer.sendNeedWrap")})]}),n("div",{style:{marginTop:4,fontSize:10,color:"var(--fg-subtle)"},children:[a==="enter"?c("composer.keyEnter"):c("composer.keyCtrlEnter"),c("composer.escClose")]}),C&&n("div",{style:{marginTop:8,padding:8,background:"var(--sl2)",border:"1px solid var(--border)",borderRadius:6},children:[n("div",{style:{fontSize:12,color:C.ok?"var(--pass)":"var(--accent)",marginBottom:C.reply?6:0},children:C.label}),C.reply&&n("div",{style:{maxHeight:160,overflowY:"auto"},children:n(cn,{text:C.reply})})]})]})]})}function si({s:t,onClose:e,clientType:s,onSetClientType:r,onFocus:i,onSend:o,sendKey:u,pendingAsk:a,askDismissed:l,onReopenAsk:f,activity:p,transcript:g,transcriptLoading:m,transcriptError:x,transcriptLimit:d,onSetTranscriptLimit:P,onReloadTranscript:R,showTools:b,onSetShowTools:w,streamingText:E,streamingStartTs:_,userOverlayText:C,userOverlayTs:B}){K(()=>{function v(Z){Z.key==="Escape"&&e()}return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[e]),K(()=>{const v=document.body,Z={position:v.style.position,top:v.style.top,left:v.style.left,right:v.style.right,width:v.style.width,overflow:v.style.overflow},J=window.scrollY||window.pageYOffset||0;return v.style.position="fixed",v.style.top=`-${J}px`,v.style.left="0",v.style.right="0",v.style.width="100%",v.style.overflow="hidden",()=>{v.style.position=Z.position,v.style.top=Z.top,v.style.left=Z.left,v.style.right=Z.right,v.style.width=Z.width,v.style.overflow=Z.overflow,window.scrollTo(0,J)}},[]);const U=G(null);return K(()=>{const v=U.current;if(!v)return;let Z=0,J=0,te=!1,se=!1,L=!1;function ee(){te=!1,se=!1,L=!1,v.style.transition="transform 0.18s ease-out",v.style.transform=""}function de(W){const O=W;return O?!!(O.closest("textarea, input, select")||O.closest(".pmode-menu")):!1}function ie(W){if(W.touches.length!==1){te=!1;return}const O=W.touches[0];if(!v.contains(O.target)){te=!1;return}Z=O.clientX,J=O.clientY,te=!0,se=!1,L=de(O.target),v.style.transition="none"}function oe(W){if(!te||L)return;const O=W.touches[0];if(!O)return;const V=O.clientX-Z,be=O.clientY-J;if(!se){if(Math.abs(V)<8&&Math.abs(be)<8)return;if(Math.abs(be)>Math.abs(V)){te=!1;return}se=!0}V>0?(v.style.transform=`translateX(${V}px)`,W.cancelable&&W.preventDefault()):v.style.transform=""}function D(W){if(!te){ee();return}const O=W.changedTouches[0];if(!O){ee();return}const V=O.clientX-Z,be=O.clientY-J;se&&V>80&&Math.abs(V)>Math.abs(be)*1.2?(v.style.transition="transform 0.16s ease-out",v.style.transform="translateX(100%)",window.setTimeout(()=>{e()},160)):ee()}return document.addEventListener("touchstart",ie,{passive:!0}),document.addEventListener("touchmove",oe,{passive:!1}),document.addEventListener("touchend",D,{passive:!0}),document.addEventListener("touchcancel",ee,{passive:!0}),()=>{document.removeEventListener("touchstart",ie),document.removeEventListener("touchmove",oe),document.removeEventListener("touchend",D),document.removeEventListener("touchcancel",ee)}},[e]),n("div",{class:"cell-modal-backdrop",onClick:e,children:n("div",{ref:U,class:"cell-modal",onClick:v=>v.stopPropagation(),children:[n("button",{class:"cell-modal-close",onClick:e,title:c("session.modalClose"),children:"×"}),a&&l&&n("div",{class:"cell-modal-ask-banner",children:[n("span",{children:c("session.claudeWaitingHere")}),n("button",{class:"btn-primary",style:{height:26,padding:"0 10px",fontSize:12},onClick:()=>{t.session_uuid&&f&&f(t.session_uuid)},children:c("session.showQuestion")})]}),n(Fs,{s:t,defaultExpanded:!0,activity:p,clientType:s,onSetClientType:r,onFocus:i,onSend:o,sendKey:u,modalMode:!0,transcript:g,transcriptLoading:m,transcriptError:x,transcriptLimit:d,onSetTranscriptLimit:P,onReloadTranscript:R,showTools:b,onSetShowTools:w,streamingText:E,streamingStartTs:_,userOverlayText:C,userOverlayTs:B})]})})}const gn="miki-moni:client-types";function ii(){try{const t=localStorage.getItem(gn);if(!t)return{};const e=JSON.parse(t);return e&&typeof e=="object"?e:{}}catch{return{}}}function ri(t){try{localStorage.setItem(gn,JSON.stringify(t))}catch{}}const mn="miki-moni:send-key";function oi(){try{return localStorage.getItem(mn)==="enter"?"enter":"ctrl-enter"}catch{return"ctrl-enter"}}function li(t){try{localStorage.setItem(mn,t)}catch{}}const kn="miki-moni:theme";function ai(){try{const t=localStorage.getItem(kn);return t==="dark"||t==="light"||t==="system"?t:"light"}catch{return"light"}}function ci(t){try{localStorage.setItem(kn,t)}catch{}}function ui(t){var e;return t==="system"?typeof window<"u"&&((e=window.matchMedia)!=null&&e.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light":t}function Zt(t){document.documentElement.setAttribute("data-theme",ui(t))}const bn="miki-moni:sort-mode";function di(){try{const t=localStorage.getItem(bn);return t==="cwd"?"uuid":t==="uuid"||t==="recent"||t==="priority"?t:"uuid"}catch{return"uuid"}}function pi(t){try{localStorage.setItem(bn,t)}catch{}}const yn="miki-moni:status-filter";function hi(){try{const t=localStorage.getItem(yn);if(t==="all"||t==="live"||t==="idle"||t==="stale")return t}catch{}return"live"}function fi(t){try{localStorage.setItem(yn,t)}catch{}}function Qt(t){switch(t){case"waiting":return 0;case"active":return 1;case"idle":return 2;case"stale":return 3;default:return 4}}function gi(t,e){const s=Qt(t.status),r=Qt(e.status);return s!==r?s-r:t.cwd.localeCompare(e.cwd)}function mi(t,e){const s=t.session_uuid,r=e.session_uuid;return s&&r?s.localeCompare(r):s?-1:r?1:t.cwd.localeCompare(e.cwd)}function ki(t,e){return t.last_event_at!==e.last_event_at?e.last_event_at-t.last_event_at:t.cwd.localeCompare(e.cwd)}function bi(t){switch(t){case"uuid":return mi;case"recent":return ki;case"priority":default:return gi}}function xn(t,e){if(t.key!=="Enter"||t.isComposing||t.keyCode===229)return!1;const s=t.metaKey||t.ctrlKey;return e==="enter"?!t.shiftKey:s}function yi(){var zt,Lt;const[t]=zn(),[e,s]=y([]),[r,i]=y({}),[o,u]=y({}),[a,l]=y({}),[f,p]=y({}),[g,m]=y({}),[x,d]=y({}),[P,R]=y(new Set),[b,w]=y("connecting"),[E,_]=y([]),[C,B]=y(()=>ii()),[U,v]=y(()=>oi()),[Z,J]=y(()=>ai()),[te,se]=y(!1),[L,ee]=y(null),[de,ie]=y(null),[oe,D]=y(!1),[W,O]=y(null),[V,be]=y(20),[Te,ye]=y(!1),Pe=G(null),Ee=G(0),Ce=G(null),xe=G(20),Re=G(!1);function ae(h,S){return S?h:Math.min(1e4,h*4)}const[Be,Ue]=y(()=>hi());function it(h){Ue(h),fi(h)}const[we,Tt]=y(()=>di());function $(h){v(h),li(h)}function ne(h){J(h),ci(h)}function ue(h){Tt(h),pi(h)}K(()=>{var T;if(Zt(Z),Z!=="system")return;const h=window.matchMedia("(prefers-color-scheme: dark)"),S=()=>Zt("system");return(T=h.addEventListener)==null||T.call(h,"change",S),()=>{var A;return(A=h.removeEventListener)==null?void 0:A.call(h,"change",S)}},[Z]);function N(h){ee(h)}function ge(){ee(null),ie(null),O(null),Pe.current=null}K(()=>{Ce.current=(L==null?void 0:L.session_uuid)??null},[L]),K(()=>{xe.current=V},[V]),K(()=>{Re.current=Te},[Te]),K(()=>{const h=L==null?void 0:L.session_uuid;h&&Qe(h,ae(V,Te))},[L==null?void 0:L.session_uuid,V,Te]);function ze(h,S){h&&B(T=>{const A={...T,[h]:S};return ri(A),A})}function Le(h){if(!h)return"vscode";const S=e.find(T=>T.session_uuid===h);return S!=null&&S.wrapped?"cli":C[h]??"vscode"}const[ve,Ct]=y(null);function X(h,S,T){const A={ts:Date.now(),level:h,msg:S,ctx:T};_(H=>[A,...H].slice(0,_s)),h==="error"?Ts(S,T):h==="warn"&&jt(S,T)}async function Ze(){try{const h=await le("/sessions/previews");if(!h.ok){X("warn",`GET /sessions/previews ${h.status}`);return}const S=await h.json(),T={};for(const A of S)T[A.session_uuid]=A;i(T),m(A=>{let H=!1;const me={};for(const[M,k]of Object.entries(A)){const Y=T[M],z=Y!=null&&Y.last_user_ts?Date.parse(Y.last_user_ts):0;if(z&&z>=k.ts){H=!0;continue}me[M]=k}return H?me:A}),p(A=>{const H=new Set,me={};for(const[M,k]of Object.entries(A)){const Y=T[M];if((Y!=null&&Y.last_assistant_ts?Date.parse(Y.last_assistant_ts):0)>=k){H.add(M);continue}me[M]=k}return H.size>0&&l(M=>{const k={...M};for(const Y of H)delete k[Y];return k}),H.size>0?me:A}),X("info","previews loaded",{count:S.length})}catch(h){X("error","previews fetch throw",{error:String(h)})}}async function Qe(h,S){if(h){D(!0),O(null);try{const T=await le(`/sessions/${encodeURIComponent(h)}/transcript?limit=${S}`);if(!T.ok){const H=await T.text().catch(()=>"");O(`HTTP ${T.status}: ${H.slice(0,200)}`);return}const A=await T.json();ie(A),Pe.current={last_modified:A.last_modified,file_size:A.file_size},X("info","transcript loaded",{session_uuid:h,turns:A.turn_count})}catch(T){O(String(T))}finally{D(!1)}}}async function wn(h,S){if(h&&!(Date.now()<Ee.current))try{const T=await le(`/sessions/${encodeURIComponent(h)}/transcript-meta`);if(T.status===404){Ee.current=Date.now()+5e3,jt("transcript-meta 404 — meta poll paused for 5s (restart daemon to re-enable)");return}if(!T.ok)return;const A=await T.json(),H=Pe.current;(!H||A.last_modified!==H.last_modified||A.file_size!==H.file_size)&&Qe(h,S)}catch{}}K(()=>{X("info",c("startup.starting")),le("/sessions").then(M=>M.json().then(k=>({ok:M.ok,status:M.status,body:k}))).then(M=>{if(!M.ok){X("error",c("startup.getSessionsFailed"),{status:M.status});return}const k=M.body;s(k);const Y={},z={};for(const I of k)I.session_uuid&&I.activity&&(Y[I.session_uuid]=I.activity),I.session_uuid&&I.pending_ask&&(z[I.session_uuid]=I.pending_ask);Object.keys(Y).length>0&&u(Y),Object.keys(z).length>0&&d(z),X("info",c("startup.gotSessions",{n:k.length})),Ze()}).catch(M=>X("error","GET /sessions throw",{error:String(M)})),X("info",c("startup.wsConnecting"),{url:"/ws (via transport)"});let h=null,S=0,T=!1;function A(){if(T)return;const M=Ln("/ws");h=M,M.onopen=()=>{w("open"),S>0?(X("info",`WS reconnected after ${S} attempt(s) — refetching state`),le("/sessions").then(k=>k.json()).then(k=>{s(k);const Y={},z={};for(const I of k)I.session_uuid&&I.activity&&(Y[I.session_uuid]=I.activity),I.session_uuid&&I.pending_ask&&(z[I.session_uuid]=I.pending_ask);u(Y),d(z)}).catch(()=>{}),Ze()):X("info","WS open"),S=0},M.onclose=k=>{if(w("closed"),X("warn","WS close",{code:k.code}),T)return;S++;const Y=Math.min(500*Math.pow(2,Math.min(S-1,4)),5e3);w("connecting"),setTimeout(A,Y)},M.onerror=()=>{X("error","WS error")},M.onmessage=H}function H(M){var Y;let k;try{k=JSON.parse(M.data)}catch{return}if(k.type==="session_changed"){const z=k.session;X("info","WS session_changed",{project:z.project_name,status:z.status,uuid:(Y=z.session_uuid)==null?void 0:Y.slice(0,8)}),s(I=>{const Q=I.filter(pe=>pe.session_uuid!==z.session_uuid);return[z,...Q].sort((pe,ce)=>ce.last_event_at-pe.last_event_at)}),rt()}else if(k.type==="session_removed"){const z=k.session_uuid;X("info","WS session_removed",{uuid:z.slice(0,8)}),s(I=>I.filter(Q=>Q.session_uuid!==z)),u(I=>{const Q={...I};return delete Q[z],Q})}else if(k.type==="activity"){const z=k.session_uuid,I=typeof k.label=="string"?k.label:null;u(Q=>{if(!I){const pe={...Q};return delete pe[z],pe}return Q[z]===I?Q:{...Q,[z]:I}})}else if(k.type==="assistant_delta_start"){const z=k.session_uuid;X("info","WS assistant_delta_start",{uuid:z.slice(0,8)}),l(I=>({...I,[z]:""})),p(I=>({...I,[z]:Date.now()}))}else if(k.type==="assistant_delta"){const z=k.session_uuid,I=typeof k.text=="string"?k.text:"";if(!I)return;l(Q=>({...Q,[z]:(Q[z]??"")+I}))}else if(k.type==="assistant_delta_end"){const z=k.session_uuid;X("info","WS assistant_delta_end",{uuid:z.slice(0,8)}),rt()}else if(k.type==="user_message"){const z=k.session_uuid,I=typeof k.text=="string"?k.text:"",Q=typeof k.ts=="number"?k.ts:Date.now();z&&I&&m(pe=>({...pe,[z]:{text:I,ts:Q}}))}else if(k.type==="ask_question"){const z=k.session_uuid,I={question_id:k.question_id,questions:k.questions};d(Q=>({...Q,[z]:I}))}else if(k.type==="ask_question_done"){const z=k.session_uuid;d(I=>{const Q={...I};return delete Q[z],Q}),R(I=>{const Q=new Set(I);return Q.delete(z),Q})}}A();const me=window.setInterval(()=>{if(T)return;le("/sessions").then(k=>k.ok?k.json():null).then(k=>{if(!k||T)return;s(z=>{const I=new Map(k.map(ce=>[ce.session_uuid??ce.cwd,ce])),Q=new Set,pe=[];for(const ce of z){const Me=ce.session_uuid??ce.cwd,$t=I.get(Me);$t&&(pe.push($t),Q.add(Me))}for(const ce of k){const Me=ce.session_uuid??ce.cwd;Q.has(Me)||pe.push(ce)}return pe.sort((ce,Me)=>Me.last_event_at-ce.last_event_at)});const Y={};for(const z of k)z.session_uuid&&z.activity&&(Y[z.session_uuid]=z.activity);u(z=>({...z,...Y}))}).catch(()=>{}),Ze();const M=Ce.current;M&&wn(M,ae(xe.current,Re.current))},2e3);return()=>{T=!0,h&&h.close(),window.clearInterval(me)}},[]);const De=G(void 0),je=G(void 0),vn=1500;function rt(){function h(){De.current&&(clearTimeout(De.current),De.current=void 0),je.current&&(clearTimeout(je.current),je.current=void 0),Ze();const S=Ce.current;S&&Qe(S,ae(xe.current,Re.current))}De.current&&clearTimeout(De.current),De.current=window.setTimeout(h,300),je.current||(je.current=window.setTimeout(h,vn))}async function Sn(h){X("info","POST /focus",{uuid:h.slice(0,8)});try{const S=await le("/focus",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:h})});let T=null;try{T=await S.json()}catch{}return X(S.ok?"info":"error",`/focus ${S.status}`,{url:T==null?void 0:T.url}),{ok:S.ok,status:S.status,url:T==null?void 0:T.url}}catch(S){return X("error","/focus throw",{error:String(S)}),{ok:!1,status:0}}}async function Rt(h,S,T,A){var me;const H=A==null?void 0:A.map(({media_type:M,data:k})=>({media_type:M,data:k}));X("info",`POST /send (mode=${T?"submit":"prefill"})`,{uuid:h.slice(0,8),len:S.length,images:(H==null?void 0:H.length)??0});try{const M=await le("/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session_uuid:h,prompt:S,submit:T,images:H})});let k=null;try{k=await M.json()}catch{}return X(M.ok?"info":"error",`/send ${M.status}`,{mode:k==null?void 0:k.mode,reply_preview:(me=k==null?void 0:k.reply)==null?void 0:me.slice(0,60),duration_ms:k==null?void 0:k.duration_ms,diag:k==null?void 0:k.diag}),M.ok&&T&&rt(),{ok:M.ok,status:M.status,url:k==null?void 0:k.url,reply:k==null?void 0:k.reply,duration_ms:k==null?void 0:k.duration_ms,diag:k==null?void 0:k.diag,error:k==null?void 0:k.error}}catch(M){return X("error","/send throw",{error:String(M)}),{ok:!1,status:0}}}function _n(h,S,T){Ct({s:h,x:S,y:T})}const ot=We(()=>{const h=new Map;for(const S of e)S.session_uuid&&h.set(S.session_uuid,S);return h},[e]),Tn=We(()=>{const h=new Set,S=[];for(const T of e){const A=T.cwd;if(!(!A||h.has(A))&&(h.add(A),S.push(A),S.length>=30))break}return S},[e]);return n("div",{class:"app-shell",children:[n("header",{style:{display:"flex",alignItems:"center",gap:12,paddingBottom:12,borderBottom:"1px solid var(--border)",position:"relative"},children:[n("h1",{style:{margin:0,display:"inline-flex",alignItems:"center",color:"var(--fg)"},title:"miki-moni","aria-label":"miki-moni",children:n(Rs,{size:24})}),n(Ks,{sessions:e,filter:Be,onFilter:it}),n("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--fg-subtle)"},children:[n(Js,{recentCwds:Tn}),n("button",{class:"btn-ghost",style:{fontSize:11,padding:"2px 6px",display:"inline-flex",alignItems:"center"},onClick:()=>se(h=>!h),title:c("settings.title"),"aria-label":c("settings.title"),children:n(Ps,{size:14})})]}),te&&n("div",{class:"settings-popover",style:{position:"absolute",top:"100%",right:0,marginTop:6,zIndex:50,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"12px 14px",minWidth:280,boxShadow:"0 6px 24px rgba(0,0,0,0.18)",maxHeight:"calc(100vh - 100px)",overflowY:"auto",overscrollBehavior:"contain"},children:[n("div",{style:{fontSize:12,fontWeight:600,marginBottom:8},children:c("settings.sendKeySection")}),n("div",{style:{display:"flex",flexDirection:"column",gap:6,fontSize:12},children:[n("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n("input",{type:"radio",name:"miki-moni-send-key",checked:U==="enter",onChange:()=>$("enter")}),n("span",{children:[n("strong",{children:c("settings.enterLabel")}),c("settings.enterDesc")]})]}),n("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n("input",{type:"radio",name:"miki-moni-send-key",checked:U==="ctrl-enter",onChange:()=>$("ctrl-enter")}),n("span",{children:[n("strong",{children:c("settings.ctrlEnterLabel")}),c("settings.ctrlEnterDesc")]})]})]}),n("div",{style:{fontSize:10,color:"var(--fg-subtle)",marginTop:8,lineHeight:1.5},children:c("settings.sendKeyHelp")}),n("div",{style:{fontSize:12,fontWeight:600,marginTop:14,marginBottom:8,paddingTop:12,borderTop:"1px solid var(--border)"},children:c("settings.appearance")}),n("div",{style:{display:"flex",gap:4,fontSize:11},children:["light","dark","system"].map(h=>n("button",{class:"btn-outline",style:{flex:1,height:28,padding:"0 8px",fontSize:11,borderColor:Z===h?"var(--fg)":"var(--border)",background:Z===h?"var(--sl3)":"var(--bg)",fontWeight:Z===h?600:400},onClick:()=>ne(h),title:h==="system"?c("settings.themeSystemTitle"):h==="dark"?c("settings.themeDarkTitle"):c("settings.themeLightTitle"),children:h==="light"?c("settings.themeLight"):h==="dark"?c("settings.themeDark"):c("settings.themeSystem")},h))}),n("div",{style:{fontSize:12,fontWeight:600,marginTop:14,marginBottom:8,paddingTop:12,borderTop:"1px solid var(--border)"},children:c("settings.sortMode")}),n("div",{style:{display:"flex",gap:4,fontSize:11},children:[{v:"priority",labelKey:"settings.sortPriorityLabel",titleKey:"settings.sortPriorityTitle"},{v:"uuid",labelKey:"settings.sortUuidLabel",titleKey:"settings.sortUuidTitle"},{v:"recent",labelKey:"settings.sortRecentLabel",titleKey:"settings.sortRecentTitle"}].map(h=>n("button",{class:"btn-outline",style:{flex:1,height:28,padding:"0 6px",fontSize:11,borderColor:we===h.v?"var(--fg)":"var(--border)",background:we===h.v?"var(--sl3)":"var(--bg)",fontWeight:we===h.v?600:400},onClick:()=>ue(h.v),title:c(h.titleKey),children:c(h.labelKey)},h.v))}),n("div",{style:{fontSize:10,color:"var(--fg-subtle)",marginTop:6,lineHeight:1.5},children:c("settings.sortHelp")}),n("div",{style:{fontSize:12,fontWeight:600,marginTop:14,marginBottom:8,paddingTop:12,borderTop:"1px solid var(--border)"},children:c("settings.language")}),n("div",{style:{display:"flex",gap:4,fontSize:11},children:$n.map(h=>{const S=t===h;return n("button",{class:"btn-outline",style:{flex:1,height:28,padding:"0 6px",fontSize:11,borderColor:S?"var(--fg)":"var(--border)",background:S?"var(--sl3)":"var(--bg)",fontWeight:S?600:400},onClick:()=>In(h),title:It[h],children:It[h]},h)})}),n("div",{style:{marginTop:10,textAlign:"right"},children:n("button",{class:"btn-ghost",style:{fontSize:11,padding:"2px 8px"},onClick:()=>se(!1),children:c("settings.close")})})]})]}),n("div",{style:{marginTop:12,marginBottom:20}}),e.length===0?n("div",{class:"card",style:{padding:"24px 14px",textAlign:"center",color:"var(--fg-subtle)",fontSize:13},children:[n("div",{children:c("overview.noSessions")}),n("div",{style:{fontSize:11,marginTop:6},children:c("overview.openPanelHint")}),n("div",{style:{fontSize:11},children:[c("overview.runHooks"),n("code",{children:"pnpm install:hooks"})]})]}):n(ti,{sessions:e.filter(h=>Be==="all"?!0:Be==="live"?h.status==="active"||h.status==="waiting":h.status===Be),sortMode:we,previews:r,activities:o,streaming:a,userOverlay:g,pendingAsks:x,dismissedAsks:P,onReopenAsk:h=>R(S=>{const T=new Set(S);return T.delete(h),T}),getClientType:Le,onSetClientType:ze,onQuickSend:_n,onOpenModal:N}),!1,n(Xs,{sessionByUuid:ot}),n(Gs,{sessions:e}),ve&&n(ni,{s:ve.s,x:ve.x,y:ve.y,clientType:Le(ve.s.session_uuid),onSetClientType:ze,onClose:()=>Ct(null),onSend:Rt,sendKey:U}),L&&n(si,{s:ot.get(L.session_uuid??"")??L,onClose:ge,clientType:Le(L.session_uuid),onSetClientType:ze,onFocus:Sn,onSend:Rt,sendKey:U,pendingAsk:L.session_uuid?x[L.session_uuid]:void 0,askDismissed:L.session_uuid?P.has(L.session_uuid):!1,onReopenAsk:h=>R(S=>{const T=new Set(S);return T.delete(h),T}),activity:L.session_uuid?o[L.session_uuid]:void 0,transcript:de,transcriptLoading:oe,transcriptError:W,transcriptLimit:V,onSetTranscriptLimit:be,onReloadTranscript:()=>{L.session_uuid&&Qe(L.session_uuid,ae(V,Te))},showTools:Te,onSetShowTools:ye,streamingText:L.session_uuid?a[L.session_uuid]:void 0,streamingStartTs:L.session_uuid?f[L.session_uuid]:void 0,userOverlayText:L.session_uuid?(zt=g[L.session_uuid])==null?void 0:zt.text:void 0,userOverlayTs:L.session_uuid?(Lt=g[L.session_uuid])==null?void 0:Lt.ts:void 0}),(()=>{const h=Object.keys(x).find(A=>!P.has(A));if(!h)return null;const S=x[h],T=ot.get(h);return n(Ws,{sessionUuid:h,ask:S,onSubmitted:()=>{d(A=>{const H={...A};return delete H[h],H}),R(A=>{const H=new Set(A);return H.delete(h),H}),X("info","ask answered",{uuid:h.slice(0,8),project:T==null?void 0:T.project_name})},onDismiss:()=>{R(A=>{const H=new Set(A);return H.add(h),H})}})})()]})}function xi(){An(n(yi,{}),document.getElementById("app"))}try{Pn()}catch{En(new vs)}xi();export{yi as App,xi as mountApp};
|