finch-markdown-editor 0.2.13 → 0.2.14
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/dist/panel.css +16 -1
- package/dist/panel.js +8 -8
- package/package.json +1 -1
package/dist/panel.css
CHANGED
|
@@ -19,6 +19,21 @@
|
|
|
19
19
|
*{box-sizing:border-box}
|
|
20
20
|
html,body{height:100%}
|
|
21
21
|
body{margin:0;background:var(--bg);color:var(--text);font:13px var(--finch-font-body,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif)}
|
|
22
|
+
/* Windows and Linux reserve a scrollbar track in Chromium. Keep a compact
|
|
23
|
+
thumb for direct dragging, but make it appear only while hovering or
|
|
24
|
+
scrolling; the track itself remains transparent. macOS keeps its system
|
|
25
|
+
scrollbar behavior unchanged. */
|
|
26
|
+
/* Do not set `scrollbar-width: thin`: it overrides the WebKit width below
|
|
27
|
+
in Chromium/Electron. */
|
|
28
|
+
body.non-mac-platform .cm-scroller{scrollbar-color:color-mix(in srgb,var(--muted) 20%,transparent) transparent}
|
|
29
|
+
/* The 2px transparent border on either side leaves an 8px painted thumb. */
|
|
30
|
+
body.non-mac-platform .cm-scroller::-webkit-scrollbar{width:12px;height:12px}
|
|
31
|
+
body.non-mac-platform .cm-scroller::-webkit-scrollbar-track{background:transparent}
|
|
32
|
+
body.non-mac-platform .cm-scroller::-webkit-scrollbar-thumb{border:2px solid transparent;border-radius:999px;background-color:color-mix(in srgb,var(--muted) 20%,transparent);background-clip:content-box}
|
|
33
|
+
body.non-mac-platform .cm-scroller:hover::-webkit-scrollbar-thumb,
|
|
34
|
+
body.non-mac-platform .cm-scroller.cm-scrollbar-active::-webkit-scrollbar-thumb{background-color:color-mix(in srgb,var(--muted) 58%,transparent)}
|
|
35
|
+
body.non-mac-platform .cm-scroller:hover{scrollbar-color:color-mix(in srgb,var(--muted) 58%,transparent) transparent}
|
|
36
|
+
body.non-mac-platform .cm-scroller.cm-scrollbar-active{scrollbar-color:color-mix(in srgb,var(--muted) 58%,transparent) transparent}
|
|
22
37
|
.app{width:100%;height:100vh;display:flex;flex-direction:column}
|
|
23
38
|
.stage{position:relative;flex:1;min-height:0}
|
|
24
39
|
.pane{position:absolute;inset:0;display:none}
|
|
@@ -203,7 +218,7 @@ body.app-view .app-toolbar{display:flex!important}
|
|
|
203
218
|
before any document is open, and the Home screen still needs its full
|
|
204
219
|
toolbar (Library/Home/Open) to navigate. */
|
|
205
220
|
body.app-view.has-document.focus-mode .app-toolbar{
|
|
206
|
-
position:fixed;top:
|
|
221
|
+
position:fixed;top:12px;right:18px;left:auto;width:auto;height:auto;
|
|
207
222
|
padding:0;gap:0;border:0;background:transparent;z-index:20;
|
|
208
223
|
}
|
|
209
224
|
body.app-view.has-document.focus-mode .app-toolbar-group:not(.app-toolbar-end){display:none!important}
|
package/dist/panel.js
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
{text}
|
|
9
9
|
|
|
10
|
-
Give a drop-in replacement snippet first; once I confirm, write it back to the source file ({path}) as a targeted local replacement, not a full resend of the document.`,"annotate.reminder":"Only propose the rewrite \u2014 don't write to the source file before I confirm. Reply in natural language (e.g. \u201CI'll put it into the file once you confirm\u201D); never name the tool or its actions. [MANDATORY, not optional] Whenever this turn proposes a rewrite and is waiting on my confirmation, calling Session action=suggest with 1\u20133 one-tap confirmations (e.g. \u201CUse this one\u201D, \u201CUse the shorter version\u201D, \u201CTry another tone\u201D) is part of completing that same turn \u2014 writing the proposal text is only half the job. Do not treat the turn as done, and do not skip the call, just because the proposal text itself was already sent.","newdoc.needChat":"Use \u201CNew Document\u201D from the Finch chat instead.","newdoc.label":"New Markdown Document","newdoc.promptText":"I want to create a new Markdown document. First work out the title, content, and a not-yet-existing absolute save path from my request \u2014 ask me first if anything is missing. Once confirmed, write the full body to that path and open the new document in the editor.","newdoc.reminder":"Only create a new file; never overwrite an existing one. Reply in natural language and never name the tool or its actions. [MANDATORY, not optional] Whenever this turn ends still waiting on me to confirm a title, an angle, or a save location, it must call Session action=suggest with 1\u20133 one-tap options before the turn ends \u2014 asking the question in plain text is not enough on its own; skipping the call leaves the question unfinished.","newdoc.added":"Added the new-document prompt to the composer.","aiStyle.label":"Design a layout based on {file}","aiStyle.note":"One-click AI layout","aiStyle.baseNoteCustom":"The current base style is kami (your custom CSS layers on top of it)","aiStyle.baseNoteOther":"The current base style is {style}","aiStyle.pathMissing":"(No local file linked)","aiStyle.promptText":'Please design a custom layout CSS for this WeChat article. {baseNote}, and your CSS will layer on top of the base style. Requirements: write plain CSS rules only, with selectors scoped to tags/structure under #bm-md (e.g. #bm-md h1, #bm-md p, #bm-md blockquote, #bm-md pre code, #bm-md a, #bm-md strong, #bm-md table); don\u2019t use classes (bm.md\u2019s output has no classes, only inline styles), and use !important where needed to override the base style. You can draw on bm.md\u2019s built-in style language: kami (warm paper feel), bauhaus (geometric color-blocking), blueprint (technical grid), botanical (fresh green), newsprint (editorial serif), retro (nostalgic), sketch (hand-drawn), terminal (monospace dark). Article path: {path}. Once it\u2019s ready, call set_style directly (pass path="{path}", css, and a short label, no slot \u2014 passing path lets it find the right preview panel for this document even if I\u2019ve switched away) \u2014 don\u2019t ask me which slot to use first; the panel will pop up a lightweight \u201Csave as custom style\u201D button so I can decide after seeing the result.',"aiStyle.reminder":"Don\u2019t ask which slot to use before applying \u2014 just design it and call set_style (without slot) to apply it to the preview; whether to save it is for me to decide from the panel. Reply in natural language and never name the tool or its actions.","aiStyle.requested":"Asked AI to design a custom layout.","aiStyle.applied":"AI designed a layout and applied it to the preview.","aiStyle.saveToSlot":"Save as style {n}","aiStyle.appViewDesigning":"AI is designing a layout\u2026","aiStyle.appViewDone":"Layout design finished.","aiStyle.appViewFailed":"Layout design did not finish.","status.saved":"Saved.","status.savedWithNewChanges":"Saved \u2014 but the editor already has newer changes.","status.saveFailed":"Save failed: {err}","status.saving":"Saving\u2026","status.noSourceFile":"Not linked to a local file: click \u201COpen\u201D in the toolbar again to link it and enable saving.","status.pickerTimeout":'The file picker took too long to respond and switched to the in-browser picker \u2014 please click "Open" again.',"status.externalUpdateSkipped":"Detected an external file update; not loaded yet to avoid overwriting unsaved changes.","status.draftRestored":'Restored your last unsaved edits (differs from the file on disk). To discard, click "Open" and pick this file again, then choose "Discard".',"status.draftConflict":"A local unsaved draft exists, but the file was changed and saved elsewhere; loaded the latest file content \u2014 the draft is kept, not discarded.","status.sourceMissing":"The original file was moved or deleted; your content is still here \u2014 saving will recreate the file at its original path.","status.externalUpdateApplied":"Detected a file update and refreshed.","status.openingPicker":"Opening the file picker\u2026","status.opening":"Opening\u2026","status.opened":"Opened {file}.","status.contentUpdated":"Content updated.","status.contentUpdatedLine":"Updated line {line}.","status.contentUpdatedLines":"Updated lines {from}\u2013{to}.","status.contentUpdatedSpots":"Updated {count} spots, {lines} lines in total.","status.pasteImageTimeout":"Paste image timed out","status.pasteImageFailed":"Paste image failed: {msg}","status.clipboardPrepareTimeout":"Preparing WeChat images timed out","status.pleaseOpenArticle":"Open an article first.","status.copiedRich":"Rich HTML copied \u2014 paste it directly into the WeChat editor.","status.copiedPlainOnly":"Only plain text was copied; formatting didn't come through \u2014 please try again.","status.copyFailed":"Copy failed \u2014 please try again.","status.richCopyFailed":"Rich-text copy failed: {err}","status.clipboardUnsupported":"Copying images isn\u2019t supported here \u2014 use \u201CExport Image\u201D instead.","status.generatingImage":"Generating image\u2026","status.previewNotReady":"Preview isn't ready yet","status.imageCopied":"Image copied to the clipboard.","status.copyImageFailed":"Copy image failed: {err} (try \u201CExport Image\u201D instead)","status.exportImageFailedGeneric":"Export image failed: preview isn't ready yet.","status.exportImageFailed":"Export image failed: {err}","status.generatingPdf":"Generating PDF\u2026","status.exportPdfFailedGeneric":"Export PDF failed: preview isn't ready yet.","status.exportPdfFailed":"Export PDF failed: {err}","status.exported":"Exported: {path}","status.annotateOn":"Annotate is on \u2014 select text to ask AI to revise it.","status.annotateOff":"Annotate is off.","status.comfortWrite":"Comfortable mode is on \u2014 roomier line spacing.","status.comfortRead":"Compact mode is on.","status.focusOn":"Focus mode is on \u2014 inactive lines are dimmed.","status.focusOff":"Focus mode is off.","status.saveFailedNoReturn":"Save failed \u2014 staying on this document.","status.rendererAboutPrefix":"Renderer: local bmmd CLI (","status.rendererAboutSuffix":", LGPL-3.0).","status.appliedStyleSlot":"Applied \u201C{label}\u201D.","status.needCustomStyleFirst":"Apply a custom/AI-designed style first before saving it to a slot.","status.savedToSlot":"Saved to slot {slot}: {label}","status.serializeFailed":"Failed to serialize the preview content: {err}","status.imageConversionFailed":"The preview couldn't be converted to an image (it may contain external images that can't be read cross-origin)","status.imageGenFailed":"Failed to generate image data","status.clipboardPrepareFailedDefault":"Failed to prepare WeChat images","status.pasteImageFailedDefault":"Paste image failed","status.savedAppliedToSlot":"{labelPrefix}Saved and applied to custom style {slot}."}};function n(e,t){var a=it?st.zh:st.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(st.en,e)?st.en[e]:e;if(t)for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r=r.split("{"+o+"}").join(String(t[o])));return r}function Dt(e){var t=e||document;document.documentElement.lang=it?"zh-CN":"en",document.title=n("meta.title"),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n]"),function(a){a.textContent=n(a.getAttribute("data-i18n"))}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-title]"),function(a){a.title=n(a.getAttribute("data-i18n-title"))}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-tooltip]"),function(a){var r=n(a.getAttribute("data-i18n-tooltip"));a.setAttribute("data-tooltip",r),a.setAttribute("aria-label",r)}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-aria]"),function(a){a.setAttribute("aria-label",n(a.getAttribute("data-i18n-aria")))})}var Ft=document.getElementById("empty"),ha=document.getElementById("emptyNew"),ya=document.getElementById("emptyOpen"),Tt=document.getElementById("homeRecent"),le=document.getElementById("homeGrid"),lt=document.getElementById("homeHint"),Pt=[],ba=document.getElementById("homeTagline"),Ir=document.getElementById("editPane"),Ot=document.getElementById("previewPane"),ce=document.getElementById("previewResizer"),ke=document.getElementById("editor"),y=document.getElementById("article"),M=document.getElementById("status"),I=document.getElementById("popup"),_=document.getElementById("popupInput"),wa=document.getElementById("popupSend"),Sa=document.getElementById("popupShortcut"),Re=document.getElementById("actions"),Lr=document.getElementById("actCopyWx"),Ar=document.getElementById("actCopyImg"),Cr=document.getElementById("actSaveImg"),Dr=document.getElementById("actSavePdf"),xe=document.getElementById("actAiStyle"),ka=document.getElementById("actToggle"),ue=document.getElementById("confirmOverlay"),xa=document.getElementById("confirmMessage"),Rt=document.getElementById("confirmCancel"),Bt=document.getElementById("confirmDiscard"),Be=document.getElementById("confirmSave"),Ea=document.getElementById("appToolbar"),Ma=document.getElementById("appHome"),Ia=document.getElementById("appLibrary"),ct=document.getElementById("appOpen"),re=document.getElementById("appSave"),Ne=document.getElementById("appPreview"),ut=document.getElementById("appStyle"),dt=document.getElementById("appStyleMenu"),de=document.getElementById("appFocus"),Nt=document.getElementById("appFont"),pt=document.getElementById("appFontMenu"),Fr=document.getElementById("appMore"),ft=document.getElementById("appMoreMenu"),qt=document.getElementById("libraryDrawer"),mt=document.getElementById("libraryBackdrop"),La=document.getElementById("libraryClose"),vt=document.getElementById("libraryReorder"),Aa=document.getElementById("libraryReorderFooter"),Ca=document.getElementById("libraryReorderDone"),C=document.getElementById("libraryGroups"),Da="md-editor-library-groups-v1",pe=[],Ee={},fe=null,qe=null,ne=!1,He=[],j=null,Ht=!1,g=!1,Fa=!1,Ta=!1,H=null,me=null,G=!0,Tr=!1,gt=0,We=!1,te=!0,x="edit",L="kami",R="",Me="",W=[null,null,null],Ie={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},z=14,J="rounded",B=!1,D=!1;try{var ht=Number(localStorage.getItem("md-editor-font-size"));(ht===14||ht===16||ht===18)&&(z=ht);var Wt=localStorage.getItem("md-editor-font-family");Ie[Wt]?J=Wt:Wt&&localStorage.removeItem("md-editor-font-family"),B=localStorage.getItem("md-editor-comfort-writing")==="1",D=localStorage.getItem("md-editor-focus-mode")==="1";var ze=JSON.parse(localStorage.getItem(Da)||"{}");Array.isArray(ze.order)&&(pe=ze.order.filter(function(e){return typeof e=="string"})),ze.collapsed&&typeof ze.collapsed=="object"&&(Ee=ze.collapsed)}catch{}te=!D;var h="",Ue="",U="",m="",P=null,N="",Le=!1,Pa=0,Ve=!1,Oa=0,zt={},Ae={},Pr=0,ve={},Or=0,ge={},_e=0,$=null,yt=0,Ce=0,Ut=!1,w={text:"",mode:"replace"},E=0;function c(e,t){E&&(clearTimeout(E),E=0),M.textContent=e||"",M.className="status"+(t?" error":""),e&&(E=setTimeout(function(){E=0,M.textContent="",M.className="status"},5e3))}function he(e,t,a,r){if(E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(e||"")),M.className="status"+(t?" error":""),a){var o=document.createElement("button");o.type="button",o.className="status-inline-btn",o.textContent=n("appview.openSession"),o.addEventListener("click",function(){i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(a)}),M.appendChild(o)}r&&(E=setTimeout(function(){E=0,M.replaceChildren(),M.className="status"},r))}function Rr(){E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(n("status.rendererAboutPrefix")));var e=document.createElement("a");e.href="https://bm.md/",e.textContent="bm.md",e.title="https://bm.md/",e.addEventListener("click",function(t){t.preventDefault(),i&&i.postMessage&&i.postMessage({type:"openLink",url:"https://bm.md/"})}),M.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),M.className="status",E=setTimeout(function(){E=0,M.textContent="",M.className="status"},5e3)}function A(){return!!h||!!m}ha&&ha.addEventListener("click",async function(){if(!i||!i.composer){c(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),c(n("newdoc.added"))}catch(e){c(String(e),!0)}}),ya&&ya.addEventListener("click",function(){ia()});var je="",Vt="",_t="",bt=!1,Ra=!1,Ge="",ye="";function S(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function Ba(){ba&&(ba.textContent=Ge?n("home.tagline.withAssistant",{name:Ge}):n("home.tagline.default"))}function wt(){_&&(_.placeholder=w.mode==="continue"?n("popup.placeholderContinue",{name:Ge||"Finch"}):n("popup.placeholder",{name:Ge||"Finch"}))}function Br(e){return e?ye&&e===ye?"~":ye&&(e.indexOf(ye+"/")===0||e.indexOf(ye+"\\")===0)?"~"+e.slice(ye.length):e:""}function Nr(e){var t=46;if(!e||e.length<=t)return e;var a=e.indexOf("/")===-1&&e.indexOf("\\")!==-1?"\\":"/",r=e.slice(-(t-1)),o=r.indexOf(a);return o>0&&o<10&&(r=r.slice(o)),"\u2026"+r}function qr(){kt(Pt)}function Na(e){var t=new Date(e);if(!e||isNaN(t.getTime()))return"";var a=new Date,r=function(u){return u<10?"0"+u:String(u)},o=r(t.getHours())+":"+r(t.getMinutes()),s=t.toDateString()===a.toDateString();if(s)return n("home.today",{clock:o});var l=new Date(a.getTime()-864e5);return t.toDateString()===l.toDateString()?n("home.yesterday",{clock:o}):t.getFullYear()===a.getFullYear()?r(t.getMonth()+1)+"-"+r(t.getDate()):t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())}function St(){!i||!i.postMessage||!bt||(Ra=!0,i.postMessage({type:"requestRecentDocuments",cwd:je,sessionId:Vt,spaceId:_t}))}function Hr(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+S(e.path||"")+'" title="'+S(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+S(e.path||"")+'" role="button" tabindex="0" title="'+S(n("home.revealInFileManager"))+'" aria-label="'+S(n("home.revealInFileManager"))+'"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 14 1.45-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6a2 2 0 0 1-1.94 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/></svg></span><div class="doc-preview">'+S(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+S(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+S(t)+'">'+S(t)+'</span><span class="doc-time">'+S(Na(e.modifiedAt))+"</span></div></div></button>"}function kt(e){if(!(!le||!Tt||!lt)){var t=Array.isArray(e)?e:[];if(Pt=t,t.length===0){Tt.hidden=!0,lt.hidden=!1,lt.textContent=n(je?"home.hintScoped":"home.hintDefault");return}var a=qa(t);le.innerHTML=a.map(function(r){var o=r.documents.map(Hr).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+S(r.scopePath)+'" title="'+S(n("home.cwdTitle",{path:r.scopePath}))+'">'+S(Nr(Br(r.scopePath)))+"</button>":"",l='<div class="home-group-title"><span class="home-group-label">'+S(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+l+'<div class="home-grid">'+o+"</div></div>"}).join(""),Tt.hidden=!1,lt.hidden=!0,requestAnimationFrame(function(){Wr(le)})}}function Wr(e){for(var t="\u2026",a=e.querySelectorAll("[data-full-path]"),r=0;r<a.length;r++){var o=a[r],s=o.getAttribute("data-full-path")||"";if(o.textContent=s,!(!s||o.scrollWidth<=o.clientWidth+1)){for(var l=0,u=s.length,d=0;l<=u;){var f=l+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(d=f,l=f+1):u=f-1}o.textContent=d>0?t+s.slice(s.length-d):t}}}function jt(){var e={order:pe,collapsed:Ee};try{localStorage.setItem(Da,JSON.stringify(e))}catch{}i&&i.postMessage&&i.postMessage({type:"saveLibraryGroups",libraryGroups:e})}function qa(e){var t={};return(Array.isArray(e)?e:[]).forEach(function(a){var r=a.scopeKind||"external",o=r==="workspace"?n("appview.libraryWorkspace"):r==="external"?n("appview.libraryOther"):a.scopeLabel||a.spaceName||n("appview.libraryOther"),s=r==="space"?"space:"+(a.spaceId||o):r==="workspace"?"workspace":"external";t[s]||(t[s]={id:s,kind:r,label:o,scopePath:"",documents:[]}),r!=="external"&&!t[s].scopePath&&a.scopePath&&(t[s].scopePath=a.scopePath),t[s].documents.push(a)}),Object.keys(t).map(function(a){return t[a]}).sort(function(a,r){if(a.kind==="external"||r.kind==="external")return a.kind===r.kind?0:a.kind==="external"?1:-1;var o=pe.indexOf(a.id),s=pe.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var l={space:0,workspace:1},u=l[a.kind]-l[r.kind];return u||a.label.localeCompare(r.label)})}function Gt(e){if(C){He=Array.isArray(e)?e:[];var t=qa(He);if(ne){zr(t);return}C.innerHTML=t.map(function(a){var r=a.documents.map(function(l){var u=l.relativePath||l.fileName||"";return'<button class="library-row" type="button" data-path="'+S(l.path||"")+'"><span class="library-row-main"><strong>'+S(l.title||l.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+S(u)+'">'+S(u)+"</span><time>"+S(Na(l.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!Ee[a.id];return'<details class="library-group" data-library-group-id="'+S(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+S(a.label)+'</span><span class="library-group-count">'+a.documents.length+'</span></summary><div class="library-items">'+r+"</div></details>"}).join("")||'<p class="home-hint">'+S(n("home.hintDefault"))+"</p>"}}function zr(e){C.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+S(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+S(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+S(n("home.hintDefault"))+"</p>"}function Xt(e){ne=!!e,vt&&vt.classList.toggle("active",ne),Aa&&(Aa.hidden=!ne),Gt(He)}function xt(e){!qt||!mt||(qt.classList.toggle("open",!!e),qt.setAttribute("aria-hidden",e?"false":"true"),mt.hidden=!e,e?St():ne&&Xt(!1))}function Ur(){if(!(!fe||!C)){fe.classList.remove("dragging"),Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),pe=Array.prototype.map.call(C.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),kt(Pt);var e=qe||{};Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(t){var a=t.getAttribute("data-library-group-id");a in e&&(t.open=!!e[a])}),fe=null,setTimeout(function(){qe=null,jt()},0)}}function Vr(){j&&j.ghost&&j.ghost.parentNode&&j.ghost.parentNode.removeChild(j.ghost)}function Ha(e,t){var a=j;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function _r(e){var t=j;if(!(!t||t.active)){t.active=!0,fe=e,qe={},ne||Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(qe[s]=!!o.open),o.open=!1}),e.classList.add("dragging");var a=e.getBoundingClientRect(),r=e.cloneNode(!0);r.classList.add("library-drag-ghost"),r.classList.remove("dragging"),r.style.width=a.width+"px",t.ghost=r,t.offsetX=t.startX-a.left,t.offsetY=t.startY-a.top,document.body.appendChild(r),Ha(t.startX,t.startY)}}function jr(e,t){if(fe){var a=document.elementFromPoint(e,t),r=a&&a.closest?a.closest('.library-group[data-draggable="true"]'):null;if(Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(s){s.classList.remove("drag-over")}),!(!r||r===fe)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;C.insertBefore(fe,o?r.nextSibling:r)}}}function Wa(){var e=j;e&&(e.active&&(Vr(),Ur(),Ht=!0,setTimeout(function(){Ht=!1},0)),j=null)}Ia&&Ia.addEventListener("click",function(){xt(!0)}),La&&La.addEventListener("click",function(){xt(!1)}),mt&&mt.addEventListener("click",function(){xt(!1)}),vt&&vt.addEventListener("click",function(){Xt(!ne)}),Ca&&Ca.addEventListener("click",function(){Xt(!1)}),C&&C.addEventListener("click",function(e){var t=e.target&&e.target.closest?e.target.closest(".library-row"):null,a=t&&t.getAttribute("data-path");!a||!i||!i.postMessage||(xt(!1),Xe=!0,c(n("status.opening")),Yt(a))}),C&&(C.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!qe){var a=t.getAttribute("data-library-group-id");a&&(Ee[a]=!t.open,jt())}},!0),C.addEventListener("click",function(e){if(Ht){var t=e.target&&e.target.closest?e.target.closest(".library-group summary"):null;t&&(e.preventDefault(),e.stopPropagation())}},!0),C.addEventListener("pointerdown",function(e){if(e.button===0&&ne){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(j={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=j;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;_r(t.group)}e.preventDefault(),Ha(e.clientX,e.clientY),jr(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){Wa()}),window.addEventListener("pointercancel",function(){Wa()}));var Xe=!1,Et="";function Yt(e){!e||!i||!i.postMessage||(Et=e,i.postMessage({type:"loadPath",path:e}))}le&&le.addEventListener("click",function(e){if(!(!i||!i.postMessage)){var t=e.target&&e.target.closest?e.target.closest(".home-group-cwd"):null;if(t){var a=t.getAttribute("data-cwd-path")||"";a&&i.postMessage({type:"openPath",path:a});return}var r=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(r){e.preventDefault(),e.stopPropagation();var o=r.getAttribute("data-reveal-path")||"";o&&i.postMessage({type:"openPath",path:o});return}var s=e.target&&e.target.closest?e.target.closest(".doc-card"):null;if(s){var l=s.getAttribute("data-path")||"";l&&(Xe=!0,c(n("status.opening")),Yt(l))}}}),le&&le.addEventListener("keydown",function(e){if(!(e.key!=="Enter"&&e.key!==" ")){var t=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(!(!t||!i||!i.postMessage)){e.preventDefault(),e.stopPropagation();var a=t.getAttribute("data-reveal-path")||"";a&&i.postMessage({type:"openPath",path:a})}}});function Ye(){Ft.hidden=A(),document.body.classList.toggle("has-document",A()),Re&&(Re.hidden=!N),!Ft.hidden&&bt&&St()}function De(){Ir.classList.toggle("active",g?A():x==="edit"),Ot.classList.toggle("active",g?A():x==="preview"),(g||x==="edit")&&p&&requestAnimationFrame(function(){p.layout()})}function za(e){g||!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function Gr(e){return e?"document:"+encodeURIComponent(e):""}function Ua(e){if(!e||e.indexOf("document:")!==0)return"";try{var t=decodeURIComponent(e.slice(9));return/^(?:\/|[A-Za-z]:[\\/])/.test(t)?t:""}catch{return""}}var Fe="";function Va(e){!e||e===m||!i||!i.postMessage||(Fe=e,Yt(e))}function be(){if(!(!g||!i||!i.appView||!i.appView.breadcrumb)){var e=A()&&m?[{id:Gr(m),title:U||n("common.markdownDocDefault"),icon:"file-text"}]:[];i.appView.breadcrumb.set(e).catch(function(){})}}function Xr(){Ta||!i||!i.appView||!i.appView.breadcrumb||(Ta=!0,i.appView.breadcrumb.onNavigate(function(e){if(!e.id){A()&&nt().then(be);return}var t=Ua(e.id);t?Va(t):i.appView.breadcrumb.set([]).catch(function(){})}),i.appView.breadcrumb.onRestore(function(e){var t=Array.isArray(e.levels)?e.levels:[];if(!t.length){A()&&nt().then(be);return}var a=t.length===1&&Ua(t[0].id);if(!a){i.appView.breadcrumb.set([]).catch(function(){}),A()&&nt().then(be);return}Va(a)}))}function Yr(){var e=[{id:"style:kami",label:"Kami"},{id:"style:bauhaus",label:"Bauhaus"},{id:"style:blueprint",label:"Blueprint"},{id:"style:botanical",label:"Botanical"},{id:"style:newsprint",label:"Newsprint"},{id:"style:retro",label:"Retro"},{id:"style:sketch",label:"Sketch"},{id:"style:terminal",label:"Terminal"},{id:"style-sep",label:"",separator:!0}],t=L==="custom"&&!!R&&!W.some(function(s){return s&&s.css===R});if(t){for(var a=0;a<3;a++)e.push({id:"style:slot-save:"+a,label:n("aiStyle.saveToSlot",{n:a+1})});e.push({id:"style-save-sep",label:"",separator:!0})}for(var r=0;r<3;r++){var o=W[r];e.push(o?{id:"style:slot-use:"+r,label:n("toolbar.style.customSlot",{n:r+1,label:o.label})}:{id:"style:slot-use:"+r,label:n("toolbar.style.customSlotEmpty",{n:r+1}),disabled:!0})}return e}function Kr(){var e="ext:markdown-editor-icons/save",t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDefault");O?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):Pe&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=A();return[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:m||U||n("toolbar.open.tooltipDefault"),disabled:Y},{id:"save",icon:e,label:t,tooltip:a,disabled:!O},{type:"separator"},{id:"mode",icon:Ve?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?Ve?"toolbar.mode.tooltipRendering":x==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:x==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(x==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:x!=="preview",items:Yr()},{type:"spacer"},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?D?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:D,disabled:!r||x==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?x==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||x==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!B},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:B},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:z===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:z===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:z===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:J==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:J==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:x!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"recentSession",label:n("toolbar.more.recentSession"),disabled:!me},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}]}function F(e,t,a,r){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+(r?" disabled":"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function _a(){if(dt){var e=["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"],t=e.map(function(s){return F("style:"+s,s[0].toUpperCase()+s.slice(1),L===s)}).join("")+"<hr>",a=L==="custom"&&!!R&&!W.some(function(s){return s&&s.css===R});a&&(t+=[0,1,2].map(function(s){return F("style:slot-save:"+s,n("aiStyle.saveToSlot",{n:s+1}),!1)}).join("")+"<hr>");for(var r=0;r<3;r++){var o=W[r];t+=o?F("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),L==="custom"&&R===o.css):F("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}dt.innerHTML=t}pt&&(pt.innerHTML=F("comfort:read",n("toolbar.comfort.read"),!B)+F("comfort:write",n("toolbar.comfort.write"),B)+"<hr>"+F("font-size:14",n("toolbar.fontSize.small"),z===14)+F("font-size:16",n("toolbar.fontSize.medium"),z===16)+F("font-size:18",n("toolbar.fontSize.large"),z===18)+"<hr>"+F("font-family:rounded",n("toolbar.fontFamily.default"),J==="rounded")+F("font-family:songti",n("toolbar.fontFamily.serif"),J==="songti")),ft&&(ft.innerHTML=F("reload",n("toolbar.more.reload"),!1)+F("reveal",n("toolbar.more.reveal"),!1)+F("recentSession",n("toolbar.more.recentSession"),!1,!me)+"<hr>"+F("about",n("toolbar.more.about"),!1))}function Jr(){if(g){var e=A();if(re){re.disabled=!O,re.classList.toggle("dirty",O);var t=Pe?"toolbar.save.tooltipSaved":O?"toolbar.save.tooltipDirty":"toolbar.save.tooltipDefault";re.setAttribute("data-tooltip",n(t));var a=re.querySelector(".ic-save"),r=re.querySelector(".ic-save-check");a&&(a.hidden=Pe),r&&(r.hidden=!Pe)}if(de){de.disabled=!e,de.classList.toggle("checked",D);var o=n(D?"appview.focusExit":"appview.focus");de.setAttribute("data-tooltip",o),de.setAttribute("aria-label",o)}Ne&&(Ne.disabled=!e,Ne.classList.toggle("checked",G)),ct&&(ct.disabled=Y),ut&&(ut.disabled=!e||!G,ut.setAttribute("data-tooltip",n(G?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),Nt&&(Nt.disabled=!e),_a()}}function k(){g?Jr():i&&i.postMessage({type:"setToolbar",toolbar:Kr()})}function Ke(e){if(T(),g){x="edit",De(),X(),k();return}x=e,De(),k(),x==="preview"&&X()}function $r(e){return!i||!i.postMessage?Promise.reject(new Error("No host bridge.")):new Promise(function(t,a){var r=new FileReader;r.onload=function(){var o=typeof r.result=="string"?r.result:"",s=o.indexOf(","),l=s>=0?o.slice(s+1):"";if(!l){a(new Error("Could not read pasted image."));return}var u=++Pr;ve[u]={resolve:t,reject:a},setTimeout(function(){ve[u]&&(delete ve[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:l,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var p=window.MarkdownCodeMirror.create({parent:ke,value:h,onChange:function(e){h=e,T(),Ye(),Oe(!0),lr(),sn()},onOpenLink:function(e){i&&i.postMessage&&i.postMessage({type:"openLink",url:e})},onOpenImage:function(e){if(!(!i||!i.postMessage)){try{var t=new URL(e);if(t.protocol==="finch-file:"&&t.hostname==="local"){var a=t.searchParams.get("path");if(a){i.postMessage({type:"openImage",path:a});return}}}catch{}i.postMessage({type:"openImage",url:e})}},onPasteImage:$r,onAiHintTrigger:En,onAiWorkingCancel:function(){!g||!H||!m||!i||!i.postMessage||i.postMessage({type:"cancelRewrite",path:m,sessionId:H.sessionId,turnId:H.turnId})}});p.setFontSize(z),p.setFontFamily(Ie[J]),p.setComfortWriting(B),p.setFocusMode(D),document.body.classList.toggle("focus-mode",D),p.scrollDOM.addEventListener("scroll",T);function Zr(){return L==="custom"?R:""}var ja="user-content-mdl-",Kt=0,Jt={side:"",value:-1,at:0},Je={editor:!1,preview:!1},Te=[];function Qr(e){if(!g)return e;for(var t=e.split(`
|
|
10
|
+
Give a drop-in replacement snippet first; once I confirm, write it back to the source file ({path}) as a targeted local replacement, not a full resend of the document.`,"annotate.reminder":"Only propose the rewrite \u2014 don't write to the source file before I confirm. Reply in natural language (e.g. \u201CI'll put it into the file once you confirm\u201D); never name the tool or its actions. [MANDATORY, not optional] Whenever this turn proposes a rewrite and is waiting on my confirmation, calling Session action=suggest with 1\u20133 one-tap confirmations (e.g. \u201CUse this one\u201D, \u201CUse the shorter version\u201D, \u201CTry another tone\u201D) is part of completing that same turn \u2014 writing the proposal text is only half the job. Do not treat the turn as done, and do not skip the call, just because the proposal text itself was already sent.","newdoc.needChat":"Use \u201CNew Document\u201D from the Finch chat instead.","newdoc.label":"New Markdown Document","newdoc.promptText":"I want to create a new Markdown document. First work out the title, content, and a not-yet-existing absolute save path from my request \u2014 ask me first if anything is missing. Once confirmed, write the full body to that path and open the new document in the editor.","newdoc.reminder":"Only create a new file; never overwrite an existing one. Reply in natural language and never name the tool or its actions. [MANDATORY, not optional] Whenever this turn ends still waiting on me to confirm a title, an angle, or a save location, it must call Session action=suggest with 1\u20133 one-tap options before the turn ends \u2014 asking the question in plain text is not enough on its own; skipping the call leaves the question unfinished.","newdoc.added":"Added the new-document prompt to the composer.","aiStyle.label":"Design a layout based on {file}","aiStyle.note":"One-click AI layout","aiStyle.baseNoteCustom":"The current base style is kami (your custom CSS layers on top of it)","aiStyle.baseNoteOther":"The current base style is {style}","aiStyle.pathMissing":"(No local file linked)","aiStyle.promptText":'Please design a custom layout CSS for this WeChat article. {baseNote}, and your CSS will layer on top of the base style. Requirements: write plain CSS rules only, with selectors scoped to tags/structure under #bm-md (e.g. #bm-md h1, #bm-md p, #bm-md blockquote, #bm-md pre code, #bm-md a, #bm-md strong, #bm-md table); don\u2019t use classes (bm.md\u2019s output has no classes, only inline styles), and use !important where needed to override the base style. You can draw on bm.md\u2019s built-in style language: kami (warm paper feel), bauhaus (geometric color-blocking), blueprint (technical grid), botanical (fresh green), newsprint (editorial serif), retro (nostalgic), sketch (hand-drawn), terminal (monospace dark). Article path: {path}. Once it\u2019s ready, call set_style directly (pass path="{path}", css, and a short label, no slot \u2014 passing path lets it find the right preview panel for this document even if I\u2019ve switched away) \u2014 don\u2019t ask me which slot to use first; the panel will pop up a lightweight \u201Csave as custom style\u201D button so I can decide after seeing the result.',"aiStyle.reminder":"Don\u2019t ask which slot to use before applying \u2014 just design it and call set_style (without slot) to apply it to the preview; whether to save it is for me to decide from the panel. Reply in natural language and never name the tool or its actions.","aiStyle.requested":"Asked AI to design a custom layout.","aiStyle.applied":"AI designed a layout and applied it to the preview.","aiStyle.saveToSlot":"Save as style {n}","aiStyle.appViewDesigning":"AI is designing a layout\u2026","aiStyle.appViewDone":"Layout design finished.","aiStyle.appViewFailed":"Layout design did not finish.","status.saved":"Saved.","status.savedWithNewChanges":"Saved \u2014 but the editor already has newer changes.","status.saveFailed":"Save failed: {err}","status.saving":"Saving\u2026","status.noSourceFile":"Not linked to a local file: click \u201COpen\u201D in the toolbar again to link it and enable saving.","status.pickerTimeout":'The file picker took too long to respond and switched to the in-browser picker \u2014 please click "Open" again.',"status.externalUpdateSkipped":"Detected an external file update; not loaded yet to avoid overwriting unsaved changes.","status.draftRestored":'Restored your last unsaved edits (differs from the file on disk). To discard, click "Open" and pick this file again, then choose "Discard".',"status.draftConflict":"A local unsaved draft exists, but the file was changed and saved elsewhere; loaded the latest file content \u2014 the draft is kept, not discarded.","status.sourceMissing":"The original file was moved or deleted; your content is still here \u2014 saving will recreate the file at its original path.","status.externalUpdateApplied":"Detected a file update and refreshed.","status.openingPicker":"Opening the file picker\u2026","status.opening":"Opening\u2026","status.opened":"Opened {file}.","status.contentUpdated":"Content updated.","status.contentUpdatedLine":"Updated line {line}.","status.contentUpdatedLines":"Updated lines {from}\u2013{to}.","status.contentUpdatedSpots":"Updated {count} spots, {lines} lines in total.","status.pasteImageTimeout":"Paste image timed out","status.pasteImageFailed":"Paste image failed: {msg}","status.clipboardPrepareTimeout":"Preparing WeChat images timed out","status.pleaseOpenArticle":"Open an article first.","status.copiedRich":"Rich HTML copied \u2014 paste it directly into the WeChat editor.","status.copiedPlainOnly":"Only plain text was copied; formatting didn't come through \u2014 please try again.","status.copyFailed":"Copy failed \u2014 please try again.","status.richCopyFailed":"Rich-text copy failed: {err}","status.clipboardUnsupported":"Copying images isn\u2019t supported here \u2014 use \u201CExport Image\u201D instead.","status.generatingImage":"Generating image\u2026","status.previewNotReady":"Preview isn't ready yet","status.imageCopied":"Image copied to the clipboard.","status.copyImageFailed":"Copy image failed: {err} (try \u201CExport Image\u201D instead)","status.exportImageFailedGeneric":"Export image failed: preview isn't ready yet.","status.exportImageFailed":"Export image failed: {err}","status.generatingPdf":"Generating PDF\u2026","status.exportPdfFailedGeneric":"Export PDF failed: preview isn't ready yet.","status.exportPdfFailed":"Export PDF failed: {err}","status.exported":"Exported: {path}","status.annotateOn":"Annotate is on \u2014 select text to ask AI to revise it.","status.annotateOff":"Annotate is off.","status.comfortWrite":"Comfortable mode is on \u2014 roomier line spacing.","status.comfortRead":"Compact mode is on.","status.focusOn":"Focus mode is on \u2014 inactive lines are dimmed.","status.focusOff":"Focus mode is off.","status.saveFailedNoReturn":"Save failed \u2014 staying on this document.","status.rendererAboutPrefix":"Renderer: local bmmd CLI (","status.rendererAboutSuffix":", LGPL-3.0).","status.appliedStyleSlot":"Applied \u201C{label}\u201D.","status.needCustomStyleFirst":"Apply a custom/AI-designed style first before saving it to a slot.","status.savedToSlot":"Saved to slot {slot}: {label}","status.serializeFailed":"Failed to serialize the preview content: {err}","status.imageConversionFailed":"The preview couldn't be converted to an image (it may contain external images that can't be read cross-origin)","status.imageGenFailed":"Failed to generate image data","status.clipboardPrepareFailedDefault":"Failed to prepare WeChat images","status.pasteImageFailedDefault":"Paste image failed","status.savedAppliedToSlot":"{labelPrefix}Saved and applied to custom style {slot}."}};function n(e,t){var a=it?st.zh:st.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(st.en,e)?st.en[e]:e;if(t)for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r=r.split("{"+o+"}").join(String(t[o])));return r}function Ft(e){var t=e||document;document.documentElement.lang=it?"zh-CN":"en",document.title=n("meta.title"),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n]"),function(a){a.textContent=n(a.getAttribute("data-i18n"))}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-title]"),function(a){a.title=n(a.getAttribute("data-i18n-title"))}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-tooltip]"),function(a){var r=n(a.getAttribute("data-i18n-tooltip"));a.setAttribute("data-tooltip",r),a.setAttribute("aria-label",r)}),Array.prototype.forEach.call(t.querySelectorAll("[data-i18n-aria]"),function(a){a.setAttribute("aria-label",n(a.getAttribute("data-i18n-aria")))})}var Tt=document.getElementById("empty"),ha=document.getElementById("emptyNew"),ya=document.getElementById("emptyOpen"),Pt=document.getElementById("homeRecent"),le=document.getElementById("homeGrid"),lt=document.getElementById("homeHint"),Ot=[],ba=document.getElementById("homeTagline"),Ir=document.getElementById("editPane"),Rt=document.getElementById("previewPane"),ce=document.getElementById("previewResizer"),ke=document.getElementById("editor"),y=document.getElementById("article"),M=document.getElementById("status"),L=document.getElementById("popup"),_=document.getElementById("popupInput"),wa=document.getElementById("popupSend"),Sa=document.getElementById("popupShortcut"),Re=document.getElementById("actions"),Ar=document.getElementById("actCopyWx"),Cr=document.getElementById("actCopyImg"),Dr=document.getElementById("actSaveImg"),Fr=document.getElementById("actSavePdf"),xe=document.getElementById("actAiStyle"),ka=document.getElementById("actToggle"),ue=document.getElementById("confirmOverlay"),xa=document.getElementById("confirmMessage"),Bt=document.getElementById("confirmCancel"),Nt=document.getElementById("confirmDiscard"),Be=document.getElementById("confirmSave"),Ea=document.getElementById("appToolbar"),Ma=document.getElementById("appHome"),La=document.getElementById("appLibrary"),ct=document.getElementById("appOpen"),re=document.getElementById("appSave"),Ne=document.getElementById("appPreview"),ut=document.getElementById("appStyle"),dt=document.getElementById("appStyleMenu"),de=document.getElementById("appFocus"),qt=document.getElementById("appFont"),pt=document.getElementById("appFontMenu"),Tr=document.getElementById("appMore"),ft=document.getElementById("appMoreMenu"),Ht=document.getElementById("libraryDrawer"),mt=document.getElementById("libraryBackdrop"),Ia=document.getElementById("libraryClose"),vt=document.getElementById("libraryReorder"),Aa=document.getElementById("libraryReorderFooter"),Ca=document.getElementById("libraryReorderDone"),C=document.getElementById("libraryGroups"),Da="md-editor-library-groups-v1",pe=[],Ee={},fe=null,qe=null,ne=!1,He=[],j=null,Wt=!1,g=!1,Fa=!1,Ta=!1,H=null,me=null,G=!0,Pr=!1,gt=0,We=!1,te=!0,x="edit",I="kami",R="",Me="",W=[null,null,null],Le={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},z=14,J="rounded",B=!1,D=!1;try{var ht=Number(localStorage.getItem("md-editor-font-size"));(ht===14||ht===16||ht===18)&&(z=ht);var zt=localStorage.getItem("md-editor-font-family");Le[zt]?J=zt:zt&&localStorage.removeItem("md-editor-font-family"),B=localStorage.getItem("md-editor-comfort-writing")==="1",D=localStorage.getItem("md-editor-focus-mode")==="1";var ze=JSON.parse(localStorage.getItem(Da)||"{}");Array.isArray(ze.order)&&(pe=ze.order.filter(function(e){return typeof e=="string"})),ze.collapsed&&typeof ze.collapsed=="object"&&(Ee=ze.collapsed)}catch{}te=!D;var h="",Ue="",U="",m="",P=null,N="",Ie=!1,Pa=0,Ve=!1,Oa=0,Ut={},Ae={},Or=0,ve={},Rr=0,ge={},_e=0,$=null,yt=0,Ce=0,Vt=!1,w={text:"",mode:"replace"},E=0;function c(e,t){E&&(clearTimeout(E),E=0),M.textContent=e||"",M.className="status"+(t?" error":""),e&&(E=setTimeout(function(){E=0,M.textContent="",M.className="status"},5e3))}function he(e,t,a,r){if(E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(e||"")),M.className="status"+(t?" error":""),a){var o=document.createElement("button");o.type="button",o.className="status-inline-btn",o.textContent=n("appview.openSession"),o.addEventListener("click",function(){i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(a)}),M.appendChild(o)}r&&(E=setTimeout(function(){E=0,M.replaceChildren(),M.className="status"},r))}function Br(){E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(n("status.rendererAboutPrefix")));var e=document.createElement("a");e.href="https://bm.md/",e.textContent="bm.md",e.title="https://bm.md/",e.addEventListener("click",function(t){t.preventDefault(),i&&i.postMessage&&i.postMessage({type:"openLink",url:"https://bm.md/"})}),M.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),M.className="status",E=setTimeout(function(){E=0,M.textContent="",M.className="status"},5e3)}function A(){return!!h||!!m}ha&&ha.addEventListener("click",async function(){if(!i||!i.composer){c(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),c(n("newdoc.added"))}catch(e){c(String(e),!0)}}),ya&&ya.addEventListener("click",function(){ia()});var je="",_t="",jt="",bt=!1,Ra=!1,Ge="",ye="";function S(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function Ba(){ba&&(ba.textContent=Ge?n("home.tagline.withAssistant",{name:Ge}):n("home.tagline.default"))}function wt(){_&&(_.placeholder=w.mode==="continue"?n("popup.placeholderContinue",{name:Ge||"Finch"}):n("popup.placeholder",{name:Ge||"Finch"}))}function Nr(e){return e?ye&&e===ye?"~":ye&&(e.indexOf(ye+"/")===0||e.indexOf(ye+"\\")===0)?"~"+e.slice(ye.length):e:""}function qr(e){var t=46;if(!e||e.length<=t)return e;var a=e.indexOf("/")===-1&&e.indexOf("\\")!==-1?"\\":"/",r=e.slice(-(t-1)),o=r.indexOf(a);return o>0&&o<10&&(r=r.slice(o)),"\u2026"+r}function Hr(){kt(Ot)}function Na(e){var t=new Date(e);if(!e||isNaN(t.getTime()))return"";var a=new Date,r=function(u){return u<10?"0"+u:String(u)},o=r(t.getHours())+":"+r(t.getMinutes()),s=t.toDateString()===a.toDateString();if(s)return n("home.today",{clock:o});var l=new Date(a.getTime()-864e5);return t.toDateString()===l.toDateString()?n("home.yesterday",{clock:o}):t.getFullYear()===a.getFullYear()?r(t.getMonth()+1)+"-"+r(t.getDate()):t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())}function St(){!i||!i.postMessage||!bt||(Ra=!0,i.postMessage({type:"requestRecentDocuments",cwd:je,sessionId:_t,spaceId:jt}))}function Wr(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+S(e.path||"")+'" title="'+S(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+S(e.path||"")+'" role="button" tabindex="0" title="'+S(n("home.revealInFileManager"))+'" aria-label="'+S(n("home.revealInFileManager"))+'"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 14 1.45-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6a2 2 0 0 1-1.94 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/></svg></span><div class="doc-preview">'+S(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+S(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+S(t)+'">'+S(t)+'</span><span class="doc-time">'+S(Na(e.modifiedAt))+"</span></div></div></button>"}function kt(e){if(!(!le||!Pt||!lt)){var t=Array.isArray(e)?e:[];if(Ot=t,t.length===0){Pt.hidden=!0,lt.hidden=!1,lt.textContent=n(je?"home.hintScoped":"home.hintDefault");return}var a=qa(t);le.innerHTML=a.map(function(r){var o=r.documents.map(Wr).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+S(r.scopePath)+'" title="'+S(n("home.cwdTitle",{path:r.scopePath}))+'">'+S(qr(Nr(r.scopePath)))+"</button>":"",l='<div class="home-group-title"><span class="home-group-label">'+S(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+l+'<div class="home-grid">'+o+"</div></div>"}).join(""),Pt.hidden=!1,lt.hidden=!0,requestAnimationFrame(function(){zr(le)})}}function zr(e){for(var t="\u2026",a=e.querySelectorAll("[data-full-path]"),r=0;r<a.length;r++){var o=a[r],s=o.getAttribute("data-full-path")||"";if(o.textContent=s,!(!s||o.scrollWidth<=o.clientWidth+1)){for(var l=0,u=s.length,d=0;l<=u;){var f=l+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(d=f,l=f+1):u=f-1}o.textContent=d>0?t+s.slice(s.length-d):t}}}function Gt(){var e={order:pe,collapsed:Ee};try{localStorage.setItem(Da,JSON.stringify(e))}catch{}i&&i.postMessage&&i.postMessage({type:"saveLibraryGroups",libraryGroups:e})}function qa(e){var t={};return(Array.isArray(e)?e:[]).forEach(function(a){var r=a.scopeKind||"external",o=r==="workspace"?n("appview.libraryWorkspace"):r==="external"?n("appview.libraryOther"):a.scopeLabel||a.spaceName||n("appview.libraryOther"),s=r==="space"?"space:"+(a.spaceId||o):r==="workspace"?"workspace":"external";t[s]||(t[s]={id:s,kind:r,label:o,scopePath:"",documents:[]}),r!=="external"&&!t[s].scopePath&&a.scopePath&&(t[s].scopePath=a.scopePath),t[s].documents.push(a)}),Object.keys(t).map(function(a){return t[a]}).sort(function(a,r){if(a.kind==="external"||r.kind==="external")return a.kind===r.kind?0:a.kind==="external"?1:-1;var o=pe.indexOf(a.id),s=pe.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var l={space:0,workspace:1},u=l[a.kind]-l[r.kind];return u||a.label.localeCompare(r.label)})}function Xt(e){if(C){He=Array.isArray(e)?e:[];var t=qa(He);if(ne){Ur(t);return}C.innerHTML=t.map(function(a){var r=a.documents.map(function(l){var u=l.relativePath||l.fileName||"";return'<button class="library-row" type="button" data-path="'+S(l.path||"")+'"><span class="library-row-main"><strong>'+S(l.title||l.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+S(u)+'">'+S(u)+"</span><time>"+S(Na(l.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!Ee[a.id];return'<details class="library-group" data-library-group-id="'+S(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+S(a.label)+'</span><span class="library-group-count">'+a.documents.length+'</span></summary><div class="library-items">'+r+"</div></details>"}).join("")||'<p class="home-hint">'+S(n("home.hintDefault"))+"</p>"}}function Ur(e){C.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+S(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+S(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+S(n("home.hintDefault"))+"</p>"}function Yt(e){ne=!!e,vt&&vt.classList.toggle("active",ne),Aa&&(Aa.hidden=!ne),Xt(He)}function xt(e){!Ht||!mt||(Ht.classList.toggle("open",!!e),Ht.setAttribute("aria-hidden",e?"false":"true"),mt.hidden=!e,e?St():ne&&Yt(!1))}function Vr(){if(!(!fe||!C)){fe.classList.remove("dragging"),Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),pe=Array.prototype.map.call(C.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),kt(Ot);var e=qe||{};Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(t){var a=t.getAttribute("data-library-group-id");a in e&&(t.open=!!e[a])}),fe=null,setTimeout(function(){qe=null,Gt()},0)}}function _r(){j&&j.ghost&&j.ghost.parentNode&&j.ghost.parentNode.removeChild(j.ghost)}function Ha(e,t){var a=j;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function jr(e){var t=j;if(!(!t||t.active)){t.active=!0,fe=e,qe={},ne||Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(qe[s]=!!o.open),o.open=!1}),e.classList.add("dragging");var a=e.getBoundingClientRect(),r=e.cloneNode(!0);r.classList.add("library-drag-ghost"),r.classList.remove("dragging"),r.style.width=a.width+"px",t.ghost=r,t.offsetX=t.startX-a.left,t.offsetY=t.startY-a.top,document.body.appendChild(r),Ha(t.startX,t.startY)}}function Gr(e,t){if(fe){var a=document.elementFromPoint(e,t),r=a&&a.closest?a.closest('.library-group[data-draggable="true"]'):null;if(Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(s){s.classList.remove("drag-over")}),!(!r||r===fe)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;C.insertBefore(fe,o?r.nextSibling:r)}}}function Wa(){var e=j;e&&(e.active&&(_r(),Vr(),Wt=!0,setTimeout(function(){Wt=!1},0)),j=null)}La&&La.addEventListener("click",function(){xt(!0)}),Ia&&Ia.addEventListener("click",function(){xt(!1)}),mt&&mt.addEventListener("click",function(){xt(!1)}),vt&&vt.addEventListener("click",function(){Yt(!ne)}),Ca&&Ca.addEventListener("click",function(){Yt(!1)}),C&&C.addEventListener("click",function(e){var t=e.target&&e.target.closest?e.target.closest(".library-row"):null,a=t&&t.getAttribute("data-path");!a||!i||!i.postMessage||(xt(!1),Xe=!0,c(n("status.opening")),Kt(a))}),C&&(C.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!qe){var a=t.getAttribute("data-library-group-id");a&&(Ee[a]=!t.open,Gt())}},!0),C.addEventListener("click",function(e){if(Wt){var t=e.target&&e.target.closest?e.target.closest(".library-group summary"):null;t&&(e.preventDefault(),e.stopPropagation())}},!0),C.addEventListener("pointerdown",function(e){if(e.button===0&&ne){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(j={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=j;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;jr(t.group)}e.preventDefault(),Ha(e.clientX,e.clientY),Gr(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){Wa()}),window.addEventListener("pointercancel",function(){Wa()}));var Xe=!1,Et="";function Kt(e){!e||!i||!i.postMessage||(Et=e,i.postMessage({type:"loadPath",path:e}))}le&&le.addEventListener("click",function(e){if(!(!i||!i.postMessage)){var t=e.target&&e.target.closest?e.target.closest(".home-group-cwd"):null;if(t){var a=t.getAttribute("data-cwd-path")||"";a&&i.postMessage({type:"openPath",path:a});return}var r=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(r){e.preventDefault(),e.stopPropagation();var o=r.getAttribute("data-reveal-path")||"";o&&i.postMessage({type:"openPath",path:o});return}var s=e.target&&e.target.closest?e.target.closest(".doc-card"):null;if(s){var l=s.getAttribute("data-path")||"";l&&(Xe=!0,c(n("status.opening")),Kt(l))}}}),le&&le.addEventListener("keydown",function(e){if(!(e.key!=="Enter"&&e.key!==" ")){var t=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(!(!t||!i||!i.postMessage)){e.preventDefault(),e.stopPropagation();var a=t.getAttribute("data-reveal-path")||"";a&&i.postMessage({type:"openPath",path:a})}}});function Ye(){Tt.hidden=A(),document.body.classList.toggle("has-document",A()),Re&&(Re.hidden=!N),!Tt.hidden&&bt&&St()}function De(){Ir.classList.toggle("active",g?A():x==="edit"),Rt.classList.toggle("active",g?A():x==="preview"),(g||x==="edit")&&p&&requestAnimationFrame(function(){p.layout()})}function za(e){g||!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function Xr(e){return e?"document:"+encodeURIComponent(e):""}function Ua(e){if(!e||e.indexOf("document:")!==0)return"";try{var t=decodeURIComponent(e.slice(9));return/^(?:\/|[A-Za-z]:[\\/])/.test(t)?t:""}catch{return""}}var Fe="";function Va(e){!e||e===m||!i||!i.postMessage||(Fe=e,Kt(e))}function be(){if(!(!g||!i||!i.appView||!i.appView.breadcrumb)){var e=A()&&m?[{id:Xr(m),title:U||n("common.markdownDocDefault"),icon:"file-text"}]:[];i.appView.breadcrumb.set(e).catch(function(){})}}function Yr(){Ta||!i||!i.appView||!i.appView.breadcrumb||(Ta=!0,i.appView.breadcrumb.onNavigate(function(e){if(!e.id){A()&&nt().then(be);return}var t=Ua(e.id);t?Va(t):i.appView.breadcrumb.set([]).catch(function(){})}),i.appView.breadcrumb.onRestore(function(e){var t=Array.isArray(e.levels)?e.levels:[];if(!t.length){A()&&nt().then(be);return}var a=t.length===1&&Ua(t[0].id);if(!a){i.appView.breadcrumb.set([]).catch(function(){}),A()&&nt().then(be);return}Va(a)}))}function Kr(){var e=[{id:"style:kami",label:"Kami"},{id:"style:bauhaus",label:"Bauhaus"},{id:"style:blueprint",label:"Blueprint"},{id:"style:botanical",label:"Botanical"},{id:"style:newsprint",label:"Newsprint"},{id:"style:retro",label:"Retro"},{id:"style:sketch",label:"Sketch"},{id:"style:terminal",label:"Terminal"},{id:"style-sep",label:"",separator:!0}],t=I==="custom"&&!!R&&!W.some(function(s){return s&&s.css===R});if(t){for(var a=0;a<3;a++)e.push({id:"style:slot-save:"+a,label:n("aiStyle.saveToSlot",{n:a+1})});e.push({id:"style-save-sep",label:"",separator:!0})}for(var r=0;r<3;r++){var o=W[r];e.push(o?{id:"style:slot-use:"+r,label:n("toolbar.style.customSlot",{n:r+1,label:o.label})}:{id:"style:slot-use:"+r,label:n("toolbar.style.customSlotEmpty",{n:r+1}),disabled:!0})}return e}function Jr(){var e="ext:markdown-editor-icons/save",t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDefault");O?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):Pe&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=A();return[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:m||U||n("toolbar.open.tooltipDefault"),disabled:Y},{id:"save",icon:e,label:t,tooltip:a,disabled:!O},{type:"separator"},{id:"mode",icon:Ve?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?Ve?"toolbar.mode.tooltipRendering":x==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:x==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(x==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:x!=="preview",items:Kr()},{type:"spacer"},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?D?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:D,disabled:!r||x==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?x==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||x==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!B},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:B},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:z===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:z===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:z===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:J==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:J==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:x!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"recentSession",label:n("toolbar.more.recentSession"),disabled:!me},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}]}function F(e,t,a,r){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+(r?" disabled":"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function _a(){if(dt){var e=["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"],t=e.map(function(s){return F("style:"+s,s[0].toUpperCase()+s.slice(1),I===s)}).join("")+"<hr>",a=I==="custom"&&!!R&&!W.some(function(s){return s&&s.css===R});a&&(t+=[0,1,2].map(function(s){return F("style:slot-save:"+s,n("aiStyle.saveToSlot",{n:s+1}),!1)}).join("")+"<hr>");for(var r=0;r<3;r++){var o=W[r];t+=o?F("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),I==="custom"&&R===o.css):F("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}dt.innerHTML=t}pt&&(pt.innerHTML=F("comfort:read",n("toolbar.comfort.read"),!B)+F("comfort:write",n("toolbar.comfort.write"),B)+"<hr>"+F("font-size:14",n("toolbar.fontSize.small"),z===14)+F("font-size:16",n("toolbar.fontSize.medium"),z===16)+F("font-size:18",n("toolbar.fontSize.large"),z===18)+"<hr>"+F("font-family:rounded",n("toolbar.fontFamily.default"),J==="rounded")+F("font-family:songti",n("toolbar.fontFamily.serif"),J==="songti")),ft&&(ft.innerHTML=F("reload",n("toolbar.more.reload"),!1)+F("reveal",n("toolbar.more.reveal"),!1)+F("recentSession",n("toolbar.more.recentSession"),!1,!me)+"<hr>"+F("about",n("toolbar.more.about"),!1))}function $r(){if(g){var e=A();if(re){re.disabled=!O,re.classList.toggle("dirty",O);var t=Pe?"toolbar.save.tooltipSaved":O?"toolbar.save.tooltipDirty":"toolbar.save.tooltipDefault";re.setAttribute("data-tooltip",n(t));var a=re.querySelector(".ic-save"),r=re.querySelector(".ic-save-check");a&&(a.hidden=Pe),r&&(r.hidden=!Pe)}if(de){de.disabled=!e,de.classList.toggle("checked",D);var o=n(D?"appview.focusExit":"appview.focus");de.setAttribute("data-tooltip",o),de.setAttribute("aria-label",o)}Ne&&(Ne.disabled=!e,Ne.classList.toggle("checked",G)),ct&&(ct.disabled=Y),ut&&(ut.disabled=!e||!G,ut.setAttribute("data-tooltip",n(G?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),qt&&(qt.disabled=!e),_a()}}function k(){g?$r():i&&i.postMessage({type:"setToolbar",toolbar:Jr()})}function Ke(e){if(T(),g){x="edit",De(),X(),k();return}x=e,De(),k(),x==="preview"&&X()}function Zr(e){return!i||!i.postMessage?Promise.reject(new Error("No host bridge.")):new Promise(function(t,a){var r=new FileReader;r.onload=function(){var o=typeof r.result=="string"?r.result:"",s=o.indexOf(","),l=s>=0?o.slice(s+1):"";if(!l){a(new Error("Could not read pasted image."));return}var u=++Or;ve[u]={resolve:t,reject:a},setTimeout(function(){ve[u]&&(delete ve[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:l,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var p=window.MarkdownCodeMirror.create({parent:ke,value:h,onChange:function(e){h=e,T(),Ye(),Oe(!0),cr(),ln()},onOpenLink:function(e){i&&i.postMessage&&i.postMessage({type:"openLink",url:e})},onOpenImage:function(e){if(!(!i||!i.postMessage)){try{var t=new URL(e);if(t.protocol==="finch-file:"&&t.hostname==="local"){var a=t.searchParams.get("path");if(a){i.postMessage({type:"openImage",path:a});return}}}catch{}i.postMessage({type:"openImage",url:e})}},onPasteImage:Zr,onAiHintTrigger:Mn,onAiWorkingCancel:function(){!g||!H||!m||!i||!i.postMessage||i.postMessage({type:"cancelRewrite",path:m,sessionId:H.sessionId,turnId:H.turnId})}});p.setFontSize(z),p.setFontFamily(Le[J]),p.setComfortWriting(B),p.setFocusMode(D),document.body.classList.toggle("focus-mode",D);var ja=0;p.scrollDOM.addEventListener("scroll",function(){T(),p.scrollDOM.classList.add("cm-scrollbar-active"),window.clearTimeout(ja),ja=window.setTimeout(function(){p.scrollDOM.classList.remove("cm-scrollbar-active")},800)});function Qr(){return I==="custom"?R:""}var Ga="user-content-mdl-",Jt=0,$t={side:"",value:-1,at:0},Je={editor:!1,preview:!1},Te=[];function en(e){if(!g)return e;for(var t=e.split(`
|
|
11
11
|
`),a=[],r=!1,o=0;o<t.length;o++){var s=t[o],l=/^[ \t]*(?:```|~~~)/.test(s),u=o+1;if(l){r=!r,a.push(s);continue}var d=s.trim(),f=r||d===""||/\\\s*$/.test(s)||/^<[a-zA-Z!]/.test(d)||/^!\[[^\]]*\]\([^)]*\)\s*$/.test(d)||/^\s*\|/.test(s)&&/[|]\s*$/.test(s),b=!f&&/[|]/.test(s)&&o+1<t.length&&/^[ \t]*\|?[\s:|-]+\|?[ \t]*$/.test(t[o+1])&&/-/.test(t[o+1]);if(b){a.push(s);for(var v=o+1;v<t.length&&/[|]/.test(t[v]);)a.push(t[v]),v++;o=v-1;continue}a.push(f?s:s+'<a id="mdl-'+u+'"></a>')}return a.join(`
|
|
12
|
-
`)}function
|
|
12
|
+
`)}function Zt(){if(Te=[],Z=null,!(!g||!Ie)){var e=y.contentDocument;if(e){var t=e.querySelector("#bm-md");if(t){for(var a=e.querySelectorAll('a[id^="'+Ga+'"]'),r=0;r<a.length;r++){var o=a[r].id,s=Number(o.slice(Ga.length));!Number.isFinite(s)||s<1||t.contains(a[r])&&Te.push({line:s,el:a[r]})}Te.sort(function(l,u){return l.line-u.line}),Z=null}}}}function Xa(){var e=y.contentDocument;return e&&e.scrollingElement?e.scrollingElement.scrollTop:0}function tn(e){var t=y.contentDocument;if(!(!t||!t.scrollingElement)){var a=t.scrollingElement,r=Math.max(0,Math.min(e,a.scrollHeight-a.clientHeight));Math.abs(a.scrollTop-r)<1||($t={side:"preview",value:r,at:Date.now()},a.scrollTop=r)}}function an(e){if(!e)return 0;var t=y.contentDocument,a=t&&t.scrollingElement;return e.getBoundingClientRect().bottom+(a?a.scrollTop:0)}var Z=null;function rn(){if(Z=null,!Te.length||!p||!p.scrollDOM)return null;var e=y.contentDocument,t=e&&e.scrollingElement;if(!t)return null;var a=Math.max(0,p.scrollDOM.scrollHeight-p.scrollDOM.clientHeight),r=Math.max(0,t.scrollHeight-t.clientHeight);if(a<=0||r<=0)return null;for(var o=[0],s=[0],l=0;l<Te.length;l++){var u=Te[l],d=p.lineBottom(u.line);if(d!=null){var f=an(u.el);if(!(!(d>o[o.length-1]+1)||!(f>s[s.length-1]+1))){if(d>=a||f>=r)break;o.push(d),s.push(f)}}}return o.push(a),s.push(r),Z={e:o,p:s,eMax:a,pMax:r,pHeight:t.scrollHeight,eHeight:p.scrollDOM.scrollHeight},Z}function nn(){var e=y.contentDocument,t=e&&e.scrollingElement;return!t||!p||!p.scrollDOM?null:!Z||Z.pHeight!==t.scrollHeight||Z.eHeight!==p.scrollDOM.scrollHeight?rn():Z}function Ya(e,t,a){var r=e.length;if(!r)return a;if(a<=e[0])return t[0];if(a>=e[r-1])return t[r-1];for(var o=0,s=r-1;o<s-1;){var l=o+s>>1;e[l]<=a?o=l:s=l}var u=e[s]-e[o]||1;return t[o]+(a-e[o])/u*(t[s]-t[o])}function Ka(e){Je[e]=!0,!Jt&&(Jt=requestAnimationFrame(function(){Jt=0,on()}))}function Ja(e){var t=$t;if(t.side!==e||Date.now()-t.at>300)return!1;var a=e==="editor"?p.scrollDOM.scrollTop:Xa();return!(Math.abs(t.value-a)>2)}function on(){var e=Je.editor,t=Je.preview;if(Je.editor=!1,Je.preview=!1,!(!g||!A()||!G)){var a=nn();if(a){if(e)tn(Ya(a.e,a.p,p.scrollDOM.scrollTop));else if(t){var r=Ya(a.p,a.e,Xa());$t={side:"editor",value:r,at:Date.now()},Math.abs(p.scrollDOM.scrollTop-r)>=1&&(p.scrollDOM.scrollTop=r)}}}}function sn(){Ja("editor")||!g||!A()||!G||Ka("editor")}function $a(){Ja("preview")||!g||!A()||!G||Ka("preview")}function ln(){g&&(gt&&clearTimeout(gt),gt=setTimeout(function(){gt=0,X()},420))}function X(){if(!(!h||!i)){var e=++Pa;Ve=!0,k(),i.postMessage({type:"renderBm",markdown:en(h),markdownStyle:I==="custom"?"kami":I,customCss:Qr(),requestId:e})}}function cn(){var e=y.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function un(e){var t=y.contentDocument,a=t&&t.scrollingElement;!e||!a||(a.scrollTop=Math.min(e.top,Math.max(0,a.scrollHeight-a.clientHeight)))}function dn(){try{return getComputedStyle(y).backgroundColor||""}catch{return""}}function pn(e,t,a){var r=Math.min(3,Math.max(2,(window.devicePixelRatio||1)*2)),o;try{o=new XMLSerializer().serializeToString(e)}catch(l){return Promise.reject(l)}var s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.max(1,Math.round(t*r)),f.height=Math.max(1,Math.round(a*r));var b=f.getContext("2d");b.scale(r,r);var v="";try{v=getComputedStyle(e).backgroundColor}catch{v=""}v&&v!=="rgba(0, 0, 0, 0)"&&v!=="transparent"&&(b.fillStyle=v,b.fillRect(0,0,t,a)),b.drawImage(d,0,0,t,a),l(f.toDataURL("image/png"))}catch(q){u(q)}},d.onerror=function(){u(new Error("svg rasterize failed"))},d.src=s})}function Za(){if(!(!Ie||!y.contentDocument||!y.contentDocument.body)){var e=y.contentDocument,t=Array.prototype.slice.call(e.querySelectorAll("figure.figure-mermaid > svg, figure.figure-infographic > svg"));t.length&&Promise.all(t.map(function(a){var r=a.closest("figure"),o=a.getBoundingClientRect(),s=Math.ceil(o.width)||a.viewBox&&a.viewBox.baseVal&&a.viewBox.baseVal.width||600,l=Math.ceil(o.height)||a.viewBox&&a.viewBox.baseVal&&a.viewBox.baseVal.height||400;return pn(a,s,l).then(function(u){var d=e.createElement("img");d.src=u,d.alt=r&&r.classList.contains("figure-infographic")?"Infographic":"Mermaid diagram",d.style.display="block",d.style.width="100%",d.style.height="auto",a.replaceWith(d)}).catch(function(){})})).then(function(){e.body&&(N=e.body.innerHTML)})}}function Qa(e){var t=cn(),a=y.contentDocument;N=e;var r=dn();if(Ie&&a&&a.body){a.body.innerHTML=N,r&&(a.body.style.background=r),un(t),tr(),Zt(),Za();return}y.srcdoc='<!doctype html><meta charset="utf-8"><base target="_blank"><style>html,body{margin:0!important;padding:0!important;min-height:100%}body{background:'+(r||"transparent")+"}#bm-md{min-height:100dvh}</style><body>"+N}function er(e,t,a){return{start:e.slice(0,t).split(`
|
|
13
13
|
`).length,end:e.slice(0,a).split(`
|
|
14
|
-
`).length}}function
|
|
15
|
-
`;if(s){var l=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(l){o+=l[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var d=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(d){for(var f=o+d[0].indexOf("[")+1,b=0;b<d[1].length;b++)/[*_~`]/.test(d[1][b])||r(d[1][b],f+b);o+=d[0].length;continue}var v=/^<[^>]+>/.exec(e.slice(o));if(v){o+=v[0].length;continue}if(e[o]==="\\"&&o+1<e.length){r(e[o+1],o+1),o+=2;continue}if(/[*_~`]/.test(e[o])){o++;continue}r(e[o],o),o++}return pn(t,a)}function mn(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=fn(e),o=t.replace(/\s+/g," ").trim(),s=r.text.indexOf(o);if(s>=0)return{start:r.map[s],end:r.map[s+o.length-1]+1};if(o.length>=12){var l=o.slice(0,6),u=o.slice(-6),d=r.text.indexOf(l),f=r.text.indexOf(u,Math.max(0,d+l.length));if(d>=0&&f>=d)return{start:r.map[d],end:r.map[f+u.length-1]+1}}return null}function vn(e){return String(e||"").split(/[\\/]/).pop()||""}function er(){var e=y.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(te){var a=y.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),l=Array.from(s.getClientRects()),u=y.getBoundingClientRect(),d=l.map(function(V){return{top:u.top+V.top,left:u.left+V.left,width:V.width,height:V.height}}),f=l[0]||s.getBoundingClientRect(),b=l[l.length-1]||f,v=mn(h,o),q=v?Qa(h,v.start,v.end):null;ar(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+b.bottom,endLeft:u.left+b.left},d,q,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){we(),T()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),Ke("edit"))}),e.addEventListener("scroll",function(){we(),T()},!0),y.contentWindow.addEventListener("scroll",function(){we(),T()})}y.onload=function(){Le=!0,er(),$t()};function tr(){p&&p.scrollDOM&&!p.scrollDOM.__scrollSyncBound&&(p.scrollDOM.__scrollSyncBound=!0,p.scrollDOM.addEventListener("scroll",on,{passive:!0}));var e=y.contentDocument;if(e&&!e.__scrollSyncBound){e.__scrollSyncBound=!0;var t=e.scrollingElement||e.documentElement;t&&t.addEventListener("scroll",Ja,{passive:!0}),e.defaultView&&e.defaultView.addEventListener("scroll",Ja,{passive:!0})}}tr(),window.addEventListener("resize",function(){Z=null}),y.addEventListener("load",function(){requestAnimationFrame(function(){Le=!0,$t(),tr(),$a()})});var Mt=0,Zt=[];function ar(e,t,a,r,o){we(),Mt=setTimeout(function(){rr(e,t,a,r,o)},300)}function we(){Mt&&(clearTimeout(Mt),Mt=0)}function rr(e,t,a,r,o,s){w.text=e,w.lines=r||null,w.origin=o||"",w.mode=s||"replace",wt(),I.classList.remove("hidden"),I.classList.toggle("popup-bar",!!(t&&t.width)),_.value="",hn(a),requestAnimationFrame(function(){gn(t),t&&t.focus&&_.focus()})}function gn(e){var t=8,a=10,r=e||{},o=g?t+48:t;if(I.style.width=r.width?r.width+"px":"",r.width){I.style.left=Math.max(t,r.startLeft||0)+"px",I.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(I.offsetHeight||44)-t))+"px";return}var s=I.offsetWidth||300,l=I.offsetHeight||44,u=(r.startTop||0)-a-l,d=u>=o,f=d?u:(r.endBottom||0)+a,b=d?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;I.style.left=Math.max(t,Math.min(b,window.innerWidth-s-t))+"px",I.style.top=Math.max(o,Math.min(f,window.innerHeight-l-t))+"px"}function hn(e){nr(),(e||[]).forEach(function(t){var a=document.createElement("div");a.className="fake-sel",a.style.top=t.top+"px",a.style.left=t.left+"px",a.style.width=t.width+"px",a.style.height=t.height+"px",document.body.appendChild(a),Zt.push(a)})}function nr(){Zt.forEach(function(e){e.remove()}),Zt=[]}var yn=navigator.platform||navigator.userAgent||"",Qt=/Mac|iPhone|iPod|iPad/.test(yn);function bn(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Qt?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(Sa){var t=Qt?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Qt?"":"+";Sa.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function T(e){var t=e===!0&&w.origin==="editor"&&x==="edit";we(),I.classList.add("hidden"),I.classList.remove("popup-bar"),I.classList.remove("focused"),I.style.width="",w.text="",w.lines=null,w.origin="",w.mode="replace",nr(),t&&requestAnimationFrame(function(){p.focus()})}wa.onclick=ir;var or=0;_.addEventListener("compositionend",function(){or=Date.now()});function wn(e){return e.isComposing||e.keyCode===229?!0:Date.now()-or<100}_.addEventListener("keydown",function(e){if(e.key==="Enter"){if(wn(e))return;ir()}e.key==="Escape"&&T(!0)}),_.addEventListener("focus",function(){I.classList.add("focused")}),_.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==wa&&I.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!I.classList.contains("hidden")&&T(!0)}),document.addEventListener("keydown",function(e){bn(e)&&(I.classList.contains("hidden")||(e.preventDefault(),_.focus(),_.select()))}),document.addEventListener("mousedown",function(e){I.contains(e.target)||(we(),T())}),window.addEventListener("resize",T);function Sn(){if(!w.lines)return n("annotate.lineUnknown");var e=w.lines.start,t=w.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function kn(){return w.lines?w.lines.start+"-"+w.lines.end:n("annotate.lineCompactUnknown")}async function ir(){var e=_.value.trim(),t=w.mode==="continue",a=w.mode==="annotate-line";if(!(!w.text&&!t&&!a||!i)){if(O&&m){var r=await da();if(!r){c(n("status.saveFailedNoReturn"),!0);return}}if(g){if(!m||!i.postMessage){c(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:m,selectedText:w.text,requirement:e,startLine:w.lines&&w.lines.start,endLine:w.lines&&w.lines.end,rewriteMode:t?"continue":"replace"}),T(!0),c(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!w.text&&!a){T(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(U||"Markdown")+":"+kn(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:Sn(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:w.text||n("annotate.emptyLine"),path:m||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),T(!0),c(n("annotate.added"))}catch(o){c(String(o),!0)}}}function xn(){var e=p.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=Qa(p.getValue(),e.start,e.end);return ar(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function sr(){te&&xn()}function En(e){if(!A()||!e)return!1;we();var t=ke.querySelector(".cm-line")||ke.querySelector(".cm-content"),a=(t||ke).getBoundingClientRect();return rr("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",g?"continue":"annotate-line"),!0}ke.addEventListener("mouseup",sr),ke.addEventListener("keyup",function(e){e.shiftKey&&sr()});var O=!1,$e=0,oe=null,ea=!1,Pe=!1,ta="",aa=null;function Mn(e){ta=e,aa=h,i.postMessage({type:"saveDraft",path:e,markdown:h,base:P})}function lr(){!m||!i||!i.postMessage||ta===m&&aa===h||Mn(m)}function ra(){ta="",aa=null}function na(e){ra(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function Oe(e,t){O=e,_e&&(clearTimeout(_e),_e=0),Pe=!O&&!!t,k(),!O&&t&&(_e=setTimeout(function(){_e=0,O||(Pe=!1,k())},3e3))}async function cr(e){if(oe)return dr(),c("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if($&&$.createWritable)try{var t=await $.createWritable();return await t.write(e),await t.close(),yt=(await $.getFile()).lastModified,P=e,Oe(h!==e,h===e),c(n(h===e?"status.saved":"status.savedWithNewChanges")),ra(),!0}catch(r){return c(n("status.saveFailed",{err:String(r)}),!0),!1}if(m){var a=++Oa;return c(n("status.saving")),zt[a]=e,i.postMessage({type:"saveMarkdown",path:m,markdown:e,requestId:a}),new Promise(function(r){Ae[a]=r})}return c(n("status.noSourceFile"),!0),!1}document.addEventListener("keydown",function(e){var t=e.metaKey||e.ctrlKey;if(t&&(e.key==="s"||e.key==="S")){e.preventDefault(),ua();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),Ke(x==="edit"?"preview":"edit"))});function ur(){Ce&&(clearInterval(Ce),Ce=0),$=null}var oa=null;function Ze(e,t,a,r,o,s){if(!r&&O&&P!==null&&e!==P)return oe={markdown:e,name:t,path:a,diskBaseline:o},c(n("status.externalUpdateSkipped"),!0),dr(),!1;var l=P!==null&&(!a||!m||a===m);return l||(te=!0),h=e,Ue=t,a&&(m=a),U=vn(a||m)||t||"Markdown",P=typeof o=="string"?o:h,oa=l?p.applyExternalValue(h):null,oa||p.setValue(h),Oe(!1),za(U),s||be(),Ye(),De(),(g||x==="preview")&&X(),!0}async function dr(){if(!(ea||!oe||!O)){var e=oe,t=P;if(h===t){oe=null,Ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){oe=null;return}ea=!0;var a=await Gn();if(ea=!1,oe===e){if(a==="later"){c("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(oe=null,a==="remote"){na(m),Ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(P=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,lr(),c("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function pr(e){Ue=e.name,yt=e.lastModified,typeof e.path=="string"&&e.path?(m=e.path,i&&i.postMessage({type:"watchPath",path:m})):m="",Ze(await e.text(),Ue,m,!0)}function In(){$&&(Ce&&clearInterval(Ce),Ce=setInterval(async function(){if(!(Ut||!$)){Ut=!0;try{var e=await $.getFile();if(e.lastModified!==yt){yt=e.lastModified;var t=await e.text();t!==P&&Ze(t,Ue,m)&&c(n("status.externalUpdateApplied"))}}catch{}Ut=!1}},800))}var Y=!1,Qe=0;function et(){Qe&&(clearTimeout(Qe),Qe=0)}function Ln(){et(),Qe=setTimeout(function(){Qe=0,Y&&(Y=!1,We=!1,k(),c(n("status.pickerTimeout"),!0))},2e4)}async function ia(){if(O){var e=await Sr(n("confirm.message",{file:U||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await da();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&na(m)}if(ur(),We&&i&&i.postMessage){if(Y){et(),We=!1,Y=!1,k(),await fr();return}Y=!0,Ln(),k(),c(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await fr()}async function fr(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});$=e[0],await pr(await $.getFile()),In();return}catch(a){if(a&&a.name==="AbortError")return}var t=document.createElement("input");t.type="file",t.accept=".md,.markdown,text/markdown",t.onchange=function(){var a=t.files&&t.files[0];a&&pr(a).catch(function(r){c(String(r),!0)})},t.click()}function An(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function Cn(e){for(var t=0;t<e;t++){if(An(),await new Promise(function(a){requestAnimationFrame(function(){requestAnimationFrame(a)})}),document.hasFocus())return!0;await new Promise(function(a){setTimeout(a,40)})}return document.hasFocus()}function mr(e){var t=Array.from(new Set(e.match(/finch-file:\/\/local\?path=[^\s)"']+/g)||[]));return!t.length||!i||!i.postMessage?Promise.resolve(e):new Promise(function(a,r){var o=++Or;ge[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){ge[o]&&(delete ge[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function Dn(e){var t=new DOMParser().parseFromString(e,"text/html");function a(r){return r&&r.tagName==="P"&&!r.textContent.trim()&&!r.querySelector("img,video,iframe,table")}return Array.from(t.querySelectorAll("figure.figure-image")).forEach(function(r){var o=r.previousElementSibling,s=r.nextElementSibling;a(o)&&o.remove(),a(s)&&s.remove()}),t.body.innerHTML}async function vr(e,t){if(document.hasFocus()||await Cn(5),window.ClipboardItem&&navigator.clipboard&&navigator.clipboard.write)try{return await navigator.clipboard.write([new ClipboardItem({"text/html":Promise.resolve(e).then(function(r){return new Blob([r],{type:"text/html"})}),"text/plain":new Blob([t],{type:"text/plain"})})]),"rich"}catch{}var a=await Promise.resolve(e);return Fn(a)?"rich":Tn(t)?"plain":"none"}function Fn(e){var t=document.createElement("div");t.contentEditable="true",t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.innerHTML=e,document.body.appendChild(t);var a=document.createRange();a.selectNodeContents(t);var r=window.getSelection();r.removeAllRanges(),r.addRange(a);var o=!1;try{o=document.execCommand("copy")}catch{o=!1}return r.removeAllRanges(),t.remove(),o}function Tn(e){var t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",t.style.top="0",document.body.appendChild(t),t.focus(),t.select();var a=!1;try{a=document.execCommand("copy")}catch{a=!1}return t.remove(),a}async function Pn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{var e=y.contentDocument&&y.contentDocument.body?y.contentDocument.body.innerText:N.replace(/<[^>]+>/g,""),t=await vr(mr(N),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await vr(mr(N),e)),t==="rich"?c(n("status.copiedRich")):c(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){c(n("status.richCopyFailed",{err:String(a)}),!0)}finally{x==="edit"&&requestAnimationFrame(function(){p.focus()})}}function On(){if(!Le||!y.contentDocument)return null;var e=y.contentDocument.querySelector("#bm-md");if(!e)return null;var t=e.getBoundingClientRect();return{root:e,width:Math.ceil(t.width||e.scrollWidth),height:Math.ceil(t.height||e.scrollHeight)}}function sa(){var e=On();if(!e||!e.width||!e.height)return Promise.resolve(null);var t=2,a=e.root.cloneNode(!0);a.style.minHeight=e.height+"px",a.style.margin="0",a.style.boxSizing="border-box";var r;try{r=new XMLSerializer().serializeToString(a)}catch(l){return Promise.reject(new Error(n("status.serializeFailed",{err:String(l)})))}var o='<svg xmlns="http://www.w3.org/2000/svg" width="'+e.width+'" height="'+e.height+'"><foreignObject x="0" y="0" width="'+e.width+'" height="'+e.height+'">'+r+"</foreignObject></svg>",s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var b=f.getContext("2d");b.scale(t,t);var v="";try{v=y.contentWindow.getComputedStyle(e.root).backgroundColor}catch{v=""}v&&v!=="rgba(0, 0, 0, 0)"&&v!=="transparent"&&(b.fillStyle=v,b.fillRect(0,0,e.width,e.height)),b.drawImage(d,0,0,e.width,e.height),l({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(q){u(q)}},d.onerror=function(){u(new Error(n("status.imageConversionFailed")))},d.src=s})}function la(e,t,a){return new Promise(function(r,o){e.toBlob(function(s){s?r(s):o(new Error(n("status.imageGenFailed")))},t,a)})}function gr(e){for(var t="",a=32768,r=0;r<e.length;r+=a)t+=String.fromCharCode.apply(null,e.subarray(r,r+a));return btoa(t)}async function Rn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){c(n("status.clipboardUnsupported"),!0);return}c(n("status.generatingImage"));var e=sa().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return la(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),c(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),c(n("status.imageCopied"));return}catch(r){c(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function Bn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingImage"));var e=await sa();if(!e){c(n("status.exportImageFailedGeneric"),!0);return}var t=await la(e.canvas,"image/png"),a=await t.arrayBuffer(),r=gr(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:m,fileName:U,markdown:h})}catch(o){c(n("status.exportImageFailed",{err:String(o)}),!0)}}function Nn(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function Q(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function ca(e){for(var t=0,a=0;a<e.length;a++)t+=e[a].length;for(var r=new Uint8Array(t),o=0,a=0;a<e.length;a++)r.set(e[a],o),o+=e[a].length;return r}function qn(e,t,a,r,o){var s=Q(`%PDF-1.4
|
|
14
|
+
`).length}}function fn(e,t){for(var a="",r=[],o=0;o<e.length;o++)/\s/.test(e[o])?a&&a[a.length-1]!==" "&&(a+=" ",r.push(t[o])):(a+=e[o],r.push(t[o]));return a.endsWith(" ")&&(a=a.slice(0,-1),r.pop()),{text:a,map:r}}function mn(e){var t="",a=[];function r(q,V){t+=q,a.push(V)}for(var o=0;o<e.length;){var s=o===0||e[o-1]===`
|
|
15
|
+
`;if(s){var l=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(l){o+=l[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var d=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(d){for(var f=o+d[0].indexOf("[")+1,b=0;b<d[1].length;b++)/[*_~`]/.test(d[1][b])||r(d[1][b],f+b);o+=d[0].length;continue}var v=/^<[^>]+>/.exec(e.slice(o));if(v){o+=v[0].length;continue}if(e[o]==="\\"&&o+1<e.length){r(e[o+1],o+1),o+=2;continue}if(/[*_~`]/.test(e[o])){o++;continue}r(e[o],o),o++}return fn(t,a)}function vn(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=mn(e),o=t.replace(/\s+/g," ").trim(),s=r.text.indexOf(o);if(s>=0)return{start:r.map[s],end:r.map[s+o.length-1]+1};if(o.length>=12){var l=o.slice(0,6),u=o.slice(-6),d=r.text.indexOf(l),f=r.text.indexOf(u,Math.max(0,d+l.length));if(d>=0&&f>=d)return{start:r.map[d],end:r.map[f+u.length-1]+1}}return null}function gn(e){return String(e||"").split(/[\\/]/).pop()||""}function tr(){var e=y.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(te){var a=y.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),l=Array.from(s.getClientRects()),u=y.getBoundingClientRect(),d=l.map(function(V){return{top:u.top+V.top,left:u.left+V.left,width:V.width,height:V.height}}),f=l[0]||s.getBoundingClientRect(),b=l[l.length-1]||f,v=vn(h,o),q=v?er(h,v.start,v.end):null;rr(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+b.bottom,endLeft:u.left+b.left},d,q,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){we(),T()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),Ke("edit"))}),e.addEventListener("scroll",function(){we(),T()},!0),y.contentWindow.addEventListener("scroll",function(){we(),T()})}y.onload=function(){Ie=!0,tr(),Zt()};function ar(){p&&p.scrollDOM&&!p.scrollDOM.__scrollSyncBound&&(p.scrollDOM.__scrollSyncBound=!0,p.scrollDOM.addEventListener("scroll",sn,{passive:!0}));var e=y.contentDocument;if(e&&!e.__scrollSyncBound){e.__scrollSyncBound=!0;var t=e.scrollingElement||e.documentElement;t&&t.addEventListener("scroll",$a,{passive:!0}),e.defaultView&&e.defaultView.addEventListener("scroll",$a,{passive:!0})}}ar(),window.addEventListener("resize",function(){Z=null}),y.addEventListener("load",function(){requestAnimationFrame(function(){Ie=!0,Zt(),ar(),Za()})});var Mt=0,Qt=[];function rr(e,t,a,r,o){we(),Mt=setTimeout(function(){nr(e,t,a,r,o)},300)}function we(){Mt&&(clearTimeout(Mt),Mt=0)}function nr(e,t,a,r,o,s){w.text=e,w.lines=r||null,w.origin=o||"",w.mode=s||"replace",wt(),L.classList.remove("hidden"),L.classList.toggle("popup-bar",!!(t&&t.width)),_.value="",yn(a),requestAnimationFrame(function(){hn(t),t&&t.focus&&_.focus()})}function hn(e){var t=8,a=10,r=e||{},o=g?t+48:t;if(L.style.width=r.width?r.width+"px":"",r.width){L.style.left=Math.max(t,r.startLeft||0)+"px",L.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(L.offsetHeight||44)-t))+"px";return}var s=L.offsetWidth||300,l=L.offsetHeight||44,u=(r.startTop||0)-a-l,d=u>=o,f=d?u:(r.endBottom||0)+a,b=d?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;L.style.left=Math.max(t,Math.min(b,window.innerWidth-s-t))+"px",L.style.top=Math.max(o,Math.min(f,window.innerHeight-l-t))+"px"}function yn(e){or(),(e||[]).forEach(function(t){var a=document.createElement("div");a.className="fake-sel",a.style.top=t.top+"px",a.style.left=t.left+"px",a.style.width=t.width+"px",a.style.height=t.height+"px",document.body.appendChild(a),Qt.push(a)})}function or(){Qt.forEach(function(e){e.remove()}),Qt=[]}var bn=navigator.platform||navigator.userAgent||"",Lt=/Mac|iPhone|iPod|iPad/.test(bn);document.body.classList.toggle("non-mac-platform",!Lt);function wn(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Lt?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(Sa){var t=Lt?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Lt?"":"+";Sa.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function T(e){var t=e===!0&&w.origin==="editor"&&x==="edit";we(),L.classList.add("hidden"),L.classList.remove("popup-bar"),L.classList.remove("focused"),L.style.width="",w.text="",w.lines=null,w.origin="",w.mode="replace",or(),t&&requestAnimationFrame(function(){p.focus()})}wa.onclick=sr;var ir=0;_.addEventListener("compositionend",function(){ir=Date.now()});function Sn(e){return e.isComposing||e.keyCode===229?!0:Date.now()-ir<100}_.addEventListener("keydown",function(e){if(e.key==="Enter"){if(Sn(e))return;sr()}e.key==="Escape"&&T(!0)}),_.addEventListener("focus",function(){L.classList.add("focused")}),_.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==wa&&L.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!L.classList.contains("hidden")&&T(!0)}),document.addEventListener("keydown",function(e){wn(e)&&(L.classList.contains("hidden")||(e.preventDefault(),_.focus(),_.select()))}),document.addEventListener("mousedown",function(e){L.contains(e.target)||(we(),T())}),window.addEventListener("resize",T);function kn(){if(!w.lines)return n("annotate.lineUnknown");var e=w.lines.start,t=w.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function xn(){return w.lines?w.lines.start+"-"+w.lines.end:n("annotate.lineCompactUnknown")}async function sr(){var e=_.value.trim(),t=w.mode==="continue",a=w.mode==="annotate-line";if(!(!w.text&&!t&&!a||!i)){if(O&&m){var r=await da();if(!r){c(n("status.saveFailedNoReturn"),!0);return}}if(g){if(!m||!i.postMessage){c(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:m,selectedText:w.text,requirement:e,startLine:w.lines&&w.lines.start,endLine:w.lines&&w.lines.end,rewriteMode:t?"continue":"replace"}),T(!0),c(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!w.text&&!a){T(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(U||"Markdown")+":"+xn(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:kn(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:w.text||n("annotate.emptyLine"),path:m||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),T(!0),c(n("annotate.added"))}catch(o){c(String(o),!0)}}}function En(){var e=p.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=er(p.getValue(),e.start,e.end);return rr(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function lr(){te&&En()}function Mn(e){if(!A()||!e)return!1;we();var t=ke.querySelector(".cm-line")||ke.querySelector(".cm-content"),a=(t||ke).getBoundingClientRect();return nr("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",g?"continue":"annotate-line"),!0}ke.addEventListener("mouseup",lr),ke.addEventListener("keyup",function(e){e.shiftKey&&lr()});var O=!1,$e=0,oe=null,ea=!1,Pe=!1,ta="",aa=null;function Ln(e){ta=e,aa=h,i.postMessage({type:"saveDraft",path:e,markdown:h,base:P})}function cr(){!m||!i||!i.postMessage||ta===m&&aa===h||Ln(m)}function ra(){ta="",aa=null}function na(e){ra(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function Oe(e,t){O=e,_e&&(clearTimeout(_e),_e=0),Pe=!O&&!!t,k(),!O&&t&&(_e=setTimeout(function(){_e=0,O||(Pe=!1,k())},3e3))}async function ur(e){if(oe)return pr(),c("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if($&&$.createWritable)try{var t=await $.createWritable();return await t.write(e),await t.close(),yt=(await $.getFile()).lastModified,P=e,Oe(h!==e,h===e),c(n(h===e?"status.saved":"status.savedWithNewChanges")),ra(),!0}catch(r){return c(n("status.saveFailed",{err:String(r)}),!0),!1}if(m){var a=++Oa;return c(n("status.saving")),Ut[a]=e,i.postMessage({type:"saveMarkdown",path:m,markdown:e,requestId:a}),new Promise(function(r){Ae[a]=r})}return c(n("status.noSourceFile"),!0),!1}document.addEventListener("keydown",function(e){var t=e.metaKey||e.ctrlKey;if(t&&(e.key==="s"||e.key==="S")){e.preventDefault(),ua();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),Ke(x==="edit"?"preview":"edit"))});function dr(){Ce&&(clearInterval(Ce),Ce=0),$=null}var oa=null;function Ze(e,t,a,r,o,s){if(!r&&O&&P!==null&&e!==P)return oe={markdown:e,name:t,path:a,diskBaseline:o},c(n("status.externalUpdateSkipped"),!0),pr(),!1;var l=P!==null&&(!a||!m||a===m);return l||(te=!0),h=e,Ue=t,a&&(m=a),U=gn(a||m)||t||"Markdown",P=typeof o=="string"?o:h,oa=l?p.applyExternalValue(h):null,oa||p.setValue(h),Oe(!1),za(U),s||be(),Ye(),De(),(g||x==="preview")&&X(),!0}async function pr(){if(!(ea||!oe||!O)){var e=oe,t=P;if(h===t){oe=null,Ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){oe=null;return}ea=!0;var a=await Xn();if(ea=!1,oe===e){if(a==="later"){c("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(oe=null,a==="remote"){na(m),Ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(P=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,cr(),c("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function fr(e){Ue=e.name,yt=e.lastModified,typeof e.path=="string"&&e.path?(m=e.path,i&&i.postMessage({type:"watchPath",path:m})):m="",Ze(await e.text(),Ue,m,!0)}function In(){$&&(Ce&&clearInterval(Ce),Ce=setInterval(async function(){if(!(Vt||!$)){Vt=!0;try{var e=await $.getFile();if(e.lastModified!==yt){yt=e.lastModified;var t=await e.text();t!==P&&Ze(t,Ue,m)&&c(n("status.externalUpdateApplied"))}}catch{}Vt=!1}},800))}var Y=!1,Qe=0;function et(){Qe&&(clearTimeout(Qe),Qe=0)}function An(){et(),Qe=setTimeout(function(){Qe=0,Y&&(Y=!1,We=!1,k(),c(n("status.pickerTimeout"),!0))},2e4)}async function ia(){if(O){var e=await kr(n("confirm.message",{file:U||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await da();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&na(m)}if(dr(),We&&i&&i.postMessage){if(Y){et(),We=!1,Y=!1,k(),await mr();return}Y=!0,An(),k(),c(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await mr()}async function mr(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});$=e[0],await fr(await $.getFile()),In();return}catch(a){if(a&&a.name==="AbortError")return}var t=document.createElement("input");t.type="file",t.accept=".md,.markdown,text/markdown",t.onchange=function(){var a=t.files&&t.files[0];a&&fr(a).catch(function(r){c(String(r),!0)})},t.click()}function Cn(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function Dn(e){for(var t=0;t<e;t++){if(Cn(),await new Promise(function(a){requestAnimationFrame(function(){requestAnimationFrame(a)})}),document.hasFocus())return!0;await new Promise(function(a){setTimeout(a,40)})}return document.hasFocus()}function vr(e){var t=Array.from(new Set(e.match(/finch-file:\/\/local\?path=[^\s)"']+/g)||[]));return!t.length||!i||!i.postMessage?Promise.resolve(e):new Promise(function(a,r){var o=++Rr;ge[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){ge[o]&&(delete ge[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function Fn(e){var t=new DOMParser().parseFromString(e,"text/html");function a(r){return r&&r.tagName==="P"&&!r.textContent.trim()&&!r.querySelector("img,video,iframe,table")}return Array.from(t.querySelectorAll("figure.figure-image")).forEach(function(r){var o=r.previousElementSibling,s=r.nextElementSibling;a(o)&&o.remove(),a(s)&&s.remove()}),t.body.innerHTML}async function gr(e,t){if(document.hasFocus()||await Dn(5),window.ClipboardItem&&navigator.clipboard&&navigator.clipboard.write)try{return await navigator.clipboard.write([new ClipboardItem({"text/html":Promise.resolve(e).then(function(r){return new Blob([r],{type:"text/html"})}),"text/plain":new Blob([t],{type:"text/plain"})})]),"rich"}catch{}var a=await Promise.resolve(e);return Tn(a)?"rich":Pn(t)?"plain":"none"}function Tn(e){var t=document.createElement("div");t.contentEditable="true",t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.innerHTML=e,document.body.appendChild(t);var a=document.createRange();a.selectNodeContents(t);var r=window.getSelection();r.removeAllRanges(),r.addRange(a);var o=!1;try{o=document.execCommand("copy")}catch{o=!1}return r.removeAllRanges(),t.remove(),o}function Pn(e){var t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",t.style.top="0",document.body.appendChild(t),t.focus(),t.select();var a=!1;try{a=document.execCommand("copy")}catch{a=!1}return t.remove(),a}async function On(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{var e=y.contentDocument&&y.contentDocument.body?y.contentDocument.body.innerText:N.replace(/<[^>]+>/g,""),t=await gr(vr(N),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await gr(vr(N),e)),t==="rich"?c(n("status.copiedRich")):c(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){c(n("status.richCopyFailed",{err:String(a)}),!0)}finally{x==="edit"&&requestAnimationFrame(function(){p.focus()})}}function Rn(){if(!Ie||!y.contentDocument)return null;var e=y.contentDocument.querySelector("#bm-md");if(!e)return null;var t=e.getBoundingClientRect();return{root:e,width:Math.ceil(t.width||e.scrollWidth),height:Math.ceil(t.height||e.scrollHeight)}}function sa(){var e=Rn();if(!e||!e.width||!e.height)return Promise.resolve(null);var t=2,a=e.root.cloneNode(!0);a.style.minHeight=e.height+"px",a.style.margin="0",a.style.boxSizing="border-box";var r;try{r=new XMLSerializer().serializeToString(a)}catch(l){return Promise.reject(new Error(n("status.serializeFailed",{err:String(l)})))}var o='<svg xmlns="http://www.w3.org/2000/svg" width="'+e.width+'" height="'+e.height+'"><foreignObject x="0" y="0" width="'+e.width+'" height="'+e.height+'">'+r+"</foreignObject></svg>",s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var b=f.getContext("2d");b.scale(t,t);var v="";try{v=y.contentWindow.getComputedStyle(e.root).backgroundColor}catch{v=""}v&&v!=="rgba(0, 0, 0, 0)"&&v!=="transparent"&&(b.fillStyle=v,b.fillRect(0,0,e.width,e.height)),b.drawImage(d,0,0,e.width,e.height),l({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(q){u(q)}},d.onerror=function(){u(new Error(n("status.imageConversionFailed")))},d.src=s})}function la(e,t,a){return new Promise(function(r,o){e.toBlob(function(s){s?r(s):o(new Error(n("status.imageGenFailed")))},t,a)})}function hr(e){for(var t="",a=32768,r=0;r<e.length;r+=a)t+=String.fromCharCode.apply(null,e.subarray(r,r+a));return btoa(t)}async function Bn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){c(n("status.clipboardUnsupported"),!0);return}c(n("status.generatingImage"));var e=sa().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return la(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),c(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),c(n("status.imageCopied"));return}catch(r){c(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function Nn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingImage"));var e=await sa();if(!e){c(n("status.exportImageFailedGeneric"),!0);return}var t=await la(e.canvas,"image/png"),a=await t.arrayBuffer(),r=hr(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:m,fileName:U,markdown:h})}catch(o){c(n("status.exportImageFailed",{err:String(o)}),!0)}}function qn(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function Q(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function ca(e){for(var t=0,a=0;a<e.length;a++)t+=e[a].length;for(var r=new Uint8Array(t),o=0,a=0;a<e.length;a++)r.set(e[a],o),o+=e[a].length;return r}function Hn(e,t,a,r,o){var s=Q(`%PDF-1.4
|
|
16
16
|
%\xE2\xE3\xCF\xD3
|
|
17
|
-
`),l=[s],u=[0],d=s.length;function f(
|
|
17
|
+
`),l=[s],u=[0],d=s.length;function f(Ct){u.push(d),l.push(Ct),d+=Ct.length}f(Q(`1 0 obj
|
|
18
18
|
<< /Type /Catalog /Pages 2 0 R >>
|
|
19
19
|
endobj
|
|
20
20
|
`)),f(Q(`2 0 obj
|
|
@@ -38,9 +38,9 @@ endobj
|
|
|
38
38
|
`)]));for(var ee=d,ie=[`xref
|
|
39
39
|
0 6
|
|
40
40
|
0000000000 65535 f
|
|
41
|
-
`],ae=1;ae<=5;ae++)ie.push(
|
|
42
|
-
`);var
|
|
41
|
+
`],ae=1;ae<=5;ae++)ie.push(qn(u[ae])+` 00000 n
|
|
42
|
+
`);var At=`trailer
|
|
43
43
|
<< /Size 6 /Root 1 0 R >>
|
|
44
44
|
startxref
|
|
45
45
|
`+ee+`
|
|
46
|
-
%%EOF`;return l.push(Q(ie.join("")+Lt)),ca(l)}async function Hn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingPdf"));var e=await sa();if(!e){c(n("status.exportPdfFailedGeneric"),!0);return}var t=await la(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,l=qn(r,e.canvas.width,e.canvas.height,o,s),u=gr(l);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:m,fileName:U,markdown:h})}catch(d){c(n("status.exportPdfFailed",{err:String(d)}),!0)}}function tt(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){c(String(r),!0)}).then(function(){e.disabled=!1}))})}tt(Lr,Pn),tt(Ar,Rn),tt(Cr,Bn),tt(Dr,Hn),tt(xe,Wn);var hr="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(hr)==="1"}catch{}Re&&Re.classList.toggle("collapsed",t)})(),ka&&ka.addEventListener("click",function(e){e.preventDefault();var t=Re.classList.toggle("collapsed");try{localStorage.setItem(hr,t?"1":"0")}catch{}});function ua(){cr(h)}function It(e){if(Tr=e,!!xe){xe.classList.toggle("loading",e),xe.disabled=e;var t=xe.querySelector(".ic-ai-style"),a=xe.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function yr(){if(!h||!m||!i||!i.postMessage){c(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:m,baseStyle:L}),It(!0),c(n("aiStyle.appViewDesigning"))}async function Wn(){if(!h){c(n("status.pleaseOpenArticle"),!0);return}if(g||!i||!i.composer){yr();return}var e=L==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:L});try{await i.composer.addContexts([{type:"annotation",label:n("aiStyle.label",{file:U||n("common.markdownDocDefault")}),note:n("aiStyle.note"),promptText:n("aiStyle.promptText",{baseNote:e,path:m||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),c(n("aiStyle.requested"))}catch{yr()}}function zn(){return{fontSize:z,fontFamily:J,comfortWriting:B,style:L,customCss:L==="custom"?R:"",customStyleLabel:L==="custom"?Me:""}}function Se(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:zn()})}function Un(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(z=e.fontSize),Ie[e.fontFamily]&&(J=e.fontFamily),B=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(L="custom",R=e.customCss,Me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(L=e.style,R="",Me=""),p.setFontSize(z),p.setFontFamily(Ie[J]),p.setComfortWriting(B),!0)}function Vn(e){L=e,Se(),(g||x==="preview")&&X(),k()}function _n(e){if(!(e!==14&&e!==16&&e!==18)){z=e,p.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}Se(),k()}}function jn(e){if(Ie[e]){J=e,p.setFontFamily(Ie[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}Se(),k()}}function br(e){B=!!e,p.setComfortWriting(B);try{localStorage.setItem("md-editor-comfort-writing",B?"1":"0")}catch{}Se(),k(),c(n(B?"status.comfortWrite":"status.comfortRead"))}function wr(){D=!D,D&&te?(te=!1,T()):!D&&!te&&(te=!0),p.setFocusMode(D),document.body.classList.toggle("focus-mode",D);try{localStorage.setItem("md-editor-focus-mode",D?"1":"0")}catch{}k(),c(n(D?"status.focusOn":"status.focusOff"))}var at=null;function rt(e){ue.hidden=!0;var t=at;at=null,t&&t(e)}function Sr(e){return new Promise(function(t){at=t,xa.textContent=e,ue.hidden=!1,Be.focus()})}async function Gn(){xa.textContent="AI \u5DF2\u5199\u56DE\u6587\u4EF6\uFF0C\u4F46\u4F60\u4E5F\u6709\u672A\u4FDD\u5B58\u7F16\u8F91\u3002\u8BF7\u9009\u62E9\u4FDD\u7559\u672C\u5730\u5185\u5BB9\u6216\u91C7\u7528 AI \u7248\u672C\u3002",Rt.textContent="\u7A0D\u540E\u5904\u7406",Bt.textContent="\u4FDD\u7559\u672C\u5730",Be.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){at=t,ue.hidden=!1,Be.focus()});return Dt(ue),e==="save"?"remote":e==="discard"?"local":"later"}Rt&&Rt.addEventListener("click",function(){rt("cancel")}),Bt&&Bt.addEventListener("click",function(){rt("discard")}),Be&&Be.addEventListener("click",function(){rt("save")}),ue&&ue.addEventListener("click",function(e){e.target===ue&&rt("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&at&&rt("cancel")});async function da(){return await cr(h)}function Xn(){ur(),ra(),T(),h="",Ue="",U="",m="",P=null,me=null,N="",te=!1,x="edit",p&&p.setValue(""),za(n("home.title")),be(),Za(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),Ye(),De(),Oe(!1),c("")}async function nt(){if(O){var e=await Sr(n("confirm.message",{file:U||n("common.markdownDocDefault")}));if(e==="cancel")return;if(i&&i.postMessage&&i.postMessage({type:"goHome"}),e==="save"){var t=await da();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&na(m)}Xn()}function kr(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){nt();return}if(e==="open"){ia();return}if(e==="mode"){Ke(x==="edit"?"preview":"edit");return}if(e==="save"){ua();return}if(e==="reload"){X();return}if(e==="reveal"){m&&i&&i.postMessage&&i.postMessage({type:"openPath",path:m});return}if(e==="recentSession"){me&&i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(me);return}if(e&&e.indexOf("font-size:")===0){_n(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){jn(e.slice(12));return}if(e==="comfort:read"){br(!1);return}if(e==="comfort:write"){br(!0);return}if(e==="focus"){wr();return}if(e==="about"){Rr();return}if(e&&e.indexOf("style:slot-use:")===0){Kn(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Er(+e.slice(16));return}if(e&&e.indexOf("style:")===0){Vn(e.slice(6));return}}function pa(){[dt,pt,ft].forEach(function(e){e&&(e.hidden=!0)})}function Yn(e){if(e){var t=e.hidden;pa(),e.hidden=!t}}function fa(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),Yn(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null;if(!(r&&r.disabled)){var o=r&&r.getAttribute("data-app-action");o&&(kr(o),pa())}})}Ma&&Ma.addEventListener("click",nt),ct&&ct.addEventListener("click",ia),re&&re.addEventListener("click",ua),de&&de.addEventListener("click",wr),Ne&&Ne.addEventListener("click",function(){G=!G,document.body.classList.toggle("preview-hidden",!G),k(),G&&requestAnimationFrame(function(){p.layout(),X()})}),fa(ut,dt),fa(Nt,pt),fa(Fr,ft),document.addEventListener("click",pa);var ma=370,va=560,xr=480;ce&&ce.addEventListener("mousedown",function(e){e.preventDefault();var t=ce.parentElement;if(!t)return;var a=e.clientX,r=Ot?Ot.getBoundingClientRect().width:xr;ce.classList.add("active");var o=document.createElement("div");o.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(o);function s(d){return Math.max(ma,Math.min(va,d))}function l(d){var f=d.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){ce.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",l),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(g){var e=ce&&ce.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||xr;(t>va||t<ma)&&e.style.setProperty("--preview-width",Math.max(ma,Math.min(va,t))+"px")}}});function Kn(e){var t=W[e];t&&(R=t.css,Me=t.label,L="custom",Se(),c(n("status.appliedStyleSlot",{label:t.label})),x==="preview"?X():Ke("preview"),k())}function Er(e){if(L!=="custom"||!R){c(n("status.needCustomStyleFirst"),!0);return}var t=Me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:R,label:t,path:m})}function Jn(){E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),M.className="status status-style-prompt";for(var e=0;e<3;e++)(function(t){var a=document.createElement("button");a.type="button",a.className="status-inline-btn",a.textContent=n("aiStyle.saveToSlot",{n:t+1});var r=W[t];r&&(a.title=r.label),a.addEventListener("click",function(){Er(t)}),M.appendChild(a)})(e);E=setTimeout(function(){E=0,M.replaceChildren(),M.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(We=!!e.pickFileSupported,W=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],Un(e.writingPreferences)?g&&A()&&X():Se(),e.libraryGroups&&typeof e.libraryGroups=="object"?(pe=Array.isArray(e.libraryGroups.order)?e.libraryGroups.order.filter(function(se){return typeof se=="string"}):[],Ee=e.libraryGroups.collapsed&&typeof e.libraryGroups.collapsed=="object"?e.libraryGroups.collapsed:{},He.length&&Gt(He)):(pe.length||Object.keys(Ee).length)&&jt(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==it&&(it=t,Dt(),wt())}e.assistantName&&(Ge=e.assistantName,wt()),Ba(),e.homeDir&&(ye=e.homeDir,qr()),k();return}if(e.type==="styleSlots"){W=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&W[e.savedSlot]&&c(n("status.savedToSlot",{slot:e.savedSlot+1,label:W[e.savedSlot].label})),k();return}if(e.type==="clipboardImages"){var a=ge[e.requestId];if(a){delete ge[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(se){typeof o[se]=="string"&&(r=r.split(se).join(o[se]))}),a.resolve(Dn(r))}return}if(e.type==="clipboardImagesError"){var s=ge[e.requestId];s&&(delete ge[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var l=ve[e.requestId];l&&(delete ve[e.requestId],l.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ve[e.requestId];u&&(delete ve[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),c(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){g=e.view==="appView",g&&(i&&i.panel&&i.panel.setTitle&&i.panel.setTitle(n("home.title")).catch(function(){}),be(),Xr()),g&&!Fa&&(Fa=!0,G=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",g),Ea&&(Ea.hidden=!g),p.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var d=e.cwd||"",f=e.sessionId||"",b=e.spaceId||"";(d!==je||f!==Vt||b!==_t||!bt)&&(je=d,Vt=f,_t=b,bt=!0,kt([])),De(),be(),k(),g&&A()&&X(),(!Ft.hidden||g)&&St();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==je)return;kt(e.documents),e.library&&Gt(e.documents);return}if(e.type==="status"){c(e.message);return}if(e.type==="rewriteSessionStarted"){H=e.sessionId&&e.turnId?{sessionId:e.sessionId,turnId:e.turnId}:null,p.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),he(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"),!1,e.sessionId,0);return}if(e.type==="rewriteCancellationRequested"){H&&H.turnId===e.turnId&&(H.cancelling=!0),he(n("appview.cancelling"),!1,e.sessionId,0);return}if(e.type==="rewriteSessionFinished"){H=null,p.setAiWorkingLines(0,0),he(n("appview.rewriteDone"),!1,e.sessionId,5e3);return}if(e.type==="rewriteSessionFailed"){var v=H&&H.turnId===e.turnId&&H.cancelling;H=null,p.setAiWorkingLines(0,0),he(v?n("appview.cancelled"):e.message||"Rewrite failed.",!v,e.sessionId,5e3);return}if(e.type==="styleSessionStarted"){It(!0),he(n("aiStyle.appViewDesigning"),!1,e.sessionId,0);return}if(e.type==="styleSessionFinished"){It(!1),he(e.message||n("aiStyle.appViewDone"),!1,e.sessionId,5e3);return}if(e.type==="styleSessionFailed"){It(!1),he(e.message||n("aiStyle.appViewFailed"),!0,e.sessionId,5e3);return}if(e.type!=="lastFileUnavailable"){if(e.type==="lastSessionInfo"){me=e.sessionId||null,k(),_a();return}if(e.type==="finch:menu"){kr(e.itemId);return}if(e.type==="document"){var q=Y;Y=!1,et();var V=e.markdown||"",ee=e.path||"",ie=Number(e.revision)||0;if(ee&&ee===m&&ie&&ie<=$e)return;var ae=!!ee&&!!m&&ee!==m;if((ae||P===null)&&(me=null),ae&&Et&&ee!==Et){Fe===ee&&(Fe="");return}if(!ae&&V===P){ie&&($e=Math.max($e,ie)),k();return}var Lt=P===null,At=Xe;Xe=!1;var $n=!!ee&&Fe===ee;Fe="";var Zn=Ze(V,e.title||n("common.markdownDocDefault"),e.path||m,q||Lt||ae,e.diskMarkdown,$n);if(!Zn){k();return}if($e=ie||(ae?0:$e),e.draftRestored)Oe(!0),c(n("status.draftRestored"));else if(e.draftConflict)c(n("status.draftConflict"),!0);else if(At)c(n("status.opened",{file:U}));else if(!Lt){var K=oa;K&&K.hunks>1?c(n("status.contentUpdatedSpots",{count:K.hunks,lines:K.changedLines})):K&&K.fromLine===K.toLine?c(n("status.contentUpdatedLine",{line:K.fromLine})):c(K?n("status.contentUpdatedLines",{from:K.fromLine,to:K.toLine}):n("status.contentUpdated"))}return}if(e.type==="sourceMissing"){e.path&&e.path===m&&c(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==Pa)return;Za(e.html||""),Ye(),Ve=!1,k(),c("");return}if(e.type==="savedMarkdown"){var ot=zt[e.requestId];delete zt[e.requestId];var Ct=Ae[e.requestId];if(delete Ae[e.requestId],e.requestId!==Oa||typeof ot!="string"){Ct&&Ct(!1);return}P=ot,Oe(h!==ot,h===ot),c(n(h===ot?"status.saved":"status.savedWithNewChanges")),Ct&&Ct(!0);return}if(e.type==="customStyleSet"){R=e.css||"",Me=e.label||n("common.customStyleDefault"),L="custom",Se(),typeof e.savedSlot=="number"?(W=Array.isArray(e.styleSlots)?e.styleSlots:W,c(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):Jn(),x==="preview"?X():Ke("preview"),k();return}if(e.type==="exported"){c(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){Y=!1,et(),k(),c("");return}if(e.type==="error"){Xe=!1,Et="",Fe="",Object.keys(Ae).forEach(function(se){var Mr=Ae[se];delete Ae[se],Mr&&Mr(!1)}),Y=!1,et(),e.fallback&&(We=!1),Ve=!1,k(),c(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!A()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),Ra||St()},400),Dt(),Ba(),wt(),Ye(),De()})();})();
|
|
46
|
+
%%EOF`;return l.push(Q(ie.join("")+At)),ca(l)}async function Wn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingPdf"));var e=await sa();if(!e){c(n("status.exportPdfFailedGeneric"),!0);return}var t=await la(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,l=Hn(r,e.canvas.width,e.canvas.height,o,s),u=hr(l);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:m,fileName:U,markdown:h})}catch(d){c(n("status.exportPdfFailed",{err:String(d)}),!0)}}function tt(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){c(String(r),!0)}).then(function(){e.disabled=!1}))})}tt(Ar,On),tt(Cr,Bn),tt(Dr,Nn),tt(Fr,Wn),tt(xe,zn);var yr="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(yr)==="1"}catch{}Re&&Re.classList.toggle("collapsed",t)})(),ka&&ka.addEventListener("click",function(e){e.preventDefault();var t=Re.classList.toggle("collapsed");try{localStorage.setItem(yr,t?"1":"0")}catch{}});function ua(){ur(h)}function It(e){if(Pr=e,!!xe){xe.classList.toggle("loading",e),xe.disabled=e;var t=xe.querySelector(".ic-ai-style"),a=xe.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function br(){if(!h||!m||!i||!i.postMessage){c(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:m,baseStyle:I}),It(!0),c(n("aiStyle.appViewDesigning"))}async function zn(){if(!h){c(n("status.pleaseOpenArticle"),!0);return}if(g||!i||!i.composer){br();return}var e=I==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:I});try{await i.composer.addContexts([{type:"annotation",label:n("aiStyle.label",{file:U||n("common.markdownDocDefault")}),note:n("aiStyle.note"),promptText:n("aiStyle.promptText",{baseNote:e,path:m||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),c(n("aiStyle.requested"))}catch{br()}}function Un(){return{fontSize:z,fontFamily:J,comfortWriting:B,style:I,customCss:I==="custom"?R:"",customStyleLabel:I==="custom"?Me:""}}function Se(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:Un()})}function Vn(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(z=e.fontSize),Le[e.fontFamily]&&(J=e.fontFamily),B=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(I="custom",R=e.customCss,Me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(I=e.style,R="",Me=""),p.setFontSize(z),p.setFontFamily(Le[J]),p.setComfortWriting(B),!0)}function _n(e){I=e,Se(),(g||x==="preview")&&X(),k()}function jn(e){if(!(e!==14&&e!==16&&e!==18)){z=e,p.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}Se(),k()}}function Gn(e){if(Le[e]){J=e,p.setFontFamily(Le[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}Se(),k()}}function wr(e){B=!!e,p.setComfortWriting(B);try{localStorage.setItem("md-editor-comfort-writing",B?"1":"0")}catch{}Se(),k(),c(n(B?"status.comfortWrite":"status.comfortRead"))}function Sr(){D=!D,D&&te?(te=!1,T()):!D&&!te&&(te=!0),p.setFocusMode(D),document.body.classList.toggle("focus-mode",D);try{localStorage.setItem("md-editor-focus-mode",D?"1":"0")}catch{}k(),c(n(D?"status.focusOn":"status.focusOff"))}var at=null;function rt(e){ue.hidden=!0;var t=at;at=null,t&&t(e)}function kr(e){return new Promise(function(t){at=t,xa.textContent=e,ue.hidden=!1,Be.focus()})}async function Xn(){xa.textContent="AI \u5DF2\u5199\u56DE\u6587\u4EF6\uFF0C\u4F46\u4F60\u4E5F\u6709\u672A\u4FDD\u5B58\u7F16\u8F91\u3002\u8BF7\u9009\u62E9\u4FDD\u7559\u672C\u5730\u5185\u5BB9\u6216\u91C7\u7528 AI \u7248\u672C\u3002",Bt.textContent="\u7A0D\u540E\u5904\u7406",Nt.textContent="\u4FDD\u7559\u672C\u5730",Be.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){at=t,ue.hidden=!1,Be.focus()});return Ft(ue),e==="save"?"remote":e==="discard"?"local":"later"}Bt&&Bt.addEventListener("click",function(){rt("cancel")}),Nt&&Nt.addEventListener("click",function(){rt("discard")}),Be&&Be.addEventListener("click",function(){rt("save")}),ue&&ue.addEventListener("click",function(e){e.target===ue&&rt("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&at&&rt("cancel")});async function da(){return await ur(h)}function Yn(){dr(),ra(),T(),h="",Ue="",U="",m="",P=null,me=null,N="",te=!1,x="edit",p&&p.setValue(""),za(n("home.title")),be(),Qa(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),Ye(),De(),Oe(!1),c("")}async function nt(){if(O){var e=await kr(n("confirm.message",{file:U||n("common.markdownDocDefault")}));if(e==="cancel")return;if(i&&i.postMessage&&i.postMessage({type:"goHome"}),e==="save"){var t=await da();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&na(m)}Yn()}function xr(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){nt();return}if(e==="open"){ia();return}if(e==="mode"){Ke(x==="edit"?"preview":"edit");return}if(e==="save"){ua();return}if(e==="reload"){X();return}if(e==="reveal"){m&&i&&i.postMessage&&i.postMessage({type:"openPath",path:m});return}if(e==="recentSession"){me&&i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(me);return}if(e&&e.indexOf("font-size:")===0){jn(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){Gn(e.slice(12));return}if(e==="comfort:read"){wr(!1);return}if(e==="comfort:write"){wr(!0);return}if(e==="focus"){Sr();return}if(e==="about"){Br();return}if(e&&e.indexOf("style:slot-use:")===0){Jn(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Mr(+e.slice(16));return}if(e&&e.indexOf("style:")===0){_n(e.slice(6));return}}function pa(){[dt,pt,ft].forEach(function(e){e&&(e.hidden=!0)})}function Kn(e){if(e){var t=e.hidden;pa(),e.hidden=!t}}function fa(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),Kn(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null;if(!(r&&r.disabled)){var o=r&&r.getAttribute("data-app-action");o&&(xr(o),pa())}})}Ma&&Ma.addEventListener("click",nt),ct&&ct.addEventListener("click",ia),re&&re.addEventListener("click",ua),de&&de.addEventListener("click",Sr),Ne&&Ne.addEventListener("click",function(){G=!G,document.body.classList.toggle("preview-hidden",!G),k(),G&&requestAnimationFrame(function(){p.layout(),X()})}),fa(ut,dt),fa(qt,pt),fa(Tr,ft),document.addEventListener("click",pa);var ma=370,va=560,Er=480;ce&&ce.addEventListener("mousedown",function(e){e.preventDefault();var t=ce.parentElement;if(!t)return;var a=e.clientX,r=Rt?Rt.getBoundingClientRect().width:Er;ce.classList.add("active");var o=document.createElement("div");o.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(o);function s(d){return Math.max(ma,Math.min(va,d))}function l(d){var f=d.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){ce.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",l),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(g){var e=ce&&ce.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||Er;(t>va||t<ma)&&e.style.setProperty("--preview-width",Math.max(ma,Math.min(va,t))+"px")}}});function Jn(e){var t=W[e];t&&(R=t.css,Me=t.label,I="custom",Se(),c(n("status.appliedStyleSlot",{label:t.label})),x==="preview"?X():Ke("preview"),k())}function Mr(e){if(I!=="custom"||!R){c(n("status.needCustomStyleFirst"),!0);return}var t=Me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:R,label:t,path:m})}function $n(){E&&(clearTimeout(E),E=0),M.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),M.className="status status-style-prompt";for(var e=0;e<3;e++)(function(t){var a=document.createElement("button");a.type="button",a.className="status-inline-btn",a.textContent=n("aiStyle.saveToSlot",{n:t+1});var r=W[t];r&&(a.title=r.label),a.addEventListener("click",function(){Mr(t)}),M.appendChild(a)})(e);E=setTimeout(function(){E=0,M.replaceChildren(),M.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(We=!!e.pickFileSupported,W=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],Vn(e.writingPreferences)?g&&A()&&X():Se(),e.libraryGroups&&typeof e.libraryGroups=="object"?(pe=Array.isArray(e.libraryGroups.order)?e.libraryGroups.order.filter(function(se){return typeof se=="string"}):[],Ee=e.libraryGroups.collapsed&&typeof e.libraryGroups.collapsed=="object"?e.libraryGroups.collapsed:{},He.length&&Xt(He)):(pe.length||Object.keys(Ee).length)&&Gt(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==it&&(it=t,Ft(),wt())}e.assistantName&&(Ge=e.assistantName,wt()),Ba(),e.homeDir&&(ye=e.homeDir,Hr()),k();return}if(e.type==="styleSlots"){W=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&W[e.savedSlot]&&c(n("status.savedToSlot",{slot:e.savedSlot+1,label:W[e.savedSlot].label})),k();return}if(e.type==="clipboardImages"){var a=ge[e.requestId];if(a){delete ge[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(se){typeof o[se]=="string"&&(r=r.split(se).join(o[se]))}),a.resolve(Fn(r))}return}if(e.type==="clipboardImagesError"){var s=ge[e.requestId];s&&(delete ge[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var l=ve[e.requestId];l&&(delete ve[e.requestId],l.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ve[e.requestId];u&&(delete ve[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),c(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){g=e.view==="appView",g&&(i&&i.panel&&i.panel.setTitle&&i.panel.setTitle(n("home.title")).catch(function(){}),be(),Yr()),g&&!Fa&&(Fa=!0,G=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",g),Ea&&(Ea.hidden=!g),p.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var d=e.cwd||"",f=e.sessionId||"",b=e.spaceId||"";(d!==je||f!==_t||b!==jt||!bt)&&(je=d,_t=f,jt=b,bt=!0,kt([])),De(),be(),k(),g&&A()&&X(),(!Tt.hidden||g)&&St();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==je)return;kt(e.documents),e.library&&Xt(e.documents);return}if(e.type==="status"){c(e.message);return}if(e.type==="rewriteSessionStarted"){H=e.sessionId&&e.turnId?{sessionId:e.sessionId,turnId:e.turnId}:null,p.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),he(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"),!1,e.sessionId,0);return}if(e.type==="rewriteCancellationRequested"){H&&H.turnId===e.turnId&&(H.cancelling=!0),he(n("appview.cancelling"),!1,e.sessionId,0);return}if(e.type==="rewriteSessionFinished"){H=null,p.setAiWorkingLines(0,0),he(n("appview.rewriteDone"),!1,e.sessionId,5e3);return}if(e.type==="rewriteSessionFailed"){var v=H&&H.turnId===e.turnId&&H.cancelling;H=null,p.setAiWorkingLines(0,0),he(v?n("appview.cancelled"):e.message||"Rewrite failed.",!v,e.sessionId,5e3);return}if(e.type==="styleSessionStarted"){It(!0),he(n("aiStyle.appViewDesigning"),!1,e.sessionId,0);return}if(e.type==="styleSessionFinished"){It(!1),he(e.message||n("aiStyle.appViewDone"),!1,e.sessionId,5e3);return}if(e.type==="styleSessionFailed"){It(!1),he(e.message||n("aiStyle.appViewFailed"),!0,e.sessionId,5e3);return}if(e.type!=="lastFileUnavailable"){if(e.type==="lastSessionInfo"){me=e.sessionId||null,k(),_a();return}if(e.type==="finch:menu"){xr(e.itemId);return}if(e.type==="document"){var q=Y;Y=!1,et();var V=e.markdown||"",ee=e.path||"",ie=Number(e.revision)||0;if(ee&&ee===m&&ie&&ie<=$e)return;var ae=!!ee&&!!m&&ee!==m;if((ae||P===null)&&(me=null),ae&&Et&&ee!==Et){Fe===ee&&(Fe="");return}if(!ae&&V===P){ie&&($e=Math.max($e,ie)),k();return}var At=P===null,Ct=Xe;Xe=!1;var Zn=!!ee&&Fe===ee;Fe="";var Qn=Ze(V,e.title||n("common.markdownDocDefault"),e.path||m,q||At||ae,e.diskMarkdown,Zn);if(!Qn){k();return}if($e=ie||(ae?0:$e),e.draftRestored)Oe(!0),c(n("status.draftRestored"));else if(e.draftConflict)c(n("status.draftConflict"),!0);else if(Ct)c(n("status.opened",{file:U}));else if(!At){var K=oa;K&&K.hunks>1?c(n("status.contentUpdatedSpots",{count:K.hunks,lines:K.changedLines})):K&&K.fromLine===K.toLine?c(n("status.contentUpdatedLine",{line:K.fromLine})):c(K?n("status.contentUpdatedLines",{from:K.fromLine,to:K.toLine}):n("status.contentUpdated"))}return}if(e.type==="sourceMissing"){e.path&&e.path===m&&c(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==Pa)return;Qa(e.html||""),Ye(),Ve=!1,k(),c("");return}if(e.type==="savedMarkdown"){var ot=Ut[e.requestId];delete Ut[e.requestId];var Dt=Ae[e.requestId];if(delete Ae[e.requestId],e.requestId!==Oa||typeof ot!="string"){Dt&&Dt(!1);return}P=ot,Oe(h!==ot,h===ot),c(n(h===ot?"status.saved":"status.savedWithNewChanges")),Dt&&Dt(!0);return}if(e.type==="customStyleSet"){R=e.css||"",Me=e.label||n("common.customStyleDefault"),I="custom",Se(),typeof e.savedSlot=="number"?(W=Array.isArray(e.styleSlots)?e.styleSlots:W,c(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):$n(),x==="preview"?X():Ke("preview"),k();return}if(e.type==="exported"){c(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){Y=!1,et(),k(),c("");return}if(e.type==="error"){Xe=!1,Et="",Fe="",Object.keys(Ae).forEach(function(se){var Lr=Ae[se];delete Ae[se],Lr&&Lr(!1)}),Y=!1,et(),e.fallback&&(We=!1),Ve=!1,k(),c(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!A()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),Ra||St()},400),Ft(),Ba(),wt(),Ye(),De()})();})();
|
package/package.json
CHANGED