finch-markdown-editor 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codemirror.js +33 -33
- package/dist/panel.css +31 -11
- package/dist/panel.html +31 -2
- package/dist/panel.js +12 -12
- package/package.json +1 -1
package/dist/panel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";(()=>{(function(){"use strict";var i=window.finch;function
|
|
2
|
-
`+String(o.stack):""))},window.addEventListener("unhandledrejection",function(e){var t=e.reason,a=t&&(t.stack||t.message||String(t))||"unknown";
|
|
1
|
+
"use strict";(()=>{(function(){"use strict";var i=window.finch;function Pa(e,t){var a="[panel error] "+e+": "+String(t).slice(0,4e3);try{console.error(a,t)}catch{}if(i&&i.postMessage)try{i.postMessage({type:"clientLog",message:a})}catch{}}window.onerror=function(e,t,a,r,o){Pa("window.onerror",String(e)+" at "+t+":"+a+":"+r+(o&&o.stack?`
|
|
2
|
+
`+String(o.stack):""))},window.addEventListener("unhandledrejection",function(e){var t=e.reason,a=t&&(t.stack||t.message||String(t))||"unknown";Pa("unhandledrejection",a)}),window.__mdLog=function(e){if(i&&i.postMessage)try{i.postMessage({type:"clientLog",message:String(e)})}catch{}};var lt=!1,Oa=!1,Ht=!1,ct=null,Zr=400,$r=1500,ut=["bg","card","text","muted","border","accent","hover","active"],Ra="md-theme-aliases";function zt(){try{var e=getComputedStyle(document.documentElement);return!!e.getPropertyValue("--finch-theme-mode").trim()||!!e.getPropertyValue("--finch-bg-main").trim()}catch{return!0}}function Jr(){for(var e={},t=getComputedStyle(document.documentElement),a=0;a<ut.length;a++){var r=ut[a],o=t.getPropertyValue("--"+r).trim();if(!o)return null;e[r]=o}return e}var Ut=null;try{Ut=localStorage.getItem(Ra)}catch{}function Qr(){var e=Jr();if(e){var t=JSON.stringify(e);if(t!==Ut){Ut=t;try{localStorage.setItem(Ra,t)}catch{}}}}function _t(){for(var e=document.documentElement,t=0;t<ut.length;t++)e.style.removeProperty("--"+ut[t]);Qr()}function Vt(){ct&&(clearInterval(ct),ct=null)}function jt(){if(!(Ht||!lt||!Oa)){Ht=!0,Vt(),document.documentElement.classList.remove("md-boot");try{p&&p.layout&&requestAnimationFrame(function(){p.layout()})}catch{}}}function Gt(){Oa=!0,jt()}if(i){let e=function(){zt()&&_t()};if(zt())_t(),lt=!0;else{var en=Date.now();ct=setInterval(function(){if(zt()){Vt(),_t(),lt=!0,jt();return}Date.now()-en<Zr||(Vt(),lt=!0,jt())},16)}document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"&&e()}),window.addEventListener("pagehide",e);try{var Yt=window.matchMedia("(prefers-color-scheme: dark)");Yt&&Yt.addEventListener&&Yt.addEventListener("change",e)}catch{}setInterval(e,5e3),setTimeout(Gt,$r)}else Ht=!0,document.documentElement.classList.remove("md-boot");var dt=/^zh/i.test(navigator.language||""),pt={zh:{"meta.title":"\u516C\u4F17\u53F7\u6587\u7AE0\u9884\u89C8","home.title":"\u5199\u5B57","home.tagline.withAssistant":"\u4F60\u4E0E{name}\u4E00\u8D77\u7F16\u6392 Markdown \u6587\u4EF6","home.tagline.default":"\u6253\u5F00\u4E00\u4E2A Markdown \u6587\u4EF6\u5F00\u59CB\u7F16\u8F91\u4E0E\u9884\u89C8\uFF0C\u6216\u65B0\u5EFA\u4E00\u7BC7\u6587\u7AE0\u3002","home.openFile":"\u6253\u5F00\u6587\u4EF6","home.newDoc":"\u65B0\u5EFA\u6587\u6863","home.recentLabel":"\u6700\u8FD1\u7F16\u8F91","home.hintScoped":"\u8FD9\u4E2A\u76EE\u5F55\u91CC\u8FD8\u6CA1\u6709\u7528\u7F16\u8F91\u5668\u6253\u5F00\u8FC7\u7684 Markdown \u6587\u6863\u3002","home.hintDefault":"\u6253\u5F00\u4E00\u4E2A Markdown \u6587\u4EF6\uFF0C\u4E4B\u540E\u8FD9\u91CC\u4F1A\u5217\u51FA\u6700\u8FD1\u7F16\u8F91\u7684\u6587\u6863\u3002","home.untitled":"\u672A\u547D\u540D","home.revealInFileManager":"\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u5B9A\u4F4D","home.emptyDoc":"\uFF08\u7A7A\u6587\u6863\uFF09","home.cwdTitle":"\u5728\u8BBF\u8FBE / \u6587\u4EF6\u8D44\u6E90\u7BA1\u7406\u5668\u4E2D\u6253\u5F00\uFF1A{path}","home.cwdFallback":"homePath\uFF08\u65E0 cwd \u56DE\u9000\uFF09","home.today":"\u4ECA\u5929 {clock}","home.yesterday":"\u6628\u5929 {clock}","appview.library":"\u8D44\u6599\u5E93","appview.libraryHint":"\u6240\u6709\u7A7A\u95F4\u7684\u6700\u8FD1\u6587\u6863","appview.libraryWorkspace":"\u5DE5\u4F5C\u95F4\u6587\u4EF6","appview.libraryOther":"\u5176\u4ED6","appview.libraryReorder":"\u6392\u5E8F","appview.libraryReorderDone":"\u5DF2\u5B8C\u6210","appview.rewrite":"\u6539\u5199","appview.focus":"\u4E13\u6CE8","appview.focusExit":"\u9000\u51FA\u4E13\u6CE8\u6A21\u5F0F","appview.openSession":"\u6253\u5F00\u6539\u5199\u4F1A\u8BDD","appview.rewriting":"\u5DF2\u53D1\u8D77\u6539\u5199\uFF0C\u4F1A\u8BDD\u6B63\u5728\u5904\u7406\u5E76\u5C06\u76F4\u63A5\u5199\u56DE\u6587\u4EF6\u3002","appview.continuing":"\u5DF2\u53D1\u8D77\u7EED\u5199\uFF0C\u4F1A\u8BDD\u6B63\u5728\u5904\u7406\u5E76\u5C06\u76F4\u63A5\u5199\u56DE\u6587\u4EF6\u3002","appview.hintSpace":"\u6309 space\uFF08\u7A7A\u683C\uFF09\u4EE5\u542F\u7528 AI \xB7 \u6309 / \u9009\u62E9\u683C\u5F0F","appview.hintSpaceCode":"\u6309 space\uFF08\u7A7A\u683C\uFF09\u4EE5\u542F\u7528 AI","appview.rewriteDone":"\u6539\u5199\u5DF2\u5B8C\u6210\uFF0C\u6587\u4EF6\u5185\u5BB9\u5DF2\u5237\u65B0\u3002","appview.cancelling":"\u6B63\u5728\u4E2D\u65AD\u6539\u5199\u2026","appview.cancelled":"\u6539\u5199\u5DF2\u4E2D\u65AD\u3002","editor.ariaLabel":"\u5199\u5B57\u7F16\u8F91\u5668","actions.copyToWx":"\u590D\u5236\u5230\u516C\u4F17\u53F7","actions.copyImg":"\u590D\u5236\u56FE\u7247","actions.exportImg":"\u5BFC\u51FA\u56FE\u7247\uFF08\u4E0B\u8F7D\uFF09","actions.exportPdf":"\u5BFC\u51FA PDF","actions.aiStyle":"\u8BA9 AI \u8BBE\u8BA1\u6392\u7248","actions.toggle":"\u5C55\u5F00/\u6536\u8D77","popup.placeholder":"\u8BA9 {name} \u7F16\u8F91","popup.placeholderContinue":"\u8BA9 {name} \u4ECE\u8FD9\u91CC\u7EED\u5199\u2026","popup.send":"\u53D1\u9001","confirm.cancel":"\u53D6\u6D88","confirm.discard":"\u4E0D\u4FDD\u5B58","confirm.save":"\u4FDD\u5B58\u5E76\u8FD4\u56DE","confirm.message":"\u300C{file}\u300D\u8FD8\u6709\u672A\u4FDD\u5B58\u7684\u6539\u52A8\uFF0C\u8981\u4FDD\u5B58\u540E\u518D\u8FD4\u56DE\u9996\u9875\u5417\uFF1F","common.markdownDocDefault":"Markdown \u6587\u6863","common.customStyleDefault":"\u81EA\u5B9A\u4E49\u98CE\u683C","wordCount.home.label":"\u5B57\u6570","wordCount.home.tooltip.character":"\u6309\u5B57\u7B26\u7EDF\u8BA1","wordCount.home.tooltip.word":"\u6309\u8BCD\u7EC4\u7EDF\u8BA1","wordCount.label.character":"{total}","wordCount.label.word":"{total}","wordCount.tooltip.character":`\u6309\u5B57\u7B26\u7EDF\u8BA1 {total}
|
|
3
3
|
\u975E\u82F1\u6587 {nonEnglish} \xB7 \u82F1\u6587 {english}`,"wordCount.tooltip.word":`\u6309\u8BCD\u7EC4\u7EDF\u8BA1 {total}
|
|
4
4
|
\u975E\u82F1\u6587 {nonEnglish} \xB7 \u82F1\u6587 {english}`,"wordCount.mode.character":"\u6309\u5B57\u7B26","wordCount.mode.word":"\u6309\u8BCD\u7EC4","toolbar.home.tooltip":"\u8FD4\u56DE\u9996\u9875","toolbar.open.tooltipDefault":"\u6253\u5F00 Markdown \u6587\u4EF6","toolbar.save.label":"\u4FDD\u5B58","toolbar.save.tooltipDefault":"\u4FDD\u5B58\uFF08\u2318/Ctrl+S\uFF09","toolbar.save.tooltipDirty":"\u6709\u672A\u4FDD\u5B58\u7684\u6539\u52A8\uFF08\u2318/Ctrl+S\uFF09","toolbar.save.labelSaved":"\u5DF2\u4FDD\u5B58","toolbar.save.tooltipSaved":"\u5DF2\u4FDD\u5B58","toolbar.annotate.label":"\u6279\u6CE8","toolbar.annotate.tooltipOn":"\u6279\u6CE8\u5DF2\u5F00\u542F\uFF1A\u9009\u4E2D\u6587\u5B57\u53EF\u53D1\u8D77 AI \u4FEE\u6539","toolbar.annotate.tooltipOff":"\u5F00\u542F\u6279\u6CE8\uFF1A\u9009\u4E2D\u6587\u5B57\u540E\u53EF\u53D1\u8D77 AI \u4FEE\u6539","toolbar.needDoc":"\u8BF7\u5148\u6253\u5F00\u6587\u6863","toolbar.mode.label":"\u9884\u89C8","toolbar.mode.tooltipToPreview":"\u5207\u6362\u5230\u9884\u89C8","toolbar.mode.tooltipToEdit":"\u5207\u6362\u5230\u7F16\u8F91","toolbar.mode.tooltipRendering":"\u6B63\u5728\u6E32\u67D3\u9884\u89C8\u2026","toolbar.style.tooltip":"\u6392\u7248\u98CE\u683C","toolbar.style.tooltipNeedsPreview":"\u8BF7\u5148\u5207\u6362\u5230\u9884\u89C8","toolbar.style.customSlot":"\u81EA\u5B9A\u4E49\u98CE\u683C {n} \xB7 {label}","toolbar.style.customSlotEmpty":"\u81EA\u5B9A\u4E49\u98CE\u683C {n}\uFF08\u7A7A\uFF09","toolbar.fontSize.tooltipPreview":"\u9884\u89C8\u65F6\u4E0D\u53EF\u66F4\u6539\u5B57\u4F53","toolbar.fontSize.tooltipEdit":"\u7F16\u8F91\u5668\u5B57\u4F53\u5927\u5C0F","toolbar.fontSize.small":"\u5C0F","toolbar.fontSize.medium":"\u4E2D","toolbar.fontSize.large":"\u5927","toolbar.fontFamily.default":"\u9ED8\u8BA4\uFF08\u65E0\u886C\u7EBF\uFF09","toolbar.fontFamily.serif":"\u886C\u7EBF\u4F53","toolbar.comfort.read":"\u7D27\u51D1","toolbar.comfort.write":"\u8212\u9002","toolbar.focus.tooltipOn":"\u4E13\u6CE8\u5DF2\u5F00\u542F\uFF1A\u975E\u5F53\u524D\u884C\u534A\u900F\u660E","toolbar.focus.tooltipOff":"\u5F00\u542F\u4E13\u6CE8\uFF1A\u975E\u5F53\u524D\u884C\u534A\u900F\u660E","toolbar.more.reload":"\u91CD\u65B0\u6E32\u67D3","toolbar.more.reveal":"\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u5B9A\u4F4D","toolbar.more.recentSession":"\u67E5\u770B\u6700\u8FD1\u7684\u4F1A\u8BDD","toolbar.more.about":"\u5173\u4E8E\u6E32\u67D3","toolbar.more.tooltip":"\u66F4\u591A","annotate.lineUnknown":"\uFF08\u672A\u80FD\u7CBE\u786E\u5B9A\u4F4D\u5BF9\u5E94\u884C\u53F7\uFF0C\u8BF7\u4EE5\u4E0B\u65B9\u5F15\u7528\u6587\u672C\u4E3A\u51C6\uFF09","annotate.lineSingle":"\u7B2C {a} \u884C","annotate.lineRange":"\u7B2C {a}\u2013{b} \u884C","annotate.lineCompactUnknown":"\u672A\u5B9A\u4F4D","annotate.requirementWith":"\u8981\u6C42\uFF1A{comment}","annotate.requirementDefault":"\u8BA9\u8868\u8FBE\u66F4\u6E05\u6670","annotate.pathMissing":"\uFF08\u672A\u5173\u8054\u672C\u5730\u6587\u4EF6\uFF0C\u8BF7\u5148\u7C98\u8D34/\u4FDD\u5B58\u5168\u90E8\u5185\u5BB9\uFF09","annotate.emptyLine":"\uFF08\u7A7A\u884C\uFF1A\u8BF7\u6309\u6279\u6CE8\u8981\u6C42\u5728\u6B64\u5904\u8865\u5145\u6216\u7EED\u5199\u5185\u5BB9\uFF09","annotate.promptText":`\u8BF7\u6539\u5199\u8FD9\u6BB5 Markdown \u5185\u5BB9\uFF08\u4F4D\u7F6E\uFF1A{lineLabel}\uFF09\uFF0C{requirement}\uFF1A
|
|
5
5
|
|
|
@@ -11,16 +11,16 @@ Non-English {nonEnglish} \xB7 English {english}`,"wordCount.mode.character":"Cha
|
|
|
11
11
|
|
|
12
12
|
{text}
|
|
13
13
|
|
|
14
|
-
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=lt?ct.zh:ct.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(ct.en,e)?ct.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 Nt(e){var t=e||document;document.documentElement.lang=lt?"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 Wt=document.getElementById("empty"),Ca=document.getElementById("emptyNew"),Ea=document.getElementById("emptyOpen"),qt=document.getElementById("homeRecent"),ce=document.getElementById("homeGrid"),ut=document.getElementById("homeHint"),Ht=[],xa=document.getElementById("homeTagline"),Nr=document.getElementById("editPane"),zt=document.getElementById("previewPane"),ue=document.getElementById("previewResizer"),Ce=document.getElementById("editor"),y=document.getElementById("article"),x=document.getElementById("status"),M=document.getElementById("popup"),G=document.getElementById("popupInput"),Ma=document.getElementById("popupSend"),Ia=document.getElementById("popupShortcut"),Be=document.getElementById("actions"),Wr=document.getElementById("actCopyWx"),qr=document.getElementById("actCopyImg"),Hr=document.getElementById("actSaveImg"),zr=document.getElementById("actSavePdf"),Ee=document.getElementById("actAiStyle"),La=document.getElementById("actToggle"),de=document.getElementById("confirmOverlay"),Aa=document.getElementById("confirmMessage"),Ut=document.getElementById("confirmCancel"),Vt=document.getElementById("confirmDiscard"),Ne=document.getElementById("confirmSave"),Da=document.getElementById("appToolbar"),Fa=document.getElementById("appHome"),Ta=document.getElementById("appLibrary"),dt=document.getElementById("appOpen"),ne=document.getElementById("appSave"),We=document.getElementById("appPreview"),pt=document.getElementById("appStyle"),ft=document.getElementById("appStyleMenu"),Pa=document.getElementById("appWordCountWrap"),mt=document.getElementById("appWordCount"),Oa=document.getElementById("appWordCountValue"),vt=document.getElementById("appWordCountIcon"),gt=document.getElementById("appWordCountMenu"),pe=document.getElementById("appFocus"),_t=document.getElementById("appFont"),ht=document.getElementById("appFontMenu"),Ur=document.getElementById("appMore"),yt=document.getElementById("appMoreMenu"),jt=document.getElementById("libraryDrawer"),bt=document.getElementById("libraryBackdrop"),Ra=document.getElementById("libraryClose"),wt=document.getElementById("libraryReorder"),Ba=document.getElementById("libraryReorderFooter"),Na=document.getElementById("libraryReorderDone"),F=document.getElementById("libraryGroups"),Wa="md-editor-library-groups-v1",fe=[],xe={},me=null,qe=null,oe=!1,He=[],X=null,Gt=!1,v=!1,qa=!1,Ha=!1,H=null,ve=null,R=!0,ze=null,Vr=!1,St=0,Ue=!1,ae=!0,C="edit",I="kami",B="",Me="",z=[null,null,null],Ie={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},U=14,$="rounded",N=!1,V="character",A=!1;try{var kt=Number(localStorage.getItem("md-editor-font-size"));(kt===14||kt===16||kt===18)&&(U=kt);var Xt=localStorage.getItem("md-editor-font-family");Ie[Xt]?$=Xt:Xt&&localStorage.removeItem("md-editor-font-family"),N=localStorage.getItem("md-editor-comfort-writing")==="1",localStorage.getItem("md-editor-word-count-mode")==="word"&&(V="word"),A=localStorage.getItem("md-editor-focus-mode")==="1";var Ve=JSON.parse(localStorage.getItem(Wa)||"{}");Array.isArray(Ve.order)&&(fe=Ve.order.filter(function(e){return typeof e=="string"})),Ve.collapsed&&typeof Ve.collapsed=="object"&&(xe=Ve.collapsed)}catch{}ae=!A;var h="",_e="",_="",m="",P=null,W="",Le=!1,za=0,je=!1,Ua=0,Yt={},Ae={},_r=0,ge={},jr=0,he={},Ge=0,J=null,Ct=0,De=0,Kt=!1,w={text:"",mode:"replace"},E=0;function c(e,t){E&&(clearTimeout(E),E=0),x.textContent=e||"",x.className="status"+(t?" error":""),e&&(E=setTimeout(function(){E=0,x.textContent="",x.className="status"},5e3))}function ye(e,t,a,r){if(E&&(clearTimeout(E),E=0),x.replaceChildren(document.createTextNode(e||"")),x.className="status"+(t?" error":""),a){var o=document.createElement("button");o.type="button",o.className="status-inline-btn",o.textContent=n("appview.openSession"),o.addEventListener("click",function(){i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(a)}),x.appendChild(o)}r&&(E=setTimeout(function(){E=0,x.replaceChildren(),x.className="status"},r))}function Gr(){E&&(clearTimeout(E),E=0),x.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/"})}),x.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),x.className="status",E=setTimeout(function(){E=0,x.textContent="",x.className="status"},5e3)}function L(){return!!h||!!m}Ca&&Ca.addEventListener("click",async function(){if(!i||!i.composer){c(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),c(n("newdoc.added"))}catch(e){c(String(e),!0)}}),Ea&&Ea.addEventListener("click",function(){pa()});var Xe="",Zt="",$t="",Et=!1,Va=!1,Ye="",be="";function k(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function _a(){xa&&(xa.textContent=Ye?n("home.tagline.withAssistant",{name:Ye}):n("home.tagline.default"))}function xt(){G&&(G.placeholder=w.mode==="continue"?n("popup.placeholderContinue",{name:Ye||"Finch"}):n("popup.placeholder",{name:Ye||"Finch"}))}function Xr(e){return e?be&&e===be?"~":be&&(e.indexOf(be+"/")===0||e.indexOf(be+"\\")===0)?"~"+e.slice(be.length):e:""}function Yr(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 Kr(){It(Ht)}function ja(e){var t=new Date(e);if(!e||isNaN(t.getTime()))return"";var a=new Date,r=function(u){return u<10?"0"+u:String(u)},o=r(t.getHours())+":"+r(t.getMinutes()),s=t.toDateString()===a.toDateString();if(s)return n("home.today",{clock:o});var l=new Date(a.getTime()-864e5);return t.toDateString()===l.toDateString()?n("home.yesterday",{clock:o}):t.getFullYear()===a.getFullYear()?r(t.getMonth()+1)+"-"+r(t.getDate()):t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())}function Mt(){!i||!i.postMessage||!Et||(Va=!0,i.postMessage({type:"requestRecentDocuments",cwd:Xe,sessionId:Zt,spaceId:$t}))}function Zr(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+k(e.path||"")+'" title="'+k(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+k(e.path||"")+'" role="button" tabindex="0" title="'+k(n("home.revealInFileManager"))+'" aria-label="'+k(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">'+k(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+k(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+k(t)+'">'+k(t)+'</span><span class="doc-time">'+k(ja(e.modifiedAt))+"</span></div></div></button>"}function It(e){if(!(!ce||!qt||!ut)){var t=Array.isArray(e)?e:[];if(Ht=t,t.length===0){qt.hidden=!0,ut.hidden=!1,ut.textContent=n(Xe?"home.hintScoped":"home.hintDefault");return}var a=Ga(t);ce.innerHTML=a.map(function(r){var o=r.documents.map(Zr).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+k(r.scopePath)+'" title="'+k(n("home.cwdTitle",{path:r.scopePath}))+'">'+k(Yr(Xr(r.scopePath)))+"</button>":"",l='<div class="home-group-title"><span class="home-group-label">'+k(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+l+'<div class="home-grid">'+o+"</div></div>"}).join(""),qt.hidden=!1,ut.hidden=!0,requestAnimationFrame(function(){$r(ce)})}}function $r(e){for(var t="\u2026",a=e.querySelectorAll("[data-full-path]"),r=0;r<a.length;r++){var o=a[r],s=o.getAttribute("data-full-path")||"";if(o.textContent=s,!(!s||o.scrollWidth<=o.clientWidth+1)){for(var l=0,u=s.length,d=0;l<=u;){var f=l+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(d=f,l=f+1):u=f-1}o.textContent=d>0?t+s.slice(s.length-d):t}}}function Jt(){var e={order:fe,collapsed:xe};try{localStorage.setItem(Wa,JSON.stringify(e))}catch{}i&&i.postMessage&&i.postMessage({type:"saveLibraryGroups",libraryGroups:e})}function Ga(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=fe.indexOf(a.id),s=fe.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var l={space:0,workspace:1},u=l[a.kind]-l[r.kind];return u||a.label.localeCompare(r.label)})}function Qt(e){if(F){He=Array.isArray(e)?e:[];var t=Ga(He);if(oe){Jr(t);return}F.innerHTML=t.map(function(a){var r=a.documents.map(function(l){var u=l.relativePath||l.fileName||"";return'<button class="library-row" type="button" data-path="'+k(l.path||"")+'"><span class="library-row-main"><strong>'+k(l.title||l.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+k(u)+'">'+k(u)+"</span><time>"+k(ja(l.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!xe[a.id];return'<details class="library-group" data-library-group-id="'+k(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+k(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">'+k(n("home.hintDefault"))+"</p>"}}function Jr(e){F.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+k(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+k(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+k(n("home.hintDefault"))+"</p>"}function ea(e){oe=!!e,wt&&wt.classList.toggle("active",oe),Ba&&(Ba.hidden=!oe),Qt(He)}function Lt(e){!jt||!bt||(jt.classList.toggle("open",!!e),jt.setAttribute("aria-hidden",e?"false":"true"),bt.hidden=!e,e?Mt():oe&&ea(!1))}function Qr(){if(!(!me||!F)){me.classList.remove("dragging"),Array.prototype.forEach.call(F.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),fe=Array.prototype.map.call(F.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),It(Ht);var e=qe||{};Array.prototype.forEach.call(F.querySelectorAll(".library-group"),function(t){var a=t.getAttribute("data-library-group-id");a in e&&(t.open=!!e[a])}),me=null,setTimeout(function(){qe=null,Jt()},0)}}function en(){X&&X.ghost&&X.ghost.parentNode&&X.ghost.parentNode.removeChild(X.ghost)}function Xa(e,t){var a=X;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function tn(e){var t=X;if(!(!t||t.active)){t.active=!0,me=e,qe={},oe||Array.prototype.forEach.call(F.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(qe[s]=!!o.open),o.open=!1}),e.classList.add("dragging");var a=e.getBoundingClientRect(),r=e.cloneNode(!0);r.classList.add("library-drag-ghost"),r.classList.remove("dragging"),r.style.width=a.width+"px",t.ghost=r,t.offsetX=t.startX-a.left,t.offsetY=t.startY-a.top,document.body.appendChild(r),Xa(t.startX,t.startY)}}function an(e,t){if(me){var a=document.elementFromPoint(e,t),r=a&&a.closest?a.closest('.library-group[data-draggable="true"]'):null;if(Array.prototype.forEach.call(F.querySelectorAll(".library-group.drag-over"),function(s){s.classList.remove("drag-over")}),!(!r||r===me)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;F.insertBefore(me,o?r.nextSibling:r)}}}function Ya(){var e=X;e&&(e.active&&(en(),Qr(),Gt=!0,setTimeout(function(){Gt=!1},0)),X=null)}Ta&&Ta.addEventListener("click",function(){Lt(!0)}),Ra&&Ra.addEventListener("click",function(){Lt(!1)}),bt&&bt.addEventListener("click",function(){Lt(!1)}),wt&&wt.addEventListener("click",function(){ea(!oe)}),Na&&Na.addEventListener("click",function(){ea(!1)}),F&&F.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||(Lt(!1),Ke=!0,c(n("status.opening")),ta(a))}),F&&(F.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!qe){var a=t.getAttribute("data-library-group-id");a&&(xe[a]=!t.open,Jt())}},!0),F.addEventListener("click",function(e){if(Gt){var t=e.target&&e.target.closest?e.target.closest(".library-group summary"):null;t&&(e.preventDefault(),e.stopPropagation())}},!0),F.addEventListener("pointerdown",function(e){if(e.button===0&&oe){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(X={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=X;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;tn(t.group)}e.preventDefault(),Xa(e.clientX,e.clientY),an(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){Ya()}),window.addEventListener("pointercancel",function(){Ya()}));var Ke=!1,At="";function ta(e){!e||!i||!i.postMessage||(At=e,i.postMessage({type:"loadPath",path:e}))}ce&&ce.addEventListener("click",function(e){if(!(!i||!i.postMessage)){var t=e.target&&e.target.closest?e.target.closest(".home-group-cwd"):null;if(t){var a=t.getAttribute("data-cwd-path")||"";a&&i.postMessage({type:"openPath",path:a});return}var r=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(r){e.preventDefault(),e.stopPropagation();var o=r.getAttribute("data-reveal-path")||"";o&&i.postMessage({type:"openPath",path:o});return}var s=e.target&&e.target.closest?e.target.closest(".doc-card"):null;if(s){var l=s.getAttribute("data-path")||"";l&&(Ke=!0,c(n("status.opening")),ta(l))}}}),ce&&ce.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 Ze(){Wt.hidden=L(),document.body.classList.toggle("has-document",L()),Be&&(Be.hidden=!W),!Wt.hidden&&Et&&Mt()}function Fe(){Nr.classList.toggle("active",v?L():C==="edit"),zt.classList.toggle("active",v?L():C==="preview"),(v||C==="edit")&&p&&requestAnimationFrame(function(){p.layout()})}function Ka(e){v||!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function rn(e){return e?"document:"+encodeURIComponent(e):""}function Za(e){if(!e||e.indexOf("document:")!==0)return"";try{var t=decodeURIComponent(e.slice(9));return/^(?:\/|[A-Za-z]:[\\/])/.test(t)?t:""}catch{return""}}var Te="";function $a(e){!e||e===m||!i||!i.postMessage||(Te=e,ta(e))}function we(){if(!(!v||!i||!i.appView||!i.appView.breadcrumb)){var e=L()&&m?[{id:rn(m),title:_||n("common.markdownDocDefault"),icon:"file-text"}]:[];i.appView.breadcrumb.set(e).catch(function(){})}}function nn(){Ha||!i||!i.appView||!i.appView.breadcrumb||(Ha=!0,i.appView.breadcrumb.onNavigate(function(e){if(!e.id){L()&&it().then(we);return}var t=Za(e.id);t?$a(t):i.appView.breadcrumb.set([]).catch(function(){})}),i.appView.breadcrumb.onRestore(function(e){var t=Array.isArray(e.levels)?e.levels:[];if(!t.length){L()&&it().then(we);return}var a=t.length===1&&Za(t[0].id);if(!a){i.appView.breadcrumb.set([]).catch(function(){}),L()&&it().then(we);return}$a(a)}))}function on(){var e=[{id:"style:kami",label:"Kami"},{id:"style:bauhaus",label:"Bauhaus"},{id:"style:blueprint",label:"Blueprint"},{id:"style:botanical",label:"Botanical"},{id:"style:newsprint",label:"Newsprint"},{id:"style:retro",label:"Retro"},{id:"style:sketch",label:"Sketch"},{id:"style:terminal",label:"Terminal"},{id:"style-sep",label:"",separator:!0}],t=I==="custom"&&!!B&&!z.some(function(s){return s&&s.css===B});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=z[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 sn(){var e="ext:markdown-editor-icons/save",t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDefault");O?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):Oe&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=L(),o=Qa(h,r),s=[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:m||_||n("toolbar.open.tooltipDefault"),disabled:K},{id:"save",icon:e,label:t,tooltip:a,disabled:!O},{type:"separator"},{id:"mode",icon:je?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?je?"toolbar.mode.tooltipRendering":C==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:C==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(C==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:C!=="preview",items:on()},{type:"spacer"},{type:"menu",id:"wordCount",icon:o.icon,label:o.label,tooltip:o.tooltip,disabled:!r,items:[{id:"word-count:character",label:n("wordCount.mode.character"),icon:"hash",checked:V==="character"},{id:"word-count:word",label:n("wordCount.mode.word"),icon:"ext:markdown-editor-icons/whole-word",checked:V==="word"}]},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?A?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:A,disabled:!r||C==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?C==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||C==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!N},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:N},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:U===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:U===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:U===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:$==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:$==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:C!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"recentSession",label:n("toolbar.more.recentSession"),disabled:!ve},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}];return r?s:s.filter(function(l){return!("id"in l)||l.id!=="wordCount"})}function D(e,t,a,r){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+(r?" disabled":"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function Ja(){if(ft){var e=["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"],t=e.map(function(s){return D("style:"+s,s[0].toUpperCase()+s.slice(1),I===s)}).join("")+"<hr>",a=I==="custom"&&!!B&&!z.some(function(s){return s&&s.css===B});a&&(t+=[0,1,2].map(function(s){return D("style:slot-save:"+s,n("aiStyle.saveToSlot",{n:s+1}),!1)}).join("")+"<hr>");for(var r=0;r<3;r++){var o=z[r];t+=o?D("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),I==="custom"&&B===o.css):D("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}ft.innerHTML=t}gt&&(gt.innerHTML=D("word-count:character",n("wordCount.mode.character"),V==="character")+D("word-count:word",n("wordCount.mode.word"),V==="word")),ht&&(ht.innerHTML=D("comfort:read",n("toolbar.comfort.read"),!N)+D("comfort:write",n("toolbar.comfort.write"),N)+"<hr>"+D("font-size:14",n("toolbar.fontSize.small"),U===14)+D("font-size:16",n("toolbar.fontSize.medium"),U===16)+D("font-size:18",n("toolbar.fontSize.large"),U===18)+"<hr>"+D("font-family:rounded",n("toolbar.fontFamily.default"),$==="rounded")+D("font-family:songti",n("toolbar.fontFamily.serif"),$==="songti")),yt&&(yt.innerHTML=D("reload",n("toolbar.more.reload"),!1)+D("reveal",n("toolbar.more.reveal"),!1)+D("recentSession",n("toolbar.more.recentSession"),!1,!ve)+"<hr>"+D("about",n("toolbar.more.about"),!1))}function ln(e){var t=String(e||"").replace(/\r\n?/g,`
|
|
14
|
+
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=dt?pt.zh:pt.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(pt.en,e)?pt.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 Xt(e){var t=e||document;document.documentElement.lang=dt?"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 Kt=document.getElementById("empty"),Ba=document.getElementById("emptyNew"),Na=document.getElementById("emptyOpen"),Zt=document.getElementById("homeRecent"),ce=document.getElementById("homeGrid"),ft=document.getElementById("homeHint"),$t=[],Wa=document.getElementById("homeTagline"),tn=document.getElementById("editPane"),Jt=document.getElementById("previewPane"),ue=document.getElementById("previewResizer"),Ee=document.getElementById("editor"),y=document.getElementById("article"),M=document.getElementById("status"),x=document.getElementById("popup"),G=document.getElementById("popupInput"),qa=document.getElementById("popupSend"),Ha=document.getElementById("popupShortcut"),Be=document.getElementById("actions"),an=document.getElementById("actCopyWx"),rn=document.getElementById("actCopyImg"),nn=document.getElementById("actSaveImg"),on=document.getElementById("actSavePdf"),Ce=document.getElementById("actAiStyle"),za=document.getElementById("actToggle"),de=document.getElementById("confirmOverlay"),Ua=document.getElementById("confirmMessage"),Qt=document.getElementById("confirmCancel"),ea=document.getElementById("confirmDiscard"),Ne=document.getElementById("confirmSave"),_a=document.getElementById("appToolbar"),Va=document.getElementById("appHome"),ja=document.getElementById("appLibrary"),mt=document.getElementById("appOpen"),ne=document.getElementById("appSave"),We=document.getElementById("appPreview"),vt=document.getElementById("appStyle"),gt=document.getElementById("appStyleMenu"),Ga=document.getElementById("appWordCountWrap"),ht=document.getElementById("appWordCount"),Ya=document.getElementById("appWordCountValue"),yt=document.getElementById("appWordCountIcon"),bt=document.getElementById("appWordCountMenu"),pe=document.getElementById("appFocus"),ta=document.getElementById("appFont"),wt=document.getElementById("appFontMenu"),sn=document.getElementById("appMore"),St=document.getElementById("appMoreMenu"),aa=document.getElementById("libraryDrawer"),kt=document.getElementById("libraryBackdrop"),Xa=document.getElementById("libraryClose"),Et=document.getElementById("libraryReorder"),Ka=document.getElementById("libraryReorderFooter"),Za=document.getElementById("libraryReorderDone"),T=document.getElementById("libraryGroups"),$a="md-editor-library-groups-v1",fe=[],Me={},me=null,qe=null,oe=!1,He=[],Y=null,ra=!1,v=!1,Ja=!1,Qa=!1,H=null,ve=null,R=!0,ze=null,ln=!1,Ct=0,Ue=!1,ae=!0,E="edit",I="kami",B="",xe="",z=[null,null,null],Ie={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},U=14,$="rounded",N=!1,_="character",A=!1;try{var Mt=Number(localStorage.getItem("md-editor-font-size"));(Mt===14||Mt===16||Mt===18)&&(U=Mt);var na=localStorage.getItem("md-editor-font-family");Ie[na]?$=na:na&&localStorage.removeItem("md-editor-font-family"),N=localStorage.getItem("md-editor-comfort-writing")==="1",localStorage.getItem("md-editor-word-count-mode")==="word"&&(_="word"),A=localStorage.getItem("md-editor-focus-mode")==="1";var _e=JSON.parse(localStorage.getItem($a)||"{}");Array.isArray(_e.order)&&(fe=_e.order.filter(function(e){return typeof e=="string"})),_e.collapsed&&typeof _e.collapsed=="object"&&(Me=_e.collapsed)}catch{}ae=!A;var h="",Ve="",V="",m="",P=null,W="",Le=!1,er=0,je=!1,tr=0,oa={},Ae={},cn=0,ge={},un=0,he={},Ge=0,J=null,xt=0,De=0,ia=!1,w={text:"",mode:"replace"},C=0;function c(e,t){C&&(clearTimeout(C),C=0),M.textContent=e||"",M.className="status"+(t?" error":""),e&&(C=setTimeout(function(){C=0,M.textContent="",M.className="status"},5e3))}function ye(e,t,a,r){if(C&&(clearTimeout(C),C=0),M.replaceChildren(document.createTextNode(e||"")),M.className="status"+(t?" error":""),a){var o=document.createElement("button");o.type="button",o.className="status-inline-btn",o.textContent=n("appview.openSession"),o.addEventListener("click",function(){i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(a)}),M.appendChild(o)}r&&(C=setTimeout(function(){C=0,M.replaceChildren(),M.className="status"},r))}function dn(){C&&(clearTimeout(C),C=0),M.replaceChildren(document.createTextNode(n("status.rendererAboutPrefix")));var e=document.createElement("a");e.href="https://bm.md/",e.textContent="bm.md",e.title="https://bm.md/",e.addEventListener("click",function(t){t.preventDefault(),i&&i.postMessage&&i.postMessage({type:"openLink",url:"https://bm.md/"})}),M.append(e,document.createTextNode(n("status.rendererAboutSuffix"))),M.className="status",C=setTimeout(function(){C=0,M.textContent="",M.className="status"},5e3)}function L(){return!!h||!!m}Ba&&Ba.addEventListener("click",async function(){if(!i||!i.composer){c(n("newdoc.needChat"),!0);return}try{await i.composer.addContexts([{type:"annotation",label:n("newdoc.label"),promptText:n("newdoc.promptText"),reminder:n("newdoc.reminder")}]),c(n("newdoc.added"))}catch(e){c(String(e),!0)}}),Na&&Na.addEventListener("click",function(){Ea()});var Ye="",sa="",la="",It=!1,ar=!1,Xe="",be="";function k(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&":t==="<"?"<":t===">"?">":"""})}function rr(){Wa&&(Wa.textContent=Xe?n("home.tagline.withAssistant",{name:Xe}):n("home.tagline.default"))}function Lt(){G&&(G.placeholder=w.mode==="continue"?n("popup.placeholderContinue",{name:Xe||"Finch"}):n("popup.placeholder",{name:Xe||"Finch"}))}function pn(e){return e?be&&e===be?"~":be&&(e.indexOf(be+"/")===0||e.indexOf(be+"\\")===0)?"~"+e.slice(be.length):e:""}function fn(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 mn(){Dt($t)}function nr(e){var t=new Date(e);if(!e||isNaN(t.getTime()))return"";var a=new Date,r=function(u){return u<10?"0"+u:String(u)},o=r(t.getHours())+":"+r(t.getMinutes()),s=t.toDateString()===a.toDateString();if(s)return n("home.today",{clock:o});var l=new Date(a.getTime()-864e5);return t.toDateString()===l.toDateString()?n("home.yesterday",{clock:o}):t.getFullYear()===a.getFullYear()?r(t.getMonth()+1)+"-"+r(t.getDate()):t.getFullYear()+"-"+r(t.getMonth()+1)+"-"+r(t.getDate())}function At(){!i||!i.postMessage||!It||(ar=!0,i.postMessage({type:"requestRecentDocuments",cwd:Ye,sessionId:sa,spaceId:la}))}function vn(e){e=e||{};var t=e.relativePath||e.fileName||"";return'<button class="doc-card" type="button" data-path="'+k(e.path||"")+'" title="'+k(e.path||"")+'"><span class="doc-reveal" data-reveal-path="'+k(e.path||"")+'" role="button" tabindex="0" title="'+k(n("home.revealInFileManager"))+'" aria-label="'+k(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">'+k(e.preview||n("home.emptyDoc"))+'</div><div class="doc-foot"><div class="doc-title">'+k(e.title||e.fileName||n("home.untitled"))+'</div><div class="doc-sub"><span class="doc-path" data-full-path="'+k(t)+'">'+k(t)+'</span><span class="doc-time">'+k(nr(e.modifiedAt))+"</span></div></div></button>"}function Dt(e){if(!(!ce||!Zt||!ft)){var t=Array.isArray(e)?e:[];if($t=t,t.length===0){Zt.hidden=!0,ft.hidden=!1,ft.textContent=n(Ye?"home.hintScoped":"home.hintDefault");return}var a=or(t);ce.innerHTML=a.map(function(r){var o=r.documents.map(vn).join(""),s=r.scopePath?'<button type="button" class="home-group-cwd" data-cwd-path="'+k(r.scopePath)+'" title="'+k(n("home.cwdTitle",{path:r.scopePath}))+'">'+k(fn(pn(r.scopePath)))+"</button>":"",l='<div class="home-group-title"><span class="home-group-label">'+k(r.label)+'<span class="home-group-count">'+r.documents.length+"</span></span>"+s+"</div>";return'<div class="home-group">'+l+'<div class="home-grid">'+o+"</div></div>"}).join(""),Zt.hidden=!1,ft.hidden=!0,requestAnimationFrame(function(){gn(ce)})}}function gn(e){for(var t="\u2026",a=e.querySelectorAll("[data-full-path]"),r=0;r<a.length;r++){var o=a[r],s=o.getAttribute("data-full-path")||"";if(o.textContent=s,!(!s||o.scrollWidth<=o.clientWidth+1)){for(var l=0,u=s.length,d=0;l<=u;){var f=l+u>>1;o.textContent=f>0?t+s.slice(s.length-f):t,o.scrollWidth<=o.clientWidth+1?(d=f,l=f+1):u=f-1}o.textContent=d>0?t+s.slice(s.length-d):t}}}function ca(){var e={order:fe,collapsed:Me};try{localStorage.setItem($a,JSON.stringify(e))}catch{}i&&i.postMessage&&i.postMessage({type:"saveLibraryGroups",libraryGroups:e})}function or(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=fe.indexOf(a.id),s=fe.indexOf(r.id);if(o>=0||s>=0)return(o<0?9999:o)-(s<0?9999:s);var l={space:0,workspace:1},u=l[a.kind]-l[r.kind];return u||a.label.localeCompare(r.label)})}function ua(e){if(T){He=Array.isArray(e)?e:[];var t=or(He);if(oe){hn(t);return}T.innerHTML=t.map(function(a){var r=a.documents.map(function(l){var u=l.relativePath||l.fileName||"";return'<button class="library-row" type="button" data-path="'+k(l.path||"")+'"><span class="library-row-main"><strong>'+k(l.title||l.fileName||n("home.untitled"))+'</strong><span class="library-row-meta"><span class="library-row-path" title="'+k(u)+'">'+k(u)+"</span><time>"+k(nr(l.modifiedAt))+"</time></span></span></button>"}).join(""),o=a.kind!=="external",s=!Me[a.id];return'<details class="library-group" data-library-group-id="'+k(a.id)+'"'+(o?' data-draggable="true"':"")+(s?" open":"")+'><summary><span class="library-group-title">'+k(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">'+k(n("home.hintDefault"))+"</p>"}}function hn(e){T.innerHTML=e.map(function(t){var a=t.kind!=="external";return'<div class="library-group library-group-reorder" data-library-group-id="'+k(t.id)+'"'+(a?' data-draggable="true"':"")+'><span class="library-reorder-handle" aria-hidden="true">'+(a?"\u22EE\u22EE":"")+'</span><span class="library-group-title">'+k(t.label)+'</span><span class="library-group-count">'+t.documents.length+"</span></div>"}).join("")||'<p class="home-hint">'+k(n("home.hintDefault"))+"</p>"}function da(e){oe=!!e,Et&&Et.classList.toggle("active",oe),Ka&&(Ka.hidden=!oe),ua(He)}function Tt(e){!aa||!kt||(aa.classList.toggle("open",!!e),aa.setAttribute("aria-hidden",e?"false":"true"),kt.hidden=!e,e?At():oe&&da(!1))}function yn(){if(!(!me||!T)){me.classList.remove("dragging"),Array.prototype.forEach.call(T.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),fe=Array.prototype.map.call(T.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),Dt($t);var e=qe||{};Array.prototype.forEach.call(T.querySelectorAll(".library-group"),function(t){var a=t.getAttribute("data-library-group-id");a in e&&(t.open=!!e[a])}),me=null,setTimeout(function(){qe=null,ca()},0)}}function bn(){Y&&Y.ghost&&Y.ghost.parentNode&&Y.ghost.parentNode.removeChild(Y.ghost)}function ir(e,t){var a=Y;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function wn(e){var t=Y;if(!(!t||t.active)){t.active=!0,me=e,qe={},oe||Array.prototype.forEach.call(T.querySelectorAll(".library-group"),function(o){var s=o.getAttribute("data-library-group-id");s&&(qe[s]=!!o.open),o.open=!1}),e.classList.add("dragging");var a=e.getBoundingClientRect(),r=e.cloneNode(!0);r.classList.add("library-drag-ghost"),r.classList.remove("dragging"),r.style.width=a.width+"px",t.ghost=r,t.offsetX=t.startX-a.left,t.offsetY=t.startY-a.top,document.body.appendChild(r),ir(t.startX,t.startY)}}function Sn(e,t){if(me){var a=document.elementFromPoint(e,t),r=a&&a.closest?a.closest('.library-group[data-draggable="true"]'):null;if(Array.prototype.forEach.call(T.querySelectorAll(".library-group.drag-over"),function(s){s.classList.remove("drag-over")}),!(!r||r===me)){r.classList.add("drag-over");var o=t>r.getBoundingClientRect().top+r.offsetHeight/2;T.insertBefore(me,o?r.nextSibling:r)}}}function sr(){var e=Y;e&&(e.active&&(bn(),yn(),ra=!0,setTimeout(function(){ra=!1},0)),Y=null)}ja&&ja.addEventListener("click",function(){Tt(!0)}),Xa&&Xa.addEventListener("click",function(){Tt(!1)}),kt&&kt.addEventListener("click",function(){Tt(!1)}),Et&&Et.addEventListener("click",function(){da(!oe)}),Za&&Za.addEventListener("click",function(){da(!1)}),T&&T.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||(Tt(!1),Ke=!0,c(n("status.opening")),pa(a))}),T&&(T.addEventListener("toggle",function(e){var t=e.target;if(!(!t||!t.matches||!t.matches(".library-group"))&&!qe){var a=t.getAttribute("data-library-group-id");a&&(Me[a]=!t.open,ca())}},!0),T.addEventListener("click",function(e){if(ra){var t=e.target&&e.target.closest?e.target.closest(".library-group summary"):null;t&&(e.preventDefault(),e.stopPropagation())}},!0),T.addEventListener("pointerdown",function(e){if(e.button===0&&oe){var t=e.target&&e.target.closest?e.target.closest('.library-group[data-draggable="true"]'):null;t&&(Y={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=Y;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;wn(t.group)}e.preventDefault(),ir(e.clientX,e.clientY),Sn(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){sr()}),window.addEventListener("pointercancel",function(){sr()}));var Ke=!1,Ft="";function pa(e){!e||!i||!i.postMessage||(Ft=e,i.postMessage({type:"loadPath",path:e}))}ce&&ce.addEventListener("click",function(e){if(!(!i||!i.postMessage)){var t=e.target&&e.target.closest?e.target.closest(".home-group-cwd"):null;if(t){var a=t.getAttribute("data-cwd-path")||"";a&&i.postMessage({type:"openPath",path:a});return}var r=e.target&&e.target.closest?e.target.closest(".doc-reveal"):null;if(r){e.preventDefault(),e.stopPropagation();var o=r.getAttribute("data-reveal-path")||"";o&&i.postMessage({type:"openPath",path:o});return}var s=e.target&&e.target.closest?e.target.closest(".doc-card"):null;if(s){var l=s.getAttribute("data-path")||"";l&&(Ke=!0,c(n("status.opening")),pa(l))}}}),ce&&ce.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 Ze(){Kt.hidden=L(),document.body.classList.toggle("has-document",L()),Be&&(Be.hidden=!W),!Kt.hidden&&It&&At()}function Te(){tn.classList.toggle("active",v?L():E==="edit"),Jt.classList.toggle("active",v?L():E==="preview"),(v||E==="edit")&&p&&requestAnimationFrame(function(){p.layout()})}function lr(e){v||!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function kn(e){return e?"document:"+encodeURIComponent(e):""}function cr(e){if(!e||e.indexOf("document:")!==0)return"";try{var t=decodeURIComponent(e.slice(9));return/^(?:\/|[A-Za-z]:[\\/])/.test(t)?t:""}catch{return""}}var Fe="";function ur(e){!e||e===m||!i||!i.postMessage||(Fe=e,pa(e))}function we(){if(!(!v||!i||!i.appView||!i.appView.breadcrumb)){var e=L()&&m?[{id:kn(m),title:V||n("common.markdownDocDefault"),icon:"file-text"}]:[];i.appView.breadcrumb.set(e).catch(function(){})}}function En(){Qa||!i||!i.appView||!i.appView.breadcrumb||(Qa=!0,i.appView.breadcrumb.onNavigate(function(e){if(!e.id){L()&&it().then(we);return}var t=cr(e.id);t?ur(t):i.appView.breadcrumb.set([]).catch(function(){})}),i.appView.breadcrumb.onRestore(function(e){var t=Array.isArray(e.levels)?e.levels:[];if(!t.length){L()&&it().then(we);return}var a=t.length===1&&cr(t[0].id);if(!a){i.appView.breadcrumb.set([]).catch(function(){}),L()&&it().then(we);return}ur(a)}))}function Cn(){var e=[{id:"style:kami",label:"Kami"},{id:"style:bauhaus",label:"Bauhaus"},{id:"style:blueprint",label:"Blueprint"},{id:"style:botanical",label:"Botanical"},{id:"style:newsprint",label:"Newsprint"},{id:"style:retro",label:"Retro"},{id:"style:sketch",label:"Sketch"},{id:"style:terminal",label:"Terminal"},{id:"style-sep",label:"",separator:!0}],t=I==="custom"&&!!B&&!z.some(function(s){return s&&s.css===B});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=z[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 Mn(){var e="ext:markdown-editor-icons/save",t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDefault");O?(t=n("toolbar.save.label"),a=n("toolbar.save.tooltipDirty")):Oe&&(e="ext:markdown-editor-icons/save-check",t=n("toolbar.save.labelSaved"),a=n("toolbar.save.tooltipSaved"));var r=L(),o=pr(h,r),s=[{id:"home",icon:"house",tooltip:n("toolbar.home.tooltip")},{id:"open",icon:"ext:markdown-editor-icons/folder-open",tooltip:m||V||n("toolbar.open.tooltipDefault"),disabled:K},{id:"save",icon:e,label:t,tooltip:a,disabled:!O},{type:"separator"},{id:"mode",icon:je?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?je?"toolbar.mode.tooltipRendering":E==="edit"?"toolbar.mode.tooltipToPreview":"toolbar.mode.tooltipToEdit":"toolbar.needDoc"),checked:E==="preview",disabled:!r},{type:"menu",id:"style",icon:"palette",tooltip:n(E==="preview"?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"),disabled:E!=="preview",items:Cn()},{type:"spacer"},{type:"menu",id:"wordCount",icon:o.icon,label:o.label,tooltip:o.tooltip,disabled:!r,items:[{id:"word-count:character",label:n("wordCount.mode.character"),icon:"hash",checked:_==="character"},{id:"word-count:word",label:n("wordCount.mode.word"),icon:"ext:markdown-editor-icons/whole-word",checked:_==="word"}]},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?A?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:A,disabled:!r||E==="preview"},{type:"menu",id:"font-size",icon:"ext:markdown-editor-icons/type",tooltip:n(r?E==="preview"?"toolbar.fontSize.tooltipPreview":"toolbar.fontSize.tooltipEdit":"toolbar.needDoc"),disabled:!r||E==="preview",items:[{id:"comfort:read",label:n("toolbar.comfort.read"),checked:!N},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:N},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:U===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:U===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:U===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:$==="rounded"},{id:"font-family:songti",label:n("toolbar.fontFamily.serif"),checked:$==="songti"}]},{type:"menu",id:"more",icon:"settings",items:[{id:"reload",label:n("toolbar.more.reload"),disabled:E!=="preview"},{id:"reveal",label:n("toolbar.more.reveal"),disabled:!r},{id:"recentSession",label:n("toolbar.more.recentSession"),disabled:!ve},{id:"more-sep",label:"",separator:!0},{id:"about",label:n("toolbar.more.about")}]}];return r?s:s.filter(function(l){return!("id"in l)||l.id!=="wordCount"})}function D(e,t,a,r){return'<button type="button" data-app-action="'+e+'"'+(a?' class="checked"':"")+(r?" disabled":"")+"><span>"+t+"</span>"+(a?"<span>\u2713</span>":"")+"</button>"}function dr(){if(gt){var e=["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"],t=e.map(function(s){return D("style:"+s,s[0].toUpperCase()+s.slice(1),I===s)}).join("")+"<hr>",a=I==="custom"&&!!B&&!z.some(function(s){return s&&s.css===B});a&&(t+=[0,1,2].map(function(s){return D("style:slot-save:"+s,n("aiStyle.saveToSlot",{n:s+1}),!1)}).join("")+"<hr>");for(var r=0;r<3;r++){var o=z[r];t+=o?D("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),I==="custom"&&B===o.css):D("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}gt.innerHTML=t}bt&&(bt.innerHTML=D("word-count:character",n("wordCount.mode.character"),_==="character")+D("word-count:word",n("wordCount.mode.word"),_==="word")),wt&&(wt.innerHTML=D("comfort:read",n("toolbar.comfort.read"),!N)+D("comfort:write",n("toolbar.comfort.write"),N)+"<hr>"+D("font-size:14",n("toolbar.fontSize.small"),U===14)+D("font-size:16",n("toolbar.fontSize.medium"),U===16)+D("font-size:18",n("toolbar.fontSize.large"),U===18)+"<hr>"+D("font-family:rounded",n("toolbar.fontFamily.default"),$==="rounded")+D("font-family:songti",n("toolbar.fontFamily.serif"),$==="songti")),St&&(St.innerHTML=D("reload",n("toolbar.more.reload"),!1)+D("reveal",n("toolbar.more.reveal"),!1)+D("recentSession",n("toolbar.more.recentSession"),!1,!ve)+"<hr>"+D("about",n("toolbar.more.about"),!1))}function xn(e){var t=String(e||"").replace(/\r\n?/g,`
|
|
15
15
|
`).replace(/^(?:\uFEFF)?---\s*\n[\s\S]*?\n(?:---|\.\.\.)\s*(?=\n|$)/,`
|
|
16
|
-
`).replace(/```[\s\S]*?```|~~~[\s\S]*?~~~/g," ").replace(/`[^`\n]*`/g," ").replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/https?:\/\/\S+/g," ").replace(/<[^>]+>/g," ").replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-+*]\s+|\d+[.)]\s+)/gm,"").replace(/[*_~]/g," "),a=/[A-Za-z]+(?:['’][A-Za-z]+)*(?:-[A-Za-z]+(?:['’][A-Za-z]+)*)*/g,r=(t.match(a)||[]).length,o=Array.from(t).filter(function(l){return/[A-Za-z]/.test(l)}).length,s=Array.from(t.replace(a," ")).filter(function(l){return/[\p{L}\p{N}]/u.test(l)}).length;return{englishWords:r,englishCharacters:o,nonEnglish:s}}function
|
|
16
|
+
`).replace(/```[\s\S]*?```|~~~[\s\S]*?~~~/g," ").replace(/`[^`\n]*`/g," ").replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/https?:\/\/\S+/g," ").replace(/<[^>]+>/g," ").replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-+*]\s+|\d+[.)]\s+)/gm,"").replace(/[*_~]/g," "),a=/[A-Za-z]+(?:['’][A-Za-z]+)*(?:-[A-Za-z]+(?:['’][A-Za-z]+)*)*/g,r=(t.match(a)||[]).length,o=Array.from(t).filter(function(l){return/[A-Za-z]/.test(l)}).length,s=Array.from(t.replace(a," ")).filter(function(l){return/[\p{L}\p{N}]/u.test(l)}).length;return{englishWords:r,englishCharacters:o,nonEnglish:s}}function pr(e,t){var a=_==="character",r=a?"hash":"ext:markdown-editor-icons/whole-word";if(!t)return{icon:r,label:n("wordCount.home.label"),tooltip:n(a?"wordCount.home.tooltip.character":"wordCount.home.tooltip.word")};var o=xn(e),s=a?o.englishCharacters:o.englishWords,l={total:o.nonEnglish+s,nonEnglish:o.nonEnglish,english:s};return{icon:r,label:n(a?"wordCount.label.character":"wordCount.label.word",l),tooltip:n(a?"wordCount.tooltip.character":"wordCount.tooltip.word",l)}}function In(){return _==="character"?'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18"/></svg>':'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-whole-word" aria-hidden="true"><circle cx="7" cy="12" r="3"/><path d="M10 9v6"/><circle cx="17" cy="12" r="3"/><path d="M14 7v8"/><path d="M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1"/></svg>'}function Ln(){if(ht){var e=pr(h,L());Ya&&(Ya.textContent=e.label),yt&&yt.getAttribute("data-mode")!==_&&(yt.innerHTML=In(),yt.setAttribute("data-mode",_)),ht.setAttribute("data-tooltip",e.tooltip),ht.setAttribute("aria-label",e.tooltip)}}function An(){if(v){var e=L();if(Ga&&(Ga.hidden=!e),Ln(),ne){ne.disabled=!O,ne.classList.toggle("dirty",O);var t=Oe?"toolbar.save.tooltipSaved":O?"toolbar.save.tooltipDirty":"toolbar.save.tooltipDefault";ne.setAttribute("data-tooltip",n(t));var a=ne.querySelector(".ic-save"),r=ne.querySelector(".ic-save-check");a&&(a.hidden=Oe),r&&(r.hidden=!Oe)}if(pe){pe.disabled=!e,pe.classList.toggle("checked",A);var o=n(A?"appview.focusExit":"appview.focus");pe.setAttribute("data-tooltip",o),pe.setAttribute("aria-label",o)}We&&(We.disabled=!e,We.classList.toggle("checked",R)),mt&&(mt.disabled=K),vt&&(vt.disabled=!e||!R,vt.setAttribute("data-tooltip",n(R?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),ta&&(ta.disabled=!e),dr()}}function S(){v?An():i&&i.postMessage({type:"setToolbar",toolbar:Mn()})}function $e(e){if(F(),v){E="edit",Te(),X(),S();return}E=e,Te(),S(),E==="preview"&&X()}function Dn(e){return!i||!i.postMessage?Promise.reject(new Error("No host bridge.")):new Promise(function(t,a){var r=new FileReader;r.onload=function(){var o=typeof r.result=="string"?r.result:"",s=o.indexOf(","),l=s>=0?o.slice(s+1):"";if(!l){a(new Error("Could not read pasted image."));return}var u=++cn;ge[u]={resolve:t,reject:a},setTimeout(function(){ge[u]&&(delete ge[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:l,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var p=window.MarkdownCodeMirror.create({parent:Ee,value:h,onChange:function(e){h=e,F(),Ze(),Re(!0),Tr(),qn()},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:Dn,onAiHintTrigger:ao,onAiWorkingCancel:function(){!v||!H||!m||!i||!i.postMessage||i.postMessage({type:"cancelRewrite",path:m,sessionId:H.sessionId,turnId:H.turnId})}});p.setFontSize(U),p.setFontFamily(Ie[$]),p.setComfortWriting(N),p.setFocusMode(A),document.body.classList.toggle("focus-mode",A);var fr=0;p.scrollDOM.addEventListener("scroll",function(){F(),p.scrollDOM.classList.add("cm-scrollbar-active"),window.clearTimeout(fr),fr=window.setTimeout(function(){p.scrollDOM.classList.remove("cm-scrollbar-active")},800)});function Tn(){return I==="custom"?B:""}var mr="user-content-mdl-",fa=0,ma={side:"",value:-1,at:0},Je={editor:!1,preview:!1},Pe=[];function Fn(e){if(!v)return e;for(var t=e.split(`
|
|
17
17
|
`),a=[],r=!1,o=0;o<t.length;o++){var s=t[o],l=/^[ \t]*(?:```|~~~)/.test(s),u=o+1;if(l){r=!r,a.push(s);continue}var d=s.trim(),f=r||d===""||/\\\s*$/.test(s)||/^<[a-zA-Z!]/.test(d)||/^!\[[^\]]*\]\([^)]*\)\s*$/.test(d)||/^\s*\|/.test(s)&&/[|]\s*$/.test(s),b=!f&&/[|]/.test(s)&&o+1<t.length&&/^[ \t]*\|?[\s:|-]+\|?[ \t]*$/.test(t[o+1])&&/-/.test(t[o+1]);if(b){a.push(s);for(var g=o+1;g<t.length&&/[|]/.test(t[g]);)a.push(t[g]),g++;o=g-1;continue}a.push(f?s:s+'<a id="mdl-'+u+'"></a>')}return a.join(`
|
|
18
|
-
`)}function
|
|
18
|
+
`)}function va(){if(Pe=[],Q=null,!(!v||!Le)){var e=y.contentDocument;if(e){var t=e.querySelector("#bm-md");if(t){for(var a=e.querySelectorAll('a[id^="'+mr+'"]'),r=0;r<a.length;r++){var o=a[r].id,s=Number(o.slice(mr.length));!Number.isFinite(s)||s<1||t.contains(a[r])&&Pe.push({line:s,el:a[r]})}Pe.sort(function(l,u){return l.line-u.line}),Q=null}}}}function vr(){var e=y.contentDocument;return e&&e.scrollingElement?e.scrollingElement.scrollTop:0}function Pn(e){var t=y.contentDocument;if(!(!t||!t.scrollingElement)){var a=t.scrollingElement,r=Math.max(0,Math.min(e,a.scrollHeight-a.clientHeight));Math.abs(a.scrollTop-r)<1||(ma={side:"preview",value:r,at:Date.now()},a.scrollTop=r)}}function On(e){if(!e)return 0;var t=y.contentDocument,a=t&&t.scrollingElement;return e.getBoundingClientRect().bottom+(a?a.scrollTop:0)}var Q=null;function Rn(){if(Q=null,!Pe.length||!p||!p.scrollDOM)return null;var e=y.contentDocument,t=e&&e.scrollingElement;if(!t)return null;var a=Math.max(0,p.scrollDOM.scrollHeight-p.scrollDOM.clientHeight),r=Math.max(0,t.scrollHeight-t.clientHeight);if(a<=0||r<=0)return null;for(var o=[0],s=[0],l=0;l<Pe.length;l++){var u=Pe[l],d=p.lineBottom(u.line);if(d!=null){var f=On(u.el);if(!(!(d>o[o.length-1]+1)||!(f>s[s.length-1]+1))){if(d>=a||f>=r)break;o.push(d),s.push(f)}}}return o.push(a),s.push(r),Q={e:o,p:s,eMax:a,pMax:r,pHeight:t.scrollHeight,eHeight:p.scrollDOM.scrollHeight},Q}function Bn(){var e=y.contentDocument,t=e&&e.scrollingElement;return!t||!p||!p.scrollDOM?null:!Q||Q.pHeight!==t.scrollHeight||Q.eHeight!==p.scrollDOM.scrollHeight?Rn():Q}function gr(e,t,a){var r=e.length;if(!r)return a;if(a<=e[0])return t[0];if(a>=e[r-1])return t[r-1];for(var o=0,s=r-1;o<s-1;){var l=o+s>>1;e[l]<=a?o=l:s=l}var u=e[s]-e[o]||1;return t[o]+(a-e[o])/u*(t[s]-t[o])}function hr(e){Je[e]=!0,!fa&&(fa=requestAnimationFrame(function(){fa=0,Nn()}))}function yr(e){var t=ma;if(t.side!==e||Date.now()-t.at>300)return!1;var a=e==="editor"?p.scrollDOM.scrollTop:vr();return!(Math.abs(t.value-a)>2)}function Nn(){var e=Je.editor,t=Je.preview;if(Je.editor=!1,Je.preview=!1,!(!v||!L()||!R)){var a=Bn();if(a){if(e)Pn(gr(a.e,a.p,p.scrollDOM.scrollTop));else if(t){var r=gr(a.p,a.e,vr());ma={side:"editor",value:r,at:Date.now()},Math.abs(p.scrollDOM.scrollTop-r)>=1&&(p.scrollDOM.scrollTop=r)}}}}function Wn(){yr("editor")||!v||!L()||!R||hr("editor")}function br(){yr("preview")||!v||!L()||!R||hr("preview")}function qn(){v&&(Ct&&clearTimeout(Ct),Ct=setTimeout(function(){Ct=0,X()},420))}function X(){if(!(!h||!i)){var e=++er;je=!0,S(),i.postMessage({type:"renderBm",markdown:Fn(h),markdownStyle:I==="custom"?"kami":I,customCss:Tn(),requestId:e})}}function Hn(){var e=y.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function zn(e){var t=y.contentDocument,a=t&&t.scrollingElement;!e||!a||(a.scrollTop=Math.min(e.top,Math.max(0,a.scrollHeight-a.clientHeight)))}function Un(){try{return getComputedStyle(y).backgroundColor||""}catch{return""}}function _n(e,t,a){var r=Math.min(3,Math.max(2,(window.devicePixelRatio||1)*2)),o;try{o=new XMLSerializer().serializeToString(e)}catch(l){return Promise.reject(l)}var s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.max(1,Math.round(t*r)),f.height=Math.max(1,Math.round(a*r));var b=f.getContext("2d");b.scale(r,r);var g="";try{g=getComputedStyle(e).backgroundColor}catch{g=""}g&&g!=="rgba(0, 0, 0, 0)"&&g!=="transparent"&&(b.fillStyle=g,b.fillRect(0,0,t,a)),b.drawImage(d,0,0,t,a),l(f.toDataURL("image/png"))}catch(q){u(q)}},d.onerror=function(){u(new Error("svg rasterize failed"))},d.src=s})}function wr(){if(!(!Le||!y.contentDocument||!y.contentDocument.body)){var e=y.contentDocument,t=Array.prototype.slice.call(e.querySelectorAll("figure.figure-mermaid > svg, figure.figure-infographic > svg"));t.length&&Promise.all(t.map(function(a){var r=a.closest("figure"),o=a.getBoundingClientRect(),s=Math.ceil(o.width)||a.viewBox&&a.viewBox.baseVal&&a.viewBox.baseVal.width||600,l=Math.ceil(o.height)||a.viewBox&&a.viewBox.baseVal&&a.viewBox.baseVal.height||400;return _n(a,s,l).then(function(u){var d=e.createElement("img");d.src=u,d.alt=r&&r.classList.contains("figure-infographic")?"Infographic":"Mermaid diagram",d.style.display="block",d.style.width="100%",d.style.height="auto",a.replaceWith(d)}).catch(function(){})})).then(function(){e.body&&(W=e.body.innerHTML)})}}function Sr(e){var t=Hn(),a=y.contentDocument;W=e;var r=Un();if(Le&&a&&a.body){a.body.innerHTML=W,r&&(a.body.style.background=r),zn(t),Er(),va(),wr();return}y.srcdoc='<!doctype html><meta charset="utf-8"><base target="_blank"><style>html,body{margin:0!important;padding:0!important;min-height:100%}body{background:'+(r||"transparent")+"}#bm-md{min-height:100dvh}</style><body>"+W}function kr(e,t,a){return{start:e.slice(0,t).split(`
|
|
19
19
|
`).length,end:e.slice(0,a).split(`
|
|
20
|
-
`).length}}function
|
|
21
|
-
`;if(s){var l=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(l){o+=l[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var d=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(d){for(var f=o+d[0].indexOf("[")+1,b=0;b<d[1].length;b++)/[*_~`]/.test(d[1][b])||r(d[1][b],f+b);o+=d[0].length;continue}var g=/^<[^>]+>/.exec(e.slice(o));if(g){o+=g[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 Mn(t,a)}function Ln(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=In(e),o=t.replace(/\s+/g," ").trim(),s=r.text.indexOf(o);if(s>=0)return{start:r.map[s],end:r.map[s+o.length-1]+1};if(o.length>=12){var l=o.slice(0,6),u=o.slice(-6),d=r.text.indexOf(l),f=r.text.indexOf(u,Math.max(0,d+l.length));if(d>=0&&f>=d)return{start:r.map[d],end:r.map[f+u.length-1]+1}}return null}function An(e){return String(e||"").split(/[\\/]/).pop()||""}function ur(){var e=y.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(ae){var a=y.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),l=Array.from(s.getClientRects()),u=y.getBoundingClientRect(),d=l.map(function(j){return{top:u.top+j.top,left:u.left+j.left,width:j.width,height:j.height}}),f=l[0]||s.getBoundingClientRect(),b=l[l.length-1]||f,g=Ln(h,o),q=g?cr(h,g.start,g.end):null;pr(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+b.bottom,endLeft:u.left+b.left},d,q,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){Se(),T()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),$e("edit"))}),e.addEventListener("scroll",function(){Se(),T()},!0),y.contentWindow.addEventListener("scroll",function(){Se(),T()})}y.onload=function(){Le=!0,ur(),na()};function dr(){p&&p.scrollDOM&&!p.scrollDOM.__scrollSyncBound&&(p.scrollDOM.__scrollSyncBound=!0,p.scrollDOM.addEventListener("scroll",wn,{passive:!0}));var e=y.contentDocument;if(e&&!e.__scrollSyncBound){e.__scrollSyncBound=!0;var t=e.scrollingElement||e.documentElement;t&&t.addEventListener("scroll",ir,{passive:!0}),e.defaultView&&e.defaultView.addEventListener("scroll",ir,{passive:!0})}}dr(),window.addEventListener("resize",function(){Q=null}),y.addEventListener("load",function(){requestAnimationFrame(function(){Le=!0,na(),dr(),sr()})});var Dt=0,oa=[];function pr(e,t,a,r,o){Se(),Dt=setTimeout(function(){fr(e,t,a,r,o)},300)}function Se(){Dt&&(clearTimeout(Dt),Dt=0)}function fr(e,t,a,r,o,s){w.text=e,w.lines=r||null,w.origin=o||"",w.mode=s||"replace",xt(),M.classList.remove("hidden"),M.classList.toggle("popup-bar",!!(t&&t.width)),G.value="",Fn(a),requestAnimationFrame(function(){Dn(t),t&&t.focus&&G.focus()})}function Dn(e){var t=8,a=10,r=e||{},o=v?t+48:t;if(M.style.width=r.width?r.width+"px":"",r.width){M.style.left=Math.max(t,r.startLeft||0)+"px",M.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(M.offsetHeight||44)-t))+"px";return}var s=M.offsetWidth||300,l=M.offsetHeight||44,u=(r.startTop||0)-a-l,d=u>=o,f=d?u:(r.endBottom||0)+a,b=d?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;M.style.left=Math.max(t,Math.min(b,window.innerWidth-s-t))+"px",M.style.top=Math.max(o,Math.min(f,window.innerHeight-l-t))+"px"}function Fn(e){mr(),(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),oa.push(a)})}function mr(){oa.forEach(function(e){e.remove()}),oa=[]}var Tn=navigator.platform||navigator.userAgent||"",Ft=/Mac|iPhone|iPod|iPad/.test(Tn);document.body.classList.toggle("non-mac-platform",!Ft);function Pn(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Ft?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(Ia){var t=Ft?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Ft?"":"+";Ia.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function T(e){var t=e===!0&&w.origin==="editor"&&C==="edit";Se(),M.classList.add("hidden"),M.classList.remove("popup-bar"),M.classList.remove("focused"),M.style.width="",w.text="",w.lines=null,w.origin="",w.mode="replace",mr(),t&&requestAnimationFrame(function(){p.focus()})}Ma.onclick=gr;var vr=0;G.addEventListener("compositionend",function(){vr=Date.now()});function On(e){return e.isComposing||e.keyCode===229?!0:Date.now()-vr<100}G.addEventListener("keydown",function(e){if(e.key==="Enter"){if(On(e))return;gr()}e.key==="Escape"&&T(!0)}),G.addEventListener("focus",function(){M.classList.add("focused")}),G.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==Ma&&M.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!M.classList.contains("hidden")&&T(!0)}),document.addEventListener("keydown",function(e){Pn(e)&&(M.classList.contains("hidden")||(e.preventDefault(),G.focus(),G.select()))}),document.addEventListener("mousedown",function(e){M.contains(e.target)||(Se(),T())}),window.addEventListener("resize",T);function Rn(){if(!w.lines)return n("annotate.lineUnknown");var e=w.lines.start,t=w.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function Bn(){return w.lines?w.lines.start+"-"+w.lines.end:n("annotate.lineCompactUnknown")}async function gr(){var e=G.value.trim(),t=w.mode==="continue",a=w.mode==="annotate-line";if(!(!w.text&&!t&&!a||!i)){if(O&&m){var r=await ya();if(!r){c(n("status.saveFailedNoReturn"),!0);return}}if(v){if(!m||!i.postMessage){c(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:m,selectedText:w.text,requirement:e,startLine:w.lines&&w.lines.start,endLine:w.lines&&w.lines.end,rewriteMode:t?"continue":"replace"}),T(!0),c(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!w.text&&!a){T(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(_||"Markdown")+":"+Bn(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:Rn(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:w.text||n("annotate.emptyLine"),path:m||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),T(!0),c(n("annotate.added"))}catch(o){c(String(o),!0)}}}function Nn(){var e=p.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=cr(p.getValue(),e.start,e.end);return pr(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function hr(){ae&&Nn()}function Wn(e){if(!L()||!e)return!1;Se();var t=Ce.querySelector(".cm-line")||Ce.querySelector(".cm-content"),a=(t||Ce).getBoundingClientRect();return fr("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",v?"continue":"annotate-line"),!0}Ce.addEventListener("mouseup",hr),Ce.addEventListener("keyup",function(e){e.shiftKey&&hr()});var O=!1,Qe=0,ie=null,ia=!1,Oe=!1,sa="",la=null;function qn(e){sa=e,la=h,i.postMessage({type:"saveDraft",path:e,markdown:h,base:P})}function yr(){!m||!i||!i.postMessage||sa===m&&la===h||qn(m)}function ca(){sa="",la=null}function ua(e){ca(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function Re(e,t){O=e,Ge&&(clearTimeout(Ge),Ge=0),Oe=!O&&!!t,S(),!O&&t&&(Ge=setTimeout(function(){Ge=0,O||(Oe=!1,S())},3e3))}async function br(e){if(ie)return Sr(),c("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if(J&&J.createWritable)try{var t=await J.createWritable();return await t.write(e),await t.close(),Ct=(await J.getFile()).lastModified,P=e,Re(h!==e,h===e),c(n(h===e?"status.saved":"status.savedWithNewChanges")),ca(),!0}catch(r){return c(n("status.saveFailed",{err:String(r)}),!0),!1}if(m){var a=++Ua;return c(n("status.saving")),Yt[a]=e,i.postMessage({type:"saveMarkdown",path:m,markdown:e,requestId:a}),new Promise(function(r){Ae[a]=r})}return c(n("status.noSourceFile"),!0),!1}document.addEventListener("keydown",function(e){var t=e.metaKey||e.ctrlKey;if(t&&(e.key==="s"||e.key==="S")){e.preventDefault(),ga();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),$e(C==="edit"?"preview":"edit"))});function wr(){De&&(clearInterval(De),De=0),J=null}var da=null;function et(e,t,a,r,o,s){if(!r&&O&&P!==null&&e!==P)return ie={markdown:e,name:t,path:a,diskBaseline:o},c(n("status.externalUpdateSkipped"),!0),Sr(),!1;var l=P!==null&&(!a||!m||a===m);return l||(ae=!0),h=e,_e=t,a&&(m=a),_=An(a||m)||t||"Markdown",P=typeof o=="string"?o:h,da=l?p.applyExternalValue(h):null,da||p.setValue(h),Re(!1),Ka(_),s||we(),Ze(),Fe(),(v||C==="preview")&&Y(),!0}async function Sr(){if(!(ia||!ie||!O)){var e=ie,t=P;if(h===t){ie=null,et(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){ie=null;return}ia=!0;var a=await io();if(ia=!1,ie===e){if(a==="later"){c("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(ie=null,a==="remote"){ua(m),et(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(P=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,yr(),c("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function kr(e){_e=e.name,Ct=e.lastModified,typeof e.path=="string"&&e.path?(m=e.path,i&&i.postMessage({type:"watchPath",path:m})):m="",et(await e.text(),_e,m,!0)}function Hn(){J&&(De&&clearInterval(De),De=setInterval(async function(){if(!(Kt||!J)){Kt=!0;try{var e=await J.getFile();if(e.lastModified!==Ct){Ct=e.lastModified;var t=await e.text();t!==P&&et(t,_e,m)&&c(n("status.externalUpdateApplied"))}}catch{}Kt=!1}},800))}var K=!1,tt=0;function at(){tt&&(clearTimeout(tt),tt=0)}function zn(){at(),tt=setTimeout(function(){tt=0,K&&(K=!1,Ue=!1,S(),c(n("status.pickerTimeout"),!0))},2e4)}async function pa(){if(O){var e=await Tr(n("confirm.message",{file:_||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await ya();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&ua(m)}if(wr(),Ue&&i&&i.postMessage){if(K){at(),Ue=!1,K=!1,S(),await Cr();return}K=!0,zn(),S(),c(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await Cr()}async function Cr(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});J=e[0],await kr(await J.getFile()),Hn();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&&kr(a).catch(function(r){c(String(r),!0)})},t.click()}function Un(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function Vn(e){for(var t=0;t<e;t++){if(Un(),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 Er(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=++jr;he[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){he[o]&&(delete he[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function _n(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 xr(e,t){if(document.hasFocus()||await Vn(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 jn(a)?"rich":Gn(t)?"plain":"none"}function jn(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 Gn(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 Xn(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{var e=y.contentDocument&&y.contentDocument.body?y.contentDocument.body.innerText:W.replace(/<[^>]+>/g,""),t=await xr(Er(W),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await xr(Er(W),e)),t==="rich"?c(n("status.copiedRich")):c(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){c(n("status.richCopyFailed",{err:String(a)}),!0)}finally{C==="edit"&&requestAnimationFrame(function(){p.focus()})}}function Yn(){if(!Le||!y.contentDocument)return null;var e=y.contentDocument.querySelector("#bm-md");if(!e)return null;var t=e.getBoundingClientRect();return{root:e,width:Math.ceil(t.width||e.scrollWidth),height:Math.ceil(t.height||e.scrollHeight)}}function fa(){var e=Yn();if(!e||!e.width||!e.height)return Promise.resolve(null);var t=2,a=e.root.cloneNode(!0);a.style.minHeight=e.height+"px",a.style.margin="0",a.style.boxSizing="border-box";var r;try{r=new XMLSerializer().serializeToString(a)}catch(l){return Promise.reject(new Error(n("status.serializeFailed",{err:String(l)})))}var o='<svg xmlns="http://www.w3.org/2000/svg" width="'+e.width+'" height="'+e.height+'"><foreignObject x="0" y="0" width="'+e.width+'" height="'+e.height+'">'+r+"</foreignObject></svg>",s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var b=f.getContext("2d");b.scale(t,t);var g="";try{g=y.contentWindow.getComputedStyle(e.root).backgroundColor}catch{g=""}g&&g!=="rgba(0, 0, 0, 0)"&&g!=="transparent"&&(b.fillStyle=g,b.fillRect(0,0,e.width,e.height)),b.drawImage(d,0,0,e.width,e.height),l({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(q){u(q)}},d.onerror=function(){u(new Error(n("status.imageConversionFailed")))},d.src=s})}function ma(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 Mr(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 Kn(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){c(n("status.clipboardUnsupported"),!0);return}c(n("status.generatingImage"));var e=fa().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return ma(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),c(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),c(n("status.imageCopied"));return}catch(r){c(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function Zn(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingImage"));var e=await fa();if(!e){c(n("status.exportImageFailedGeneric"),!0);return}var t=await ma(e.canvas,"image/png"),a=await t.arrayBuffer(),r=Mr(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:m,fileName:_,markdown:h})}catch(o){c(n("status.exportImageFailed",{err:String(o)}),!0)}}function $n(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function ee(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function va(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 Jn(e,t,a,r,o){var s=ee(`%PDF-1.4
|
|
20
|
+
`).length}}function Vn(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 jn(e){var t="",a=[];function r(q,j){t+=q,a.push(j)}for(var o=0;o<e.length;){var s=o===0||e[o-1]===`
|
|
21
|
+
`;if(s){var l=/^[ \t]*(?:```|~~~)[^\n]*/.exec(e.slice(o));if(l){o+=l[0].length;continue}var u=/^[ \t]*(?:#{1,6}|>+|[-+*]|\d+[.)])[ \t]+/.exec(e.slice(o));if(u){o+=u[0].length;continue}}var d=/^!?\[([^\]]*)\]\((?:\\.|[^)])*\)/.exec(e.slice(o));if(d){for(var f=o+d[0].indexOf("[")+1,b=0;b<d[1].length;b++)/[*_~`]/.test(d[1][b])||r(d[1][b],f+b);o+=d[0].length;continue}var g=/^<[^>]+>/.exec(e.slice(o));if(g){o+=g[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 Vn(t,a)}function Gn(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=jn(e),o=t.replace(/\s+/g," ").trim(),s=r.text.indexOf(o);if(s>=0)return{start:r.map[s],end:r.map[s+o.length-1]+1};if(o.length>=12){var l=o.slice(0,6),u=o.slice(-6),d=r.text.indexOf(l),f=r.text.indexOf(u,Math.max(0,d+l.length));if(d>=0&&f>=d)return{start:r.map[d],end:r.map[f+u.length-1]+1}}return null}function Yn(e){return String(e||"").split(/[\\/]/).pop()||""}function Er(){var e=y.contentDocument;if(!e||e.__bound)return;e.__bound=!0;function t(){if(ae){var a=y.contentWindow,r=a.getSelection(),o=r.toString().trim();if(!(!o||!r.rangeCount)){var s=r.getRangeAt(0),l=Array.from(s.getClientRects()),u=y.getBoundingClientRect(),d=l.map(function(j){return{top:u.top+j.top,left:u.left+j.left,width:j.width,height:j.height}}),f=l[0]||s.getBoundingClientRect(),b=l[l.length-1]||f,g=Gn(h,o),q=g?kr(h,g.start,g.end):null;Mr(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+b.bottom,endLeft:u.left+b.left},d,q,"preview")}}}e.addEventListener("mouseup",t),e.addEventListener("mousedown",function(){Se(),F()}),e.addEventListener("keyup",t),e.addEventListener("keydown",function(a){(a.metaKey||a.ctrlKey)&&(a.key==="p"||a.key==="P")&&(a.preventDefault(),$e("edit"))}),e.addEventListener("scroll",function(){Se(),F()},!0),y.contentWindow.addEventListener("scroll",function(){Se(),F()})}y.onload=function(){Le=!0,Er(),va()};function Cr(){p&&p.scrollDOM&&!p.scrollDOM.__scrollSyncBound&&(p.scrollDOM.__scrollSyncBound=!0,p.scrollDOM.addEventListener("scroll",Wn,{passive:!0}));var e=y.contentDocument;if(e&&!e.__scrollSyncBound){e.__scrollSyncBound=!0;var t=e.scrollingElement||e.documentElement;t&&t.addEventListener("scroll",br,{passive:!0}),e.defaultView&&e.defaultView.addEventListener("scroll",br,{passive:!0})}}Cr(),window.addEventListener("resize",function(){Q=null}),y.addEventListener("load",function(){requestAnimationFrame(function(){Le=!0,va(),Cr(),wr()})});var Pt=0,ga=[];function Mr(e,t,a,r,o){Se(),Pt=setTimeout(function(){xr(e,t,a,r,o)},300)}function Se(){Pt&&(clearTimeout(Pt),Pt=0)}function xr(e,t,a,r,o,s){w.text=e,w.lines=r||null,w.origin=o||"",w.mode=s||"replace",Lt(),x.classList.remove("hidden"),x.classList.toggle("popup-bar",!!(t&&t.width)),G.value="",Kn(a),requestAnimationFrame(function(){Xn(t),t&&t.focus&&G.focus()})}function Xn(e){var t=8,a=10,r=e||{},o=v?t+48:t;if(x.style.width=r.width?r.width+"px":"",r.width){x.style.left=Math.max(t,r.startLeft||0)+"px",x.style.top=Math.max(o,Math.min(r.startTop||0,window.innerHeight-(x.offsetHeight||44)-t))+"px";return}var s=x.offsetWidth||300,l=x.offsetHeight||44,u=(r.startTop||0)-a-l,d=u>=o,f=d?u:(r.endBottom||0)+a,b=d?r.startLeft||0:r.endLeft!=null?r.endLeft:r.startLeft||0;x.style.left=Math.max(t,Math.min(b,window.innerWidth-s-t))+"px",x.style.top=Math.max(o,Math.min(f,window.innerHeight-l-t))+"px"}function Kn(e){Ir(),(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),ga.push(a)})}function Ir(){ga.forEach(function(e){e.remove()}),ga=[]}var Zn=navigator.platform||navigator.userAgent||"",Ot=/Mac|iPhone|iPod|iPad/.test(Zn);document.body.classList.toggle("non-mac-platform",!Ot);function $n(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Ot?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(Ha){var t=Ot?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Ot?"":"+";Ha.innerHTML=t.map(function(r){return"<kbd>"+r+"</kbd>"}).join(a?'<span class="popup-shortcut-sep">'+a+"</span>":"")}})();function F(e){var t=e===!0&&w.origin==="editor"&&E==="edit";Se(),x.classList.add("hidden"),x.classList.remove("popup-bar"),x.classList.remove("focused"),x.style.width="",w.text="",w.lines=null,w.origin="",w.mode="replace",Ir(),t&&requestAnimationFrame(function(){p.focus()})}qa.onclick=Ar;var Lr=0;G.addEventListener("compositionend",function(){Lr=Date.now()});function Jn(e){return e.isComposing||e.keyCode===229?!0:Date.now()-Lr<100}G.addEventListener("keydown",function(e){if(e.key==="Enter"){if(Jn(e))return;Ar()}e.key==="Escape"&&F(!0)}),G.addEventListener("focus",function(){x.classList.add("focused")}),G.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==qa&&x.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!x.classList.contains("hidden")&&F(!0)}),document.addEventListener("keydown",function(e){$n(e)&&(x.classList.contains("hidden")||(e.preventDefault(),G.focus(),G.select()))}),document.addEventListener("mousedown",function(e){x.contains(e.target)||(Se(),F())}),window.addEventListener("resize",F);function Qn(){if(!w.lines)return n("annotate.lineUnknown");var e=w.lines.start,t=w.lines.end;return e===t?n("annotate.lineSingle",{a:e}):n("annotate.lineRange",{a:e,b:t})}function eo(){return w.lines?w.lines.start+"-"+w.lines.end:n("annotate.lineCompactUnknown")}async function Ar(){var e=G.value.trim(),t=w.mode==="continue",a=w.mode==="annotate-line";if(!(!w.text&&!t&&!a||!i)){if(O&&m){var r=await Aa();if(!r){c(n("status.saveFailedNoReturn"),!0);return}}if(v){if(!m||!i.postMessage){c(n("status.noSourceFile"),!0);return}i.postMessage({type:"requestRewrite",path:m,selectedText:w.text,requirement:e,startLine:w.lines&&w.lines.start,endLine:w.lines&&w.lines.end,rewriteMode:t?"continue":"replace"}),F(!0),c(n(t?"appview.continuing":"appview.rewriting"));return}if(!i.composer||!w.text&&!a){F(!0);return}try{await i.composer.addContexts([{type:"annotation",label:(V||"Markdown")+":"+eo(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:Qn(),requirement:e?n("annotate.requirementWith",{comment:e}):n("annotate.requirementDefault"),text:w.text||n("annotate.emptyLine"),path:m||n("annotate.pathMissing")}),reminder:n("annotate.reminder")}]),F(!0),c(n("annotate.added"))}catch(o){c(String(o),!0)}}}function to(){var e=p.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=kr(p.getValue(),e.start,e.end);return Mr(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function Dr(){ae&&to()}function ao(e){if(!L()||!e)return!1;Se();var t=Ee.querySelector(".cm-line")||Ee.querySelector(".cm-content"),a=(t||Ee).getBoundingClientRect();return xr("",{startTop:e.rect.top,startLeft:a.left,width:Math.max(240,a.width),focus:!0},null,{start:e.line,end:e.line},"editor",v?"continue":"annotate-line"),!0}Ee.addEventListener("mouseup",Dr),Ee.addEventListener("keyup",function(e){e.shiftKey&&Dr()});var O=!1,Qe=0,ie=null,ha=!1,Oe=!1,ya="",ba=null;function ro(e){ya=e,ba=h,i.postMessage({type:"saveDraft",path:e,markdown:h,base:P})}function Tr(){!m||!i||!i.postMessage||ya===m&&ba===h||ro(m)}function wa(){ya="",ba=null}function Sa(e){wa(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function Re(e,t){O=e,Ge&&(clearTimeout(Ge),Ge=0),Oe=!O&&!!t,S(),!O&&t&&(Ge=setTimeout(function(){Ge=0,O||(Oe=!1,S())},3e3))}async function Fr(e){if(ie)return Or(),c("\u8BF7\u5148\u5904\u7406 AI \u5199\u56DE\u4E0E\u672C\u5730\u7F16\u8F91\u7684\u51B2\u7A81\u3002",!0),!1;if(J&&J.createWritable)try{var t=await J.createWritable();return await t.write(e),await t.close(),xt=(await J.getFile()).lastModified,P=e,Re(h!==e,h===e),c(n(h===e?"status.saved":"status.savedWithNewChanges")),wa(),!0}catch(r){return c(n("status.saveFailed",{err:String(r)}),!0),!1}if(m){var a=++tr;return c(n("status.saving")),oa[a]=e,i.postMessage({type:"saveMarkdown",path:m,markdown:e,requestId:a}),new Promise(function(r){Ae[a]=r})}return c(n("status.noSourceFile"),!0),!1}document.addEventListener("keydown",function(e){var t=e.metaKey||e.ctrlKey;if(t&&(e.key==="s"||e.key==="S")){e.preventDefault(),Ia();return}t&&(e.key==="p"||e.key==="P")&&(e.preventDefault(),$e(E==="edit"?"preview":"edit"))});function Pr(){De&&(clearInterval(De),De=0),J=null}var ka=null;function et(e,t,a,r,o,s){if(!r&&O&&P!==null&&e!==P)return ie={markdown:e,name:t,path:a,diskBaseline:o},c(n("status.externalUpdateSkipped"),!0),Or(),!1;var l=P!==null&&(!a||!m||a===m);return l||(ae=!0),h=e,Ve=t,a&&(m=a),V=Yn(a||m)||t||"Markdown",P=typeof o=="string"?o:h,ka=l?p.applyExternalValue(h):null,ka||p.setValue(h),Re(!1),lr(V),s||we(),Ze(),Te(),(v||E==="preview")&&X(),!0}async function Or(){if(!(ha||!ie||!O)){var e=ie,t=P;if(h===t){ie=null,et(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){ie=null;return}ha=!0;var a=await Mo();if(ha=!1,ie===e){if(a==="later"){c("AI \u5199\u56DE\u5DF2\u4FDD\u7559\u5728\u78C1\u76D8\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u540E\u518D\u5904\u7406\u3002");return}if(ie=null,a==="remote"){Sa(m),et(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(P=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,Tr(),c("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function Rr(e){Ve=e.name,xt=e.lastModified,typeof e.path=="string"&&e.path?(m=e.path,i&&i.postMessage({type:"watchPath",path:m})):m="",et(await e.text(),Ve,m,!0)}function no(){J&&(De&&clearInterval(De),De=setInterval(async function(){if(!(ia||!J)){ia=!0;try{var e=await J.getFile();if(e.lastModified!==xt){xt=e.lastModified;var t=await e.text();t!==P&&et(t,Ve,m)&&c(n("status.externalUpdateApplied"))}}catch{}ia=!1}},800))}var K=!1,tt=0;function at(){tt&&(clearTimeout(tt),tt=0)}function oo(){at(),tt=setTimeout(function(){tt=0,K&&(K=!1,Ue=!1,S(),c(n("status.pickerTimeout"),!0))},2e4)}async function Ea(){if(O){var e=await jr(n("confirm.message",{file:V||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await Aa();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&Sa(m)}if(Pr(),Ue&&i&&i.postMessage){if(K){at(),Ue=!1,K=!1,S(),await Br();return}K=!0,oo(),S(),c(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await Br()}async function Br(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});J=e[0],await Rr(await J.getFile()),no();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&&Rr(a).catch(function(r){c(String(r),!0)})},t.click()}function io(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function so(e){for(var t=0;t<e;t++){if(io(),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 Nr(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=++un;he[o]={resolve:a,reject:r,sourceHtml:e},setTimeout(function(){he[o]&&(delete he[o],r(new Error(n("status.clipboardPrepareTimeout"))))},15e3),i.postMessage({type:"readClipboardImages",urls:t,requestId:o})})}function lo(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 Wr(e,t){if(document.hasFocus()||await so(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 co(a)?"rich":uo(t)?"plain":"none"}function co(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 uo(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 po(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{var e=y.contentDocument&&y.contentDocument.body?y.contentDocument.body.innerText:W.replace(/<[^>]+>/g,""),t=await Wr(Nr(W),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await Wr(Nr(W),e)),t==="rich"?c(n("status.copiedRich")):c(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){c(n("status.richCopyFailed",{err:String(a)}),!0)}finally{E==="edit"&&requestAnimationFrame(function(){p.focus()})}}function fo(){if(!Le||!y.contentDocument)return null;var e=y.contentDocument.querySelector("#bm-md");if(!e)return null;var t=e.getBoundingClientRect();return{root:e,width:Math.ceil(t.width||e.scrollWidth),height:Math.ceil(t.height||e.scrollHeight)}}function Ca(){var e=fo();if(!e||!e.width||!e.height)return Promise.resolve(null);var t=2,a=e.root.cloneNode(!0);a.style.minHeight=e.height+"px",a.style.margin="0",a.style.boxSizing="border-box";var r;try{r=new XMLSerializer().serializeToString(a)}catch(l){return Promise.reject(new Error(n("status.serializeFailed",{err:String(l)})))}var o='<svg xmlns="http://www.w3.org/2000/svg" width="'+e.width+'" height="'+e.height+'"><foreignObject x="0" y="0" width="'+e.width+'" height="'+e.height+'">'+r+"</foreignObject></svg>",s="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(o);return new Promise(function(l,u){var d=new Image;d.decoding="sync",d.onload=function(){try{var f=document.createElement("canvas");f.width=Math.round(e.width*t),f.height=Math.round(e.height*t);var b=f.getContext("2d");b.scale(t,t);var g="";try{g=y.contentWindow.getComputedStyle(e.root).backgroundColor}catch{g=""}g&&g!=="rgba(0, 0, 0, 0)"&&g!=="transparent"&&(b.fillStyle=g,b.fillRect(0,0,e.width,e.height)),b.drawImage(d,0,0,e.width,e.height),l({canvas:f,cssWidth:e.width,cssHeight:e.height})}catch(q){u(q)}},d.onerror=function(){u(new Error(n("status.imageConversionFailed")))},d.src=s})}function Ma(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 qr(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 mo(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){c(n("status.clipboardUnsupported"),!0);return}c(n("status.generatingImage"));var e=Ca().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return Ma(a.canvas,"image/png")});try{await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),c(n("status.imageCopied"));return}catch{try{var t=await e;await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),c(n("status.imageCopied"));return}catch(r){c(n("status.copyImageFailed",{err:r&&r.message?r.message:String(r)}),!0)}}}async function vo(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingImage"));var e=await Ca();if(!e){c(n("status.exportImageFailedGeneric"),!0);return}var t=await Ma(e.canvas,"image/png"),a=await t.arrayBuffer(),r=qr(new Uint8Array(a));i&&i.postMessage&&i.postMessage({type:"exportFile",data:r,ext:"png",path:m,fileName:V,markdown:h})}catch(o){c(n("status.exportImageFailed",{err:String(o)}),!0)}}function go(e){for(var t=String(e);t.length<10;)t="0"+t;return t}function ee(e){for(var t=new Uint8Array(e.length),a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;return t}function xa(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 ho(e,t,a,r,o){var s=ee(`%PDF-1.4
|
|
22
22
|
%\xE2\xE3\xCF\xD3
|
|
23
|
-
`),l=[s],u=[0],d=s.length;function f(
|
|
23
|
+
`),l=[s],u=[0],d=s.length;function f(Wt){u.push(d),l.push(Wt),d+=Wt.length}f(ee(`1 0 obj
|
|
24
24
|
<< /Type /Catalog /Pages 2 0 R >>
|
|
25
25
|
endobj
|
|
26
26
|
`)),f(ee(`2 0 obj
|
|
@@ -35,7 +35,7 @@ stream
|
|
|
35
35
|
`),g=ee(`
|
|
36
36
|
endstream
|
|
37
37
|
endobj
|
|
38
|
-
`);f(
|
|
38
|
+
`);f(xa([b,e,g]));var q="q "+r.toFixed(2)+" 0 0 "+o.toFixed(2)+" 0 0 cm /Im0 Do Q",j=ee(q);f(xa([ee(`5 0 obj
|
|
39
39
|
<< /Length `+j.length+` >>
|
|
40
40
|
stream
|
|
41
41
|
`),j,ee(`
|
|
@@ -44,9 +44,9 @@ endobj
|
|
|
44
44
|
`)]));for(var te=d,se=[`xref
|
|
45
45
|
0 6
|
|
46
46
|
0000000000 65535 f
|
|
47
|
-
`],re=1;re<=5;re++)se.push(
|
|
48
|
-
`);var
|
|
47
|
+
`],re=1;re<=5;re++)se.push(go(u[re])+` 00000 n
|
|
48
|
+
`);var Nt=`trailer
|
|
49
49
|
<< /Size 6 /Root 1 0 R >>
|
|
50
50
|
startxref
|
|
51
51
|
`+te+`
|
|
52
|
-
%%EOF`;return l.push(ee(se.join("")+Ot)),va(l)}async function Qn(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingPdf"));var e=await fa();if(!e){c(n("status.exportPdfFailedGeneric"),!0);return}var t=await ma(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,l=Jn(r,e.canvas.width,e.canvas.height,o,s),u=Mr(l);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:m,fileName:_,markdown:h})}catch(d){c(n("status.exportPdfFailed",{err:String(d)}),!0)}}function rt(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){c(String(r),!0)}).then(function(){e.disabled=!1}))})}rt(Wr,Xn),rt(qr,Kn),rt(Hr,Zn),rt(zr,Qn),rt(Ee,eo);var Ir="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(Ir)==="1"}catch{}Be&&Be.classList.toggle("collapsed",t)})(),La&&La.addEventListener("click",function(e){e.preventDefault();var t=Be.classList.toggle("collapsed");try{localStorage.setItem(Ir,t?"1":"0")}catch{}});function ga(){br(h)}function Tt(e){if(Vr=e,!!Ee){Ee.classList.toggle("loading",e),Ee.disabled=e;var t=Ee.querySelector(".ic-ai-style"),a=Ee.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function Lr(){if(!h||!m||!i||!i.postMessage){c(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:m,baseStyle:I}),Tt(!0),c(n("aiStyle.appViewDesigning"))}async function eo(){if(!h){c(n("status.pleaseOpenArticle"),!0);return}if(v||!i||!i.composer){Lr();return}var e=I==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:I});try{await i.composer.addContexts([{type:"annotation",label:n("aiStyle.label",{file:_||n("common.markdownDocDefault")}),note:n("aiStyle.note"),promptText:n("aiStyle.promptText",{baseNote:e,path:m||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),c(n("aiStyle.requested"))}catch{Lr()}}function to(){return{fontSize:U,fontFamily:$,comfortWriting:N,style:I,customCss:I==="custom"?B:"",customStyleLabel:I==="custom"?Me:""}}function ke(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:to()})}function ao(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(U=e.fontSize),Ie[e.fontFamily]&&($=e.fontFamily),N=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(I="custom",B=e.customCss,Me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(I=e.style,B="",Me=""),p.setFontSize(U),p.setFontFamily(Ie[$]),p.setComfortWriting(N),!0)}function ro(e){I=e,ke(),(v||C==="preview")&&Y(),S()}function no(e){if(!(e!==14&&e!==16&&e!==18)){U=e,p.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}ke(),S()}}function oo(e){if(Ie[e]){$=e,p.setFontFamily(Ie[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}ke(),S()}}function Ar(e){N=!!e,p.setComfortWriting(N);try{localStorage.setItem("md-editor-comfort-writing",N?"1":"0")}catch{}ke(),S(),c(n(N?"status.comfortWrite":"status.comfortRead"))}function Dr(e){if(!(e!=="character"&&e!=="word"||V===e)){V=e;try{localStorage.setItem("md-editor-word-count-mode",V)}catch{}S()}}function ha(e){var t=!!e;t!==R&&(R=t,document.body.classList.toggle("preview-hidden",!R),S(),R&&requestAnimationFrame(function(){p.layout(),Y()}))}function Fr(){if(A=!A,A&&ae?(ae=!1,T()):!A&&!ae&&(ae=!0),p.setFocusMode(A),document.body.classList.toggle("focus-mode",A),v){if(A)ze===null&&(ze=R),ha(!1);else if(ze!==null){var e=ze;ze=null,ha(e)}}try{localStorage.setItem("md-editor-focus-mode",A?"1":"0")}catch{}S(),c(n(A?"status.focusOn":"status.focusOff"))}var nt=null;function ot(e){de.hidden=!0;var t=nt;nt=null,t&&t(e)}function Tr(e){return new Promise(function(t){nt=t,Aa.textContent=e,de.hidden=!1,Ne.focus()})}async function io(){Aa.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",Ut.textContent="\u7A0D\u540E\u5904\u7406",Vt.textContent="\u4FDD\u7559\u672C\u5730",Ne.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){nt=t,de.hidden=!1,Ne.focus()});return Nt(de),e==="save"?"remote":e==="discard"?"local":"later"}Ut&&Ut.addEventListener("click",function(){ot("cancel")}),Vt&&Vt.addEventListener("click",function(){ot("discard")}),Ne&&Ne.addEventListener("click",function(){ot("save")}),de&&de.addEventListener("click",function(e){e.target===de&&ot("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&nt&&ot("cancel")});async function ya(){return await br(h)}function so(){wr(),ca(),T(),h="",_e="",_="",m="",P=null,ve=null,W="",ae=!1,C="edit",p&&p.setValue(""),Ka(n("home.title")),we(),lr(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),Ze(),Fe(),Re(!1),c("")}async function it(){if(O){var e=await Tr(n("confirm.message",{file:_||n("common.markdownDocDefault")}));if(e==="cancel")return;if(i&&i.postMessage&&i.postMessage({type:"goHome"}),e==="save"){var t=await ya();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&ua(m)}so()}function Pr(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){it();return}if(e==="open"){pa();return}if(e==="mode"){$e(C==="edit"?"preview":"edit");return}if(e==="save"){ga();return}if(e==="reload"){Y();return}if(e==="reveal"){m&&i&&i.postMessage&&i.postMessage({type:"openPath",path:m});return}if(e==="recentSession"){ve&&i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(ve);return}if(e&&e.indexOf("font-size:")===0){no(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){oo(e.slice(12));return}if(e==="comfort:read"){Ar(!1);return}if(e==="comfort:write"){Ar(!0);return}if(e==="word-count:character"){Dr("character");return}if(e==="word-count:word"){Dr("word");return}if(e==="focus"){Fr();return}if(e==="about"){Gr();return}if(e&&e.indexOf("style:slot-use:")===0){co(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Rr(+e.slice(16));return}if(e&&e.indexOf("style:")===0){ro(e.slice(6));return}}function ba(){[ft,gt,ht,yt].forEach(function(e){e&&(e.hidden=!0)})}function lo(e){if(e){var t=e.hidden;ba(),e.hidden=!t}}function Pt(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),lo(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null;if(!(r&&r.disabled)){var o=r&&r.getAttribute("data-app-action");o&&(Pr(o),ba())}})}Fa&&Fa.addEventListener("click",it),dt&&dt.addEventListener("click",pa),ne&&ne.addEventListener("click",ga),pe&&pe.addEventListener("click",Fr),We&&We.addEventListener("click",function(){ha(!R)}),Pt(pt,ft),Pt(mt,gt),Pt(_t,ht),Pt(Ur,yt),document.addEventListener("click",ba);var wa=370,Sa=560,Or=480;ue&&ue.addEventListener("mousedown",function(e){e.preventDefault();var t=ue.parentElement;if(!t)return;var a=e.clientX,r=zt?zt.getBoundingClientRect().width:Or;ue.classList.add("active");var o=document.createElement("div");o.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(o);function s(d){return Math.max(wa,Math.min(Sa,d))}function l(d){var f=d.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){ue.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",l),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(v){var e=ue&&ue.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||Or;(t>Sa||t<wa)&&e.style.setProperty("--preview-width",Math.max(wa,Math.min(Sa,t))+"px")}}});function co(e){var t=z[e];t&&(B=t.css,Me=t.label,I="custom",ke(),c(n("status.appliedStyleSlot",{label:t.label})),C==="preview"?Y():$e("preview"),S())}function Rr(e){if(I!=="custom"||!B){c(n("status.needCustomStyleFirst"),!0);return}var t=Me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:B,label:t,path:m})}function uo(){E&&(clearTimeout(E),E=0),x.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),x.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=z[t];r&&(a.title=r.label),a.addEventListener("click",function(){Rr(t)}),x.appendChild(a)})(e);E=setTimeout(function(){E=0,x.replaceChildren(),x.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(Ue=!!e.pickFileSupported,z=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],ao(e.writingPreferences)?v&&L()&&Y():ke(),e.libraryGroups&&typeof e.libraryGroups=="object"?(fe=Array.isArray(e.libraryGroups.order)?e.libraryGroups.order.filter(function(le){return typeof le=="string"}):[],xe=e.libraryGroups.collapsed&&typeof e.libraryGroups.collapsed=="object"?e.libraryGroups.collapsed:{},He.length&&Qt(He)):(fe.length||Object.keys(xe).length)&&Jt(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==lt&&(lt=t,Nt(),xt())}e.assistantName&&(Ye=e.assistantName,xt()),_a(),e.homeDir&&(be=e.homeDir,Kr()),S();return}if(e.type==="styleSlots"){z=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&z[e.savedSlot]&&c(n("status.savedToSlot",{slot:e.savedSlot+1,label:z[e.savedSlot].label})),S();return}if(e.type==="clipboardImages"){var a=he[e.requestId];if(a){delete he[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(le){typeof o[le]=="string"&&(r=r.split(le).join(o[le]))}),a.resolve(_n(r))}return}if(e.type==="clipboardImagesError"){var s=he[e.requestId];s&&(delete he[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var l=ge[e.requestId];l&&(delete ge[e.requestId],l.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ge[e.requestId];u&&(delete ge[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),c(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){v=e.view==="appView",v&&(i&&i.panel&&i.panel.setTitle&&i.panel.setTitle(n("home.title")).catch(function(){}),we(),nn()),v&&!qa&&(qa=!0,R=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",v),Da&&(Da.hidden=!v),p.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var d=e.cwd||"",f=e.sessionId||"",b=e.spaceId||"";(d!==Xe||f!==Zt||b!==$t||!Et)&&(Xe=d,Zt=f,$t=b,Et=!0,It([])),Fe(),we(),S(),v&&L()&&Y(),(!Wt.hidden||v)&&Mt();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==Xe)return;It(e.documents),e.library&&Qt(e.documents);return}if(e.type==="status"){c(e.message);return}if(e.type==="rewriteSessionStarted"){H=e.sessionId&&e.turnId?{sessionId:e.sessionId,turnId:e.turnId}:null,p.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),ye(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"),!1,e.sessionId,0);return}if(e.type==="rewriteCancellationRequested"){H&&H.turnId===e.turnId&&(H.cancelling=!0),ye(n("appview.cancelling"),!1,e.sessionId,0);return}if(e.type==="rewriteSessionFinished"){H=null,p.setAiWorkingLines(0,0),ye(n("appview.rewriteDone"),!1,e.sessionId,5e3);return}if(e.type==="rewriteSessionFailed"){var g=H&&H.turnId===e.turnId&&H.cancelling;H=null,p.setAiWorkingLines(0,0),ye(g?n("appview.cancelled"):e.message||"Rewrite failed.",!g,e.sessionId,5e3);return}if(e.type==="styleSessionStarted"){Tt(!0),ye(n("aiStyle.appViewDesigning"),!1,e.sessionId,0);return}if(e.type==="styleSessionFinished"){Tt(!1),ye(e.message||n("aiStyle.appViewDone"),!1,e.sessionId,5e3);return}if(e.type==="styleSessionFailed"){Tt(!1),ye(e.message||n("aiStyle.appViewFailed"),!0,e.sessionId,5e3);return}if(e.type!=="lastFileUnavailable"){if(e.type==="lastSessionInfo"){ve=e.sessionId||null,S(),Ja();return}if(e.type==="finch:menu"){Pr(e.itemId);return}if(e.type==="document"){var q=K;K=!1,at();var j=e.markdown||"",te=e.path||"",se=Number(e.revision)||0;if(te&&te===m&&se&&se<=Qe)return;var re=!!te&&!!m&&te!==m;if((re||P===null)&&(ve=null),re&&At&&te!==At){Te===te&&(Te="");return}if(!re&&j===P){se&&(Qe=Math.max(Qe,se)),S();return}var Ot=P===null,Rt=Ke;Ke=!1;var po=!!te&&Te===te;Te="";var fo=et(j,e.title||n("common.markdownDocDefault"),e.path||m,q||Ot||re,e.diskMarkdown,po);if(!fo){S();return}if(Qe=se||(re?0:Qe),e.draftRestored)Re(!0),c(n("status.draftRestored"));else if(e.draftConflict)c(n("status.draftConflict"),!0);else if(Rt)c(n("status.opened",{file:_}));else if(!Ot){var Z=da;Z&&Z.hunks>1?c(n("status.contentUpdatedSpots",{count:Z.hunks,lines:Z.changedLines})):Z&&Z.fromLine===Z.toLine?c(n("status.contentUpdatedLine",{line:Z.fromLine})):c(Z?n("status.contentUpdatedLines",{from:Z.fromLine,to:Z.toLine}):n("status.contentUpdated"))}return}if(e.type==="sourceMissing"){e.path&&e.path===m&&c(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==za)return;lr(e.html||""),Ze(),je=!1,S(),c("");return}if(e.type==="savedMarkdown"){var st=Yt[e.requestId];delete Yt[e.requestId];var Bt=Ae[e.requestId];if(delete Ae[e.requestId],e.requestId!==Ua||typeof st!="string"){Bt&&Bt(!1);return}P=st,Re(h!==st,h===st),c(n(h===st?"status.saved":"status.savedWithNewChanges")),Bt&&Bt(!0);return}if(e.type==="customStyleSet"){B=e.css||"",Me=e.label||n("common.customStyleDefault"),I="custom",ke(),typeof e.savedSlot=="number"?(z=Array.isArray(e.styleSlots)?e.styleSlots:z,c(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):uo(),C==="preview"?Y():$e("preview"),S();return}if(e.type==="exported"){c(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){K=!1,at(),S(),c("");return}if(e.type==="error"){Ke=!1,At="",Te="",Object.keys(Ae).forEach(function(le){var Br=Ae[le];delete Ae[le],Br&&Br(!1)}),K=!1,at(),e.fallback&&(Ue=!1),je=!1,S(),c(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!L()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),Va||Mt()},400),Nt(),_a(),xt(),Ze(),Fe()})();})();
|
|
52
|
+
%%EOF`;return l.push(ee(se.join("")+Nt)),xa(l)}async function yo(){if(!W){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingPdf"));var e=await Ca();if(!e){c(n("status.exportPdfFailedGeneric"),!0);return}var t=await Ma(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,l=ho(r,e.canvas.width,e.canvas.height,o,s),u=qr(l);i&&i.postMessage&&i.postMessage({type:"exportFile",data:u,ext:"pdf",path:m,fileName:V,markdown:h})}catch(d){c(n("status.exportPdfFailed",{err:String(d)}),!0)}}function rt(e,t){e&&e.addEventListener("click",function(a){a.preventDefault(),!e.disabled&&(e.disabled=!0,Promise.resolve().then(t).catch(function(r){c(String(r),!0)}).then(function(){e.disabled=!1}))})}rt(an,po),rt(rn,mo),rt(nn,vo),rt(on,yo),rt(Ce,bo);var Hr="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(Hr)==="1"}catch{}Be&&Be.classList.toggle("collapsed",t)})(),za&&za.addEventListener("click",function(e){e.preventDefault();var t=Be.classList.toggle("collapsed");try{localStorage.setItem(Hr,t?"1":"0")}catch{}});function Ia(){Fr(h)}function Rt(e){if(ln=e,!!Ce){Ce.classList.toggle("loading",e),Ce.disabled=e;var t=Ce.querySelector(".ic-ai-style"),a=Ce.querySelector(".ic-ai-style-loading");t&&(t.hidden=e),a&&(a.hidden=!e)}}function zr(){if(!h||!m||!i||!i.postMessage){c(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:m,baseStyle:I}),Rt(!0),c(n("aiStyle.appViewDesigning"))}async function bo(){if(!h){c(n("status.pleaseOpenArticle"),!0);return}if(v||!i||!i.composer){zr();return}var e=I==="custom"?n("aiStyle.baseNoteCustom"):n("aiStyle.baseNoteOther",{style:I});try{await i.composer.addContexts([{type:"annotation",label:n("aiStyle.label",{file:V||n("common.markdownDocDefault")}),note:n("aiStyle.note"),promptText:n("aiStyle.promptText",{baseNote:e,path:m||n("aiStyle.pathMissing")}),reminder:n("aiStyle.reminder")}]),c(n("aiStyle.requested"))}catch{zr()}}function wo(){return{fontSize:U,fontFamily:$,comfortWriting:N,style:I,customCss:I==="custom"?B:"",customStyleLabel:I==="custom"?xe:""}}function ke(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:wo()})}function So(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(U=e.fontSize),Ie[e.fontFamily]&&($=e.fontFamily),N=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(I="custom",B=e.customCss,xe=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(I=e.style,B="",xe=""),p.setFontSize(U),p.setFontFamily(Ie[$]),p.setComfortWriting(N),!0)}function ko(e){I=e,ke(),(v||E==="preview")&&X(),S()}function Eo(e){if(!(e!==14&&e!==16&&e!==18)){U=e,p.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}ke(),S()}}function Co(e){if(Ie[e]){$=e,p.setFontFamily(Ie[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}ke(),S()}}function Ur(e){N=!!e,p.setComfortWriting(N);try{localStorage.setItem("md-editor-comfort-writing",N?"1":"0")}catch{}ke(),S(),c(n(N?"status.comfortWrite":"status.comfortRead"))}function _r(e){if(!(e!=="character"&&e!=="word"||_===e)){_=e;try{localStorage.setItem("md-editor-word-count-mode",_)}catch{}S()}}function La(e){var t=!!e;t!==R&&(R=t,document.body.classList.toggle("preview-hidden",!R),S(),R&&requestAnimationFrame(function(){p.layout(),X()}))}function Vr(){if(A=!A,A&&ae?(ae=!1,F()):!A&&!ae&&(ae=!0),p.setFocusMode(A),document.body.classList.toggle("focus-mode",A),v){if(A)ze===null&&(ze=R),La(!1);else if(ze!==null){var e=ze;ze=null,La(e)}}try{localStorage.setItem("md-editor-focus-mode",A?"1":"0")}catch{}S(),c(n(A?"status.focusOn":"status.focusOff"))}var nt=null;function ot(e){de.hidden=!0;var t=nt;nt=null,t&&t(e)}function jr(e){return new Promise(function(t){nt=t,Ua.textContent=e,de.hidden=!1,Ne.focus()})}async function Mo(){Ua.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",Qt.textContent="\u7A0D\u540E\u5904\u7406",ea.textContent="\u4FDD\u7559\u672C\u5730",Ne.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){nt=t,de.hidden=!1,Ne.focus()});return Xt(de),e==="save"?"remote":e==="discard"?"local":"later"}Qt&&Qt.addEventListener("click",function(){ot("cancel")}),ea&&ea.addEventListener("click",function(){ot("discard")}),Ne&&Ne.addEventListener("click",function(){ot("save")}),de&&de.addEventListener("click",function(e){e.target===de&&ot("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&nt&&ot("cancel")});async function Aa(){return await Fr(h)}function xo(){Pr(),wa(),F(),h="",Ve="",V="",m="",P=null,ve=null,W="",ae=!1,E="edit",p&&p.setValue(""),lr(n("home.title")),we(),Sr(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),Ze(),Te(),Re(!1),c("")}async function it(){if(O){var e=await jr(n("confirm.message",{file:V||n("common.markdownDocDefault")}));if(e==="cancel")return;if(i&&i.postMessage&&i.postMessage({type:"goHome"}),e==="save"){var t=await Aa();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&Sa(m)}xo()}function Gr(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){it();return}if(e==="open"){Ea();return}if(e==="mode"){$e(E==="edit"?"preview":"edit");return}if(e==="save"){Ia();return}if(e==="reload"){X();return}if(e==="reveal"){m&&i&&i.postMessage&&i.postMessage({type:"openPath",path:m});return}if(e==="recentSession"){ve&&i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(ve);return}if(e&&e.indexOf("font-size:")===0){Eo(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){Co(e.slice(12));return}if(e==="comfort:read"){Ur(!1);return}if(e==="comfort:write"){Ur(!0);return}if(e==="word-count:character"){_r("character");return}if(e==="word-count:word"){_r("word");return}if(e==="focus"){Vr();return}if(e==="about"){dn();return}if(e&&e.indexOf("style:slot-use:")===0){Lo(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Xr(+e.slice(16));return}if(e&&e.indexOf("style:")===0){ko(e.slice(6));return}}function Da(){[gt,bt,wt,St].forEach(function(e){e&&(e.hidden=!0)})}function Io(e){if(e){var t=e.hidden;Da(),e.hidden=!t}}function Bt(e,t){e&&e.addEventListener("click",function(a){a.stopPropagation(),Io(t)}),t&&t.addEventListener("click",function(a){var r=a.target&&a.target.closest?a.target.closest("[data-app-action]"):null;if(!(r&&r.disabled)){var o=r&&r.getAttribute("data-app-action");o&&(Gr(o),Da())}})}Va&&Va.addEventListener("click",it),mt&&mt.addEventListener("click",Ea),ne&&ne.addEventListener("click",Ia),pe&&pe.addEventListener("click",Vr),We&&We.addEventListener("click",function(){La(!R)}),Bt(vt,gt),Bt(ht,bt),Bt(ta,wt),Bt(sn,St),document.addEventListener("click",Da);var Ta=370,Fa=560,Yr=480;ue&&ue.addEventListener("mousedown",function(e){e.preventDefault();var t=ue.parentElement;if(!t)return;var a=e.clientX,r=Jt?Jt.getBoundingClientRect().width:Yr;ue.classList.add("active");var o=document.createElement("div");o.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(o);function s(d){return Math.max(Ta,Math.min(Fa,d))}function l(d){var f=d.clientX-a;t.style.setProperty("--preview-width",s(r-f)+"px")}function u(){ue.classList.remove("active"),o.remove(),window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",u)}window.addEventListener("mousemove",l),window.addEventListener("mouseup",u)}),window.addEventListener("resize",function(){if(v){var e=ue&&ue.parentElement;if(e){var t=parseFloat(getComputedStyle(e).getPropertyValue("--preview-width"))||Yr;(t>Fa||t<Ta)&&e.style.setProperty("--preview-width",Math.max(Ta,Math.min(Fa,t))+"px")}}});function Lo(e){var t=z[e];t&&(B=t.css,xe=t.label,I="custom",ke(),c(n("status.appliedStyleSlot",{label:t.label})),E==="preview"?X():$e("preview"),S())}function Xr(e){if(I!=="custom"||!B){c(n("status.needCustomStyleFirst"),!0);return}var t=xe||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:B,label:t,path:m})}function Ao(){C&&(clearTimeout(C),C=0),M.replaceChildren(document.createTextNode(n("aiStyle.applied")+" ")),M.className="status status-style-prompt";for(var e=0;e<3;e++)(function(t){var a=document.createElement("button");a.type="button",a.className="status-inline-btn",a.textContent=n("aiStyle.saveToSlot",{n:t+1});var r=z[t];r&&(a.title=r.label),a.addEventListener("click",function(){Xr(t)}),M.appendChild(a)})(e);C=setTimeout(function(){C=0,M.replaceChildren(),M.className="status"},12e3)}i&&i.onMessage&&i.onMessage(function(e){if(!(!e||typeof e!="object")){if(e.type==="ready"){if(Ue=!!e.pickFileSupported,z=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],So(e.writingPreferences)?v&&L()&&X():ke(),e.libraryGroups&&typeof e.libraryGroups=="object"?(fe=Array.isArray(e.libraryGroups.order)?e.libraryGroups.order.filter(function(le){return typeof le=="string"}):[],Me=e.libraryGroups.collapsed&&typeof e.libraryGroups.collapsed=="object"?e.libraryGroups.collapsed:{},He.length&&ua(He)):(fe.length||Object.keys(Me).length)&&ca(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==dt&&(dt=t,Xt(),Lt())}e.assistantName&&(Xe=e.assistantName,Lt()),rr(),e.homeDir&&(be=e.homeDir,mn()),S();return}if(e.type==="styleSlots"){z=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&z[e.savedSlot]&&c(n("status.savedToSlot",{slot:e.savedSlot+1,label:z[e.savedSlot].label})),S();return}if(e.type==="clipboardImages"){var a=he[e.requestId];if(a){delete he[e.requestId];var r=a.sourceHtml,o=e.images&&typeof e.images=="object"?e.images:{};Object.keys(o).forEach(function(le){typeof o[le]=="string"&&(r=r.split(le).join(o[le]))}),a.resolve(lo(r))}return}if(e.type==="clipboardImagesError"){var s=he[e.requestId];s&&(delete he[e.requestId],s.reject(new Error(e.message||n("status.clipboardPrepareFailedDefault"))));return}if(e.type==="pastedImage"){var l=ge[e.requestId];l&&(delete ge[e.requestId],l.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ge[e.requestId];u&&(delete ge[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),c(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){v=e.view==="appView",v&&(i&&i.panel&&i.panel.setTitle&&i.panel.setTitle(n("home.title")).catch(function(){}),we(),En()),v&&!Ja&&(Ja=!0,R=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",v),_a&&(_a.hidden=!v),p.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var d=e.cwd||"",f=e.sessionId||"",b=e.spaceId||"";(d!==Ye||f!==sa||b!==la||!It)&&(Ye=d,sa=f,la=b,It=!0,Dt([])),Te(),we(),S(),v&&L()&&X(),(!Kt.hidden||v)&&At();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==Ye)return;Dt(e.documents),e.library&&ua(e.documents);return}if(e.type==="status"){c(e.message);return}if(e.type==="rewriteSessionStarted"){H=e.sessionId&&e.turnId?{sessionId:e.sessionId,turnId:e.turnId}:null,p.setAiWorkingLines(Number(e.startLine)||0,Number(e.endLine)||0),ye(e.rewriteMode==="continue"?n("appview.continuing"):n("appview.rewriting"),!1,e.sessionId,0);return}if(e.type==="rewriteCancellationRequested"){H&&H.turnId===e.turnId&&(H.cancelling=!0),ye(n("appview.cancelling"),!1,e.sessionId,0);return}if(e.type==="rewriteSessionFinished"){H=null,p.setAiWorkingLines(0,0),ye(n("appview.rewriteDone"),!1,e.sessionId,5e3);return}if(e.type==="rewriteSessionFailed"){var g=H&&H.turnId===e.turnId&&H.cancelling;H=null,p.setAiWorkingLines(0,0),ye(g?n("appview.cancelled"):e.message||"Rewrite failed.",!g,e.sessionId,5e3);return}if(e.type==="styleSessionStarted"){Rt(!0),ye(n("aiStyle.appViewDesigning"),!1,e.sessionId,0);return}if(e.type==="styleSessionFinished"){Rt(!1),ye(e.message||n("aiStyle.appViewDone"),!1,e.sessionId,5e3);return}if(e.type==="styleSessionFailed"){Rt(!1),ye(e.message||n("aiStyle.appViewFailed"),!0,e.sessionId,5e3);return}if(e.type==="lastFileUnavailable"){Gt();return}if(e.type==="lastSessionInfo"){ve=e.sessionId||null,S(),dr();return}if(e.type==="finch:menu"){Gr(e.itemId);return}if(e.type==="document"){var q=K;K=!1,at();var j=e.markdown||"",te=e.path||"",se=Number(e.revision)||0;if(te&&te===m&&se&&se<=Qe)return;var re=!!te&&!!m&&te!==m;if((re||P===null)&&(ve=null),re&&Ft&&te!==Ft){Fe===te&&(Fe="");return}if(!re&&j===P){se&&(Qe=Math.max(Qe,se)),S();return}var Nt=P===null,Wt=Ke;Ke=!1;var Do=!!te&&Fe===te;Fe="";var To=et(j,e.title||n("common.markdownDocDefault"),e.path||m,q||Nt||re,e.diskMarkdown,Do);if(!To){S();return}if(Qe=se||(re?0:Qe),e.draftRestored)Re(!0),c(n("status.draftRestored"));else if(e.draftConflict)c(n("status.draftConflict"),!0);else if(Wt)c(n("status.opened",{file:V}));else if(!Nt){var Z=ka;Z&&Z.hunks>1?c(n("status.contentUpdatedSpots",{count:Z.hunks,lines:Z.changedLines})):Z&&Z.fromLine===Z.toLine?c(n("status.contentUpdatedLine",{line:Z.fromLine})):c(Z?n("status.contentUpdatedLines",{from:Z.fromLine,to:Z.toLine}):n("status.contentUpdated"))}Gt();return}if(e.type==="sourceMissing"){e.path&&e.path===m&&c(n("status.sourceMissing"),!0);return}if(e.type==="bmRendered"){if(e.requestId!==er)return;Sr(e.html||""),Ze(),je=!1,S(),c("");return}if(e.type==="savedMarkdown"){var st=oa[e.requestId];delete oa[e.requestId];var qt=Ae[e.requestId];if(delete Ae[e.requestId],e.requestId!==tr||typeof st!="string"){qt&&qt(!1);return}P=st,Re(h!==st,h===st),c(n(h===st?"status.saved":"status.savedWithNewChanges")),qt&&qt(!0);return}if(e.type==="customStyleSet"){B=e.css||"",xe=e.label||n("common.customStyleDefault"),I="custom",ke(),typeof e.savedSlot=="number"?(z=Array.isArray(e.styleSlots)?e.styleSlots:z,c(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):Ao(),E==="preview"?X():$e("preview"),S();return}if(e.type==="exported"){c(n("status.exported",{path:e.path}));return}if(e.type!=="watchStarted"){if(e.type==="pickCancelled"){K=!1,at(),S(),c("");return}if(e.type==="error"){Ke=!1,Ft="",Fe="",Object.keys(Ae).forEach(function(le){var Kr=Ae[le];delete Ae[le],Kr&&Kr(!1)}),K=!1,at(),e.fallback&&(Ue=!1),je=!1,S(),c(e.message,!0);return}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!L()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),ar||At()},400),Xt(),rr(),Lt(),Ze(),Te()})();})();
|
package/package.json
CHANGED