finch-markdown-editor 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/codemirror.js +37 -37
- package/dist/panel.js +6 -6
- package/package.json +1 -1
package/dist/panel.js
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
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=Ke?Xe.zh:Xe.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(Xe.en,e)?Xe.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 yt(e){var t=e||document;document.documentElement.lang=Ke?"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 ht=document.getElementById("empty"),ta=document.getElementById("emptyNew"),aa=document.getElementById("emptyOpen"),bt=document.getElementById("homeRecent"),ae=document.getElementById("homeGrid"),Je=document.getElementById("homeHint"),wt=[],ra=document.getElementById("homeTagline"),er=document.getElementById("editPane"),St=document.getElementById("previewPane"),re=document.getElementById("previewResizer"),pe=document.getElementById("editor"),L=document.getElementById("article"),A=document.getElementById("status"),k=document.getElementById("popup"),G=document.getElementById("popupInput"),na=document.getElementById("popupSend"),oa=document.getElementById("popupShortcut"),Ee=document.getElementById("actions"),tr=document.getElementById("actCopyWx"),ar=document.getElementById("actCopyImg"),rr=document.getElementById("actSaveImg"),nr=document.getElementById("actSavePdf"),fe=document.getElementById("actAiStyle"),ia=document.getElementById("actToggle"),ne=document.getElementById("confirmOverlay"),sa=document.getElementById("confirmMessage"),kt=document.getElementById("confirmCancel"),xt=document.getElementById("confirmDiscard"),Le=document.getElementById("confirmSave"),la=document.getElementById("appToolbar"),da=document.getElementById("appHome"),ua=document.getElementById("appLibrary"),Qe=document.getElementById("appOpen"),Z=document.getElementById("appSave"),Ce=document.getElementById("appPreview"),Ze=document.getElementById("appStyle"),$e=document.getElementById("appStyleMenu"),Me=document.getElementById("appFocus"),Et=document.getElementById("appFont"),et=document.getElementById("appFontMenu"),or=document.getElementById("appMore"),tt=document.getElementById("appMoreMenu"),Lt=document.getElementById("libraryDrawer"),at=document.getElementById("libraryBackdrop"),ca=document.getElementById("libraryClose"),rt=document.getElementById("libraryReorder"),pa=document.getElementById("libraryReorderFooter"),fa=document.getElementById("libraryReorderDone"),C=document.getElementById("libraryGroups"),ma="md-editor-library-groups-v1",Ie=[],nt={},oe=null,Ae=null,$=!1,Ct=[],H=null,Mt=!1,w=!1,ga=!1,ee=!0,ir=!1,ot=0,Fe=!1,Q=!0,b="edit",x="kami",T="",me="",N=[null,null,null],ge={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},q=14,Y="rounded",O=!1,R=!1;try{var it=Number(localStorage.getItem("md-editor-font-size"));(it===14||it===16||it===18)&&(q=it);var It=localStorage.getItem("md-editor-font-family");ge[It]?Y=It:It&&localStorage.removeItem("md-editor-font-family"),O=localStorage.getItem("md-editor-comfort-writing")==="1",R=localStorage.getItem("md-editor-focus-mode")==="1";var De=JSON.parse(localStorage.getItem(ma)||"{}");Array.isArray(De.order)&&(Ie=De.order.filter(function(e){return typeof e=="string"})),De.collapsed&&typeof De.collapsed=="object"&&(nt=De.collapsed)}catch{}Q=!R;var m="",Pe="",z="",p="",B=null,W="",At=!1,va=0,Te=!1,ya=0,Ft={},ve={},sr=0,ie={},lr=0,se={},Oe=0,K=null,st=0,ye=0,Dt=!1,v={text:"",mode:"replace"},M=0;function l(e,t){M&&(clearTimeout(M),M=0),A.textContent=e||"",A.className="status"+(t?" error":""),e&&(M=setTimeout(function(){M=0,A.textContent="",A.className="status"},5e3))}function dr(){M&&(clearTimeout(M),M=0),A.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/"})}),A.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),A.className="status",M=setTimeout(function(){M=0,A.textContent="",A.className="status"},5e3)}function X(){return!!m||!!p}ta&&ta.addEventListener("click",async function(){if(!i||!i.composer){l(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),l(n("newdoc.added"))}catch(e){l(String(e),!0)}}),aa&&aa.addEventListener("click",function(){jt()});var Re="",Pt="",Tt="",lt=!1,ha=!1,Be="",le="";function y(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function ba(){ra&&(ra.textContent=Be?n("home.tagline.withAssistant",{name:Be}):n("home.tagline.default"))}function dt(){G&&(G.placeholder=v.mode==="continue"?n("popup.placeholderContinue",{name:Be||"Finch"}):n("popup.placeholder",{name:Be||"Finch"}))}function ur(e){return e?le&&e===le?"~":le&&(e.indexOf(le+"/")===0||e.indexOf(le+"\\")===0)?"~"+e.slice(le.length):e:""}function cr(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 pr(){ct(wt)}function wa(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 d=new Date(a.getTime()-864e5);return t.toDateString()===d.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 ut(){!i||!i.postMessage||!lt||(ha=!0,i.postMessage({type:"requestRecentDocuments",cwd:Re,sessionId:Pt,spaceId:Tt}))}function fr(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+y(e.path||"")+'" title="'+y(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+y(e.path||"")+'" role="button" tabindex="0" title="'+y(n("home.revealInFileManager"))+'" aria-label="'+y(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">'+y(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+y(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+y(t)+'">'+y(t)+'</span><span class="doc-time">'+y(wa(e.modifiedAt))+"</span></div></div></button>"}function ct(e){if(!(!ae||!bt||!Je)){var t=Array.isArray(e)?e:[];if(wt=t,t.length===0){bt.hidden=!0,Je.hidden=!1,Je.textContent=n(Re?"home.hintScoped":"home.hintDefault");return}var a=ka(t);ae.innerHTML=a.map(function(r){var o=r.documents.map(fr).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+y(r.scopePath)+'" title="'+y(n("home.cwdTitle",{path:r.scopePath}))+'">'+y(cr(ur(r.scopePath)))+"</button>":"",d='<div class="home-group-title"><span class="home-group-label">'+y(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+d+'<div class="home-grid">'+o+"</div></div>"}).join(""),bt.hidden=!1,Je.hidden=!0,requestAnimationFrame(function(){mr(ae)})}}function mr(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 d=0,u=s.length,c=0;d<=u;){var f=d+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(c=f,d=f+1):u=f-1}o.textContent=c>0?t+s.slice(s.length-c):t}}}function Sa(){try{localStorage.setItem(ma,JSON.stringify({order:Ie,collapsed:nt}))}catch{}}function ka(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=Ie.indexOf(a.id),s=Ie.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var d={space:0,workspace:1},u=d[a.kind]-d[r.kind];return u||a.label.localeCompare(r.label)})}function xa(e){if(C){Ct=Array.isArray(e)?e:[];var t=ka(Ct);if($){gr(t);return}C.innerHTML=t.map(function(a){var r=a.documents.map(function(d){var u=d.relativePath||d.fileName||"";return'<button class="library-row" type="button" data-path="'+y(d.path||"")+'"><span class="library-row-main"><strong>'+y(d.title||d.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+y(u)+'">'+y(u)+"</span><time>"+y(wa(d.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!nt[a.id];return'<details class="library-group" data-library-group-id="'+y(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+y(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">'+y(n("home.hintDefault"))+"</p>"}}function gr(e){C.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+y(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+y(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+y(n("home.hintDefault"))+"</p>"}function Ot(e){$=!!e,rt&&rt.classList.toggle("active",$),pa&&(pa.hidden=!$),xa(Ct)}function pt(e){!Lt||!at||(Lt.classList.toggle("open",!!e),Lt.setAttribute("aria-hidden",e?"false":"true"),at.hidden=!e,e?ut():$&&Ot(!1))}function vr(){if(!(!oe||!C)){oe.classList.remove("dragging"),Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),Ie=Array.prototype.map.call(C.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),ct(wt);var e=Ae||{};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])}),oe=null,setTimeout(function(){Ae=null,Sa()},0)}}function yr(){H&&H.ghost&&H.ghost.parentNode&&H.ghost.parentNode.removeChild(H.ghost)}function Ea(e,t){var a=H;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function hr(e){var t=H;if(!(!t||t.active)){t.active=!0,oe=e,Ae={},$||Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(Ae[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),Ea(t.startX,t.startY)}}function br(e,t){if(oe){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===oe)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;C.insertBefore(oe,o?r.nextSibling:r)}}}function La(){var e=H;e&&(e.active&&(yr(),vr(),Mt=!0,setTimeout(function(){Mt=!1},0)),H=null)}ua&&ua.addEventListener("click",function(){pt(!0)}),ca&&ca.addEventListener("click",function(){pt(!1)}),at&&at.addEventListener("click",function(){pt(!1)}),rt&&rt.addEventListener("click",function(){Ot(!$)}),fa&&fa.addEventListener("click",function(){Ot(!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||(pt(!1),Ne=!0,l(n("status.opening")),i.postMessage({type:"loadPath",path:a}))}),C&&(C.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!Ae){var a=t.getAttribute("data-library-group-id");a&&(nt[a]=!t.open,Sa())}},!0),C.addEventListener("click",function(e){if(Mt){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&&$){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(H={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=H;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;hr(t.group)}e.preventDefault(),Ea(e.clientX,e.clientY),br(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){La()}),window.addEventListener("pointercancel",function(){La()}));var Ne=!1;ae&&ae.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 d=s.getAttribute("data-path")||"";d&&(Ne=!0,l(n("status.opening")),i.postMessage({type:"loadPath",path:d}))}}}),ae&&ae.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 qe(){ht.hidden=X(),document.body.classList.toggle("has-document",X()),Ee&&(Ee.hidden=!W),!ht.hidden&<&&ut()}function he(){er.classList.toggle("active",w?X():b==="edit"),St.classList.toggle("active",w?X():b==="preview"),(w||b==="edit")&&g&&requestAnimationFrame(function(){g.layout()})}function Ca(e){!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function wr(){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=x==="custom"&&!!T&&!N.some(function(s){return s&&s.css===T});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=N[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 Sr(){var e="ext:markdown-editor-icons/save",t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDefault");D?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):be&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=X();return[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:p||z||n("toolbar.open.tooltipDefault"),disabled:j},{id:"save",icon:e,label:t,tooltip:a,disabled:!D},{type:"separator"},{id:"mode",icon:Te?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?Te?"toolbar.mode.tooltipRendering":b==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:b==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(b==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:b!=="preview",items:wr()},{type:"spacer"},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?R?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:R,disabled:!r||b==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?b==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||b==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!O},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:O},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:q===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:q===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:q===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:Y==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:Y==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:b!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}]}function F(e,t,a){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function kr(){if($e){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),x===s)}).join("")+"<hr>",a=x==="custom"&&!!T&&!N.some(function(s){return s&&s.css===T});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=N[r];t+=o?F("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),x==="custom"&&T===o.css):F("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}$e.innerHTML=t}et&&(et.innerHTML=F("comfort:read",n("toolbar.comfort.read"),!O)+F("comfort:write",n("toolbar.comfort.write"),O)+"<hr>"+F("font-size:14",n("toolbar.fontSize.small"),q===14)+F("font-size:16",n("toolbar.fontSize.medium"),q===16)+F("font-size:18",n("toolbar.fontSize.large"),q===18)+"<hr>"+F("font-family:rounded",n("toolbar.fontFamily.default"),Y==="rounded")+F("font-family:songti",n("toolbar.fontFamily.serif"),Y==="songti")),tt&&(tt.innerHTML=F("reload",n("toolbar.more.reload"),!1)+F("reveal",n("toolbar.more.reveal"),!1)+"<hr>"+F("about",n("toolbar.more.about"),!1))}function xr(){if(w){var e=X();if(Z){Z.disabled=!D,Z.classList.toggle("dirty",D);var t=be?"toolbar.save.tooltipSaved":D?"toolbar.save.tooltipDirty":"toolbar.save.tooltipDefault";Z.setAttribute("data-tooltip",n(t));var a=Z.querySelector(".ic-save"),r=Z.querySelector(".ic-save-check");a&&(a.hidden=be),r&&(r.hidden=!be)}Me&&(Me.disabled=!e,Me.classList.toggle("checked",R)),Ce&&(Ce.disabled=!e,Ce.classList.toggle("checked",ee)),Qe&&(Qe.disabled=j),Ze&&(Ze.disabled=!e||!ee,Ze.setAttribute("data-tooltip",n(ee?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),Et&&(Et.disabled=!e),kr()}}function h(){w?xr():i&&i.postMessage({type:"setToolbar",toolbar:Sr()})}function We(e){if(I(),w){b="edit",he(),U(),h();return}b=e,he(),h(),b==="preview"&&U()}function Er(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(","),d=s>=0?o.slice(s+1):"";if(!d){a(new Error("Could not read pasted image."));return}var u=++sr;ie[u]={resolve:t,reject:a},setTimeout(function(){ie[u]&&(delete ie[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:d,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var g=window.MarkdownCodeMirror.create({parent:pe,value:m,onChange:function(e){m=e,I(),qe(),we(!0),Ra(),Cr()},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:Er,onAiHintTrigger:zr});g.setFontSize(q),g.setFontFamily(ge[Y]),g.setComfortWriting(O),g.setFocusMode(R),g.scrollDOM.addEventListener("scroll",I);function Lr(){return x==="custom"?T:""}function Cr(){w&&(ot&&clearTimeout(ot),ot=setTimeout(function(){ot=0,U()},420))}function U(){if(!(!m||!i)){var e=++va;Te=!0,h(),i.postMessage({type:"renderBm",markdown:m,markdownStyle:x==="custom"?"kami":x,customCss:Lr(),requestId:e})}}function Mr(){var e=L.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function Ir(e){var t=L.contentDocument,a=t&&t.scrollingElement;!e||!a||(a.scrollTop=Math.min(e.top,Math.max(0,a.scrollHeight-a.clientHeight)))}function Ar(){try{return getComputedStyle(L).backgroundColor||""}catch{return""}}function Ma(e){var t=Mr(),a=L.contentDocument;W=e;var r=Ar();if(At&&a&&a.body){a.body.innerHTML=W,r&&(a.body.style.background=r),Ir(t),Aa();return}L.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>"+W}function Ia(e,t,a){return{start:e.slice(0,t).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=Ke?Xe.zh:Xe.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(Xe.en,e)?Xe.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 yt(e){var t=e||document;document.documentElement.lang=Ke?"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 ht=document.getElementById("empty"),ta=document.getElementById("emptyNew"),aa=document.getElementById("emptyOpen"),bt=document.getElementById("homeRecent"),ae=document.getElementById("homeGrid"),Je=document.getElementById("homeHint"),wt=[],ra=document.getElementById("homeTagline"),tr=document.getElementById("editPane"),St=document.getElementById("previewPane"),re=document.getElementById("previewResizer"),pe=document.getElementById("editor"),L=document.getElementById("article"),A=document.getElementById("status"),k=document.getElementById("popup"),H=document.getElementById("popupInput"),na=document.getElementById("popupSend"),oa=document.getElementById("popupShortcut"),Ee=document.getElementById("actions"),ar=document.getElementById("actCopyWx"),rr=document.getElementById("actCopyImg"),nr=document.getElementById("actSaveImg"),or=document.getElementById("actSavePdf"),fe=document.getElementById("actAiStyle"),ia=document.getElementById("actToggle"),ne=document.getElementById("confirmOverlay"),sa=document.getElementById("confirmMessage"),kt=document.getElementById("confirmCancel"),xt=document.getElementById("confirmDiscard"),Le=document.getElementById("confirmSave"),la=document.getElementById("appToolbar"),da=document.getElementById("appHome"),ua=document.getElementById("appLibrary"),Qe=document.getElementById("appOpen"),Z=document.getElementById("appSave"),Ce=document.getElementById("appPreview"),Ze=document.getElementById("appStyle"),$e=document.getElementById("appStyleMenu"),Me=document.getElementById("appFocus"),Et=document.getElementById("appFont"),et=document.getElementById("appFontMenu"),ir=document.getElementById("appMore"),tt=document.getElementById("appMoreMenu"),Lt=document.getElementById("libraryDrawer"),at=document.getElementById("libraryBackdrop"),ca=document.getElementById("libraryClose"),rt=document.getElementById("libraryReorder"),pa=document.getElementById("libraryReorderFooter"),fa=document.getElementById("libraryReorderDone"),C=document.getElementById("libraryGroups"),ma="md-editor-library-groups-v1",Ie=[],nt={},oe=null,Ae=null,$=!1,Ct=[],z=null,Mt=!1,w=!1,ga=!1,ee=!0,sr=!1,ot=0,Fe=!1,Q=!0,b="edit",x="kami",T="",me="",N=[null,null,null],ge={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},q=14,Y="rounded",O=!1,R=!1;try{var it=Number(localStorage.getItem("md-editor-font-size"));(it===14||it===16||it===18)&&(q=it);var It=localStorage.getItem("md-editor-font-family");ge[It]?Y=It:It&&localStorage.removeItem("md-editor-font-family"),O=localStorage.getItem("md-editor-comfort-writing")==="1",R=localStorage.getItem("md-editor-focus-mode")==="1";var De=JSON.parse(localStorage.getItem(ma)||"{}");Array.isArray(De.order)&&(Ie=De.order.filter(function(e){return typeof e=="string"})),De.collapsed&&typeof De.collapsed=="object"&&(nt=De.collapsed)}catch{}Q=!R;var m="",Pe="",U="",p="",B=null,W="",At=!1,va=0,Te=!1,ya=0,Ft={},ve={},lr=0,ie={},dr=0,se={},Oe=0,K=null,st=0,ye=0,Dt=!1,v={text:"",mode:"replace"},M=0;function l(e,t){M&&(clearTimeout(M),M=0),A.textContent=e||"",A.className="status"+(t?" error":""),e&&(M=setTimeout(function(){M=0,A.textContent="",A.className="status"},5e3))}function ur(){M&&(clearTimeout(M),M=0),A.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/"})}),A.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),A.className="status",M=setTimeout(function(){M=0,A.textContent="",A.className="status"},5e3)}function X(){return!!m||!!p}ta&&ta.addEventListener("click",async function(){if(!i||!i.composer){l(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),l(n("newdoc.added"))}catch(e){l(String(e),!0)}}),aa&&aa.addEventListener("click",function(){jt()});var Re="",Pt="",Tt="",lt=!1,ha=!1,Be="",le="";function y(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function ba(){ra&&(ra.textContent=Be?n("home.tagline.withAssistant",{name:Be}):n("home.tagline.default"))}function dt(){H&&(H.placeholder=v.mode==="continue"?n("popup.placeholderContinue",{name:Be||"Finch"}):n("popup.placeholder",{name:Be||"Finch"}))}function cr(e){return e?le&&e===le?"~":le&&(e.indexOf(le+"/")===0||e.indexOf(le+"\\")===0)?"~"+e.slice(le.length):e:""}function pr(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 fr(){ct(wt)}function wa(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 d=new Date(a.getTime()-864e5);return t.toDateString()===d.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 ut(){!i||!i.postMessage||!lt||(ha=!0,i.postMessage({type:"requestRecentDocuments",cwd:Re,sessionId:Pt,spaceId:Tt}))}function mr(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+y(e.path||"")+'" title="'+y(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+y(e.path||"")+'" role="button" tabindex="0" title="'+y(n("home.revealInFileManager"))+'" aria-label="'+y(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">'+y(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+y(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+y(t)+'">'+y(t)+'</span><span class="doc-time">'+y(wa(e.modifiedAt))+"</span></div></div></button>"}function ct(e){if(!(!ae||!bt||!Je)){var t=Array.isArray(e)?e:[];if(wt=t,t.length===0){bt.hidden=!0,Je.hidden=!1,Je.textContent=n(Re?"home.hintScoped":"home.hintDefault");return}var a=ka(t);ae.innerHTML=a.map(function(r){var o=r.documents.map(mr).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+y(r.scopePath)+'" title="'+y(n("home.cwdTitle",{path:r.scopePath}))+'">'+y(pr(cr(r.scopePath)))+"</button>":"",d='<div class="home-group-title"><span class="home-group-label">'+y(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+d+'<div class="home-grid">'+o+"</div></div>"}).join(""),bt.hidden=!1,Je.hidden=!0,requestAnimationFrame(function(){gr(ae)})}}function gr(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 d=0,u=s.length,c=0;d<=u;){var f=d+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(c=f,d=f+1):u=f-1}o.textContent=c>0?t+s.slice(s.length-c):t}}}function Sa(){try{localStorage.setItem(ma,JSON.stringify({order:Ie,collapsed:nt}))}catch{}}function ka(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=Ie.indexOf(a.id),s=Ie.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var d={space:0,workspace:1},u=d[a.kind]-d[r.kind];return u||a.label.localeCompare(r.label)})}function xa(e){if(C){Ct=Array.isArray(e)?e:[];var t=ka(Ct);if($){vr(t);return}C.innerHTML=t.map(function(a){var r=a.documents.map(function(d){var u=d.relativePath||d.fileName||"";return'<button class="library-row" type="button" data-path="'+y(d.path||"")+'"><span class="library-row-main"><strong>'+y(d.title||d.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+y(u)+'">'+y(u)+"</span><time>"+y(wa(d.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!nt[a.id];return'<details class="library-group" data-library-group-id="'+y(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+y(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">'+y(n("home.hintDefault"))+"</p>"}}function vr(e){C.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+y(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+y(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+y(n("home.hintDefault"))+"</p>"}function Ot(e){$=!!e,rt&&rt.classList.toggle("active",$),pa&&(pa.hidden=!$),xa(Ct)}function pt(e){!Lt||!at||(Lt.classList.toggle("open",!!e),Lt.setAttribute("aria-hidden",e?"false":"true"),at.hidden=!e,e?ut():$&&Ot(!1))}function yr(){if(!(!oe||!C)){oe.classList.remove("dragging"),Array.prototype.forEach.call(C.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),Ie=Array.prototype.map.call(C.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),ct(wt);var e=Ae||{};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])}),oe=null,setTimeout(function(){Ae=null,Sa()},0)}}function hr(){z&&z.ghost&&z.ghost.parentNode&&z.ghost.parentNode.removeChild(z.ghost)}function Ea(e,t){var a=z;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function br(e){var t=z;if(!(!t||t.active)){t.active=!0,oe=e,Ae={},$||Array.prototype.forEach.call(C.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(Ae[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),Ea(t.startX,t.startY)}}function wr(e,t){if(oe){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===oe)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;C.insertBefore(oe,o?r.nextSibling:r)}}}function La(){var e=z;e&&(e.active&&(hr(),yr(),Mt=!0,setTimeout(function(){Mt=!1},0)),z=null)}ua&&ua.addEventListener("click",function(){pt(!0)}),ca&&ca.addEventListener("click",function(){pt(!1)}),at&&at.addEventListener("click",function(){pt(!1)}),rt&&rt.addEventListener("click",function(){Ot(!$)}),fa&&fa.addEventListener("click",function(){Ot(!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||(pt(!1),Ne=!0,l(n("status.opening")),i.postMessage({type:"loadPath",path:a}))}),C&&(C.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!Ae){var a=t.getAttribute("data-library-group-id");a&&(nt[a]=!t.open,Sa())}},!0),C.addEventListener("click",function(e){if(Mt){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&&$){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(z={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=z;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;br(t.group)}e.preventDefault(),Ea(e.clientX,e.clientY),wr(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){La()}),window.addEventListener("pointercancel",function(){La()}));var Ne=!1;ae&&ae.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 d=s.getAttribute("data-path")||"";d&&(Ne=!0,l(n("status.opening")),i.postMessage({type:"loadPath",path:d}))}}}),ae&&ae.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 qe(){ht.hidden=X(),document.body.classList.toggle("has-document",X()),Ee&&(Ee.hidden=!W),!ht.hidden&<&&ut()}function he(){tr.classList.toggle("active",w?X():b==="edit"),St.classList.toggle("active",w?X():b==="preview"),(w||b==="edit")&&g&&requestAnimationFrame(function(){g.layout()})}function Ca(e){!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function Sr(){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=x==="custom"&&!!T&&!N.some(function(s){return s&&s.css===T});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=N[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");D?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):be&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=X();return[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:p||U||n("toolbar.open.tooltipDefault"),disabled:_},{id:"save",icon:e,label:t,tooltip:a,disabled:!D},{type:"separator"},{id:"mode",icon:Te?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?Te?"toolbar.mode.tooltipRendering":b==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:b==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(b==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:b!=="preview",items:Sr()},{type:"spacer"},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?R?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:R,disabled:!r||b==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?b==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||b==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!O},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:O},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:q===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:q===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:q===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:Y==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:Y==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:b!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}]}function F(e,t,a){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function xr(){if($e){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),x===s)}).join("")+"<hr>",a=x==="custom"&&!!T&&!N.some(function(s){return s&&s.css===T});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=N[r];t+=o?F("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),x==="custom"&&T===o.css):F("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}$e.innerHTML=t}et&&(et.innerHTML=F("comfort:read",n("toolbar.comfort.read"),!O)+F("comfort:write",n("toolbar.comfort.write"),O)+"<hr>"+F("font-size:14",n("toolbar.fontSize.small"),q===14)+F("font-size:16",n("toolbar.fontSize.medium"),q===16)+F("font-size:18",n("toolbar.fontSize.large"),q===18)+"<hr>"+F("font-family:rounded",n("toolbar.fontFamily.default"),Y==="rounded")+F("font-family:songti",n("toolbar.fontFamily.serif"),Y==="songti")),tt&&(tt.innerHTML=F("reload",n("toolbar.more.reload"),!1)+F("reveal",n("toolbar.more.reveal"),!1)+"<hr>"+F("about",n("toolbar.more.about"),!1))}function Er(){if(w){var e=X();if(Z){Z.disabled=!D,Z.classList.toggle("dirty",D);var t=be?"toolbar.save.tooltipSaved":D?"toolbar.save.tooltipDirty":"toolbar.save.tooltipDefault";Z.setAttribute("data-tooltip",n(t));var a=Z.querySelector(".ic-save"),r=Z.querySelector(".ic-save-check");a&&(a.hidden=be),r&&(r.hidden=!be)}Me&&(Me.disabled=!e,Me.classList.toggle("checked",R)),Ce&&(Ce.disabled=!e,Ce.classList.toggle("checked",ee)),Qe&&(Qe.disabled=_),Ze&&(Ze.disabled=!e||!ee,Ze.setAttribute("data-tooltip",n(ee?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),Et&&(Et.disabled=!e),xr()}}function h(){w?Er():i&&i.postMessage({type:"setToolbar",toolbar:kr()})}function We(e){if(I(),w){b="edit",he(),j(),h();return}b=e,he(),h(),b==="preview"&&j()}function Lr(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(","),d=s>=0?o.slice(s+1):"";if(!d){a(new Error("Could not read pasted image."));return}var u=++lr;ie[u]={resolve:t,reject:a},setTimeout(function(){ie[u]&&(delete ie[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:d,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var g=window.MarkdownCodeMirror.create({parent:pe,value:m,onChange:function(e){m=e,I(),qe(),we(!0),Ba(),Mr()},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:Lr,onAiHintTrigger:jr});g.setFontSize(q),g.setFontFamily(ge[Y]),g.setComfortWriting(O),g.setFocusMode(R),g.scrollDOM.addEventListener("scroll",I);function Cr(){return x==="custom"?T:""}function Mr(){w&&(ot&&clearTimeout(ot),ot=setTimeout(function(){ot=0,j()},420))}function j(){if(!(!m||!i)){var e=++va;Te=!0,h(),i.postMessage({type:"renderBm",markdown:m,markdownStyle:x==="custom"?"kami":x,customCss:Cr(),requestId:e})}}function Ir(){var e=L.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function Ar(e){var t=L.contentDocument,a=t&&t.scrollingElement;!e||!a||(a.scrollTop=Math.min(e.top,Math.max(0,a.scrollHeight-a.clientHeight)))}function Fr(){try{return getComputedStyle(L).backgroundColor||""}catch{return""}}function Ma(e){var t=Ir(),a=L.contentDocument;W=e;var r=Fr();if(At&&a&&a.body){a.body.innerHTML=W,r&&(a.body.style.background=r),Ar(t),Aa();return}L.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>"+W}function Ia(e,t,a){return{start:e.slice(0,t).split(`
|
|
11
11
|
`).length,end:e.slice(0,a).split(`
|
|
12
|
-
`).length}}function
|
|
13
|
-
`;if(s){var d=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(d){o+=d[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var c=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(c){for(var f=o+c[0].indexOf("[")+1,S=0;S<c[1].length;S++)/[*_~`]/.test(c[1][S])||r(c[1][S],f+S);o+=c[0].length;continue}var E=/^<[^>]+>/.exec(e.slice(o));if(E){o+=E[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 Fr(t,a)}function Pr(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=Dr(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 d=o.slice(0,6),u=o.slice(-6),c=r.text.indexOf(d),f=r.text.indexOf(u,Math.max(0,c+d.length));if(c>=0&&f>=c)return{start:r.map[c],end:r.map[f+u.length-1]+1}}return null}function Tr(e){return String(e||"").split(/[\\/]/).pop()||""}function Aa(){var e=L.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(Q){var a=L.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),d=Array.from(s.getClientRects()),u=L.getBoundingClientRect(),c=d.map(function(P){return{top:u.top+P.top,left:u.left+P.left,width:P.width,height:P.height}}),f=d[0]||s.getBoundingClientRect(),S=d[d.length-1]||f,E=Pr(m,o),_=E?Ia(m,E.start,E.end):null;Fa(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+S.bottom,endLeft:u.left+S.left},c,_,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){de(),I()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),We("edit"))}),e.addEventListener("scroll",function(){de(),I()},!0),L.contentWindow.addEventListener("scroll",function(){de(),I()})}L.onload=function(){At=!0,Aa()};var ft=0,Rt=[];function Fa(e,t,a,r,o){de(),ft=setTimeout(function(){Da(e,t,a,r,o)},300)}function de(){ft&&(clearTimeout(ft),ft=0)}function Da(e,t,a,r,o,s){v.text=e,v.lines=r||null,v.origin=o||"",v.mode=s||"replace",dt(),k.classList.remove("hidden"),k.classList.toggle("popup-bar",!!(t&&t.width)),G.value="",Rr(a),requestAnimationFrame(function(){Or(t),t&&t.focus&&G.focus()})}function Or(e){var t=8,a=10,r=e||{},o=w?t+48:t;if(k.style.width=r.width?r.width+"px":"",r.width){k.style.left=Math.max(t,r.startLeft||0)+"px",k.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(k.offsetHeight||44)-t))+"px";return}var s=k.offsetWidth||300,d=k.offsetHeight||44,u=(r.startTop||0)-a-d,c=u>=o,f=c?u:(r.endBottom||0)+a,S=c?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;k.style.left=Math.max(t,Math.min(S,window.innerWidth-s-t))+"px",k.style.top=Math.max(o,Math.min(f,window.innerHeight-d-t))+"px"}function Rr(e){Pa(),(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),Rt.push(a)})}function Pa(){Rt.forEach(function(e){e.remove()}),Rt=[]}var Br=navigator.platform||navigator.userAgent||"",Bt=/Mac|iPhone|iPod|iPad/.test(Br);function Nr(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Bt?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(oa){var t=Bt?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Bt?"":"+";oa.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function I(e){var t=e===!0&&v.origin==="editor"&&b==="edit";de(),k.classList.add("hidden"),k.classList.remove("popup-bar"),k.classList.remove("focused"),k.style.width="",v.text="",v.lines=null,v.origin="",v.mode="replace",Pa(),t&&requestAnimationFrame(function(){g.focus()})}na.onclick=Ta,G.addEventListener("keydown",function(e){e.key==="Enter"&&Ta(),e.key==="Escape"&&I(!0)}),G.addEventListener("focus",function(){k.classList.add("focused")}),G.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==na&&k.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!k.classList.contains("hidden")&&I(!0)}),document.addEventListener("keydown",function(e){Nr(e)&&(k.classList.contains("hidden")||(e.preventDefault(),G.focus(),G.select()))}),document.addEventListener("mousedown",function(e){k.contains(e.target)||(de(),I())}),window.addEventListener("resize",I);function qr(){if(!v.lines)return n("annotate.lineUnknown");var e=v.lines.start,t=v.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function Wr(){return v.lines?v.lines.start+"-"+v.lines.end:n("annotate.lineCompactUnknown")}async function Ta(){var e=G.value.trim(),t=v.mode==="continue",a=v.mode==="annotate-line";if(!(!v.text&&!t&&!a||!i)){if(D&&p){var r=await Kt();if(!r){l(n("status.saveFailedNoReturn"),!0);return}}if(w){if(!p||!i.postMessage){l(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:p,selectedText:v.text,requirement:e,startLine:v.lines&&v.lines.start,endLine:v.lines&&v.lines.end,rewriteMode:t?"continue":"replace"}),I(!0),l(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!v.text&&!a){I(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(z||"Markdown")+":"+Wr(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:qr(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:v.text||n("annotate.emptyLine"),path:p||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),I(!0),l(n("annotate.added"))}catch(o){l(String(o),!0)}}}function Hr(){var e=g.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=Ia(g.getValue(),e.start,e.end);return Fa(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function Oa(){Q&&Hr()}function zr(e){if(!X()||!e)return!1;de();var t=pe.querySelector(".cm-line")||pe.querySelector(".cm-content"),a=(t||pe).getBoundingClientRect();return Da("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",w?"continue":"annotate-line"),!0}pe.addEventListener("mouseup",Oa),pe.addEventListener("keyup",function(e){e.shiftKey&&Oa()});var D=!1,He=0,te=null,Nt=!1,be=!1,qt="",Wt=null;function Ur(e){qt=e,Wt=m,i.postMessage({type:"saveDraft",path:e,markdown:m,base:B})}function Ra(){!p||!i||!i.postMessage||qt===p&&Wt===m||Ur(p)}function Ht(){qt="",Wt=null}function zt(e){Ht(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function we(e,t){D=e,Oe&&(clearTimeout(Oe),Oe=0),be=!D&&!!t,h(),!D&&t&&(Oe=setTimeout(function(){Oe=0,D||(be=!1,h())},3e3))}async function Ba(e){if(te)return qa(),l("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if(K&&K.createWritable)try{var t=await K.createWritable();return await t.write(e),await t.close(),st=(await K.getFile()).lastModified,B=e,we(m!==e,m===e),l(n(m===e?"status.saved":"status.savedWithNewChanges")),Ht(),!0}catch(r){return l(n("status.saveFailed",{err:String(r)}),!0),!1}if(p){var a=++ya;return l(n("status.saving")),Ft[a]=e,i.postMessage({type:"saveMarkdown",path:p,markdown:e,requestId:a}),new Promise(function(r){ve[a]=r})}return l(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(),Yt();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),We(b==="edit"?"preview":"edit"))});function Na(){ye&&(clearInterval(ye),ye=0),K=null}var Ut=null;function ze(e,t,a,r,o){if(!r&&D&&B!==null&&e!==B)return te={markdown:e,name:t,path:a,diskBaseline:o},l(n("status.externalUpdateSkipped"),!0),qa(),!1;var s=B!==null&&(!a||!p||a===p);return s||(Q=!0),m=e,Pe=t,a&&(p=a),z=Tr(a||p)||t||"Markdown",B=typeof o=="string"?o:m,Ut=s?g.applyExternalValue(m):null,Ut||g.setValue(m),we(!1),Ca(z),qe(),he(),(w||b==="preview")&&U(),!0}async function qa(){if(!(Nt||!te||!D)){var e=te,t=B;if(m===t){te=null,ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){te=null;return}Nt=!0;var a=await un();if(Nt=!1,te===e){if(a==="later"){l("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(te=null,a==="remote"){zt(p),ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(B=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,Ra(),l("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function Wa(e){Pe=e.name,st=e.lastModified,typeof e.path=="string"&&e.path?(p=e.path,i&&i.postMessage({type:"watchPath",path:p})):p="",ze(await e.text(),Pe,p,!0)}function jr(){K&&(ye&&clearInterval(ye),ye=setInterval(async function(){if(!(Dt||!K)){Dt=!0;try{var e=await K.getFile();if(e.lastModified!==st){st=e.lastModified;var t=await e.text();t!==B&&ze(t,Pe,p)&&l(n("status.externalUpdateApplied"))}}catch{}Dt=!1}},800))}var j=!1,Ue=0;function je(){Ue&&(clearTimeout(Ue),Ue=0)}function _r(){je(),Ue=setTimeout(function(){Ue=0,j&&(j=!1,Fe=!1,h(),l(n("status.pickerTimeout"),!0))},2e4)}async function jt(){if(D){var e=await Ka(n("confirm.message",{file:z||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await Kt();if(!t){l(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&zt(p)}if(Na(),Fe&&i&&i.postMessage){if(j){je(),Fe=!1,j=!1,h(),await Ha();return}j=!0,_r(),h(),l(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await Ha()}async function Ha(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});K=e[0],await Wa(await K.getFile()),jr();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&&Wa(a).catch(function(r){l(String(r),!0)})},t.click()}function Vr(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function Gr(e){for(var t=0;t<e;t++){if(Vr(),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 za(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=++lr;se[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){se[o]&&(delete se[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function Yr(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 Ua(e,t){if(document.hasFocus()||await Gr(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 Kr(a)?"rich":Xr(t)?"plain":"none"}function Kr(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 Xr(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 Jr(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{var e=L.contentDocument&&L.contentDocument.body?L.contentDocument.body.innerText:W.replace(/<[^>]+>/g,""),t=await Ua(za(W),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await Ua(za(W),e)),t==="rich"?l(n("status.copiedRich")):l(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){l(n("status.richCopyFailed",{err:String(a)}),!0)}finally{b==="edit"&&requestAnimationFrame(function(){g.focus()})}}function Qr(){if(!At||!L.contentDocument)return null;var e=L.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 _t(){var e=Qr();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(d){return Promise.reject(new Error(n("status.serializeFailed",{err:String(d)})))}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(d,u){var c=new Image;c.decoding="sync",c.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var S=f.getContext("2d");S.scale(t,t);var E="";try{E=L.contentWindow.getComputedStyle(e.root).backgroundColor}catch{E=""}E&&E!=="rgba(0, 0, 0, 0)"&&E!=="transparent"&&(S.fillStyle=E,S.fillRect(0,0,e.width,e.height)),S.drawImage(c,0,0,e.width,e.height),d({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(_){u(_)}},c.onerror=function(){u(new Error(n("status.imageConversionFailed")))},c.src=s})}function Vt(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 ja(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 Zr(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){l(n("status.clipboardUnsupported"),!0);return}l(n("status.generatingImage"));var e=_t().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return Vt(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),l(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),l(n("status.imageCopied"));return}catch(r){l(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function $r(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{l(n("status.generatingImage"));var e=await _t();if(!e){l(n("status.exportImageFailedGeneric"),!0);return}var t=await Vt(e.canvas,"image/png"),a=await t.arrayBuffer(),r=ja(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:p,fileName:z,markdown:m})}catch(o){l(n("status.exportImageFailed",{err:String(o)}),!0)}}function en(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function J(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function Gt(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 tn(e,t,a,r,o){var s=J(`%PDF-1.4
|
|
12
|
+
`).length}}function Dr(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 Pr(e){var t="",a=[];function r(V,P){t+=V,a.push(P)}for(var o=0;o<e.length;){var s=o===0||e[o-1]===`
|
|
13
|
+
`;if(s){var d=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(d){o+=d[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var c=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(c){for(var f=o+c[0].indexOf("[")+1,S=0;S<c[1].length;S++)/[*_~`]/.test(c[1][S])||r(c[1][S],f+S);o+=c[0].length;continue}var E=/^<[^>]+>/.exec(e.slice(o));if(E){o+=E[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 Dr(t,a)}function Tr(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=Pr(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 d=o.slice(0,6),u=o.slice(-6),c=r.text.indexOf(d),f=r.text.indexOf(u,Math.max(0,c+d.length));if(c>=0&&f>=c)return{start:r.map[c],end:r.map[f+u.length-1]+1}}return null}function Or(e){return String(e||"").split(/[\\/]/).pop()||""}function Aa(){var e=L.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(Q){var a=L.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),d=Array.from(s.getClientRects()),u=L.getBoundingClientRect(),c=d.map(function(P){return{top:u.top+P.top,left:u.left+P.left,width:P.width,height:P.height}}),f=d[0]||s.getBoundingClientRect(),S=d[d.length-1]||f,E=Tr(m,o),V=E?Ia(m,E.start,E.end):null;Fa(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+S.bottom,endLeft:u.left+S.left},c,V,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){de(),I()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),We("edit"))}),e.addEventListener("scroll",function(){de(),I()},!0),L.contentWindow.addEventListener("scroll",function(){de(),I()})}L.onload=function(){At=!0,Aa()};var ft=0,Rt=[];function Fa(e,t,a,r,o){de(),ft=setTimeout(function(){Da(e,t,a,r,o)},300)}function de(){ft&&(clearTimeout(ft),ft=0)}function Da(e,t,a,r,o,s){v.text=e,v.lines=r||null,v.origin=o||"",v.mode=s||"replace",dt(),k.classList.remove("hidden"),k.classList.toggle("popup-bar",!!(t&&t.width)),H.value="",Br(a),requestAnimationFrame(function(){Rr(t),t&&t.focus&&H.focus()})}function Rr(e){var t=8,a=10,r=e||{},o=w?t+48:t;if(k.style.width=r.width?r.width+"px":"",r.width){k.style.left=Math.max(t,r.startLeft||0)+"px",k.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(k.offsetHeight||44)-t))+"px";return}var s=k.offsetWidth||300,d=k.offsetHeight||44,u=(r.startTop||0)-a-d,c=u>=o,f=c?u:(r.endBottom||0)+a,S=c?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;k.style.left=Math.max(t,Math.min(S,window.innerWidth-s-t))+"px",k.style.top=Math.max(o,Math.min(f,window.innerHeight-d-t))+"px"}function Br(e){Pa(),(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),Rt.push(a)})}function Pa(){Rt.forEach(function(e){e.remove()}),Rt=[]}var Nr=navigator.platform||navigator.userAgent||"",Bt=/Mac|iPhone|iPod|iPad/.test(Nr);function qr(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Bt?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(oa){var t=Bt?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Bt?"":"+";oa.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function I(e){var t=e===!0&&v.origin==="editor"&&b==="edit";de(),k.classList.add("hidden"),k.classList.remove("popup-bar"),k.classList.remove("focused"),k.style.width="",v.text="",v.lines=null,v.origin="",v.mode="replace",Pa(),t&&requestAnimationFrame(function(){g.focus()})}na.onclick=Oa;var Ta=0;H.addEventListener("compositionend",function(){Ta=Date.now()});function Wr(e){return e.isComposing||e.keyCode===229?!0:Date.now()-Ta<100}H.addEventListener("keydown",function(e){if(e.key==="Enter"){if(Wr(e))return;Oa()}e.key==="Escape"&&I(!0)}),H.addEventListener("focus",function(){k.classList.add("focused")}),H.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==na&&k.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!k.classList.contains("hidden")&&I(!0)}),document.addEventListener("keydown",function(e){qr(e)&&(k.classList.contains("hidden")||(e.preventDefault(),H.focus(),H.select()))}),document.addEventListener("mousedown",function(e){k.contains(e.target)||(de(),I())}),window.addEventListener("resize",I);function Hr(){if(!v.lines)return n("annotate.lineUnknown");var e=v.lines.start,t=v.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function zr(){return v.lines?v.lines.start+"-"+v.lines.end:n("annotate.lineCompactUnknown")}async function Oa(){var e=H.value.trim(),t=v.mode==="continue",a=v.mode==="annotate-line";if(!(!v.text&&!t&&!a||!i)){if(D&&p){var r=await Kt();if(!r){l(n("status.saveFailedNoReturn"),!0);return}}if(w){if(!p||!i.postMessage){l(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:p,selectedText:v.text,requirement:e,startLine:v.lines&&v.lines.start,endLine:v.lines&&v.lines.end,rewriteMode:t?"continue":"replace"}),I(!0),l(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!v.text&&!a){I(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(U||"Markdown")+":"+zr(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:Hr(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:v.text||n("annotate.emptyLine"),path:p||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),I(!0),l(n("annotate.added"))}catch(o){l(String(o),!0)}}}function Ur(){var e=g.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=Ia(g.getValue(),e.start,e.end);return Fa(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function Ra(){Q&&Ur()}function jr(e){if(!X()||!e)return!1;de();var t=pe.querySelector(".cm-line")||pe.querySelector(".cm-content"),a=(t||pe).getBoundingClientRect();return Da("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",w?"continue":"annotate-line"),!0}pe.addEventListener("mouseup",Ra),pe.addEventListener("keyup",function(e){e.shiftKey&&Ra()});var D=!1,He=0,te=null,Nt=!1,be=!1,qt="",Wt=null;function _r(e){qt=e,Wt=m,i.postMessage({type:"saveDraft",path:e,markdown:m,base:B})}function Ba(){!p||!i||!i.postMessage||qt===p&&Wt===m||_r(p)}function Ht(){qt="",Wt=null}function zt(e){Ht(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function we(e,t){D=e,Oe&&(clearTimeout(Oe),Oe=0),be=!D&&!!t,h(),!D&&t&&(Oe=setTimeout(function(){Oe=0,D||(be=!1,h())},3e3))}async function Na(e){if(te)return Wa(),l("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if(K&&K.createWritable)try{var t=await K.createWritable();return await t.write(e),await t.close(),st=(await K.getFile()).lastModified,B=e,we(m!==e,m===e),l(n(m===e?"status.saved":"status.savedWithNewChanges")),Ht(),!0}catch(r){return l(n("status.saveFailed",{err:String(r)}),!0),!1}if(p){var a=++ya;return l(n("status.saving")),Ft[a]=e,i.postMessage({type:"saveMarkdown",path:p,markdown:e,requestId:a}),new Promise(function(r){ve[a]=r})}return l(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(),Yt();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),We(b==="edit"?"preview":"edit"))});function qa(){ye&&(clearInterval(ye),ye=0),K=null}var Ut=null;function ze(e,t,a,r,o){if(!r&&D&&B!==null&&e!==B)return te={markdown:e,name:t,path:a,diskBaseline:o},l(n("status.externalUpdateSkipped"),!0),Wa(),!1;var s=B!==null&&(!a||!p||a===p);return s||(Q=!0),m=e,Pe=t,a&&(p=a),U=Or(a||p)||t||"Markdown",B=typeof o=="string"?o:m,Ut=s?g.applyExternalValue(m):null,Ut||g.setValue(m),we(!1),Ca(U),qe(),he(),(w||b==="preview")&&j(),!0}async function Wa(){if(!(Nt||!te||!D)){var e=te,t=B;if(m===t){te=null,ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){te=null;return}Nt=!0;var a=await pn();if(Nt=!1,te===e){if(a==="later"){l("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(te=null,a==="remote"){zt(p),ze(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(B=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,Ba(),l("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function Ha(e){Pe=e.name,st=e.lastModified,typeof e.path=="string"&&e.path?(p=e.path,i&&i.postMessage({type:"watchPath",path:p})):p="",ze(await e.text(),Pe,p,!0)}function Vr(){K&&(ye&&clearInterval(ye),ye=setInterval(async function(){if(!(Dt||!K)){Dt=!0;try{var e=await K.getFile();if(e.lastModified!==st){st=e.lastModified;var t=await e.text();t!==B&&ze(t,Pe,p)&&l(n("status.externalUpdateApplied"))}}catch{}Dt=!1}},800))}var _=!1,Ue=0;function je(){Ue&&(clearTimeout(Ue),Ue=0)}function Gr(){je(),Ue=setTimeout(function(){Ue=0,_&&(_=!1,Fe=!1,h(),l(n("status.pickerTimeout"),!0))},2e4)}async function jt(){if(D){var e=await Xa(n("confirm.message",{file:U||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await Kt();if(!t){l(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&zt(p)}if(qa(),Fe&&i&&i.postMessage){if(_){je(),Fe=!1,_=!1,h(),await za();return}_=!0,Gr(),h(),l(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await za()}async function za(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});K=e[0],await Ha(await K.getFile()),Vr();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&&Ha(a).catch(function(r){l(String(r),!0)})},t.click()}function Yr(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function Kr(e){for(var t=0;t<e;t++){if(Yr(),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 Ua(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=++dr;se[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){se[o]&&(delete se[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function Xr(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 ja(e,t){if(document.hasFocus()||await Kr(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 Jr(a)?"rich":Qr(t)?"plain":"none"}function Jr(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 Qr(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 Zr(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{var e=L.contentDocument&&L.contentDocument.body?L.contentDocument.body.innerText:W.replace(/<[^>]+>/g,""),t=await ja(Ua(W),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await ja(Ua(W),e)),t==="rich"?l(n("status.copiedRich")):l(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){l(n("status.richCopyFailed",{err:String(a)}),!0)}finally{b==="edit"&&requestAnimationFrame(function(){g.focus()})}}function $r(){if(!At||!L.contentDocument)return null;var e=L.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 _t(){var e=$r();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(d){return Promise.reject(new Error(n("status.serializeFailed",{err:String(d)})))}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(d,u){var c=new Image;c.decoding="sync",c.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var S=f.getContext("2d");S.scale(t,t);var E="";try{E=L.contentWindow.getComputedStyle(e.root).backgroundColor}catch{E=""}E&&E!=="rgba(0, 0, 0, 0)"&&E!=="transparent"&&(S.fillStyle=E,S.fillRect(0,0,e.width,e.height)),S.drawImage(c,0,0,e.width,e.height),d({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(V){u(V)}},c.onerror=function(){u(new Error(n("status.imageConversionFailed")))},c.src=s})}function Vt(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 _a(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 en(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){l(n("status.clipboardUnsupported"),!0);return}l(n("status.generatingImage"));var e=_t().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return Vt(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),l(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),l(n("status.imageCopied"));return}catch(r){l(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function tn(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{l(n("status.generatingImage"));var e=await _t();if(!e){l(n("status.exportImageFailedGeneric"),!0);return}var t=await Vt(e.canvas,"image/png"),a=await t.arrayBuffer(),r=_a(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:p,fileName:U,markdown:m})}catch(o){l(n("status.exportImageFailed",{err:String(o)}),!0)}}function an(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function J(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function Gt(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 rn(e,t,a,r,o){var s=J(`%PDF-1.4
|
|
14
14
|
%\xE2\xE3\xCF\xD3
|
|
15
15
|
`),d=[s],u=[0],c=s.length;function f(gt){u.push(c),d.push(gt),c+=gt.length}f(J(`1 0 obj
|
|
16
16
|
<< /Type /Catalog /Pages 2 0 R >>
|
|
@@ -27,7 +27,7 @@ stream
|
|
|
27
27
|
`),E=J(`
|
|
28
28
|
endstream
|
|
29
29
|
endobj
|
|
30
|
-
`);f(Gt([S,e,E]));var
|
|
30
|
+
`);f(Gt([S,e,E]));var V="q "+r.toFixed(2)+" 0 0 "+o.toFixed(2)+" 0 0 cm /Im0 Do Q",P=J(V);f(Gt([J(`5 0 obj
|
|
31
31
|
<< /Length `+P.length+` >>
|
|
32
32
|
stream
|
|
33
33
|
`),P,J(`
|
|
@@ -36,9 +36,9 @@ endobj
|
|
|
36
36
|
`)]));for(var ce=c,Se=[`xref
|
|
37
37
|
0 6
|
|
38
38
|
0000000000 65535 f
|
|
39
|
-
`],ke=1;ke<=5;ke++)Se.push(
|
|
39
|
+
`],ke=1;ke<=5;ke++)Se.push(an(u[ke])+` 00000 n
|
|
40
40
|
`);var $t=`trailer
|
|
41
41
|
<< /Size 6 /Root 1 0 R >>
|
|
42
42
|
startxref
|
|
43
43
|
`+ce+`
|
|
44
|
-
%%EOF`;return d.push(J(Se.join("")+$t)),Gt(d)}async function an(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{l(n("status.generatingPdf"));var e=await _t();if(!e){l(n("status.exportPdfFailedGeneric"),!0);return}var t=await Vt(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,d=tn(r,e.canvas.width,e.canvas.height,o,s),u=ja(d);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:p,fileName:z,markdown:m})}catch(c){l(n("status.exportPdfFailed",{err:String(c)}),!0)}}function _e(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){l(String(r),!0)}).then(function(){e.disabled=!1}))})}_e(tr,Jr),_e(ar,Zr),_e(rr,$r),_e(nr,an),_e(fe,rn);var _a="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(_a)==="1"}catch{}Ee&&Ee.classList.toggle("collapsed",t)})(),ia&&ia.addEventListener("click",function(e){e.preventDefault();var t=Ee.classList.toggle("collapsed");try{localStorage.setItem(_a,t?"1":"0")}catch{}});function Yt(){Ba(m)}function mt(e){if(ir=e,!!fe){fe.classList.toggle("loading",e),fe.disabled=e;var t=fe.querySelector(".ic-ai-style"),a=fe.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function Va(){if(!m||!p||!i||!i.postMessage){l(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:p,baseStyle:x}),mt(!0),l(n("aiStyle.appViewDesigning"))}async function rn(){if(!m){l(n("status.pleaseOpenArticle"),!0);return}if(w||!i||!i.composer){Va();return}var e=x==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:x});try{await i.composer.addContexts([{type:"annotation",label:n("aiStyle.label",{file:z||n("common.markdownDocDefault")}),note:n("aiStyle.note"),promptText:n("aiStyle.promptText",{baseNote:e,path:p||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),l(n("aiStyle.requested"))}catch{Va()}}function nn(){return{fontSize:q,fontFamily:Y,comfortWriting:O,style:x,customCss:x==="custom"?T:"",customStyleLabel:x==="custom"?me:""}}function ue(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:nn()})}function on(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(q=e.fontSize),ge[e.fontFamily]&&(Y=e.fontFamily),O=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(x="custom",T=e.customCss,me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(x=e.style,T="",me=""),g.setFontSize(q),g.setFontFamily(ge[Y]),g.setComfortWriting(O),!0)}function sn(e){x=e,ue(),(w||b==="preview")&&U(),h()}function ln(e){if(!(e!==14&&e!==16&&e!==18)){q=e,g.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}ue(),h()}}function dn(e){if(ge[e]){Y=e,g.setFontFamily(ge[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}ue(),h()}}function Ga(e){O=!!e,g.setComfortWriting(O);try{localStorage.setItem("md-editor-comfort-writing",O?"1":"0")}catch{}ue(),h(),l(n(O?"status.comfortWrite":"status.comfortRead"))}function Ya(){R=!R,R&&Q?(Q=!1,I()):!R&&!Q&&(Q=!0),g.setFocusMode(R);try{localStorage.setItem("md-editor-focus-mode",R?"1":"0")}catch{}h(),l(n(R?"status.focusOn":"status.focusOff"))}var Ve=null;function Ge(e){ne.hidden=!0;var t=Ve;Ve=null,t&&t(e)}function Ka(e){return new Promise(function(t){Ve=t,sa.textContent=e,ne.hidden=!1,Le.focus()})}async function un(){sa.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",kt.textContent="\u7A0D\u540E\u5904\u7406",xt.textContent="\u4FDD\u7559\u672C\u5730",Le.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){Ve=t,ne.hidden=!1,Le.focus()});return yt(ne),e==="save"?"remote":e==="discard"?"local":"later"}kt&&kt.addEventListener("click",function(){Ge("cancel")}),xt&&xt.addEventListener("click",function(){Ge("discard")}),Le&&Le.addEventListener("click",function(){Ge("save")}),ne&&ne.addEventListener("click",function(e){e.target===ne&&Ge("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&Ve&&Ge("cancel")});async function Kt(){return await Ba(m)}function cn(){Na(),Ht(),I(),m="",Pe="",z="",p="",B=null,W="",Q=!1,b="edit",g&&g.setValue(""),Ca(n("home.title")),Ma(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),qe(),he(),we(!1),l("")}async function Xa(){if(D){var e=await Ka(n("confirm.message",{file:z||n("common.markdownDocDefault")}));if(e==="cancel")return;if(i&&i.postMessage&&i.postMessage({type:"goHome"}),e==="save"){var t=await Kt();if(!t){l(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&zt(p)}cn()}function Ja(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){Xa();return}if(e==="open"){jt();return}if(e==="mode"){We(b==="edit"?"preview":"edit");return}if(e==="save"){Yt();return}if(e==="reload"){U();return}if(e==="reveal"){p&&i&&i.postMessage&&i.postMessage({type:"openPath",path:p});return}if(e&&e.indexOf("font-size:")===0){ln(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){dn(e.slice(12));return}if(e==="comfort:read"){Ga(!1);return}if(e==="comfort:write"){Ga(!0);return}if(e==="focus"){Ya();return}if(e==="about"){dr();return}if(e&&e.indexOf("style:slot-use:")===0){fn(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Za(+e.slice(16));return}if(e&&e.indexOf("style:")===0){sn(e.slice(6));return}}function Xt(){[$e,et,tt].forEach(function(e){e&&(e.hidden=!0)})}function pn(e){if(e){var t=e.hidden;Xt(),e.hidden=!t}}function Jt(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),pn(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null,o=r&&r.getAttribute("data-app-action");o&&(Ja(o),Xt())})}da&&da.addEventListener("click",Xa),Qe&&Qe.addEventListener("click",jt),Z&&Z.addEventListener("click",Yt),Me&&Me.addEventListener("click",Ya),Ce&&Ce.addEventListener("click",function(){ee=!ee,document.body.classList.toggle("preview-hidden",!ee),h(),ee&&requestAnimationFrame(function(){g.layout(),U()})}),Jt(Ze,$e),Jt(Et,et),Jt(or,tt),document.addEventListener("click",Xt);var Qt=370,Zt=560,Qa=480;re&&re.addEventListener("mousedown",function(e){e.preventDefault();var t=re.parentElement;if(!t)return;var a=e.clientX,r=St?St.getBoundingClientRect().width:Qa;re.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(c){return Math.max(Qt,Math.min(Zt,c))}function d(c){var f=c.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){re.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",d),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(w){var e=re&&re.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||Qa;(t>Zt||t<Qt)&&e.style.setProperty("--preview-width",Math.max(Qt,Math.min(Zt,t))+"px")}}});function fn(e){var t=N[e];t&&(T=t.css,me=t.label,x="custom",ue(),l(n("status.appliedStyleSlot",{label:t.label})),b==="preview"?U():We("preview"),h())}function Za(e){if(x!=="custom"||!T){l(n("status.needCustomStyleFirst"),!0);return}var t=me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:T,label:t,path:p})}function mn(){M&&(clearTimeout(M),M=0),A.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),A.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=N[t];r&&(a.title=r.label),a.addEventListener("click",function(){Za(t)}),A.appendChild(a)})(e);M=setTimeout(function(){M=0,A.replaceChildren(),A.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(Fe=!!e.pickFileSupported,N=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],on(e.writingPreferences)?w&&X()&&U():ue(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==Ke&&(Ke=t,yt(),dt())}e.assistantName&&(Be=e.assistantName,dt()),ba(),e.homeDir&&(le=e.homeDir,pr()),h();return}if(e.type==="styleSlots"){N=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&N[e.savedSlot]&&l(n("status.savedToSlot",{slot:e.savedSlot+1,label:N[e.savedSlot].label})),h();return}if(e.type==="clipboardImages"){var a=se[e.requestId];if(a){delete se[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(xe){typeof o[xe]=="string"&&(r=r.split(xe).join(o[xe]))}),a.resolve(Yr(r))}return}if(e.type==="clipboardImagesError"){var s=se[e.requestId];s&&(delete se[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var d=ie[e.requestId];d&&(delete ie[e.requestId],d.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ie[e.requestId];u&&(delete ie[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),l(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){w=e.view==="appView",w&&!ga&&(ga=!0,ee=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",w),la&&(la.hidden=!w),g.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var c=e.cwd||"",f=e.sessionId||"",S=e.spaceId||"";(c!==Re||f!==Pt||S!==Tt||!lt)&&(Re=c,Pt=f,Tt=S,lt=!0,ct([])),he(),h(),w&&X()&&U(),(!ht.hidden||w)&&ut();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==Re)return;ct(e.documents),e.library&&xa(e.documents);return}if(e.type==="status"){l(e.message);return}if(e.type==="rewriteSessionStarted"){g.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),l(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"));return}if(e.type==="rewriteSessionFinished"){g.setAiWorkingLines(0,0),l(n("appview.rewriteDone"));return}if(e.type==="rewriteSessionFailed"){g.setAiWorkingLines(0,0),l(e.message||"Rewrite failed.",!0);return}if(e.type==="styleSessionStarted"){mt(!0),l(n("aiStyle.appViewDesigning"));return}if(e.type==="styleSessionFinished"){mt(!1),l(e.message||n("aiStyle.appViewDone"));return}if(e.type==="styleSessionFailed"){mt(!1),l(e.message||n("aiStyle.appViewFailed"),!0);return}if(e.type!=="lastFileUnavailable"){if(e.type==="finch:menu"){Ja(e.itemId);return}if(e.type==="document"){var E=j;j=!1,je();var _=e.markdown||"",P=e.path||"",ce=Number(e.revision)||0;if(P&&P===p&&ce&&ce<=He)return;var Se=!!P&&!!p&&P!==p;if(!Se&&_===B){ce&&(He=Math.max(He,ce)),h();return}var ke=B===null,$t=Ne;Ne=!1;var gt=ze(_,e.title||n("common.markdownDocDefault"),e.path||p,E||ke||Se,e.diskMarkdown);if(!gt){h();return}if(He=ce||(Se?0:He),e.draftRestored)we(!0),l(n("status.draftRestored"));else if(e.draftConflict)l(n("status.draftConflict"),!0);else if($t)l(n("status.opened",{file:z}));else if(!ke){var V=Ut;V&&V.hunks>1?l(n("status.contentUpdatedSpots",{count:V.hunks,lines:V.changedLines})):V&&V.fromLine===V.toLine?l(n("status.contentUpdatedLine",{line:V.fromLine})):l(V?n("status.contentUpdatedLines",{from:V.fromLine,to:V.toLine}):n("status.contentUpdated"))}return}if(e.type==="sourceMissing"){e.path&&e.path===p&&l(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==va)return;Ma(e.html||""),qe(),Te=!1,h(),l("");return}if(e.type==="savedMarkdown"){var Ye=Ft[e.requestId];delete Ft[e.requestId];var vt=ve[e.requestId];if(delete ve[e.requestId],e.requestId!==ya||typeof Ye!="string"){vt&&vt(!1);return}B=Ye,we(m!==Ye,m===Ye),l(n(m===Ye?"status.saved":"status.savedWithNewChanges")),vt&&vt(!0);return}if(e.type==="customStyleSet"){T=e.css||"",me=e.label||n("common.customStyleDefault"),x="custom",ue(),typeof e.savedSlot=="number"?(N=Array.isArray(e.styleSlots)?e.styleSlots:N,l(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):mn(),b==="preview"?U():We("preview"),h();return}if(e.type==="exported"){l(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){j=!1,je(),h(),l("");return}if(e.type==="error"){Ne=!1,Object.keys(ve).forEach(function(xe){var $a=ve[xe];delete ve[xe],$a&&$a(!1)}),j=!1,je(),e.fallback&&(Fe=!1),Te=!1,h(),l(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!X()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),ha||ut()},400),yt(),ba(),dt(),qe(),he()})();})();
|
|
44
|
+
%%EOF`;return d.push(J(Se.join("")+$t)),Gt(d)}async function nn(){if(!W){l(n("status.pleaseOpenArticle"),!0);return}try{l(n("status.generatingPdf"));var e=await _t();if(!e){l(n("status.exportPdfFailedGeneric"),!0);return}var t=await Vt(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,d=rn(r,e.canvas.width,e.canvas.height,o,s),u=_a(d);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:p,fileName:U,markdown:m})}catch(c){l(n("status.exportPdfFailed",{err:String(c)}),!0)}}function _e(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){l(String(r),!0)}).then(function(){e.disabled=!1}))})}_e(ar,Zr),_e(rr,en),_e(nr,tn),_e(or,nn),_e(fe,on);var Va="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(Va)==="1"}catch{}Ee&&Ee.classList.toggle("collapsed",t)})(),ia&&ia.addEventListener("click",function(e){e.preventDefault();var t=Ee.classList.toggle("collapsed");try{localStorage.setItem(Va,t?"1":"0")}catch{}});function Yt(){Na(m)}function mt(e){if(sr=e,!!fe){fe.classList.toggle("loading",e),fe.disabled=e;var t=fe.querySelector(".ic-ai-style"),a=fe.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function Ga(){if(!m||!p||!i||!i.postMessage){l(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:p,baseStyle:x}),mt(!0),l(n("aiStyle.appViewDesigning"))}async function on(){if(!m){l(n("status.pleaseOpenArticle"),!0);return}if(w||!i||!i.composer){Ga();return}var e=x==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:x});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:p||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),l(n("aiStyle.requested"))}catch{Ga()}}function sn(){return{fontSize:q,fontFamily:Y,comfortWriting:O,style:x,customCss:x==="custom"?T:"",customStyleLabel:x==="custom"?me:""}}function ue(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:sn()})}function ln(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(q=e.fontSize),ge[e.fontFamily]&&(Y=e.fontFamily),O=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(x="custom",T=e.customCss,me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(x=e.style,T="",me=""),g.setFontSize(q),g.setFontFamily(ge[Y]),g.setComfortWriting(O),!0)}function dn(e){x=e,ue(),(w||b==="preview")&&j(),h()}function un(e){if(!(e!==14&&e!==16&&e!==18)){q=e,g.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}ue(),h()}}function cn(e){if(ge[e]){Y=e,g.setFontFamily(ge[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}ue(),h()}}function Ya(e){O=!!e,g.setComfortWriting(O);try{localStorage.setItem("md-editor-comfort-writing",O?"1":"0")}catch{}ue(),h(),l(n(O?"status.comfortWrite":"status.comfortRead"))}function Ka(){R=!R,R&&Q?(Q=!1,I()):!R&&!Q&&(Q=!0),g.setFocusMode(R);try{localStorage.setItem("md-editor-focus-mode",R?"1":"0")}catch{}h(),l(n(R?"status.focusOn":"status.focusOff"))}var Ve=null;function Ge(e){ne.hidden=!0;var t=Ve;Ve=null,t&&t(e)}function Xa(e){return new Promise(function(t){Ve=t,sa.textContent=e,ne.hidden=!1,Le.focus()})}async function pn(){sa.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",kt.textContent="\u7A0D\u540E\u5904\u7406",xt.textContent="\u4FDD\u7559\u672C\u5730",Le.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){Ve=t,ne.hidden=!1,Le.focus()});return yt(ne),e==="save"?"remote":e==="discard"?"local":"later"}kt&&kt.addEventListener("click",function(){Ge("cancel")}),xt&&xt.addEventListener("click",function(){Ge("discard")}),Le&&Le.addEventListener("click",function(){Ge("save")}),ne&&ne.addEventListener("click",function(e){e.target===ne&&Ge("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&Ve&&Ge("cancel")});async function Kt(){return await Na(m)}function fn(){qa(),Ht(),I(),m="",Pe="",U="",p="",B=null,W="",Q=!1,b="edit",g&&g.setValue(""),Ca(n("home.title")),Ma(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),qe(),he(),we(!1),l("")}async function Ja(){if(D){var e=await Xa(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 Kt();if(!t){l(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&zt(p)}fn()}function Qa(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){Ja();return}if(e==="open"){jt();return}if(e==="mode"){We(b==="edit"?"preview":"edit");return}if(e==="save"){Yt();return}if(e==="reload"){j();return}if(e==="reveal"){p&&i&&i.postMessage&&i.postMessage({type:"openPath",path:p});return}if(e&&e.indexOf("font-size:")===0){un(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){cn(e.slice(12));return}if(e==="comfort:read"){Ya(!1);return}if(e==="comfort:write"){Ya(!0);return}if(e==="focus"){Ka();return}if(e==="about"){ur();return}if(e&&e.indexOf("style:slot-use:")===0){gn(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){$a(+e.slice(16));return}if(e&&e.indexOf("style:")===0){dn(e.slice(6));return}}function Xt(){[$e,et,tt].forEach(function(e){e&&(e.hidden=!0)})}function mn(e){if(e){var t=e.hidden;Xt(),e.hidden=!t}}function Jt(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),mn(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null,o=r&&r.getAttribute("data-app-action");o&&(Qa(o),Xt())})}da&&da.addEventListener("click",Ja),Qe&&Qe.addEventListener("click",jt),Z&&Z.addEventListener("click",Yt),Me&&Me.addEventListener("click",Ka),Ce&&Ce.addEventListener("click",function(){ee=!ee,document.body.classList.toggle("preview-hidden",!ee),h(),ee&&requestAnimationFrame(function(){g.layout(),j()})}),Jt(Ze,$e),Jt(Et,et),Jt(ir,tt),document.addEventListener("click",Xt);var Qt=370,Zt=560,Za=480;re&&re.addEventListener("mousedown",function(e){e.preventDefault();var t=re.parentElement;if(!t)return;var a=e.clientX,r=St?St.getBoundingClientRect().width:Za;re.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(c){return Math.max(Qt,Math.min(Zt,c))}function d(c){var f=c.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){re.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",d),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(w){var e=re&&re.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||Za;(t>Zt||t<Qt)&&e.style.setProperty("--preview-width",Math.max(Qt,Math.min(Zt,t))+"px")}}});function gn(e){var t=N[e];t&&(T=t.css,me=t.label,x="custom",ue(),l(n("status.appliedStyleSlot",{label:t.label})),b==="preview"?j():We("preview"),h())}function $a(e){if(x!=="custom"||!T){l(n("status.needCustomStyleFirst"),!0);return}var t=me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:T,label:t,path:p})}function vn(){M&&(clearTimeout(M),M=0),A.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),A.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=N[t];r&&(a.title=r.label),a.addEventListener("click",function(){$a(t)}),A.appendChild(a)})(e);M=setTimeout(function(){M=0,A.replaceChildren(),A.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(Fe=!!e.pickFileSupported,N=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],ln(e.writingPreferences)?w&&X()&&j():ue(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==Ke&&(Ke=t,yt(),dt())}e.assistantName&&(Be=e.assistantName,dt()),ba(),e.homeDir&&(le=e.homeDir,fr()),h();return}if(e.type==="styleSlots"){N=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&N[e.savedSlot]&&l(n("status.savedToSlot",{slot:e.savedSlot+1,label:N[e.savedSlot].label})),h();return}if(e.type==="clipboardImages"){var a=se[e.requestId];if(a){delete se[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(xe){typeof o[xe]=="string"&&(r=r.split(xe).join(o[xe]))}),a.resolve(Xr(r))}return}if(e.type==="clipboardImagesError"){var s=se[e.requestId];s&&(delete se[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var d=ie[e.requestId];d&&(delete ie[e.requestId],d.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ie[e.requestId];u&&(delete ie[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),l(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){w=e.view==="appView",w&&!ga&&(ga=!0,ee=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",w),la&&(la.hidden=!w),g.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var c=e.cwd||"",f=e.sessionId||"",S=e.spaceId||"";(c!==Re||f!==Pt||S!==Tt||!lt)&&(Re=c,Pt=f,Tt=S,lt=!0,ct([])),he(),h(),w&&X()&&j(),(!ht.hidden||w)&&ut();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==Re)return;ct(e.documents),e.library&&xa(e.documents);return}if(e.type==="status"){l(e.message);return}if(e.type==="rewriteSessionStarted"){g.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),l(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"));return}if(e.type==="rewriteSessionFinished"){g.setAiWorkingLines(0,0),l(n("appview.rewriteDone"));return}if(e.type==="rewriteSessionFailed"){g.setAiWorkingLines(0,0),l(e.message||"Rewrite failed.",!0);return}if(e.type==="styleSessionStarted"){mt(!0),l(n("aiStyle.appViewDesigning"));return}if(e.type==="styleSessionFinished"){mt(!1),l(e.message||n("aiStyle.appViewDone"));return}if(e.type==="styleSessionFailed"){mt(!1),l(e.message||n("aiStyle.appViewFailed"),!0);return}if(e.type!=="lastFileUnavailable"){if(e.type==="finch:menu"){Qa(e.itemId);return}if(e.type==="document"){var E=_;_=!1,je();var V=e.markdown||"",P=e.path||"",ce=Number(e.revision)||0;if(P&&P===p&&ce&&ce<=He)return;var Se=!!P&&!!p&&P!==p;if(!Se&&V===B){ce&&(He=Math.max(He,ce)),h();return}var ke=B===null,$t=Ne;Ne=!1;var gt=ze(V,e.title||n("common.markdownDocDefault"),e.path||p,E||ke||Se,e.diskMarkdown);if(!gt){h();return}if(He=ce||(Se?0:He),e.draftRestored)we(!0),l(n("status.draftRestored"));else if(e.draftConflict)l(n("status.draftConflict"),!0);else if($t)l(n("status.opened",{file:U}));else if(!ke){var G=Ut;G&&G.hunks>1?l(n("status.contentUpdatedSpots",{count:G.hunks,lines:G.changedLines})):G&&G.fromLine===G.toLine?l(n("status.contentUpdatedLine",{line:G.fromLine})):l(G?n("status.contentUpdatedLines",{from:G.fromLine,to:G.toLine}):n("status.contentUpdated"))}return}if(e.type==="sourceMissing"){e.path&&e.path===p&&l(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==va)return;Ma(e.html||""),qe(),Te=!1,h(),l("");return}if(e.type==="savedMarkdown"){var Ye=Ft[e.requestId];delete Ft[e.requestId];var vt=ve[e.requestId];if(delete ve[e.requestId],e.requestId!==ya||typeof Ye!="string"){vt&&vt(!1);return}B=Ye,we(m!==Ye,m===Ye),l(n(m===Ye?"status.saved":"status.savedWithNewChanges")),vt&&vt(!0);return}if(e.type==="customStyleSet"){T=e.css||"",me=e.label||n("common.customStyleDefault"),x="custom",ue(),typeof e.savedSlot=="number"?(N=Array.isArray(e.styleSlots)?e.styleSlots:N,l(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):vn(),b==="preview"?j():We("preview"),h();return}if(e.type==="exported"){l(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){_=!1,je(),h(),l("");return}if(e.type==="error"){Ne=!1,Object.keys(ve).forEach(function(xe){var er=ve[xe];delete ve[xe],er&&er(!1)}),_=!1,je(),e.fallback&&(Fe=!1),Te=!1,h(),l(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!X()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),ha||ut()},400),yt(),ba(),dt(),qe(),he()})();})();
|
package/package.json
CHANGED