finch-markdown-editor 0.2.15 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/panel.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";(()=>{(function(){"use strict";var i=window.finch;function wa(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){wa("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";wa("unhandledrejection",a)}),window.__mdLog=function(e){if(i&&i.postMessage)try{i.postMessage({type:"clientLog",message:String(e)})}catch{}};var st=/^zh/i.test(navigator.language||""),lt={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}
1
+ "use strict";(()=>{(function(){"use strict";var i=window.finch;function ka(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){ka("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";ka("unhandledrejection",a)}),window.__mdLog=function(e){if(i&&i.postMessage)try{i.postMessage({type:"clientLog",message:String(e)})}catch{}};var lt=/^zh/i.test(navigator.language||""),ct={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=st?lt.zh:lt.en,r=Object.prototype.hasOwnProperty.call(a,e)?a[e]:Object.prototype.hasOwnProperty.call(lt.en,e)?lt.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 Bt(e){var t=e||document;document.documentElement.lang=st?"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 Nt=document.getElementById("empty"),Sa=document.getElementById("emptyNew"),ka=document.getElementById("emptyOpen"),Wt=document.getElementById("homeRecent"),ce=document.getElementById("homeGrid"),ct=document.getElementById("homeHint"),qt=[],Ca=document.getElementById("homeTagline"),Rr=document.getElementById("editPane"),Ht=document.getElementById("previewPane"),ue=document.getElementById("previewResizer"),Ce=document.getElementById("editor"),y=document.getElementById("article"),x=document.getElementById("status"),M=document.getElementById("popup"),j=document.getElementById("popupInput"),Ea=document.getElementById("popupSend"),xa=document.getElementById("popupShortcut"),Be=document.getElementById("actions"),Br=document.getElementById("actCopyWx"),Nr=document.getElementById("actCopyImg"),Wr=document.getElementById("actSaveImg"),qr=document.getElementById("actSavePdf"),Ee=document.getElementById("actAiStyle"),Ma=document.getElementById("actToggle"),de=document.getElementById("confirmOverlay"),Ia=document.getElementById("confirmMessage"),zt=document.getElementById("confirmCancel"),Ut=document.getElementById("confirmDiscard"),Ne=document.getElementById("confirmSave"),La=document.getElementById("appToolbar"),Aa=document.getElementById("appHome"),Da=document.getElementById("appLibrary"),ut=document.getElementById("appOpen"),ne=document.getElementById("appSave"),We=document.getElementById("appPreview"),dt=document.getElementById("appStyle"),pt=document.getElementById("appStyleMenu"),Fa=document.getElementById("appWordCountWrap"),ft=document.getElementById("appWordCount"),Ta=document.getElementById("appWordCountValue"),mt=document.getElementById("appWordCountIcon"),gt=document.getElementById("appWordCountMenu"),pe=document.getElementById("appFocus"),Vt=document.getElementById("appFont"),vt=document.getElementById("appFontMenu"),Hr=document.getElementById("appMore"),ht=document.getElementById("appMoreMenu"),_t=document.getElementById("libraryDrawer"),yt=document.getElementById("libraryBackdrop"),Pa=document.getElementById("libraryClose"),bt=document.getElementById("libraryReorder"),Oa=document.getElementById("libraryReorderFooter"),Ra=document.getElementById("libraryReorderDone"),D=document.getElementById("libraryGroups"),Ba="md-editor-library-groups-v1",fe=[],xe={},me=null,qe=null,oe=!1,He=[],G=null,jt=!1,v=!1,Na=!1,Wa=!1,q=null,ge=null,X=!0,zr=!1,wt=0,ze=!1,ae=!0,C="edit",I="kami",R="",Me="",H=[null,null,null],Ie={songti:"Songti SC, STSong, SimSun, Noto Serif CJK SC, serif",rounded:"PingFang SC, Microsoft YaHei, Noto Sans CJK SC, sans-serif"},z=14,$="rounded",B=!1,U="character",F=!1;try{var St=Number(localStorage.getItem("md-editor-font-size"));(St===14||St===16||St===18)&&(z=St);var Gt=localStorage.getItem("md-editor-font-family");Ie[Gt]?$=Gt:Gt&&localStorage.removeItem("md-editor-font-family"),B=localStorage.getItem("md-editor-comfort-writing")==="1",localStorage.getItem("md-editor-word-count-mode")==="word"&&(U="word"),F=localStorage.getItem("md-editor-focus-mode")==="1";var Ue=JSON.parse(localStorage.getItem(Ba)||"{}");Array.isArray(Ue.order)&&(fe=Ue.order.filter(function(e){return typeof e=="string"})),Ue.collapsed&&typeof Ue.collapsed=="object"&&(xe=Ue.collapsed)}catch{}ae=!F;var h="",Ve="",V="",m="",P=null,N="",Le=!1,qa=0,_e=!1,Ha=0,Xt={},Ae={},Ur=0,ve={},Vr=0,he={},je=0,J=null,kt=0,De=0,Yt=!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 _r(){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}Sa&&Sa.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)}}),ka&&ka.addEventListener("click",function(){da()});var Ge="",Kt="",Zt="",Ct=!1,za=!1,Xe="",be="";function k(e){return String(e).replace(/[&<>"]/g,function(t){return t==="&"?"&amp;":t==="<"?"&lt;":t===">"?"&gt;":"&quot;"})}function Ua(){Ca&&(Ca.textContent=Xe?n("home.tagline.withAssistant",{name:Xe}):n("home.tagline.default"))}function Et(){j&&(j.placeholder=w.mode==="continue"?n("popup.placeholderContinue",{name:Xe||"Finch"}):n("popup.placeholder",{name:Xe||"Finch"}))}function jr(e){return e?be&&e===be?"~":be&&(e.indexOf(be+"/")===0||e.indexOf(be+"\\")===0)?"~"+e.slice(be.length):e:""}function Gr(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 Xr(){Mt(qt)}function Va(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 xt(){!i||!i.postMessage||!Ct||(za=!0,i.postMessage({type:"requestRecentDocuments",cwd:Ge,sessionId:Kt,spaceId:Zt}))}function Yr(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(Va(e.modifiedAt))+"</span></div></div></button>"}function Mt(e){if(!(!ce||!Wt||!ct)){var t=Array.isArray(e)?e:[];if(qt=t,t.length===0){Wt.hidden=!0,ct.hidden=!1,ct.textContent=n(Ge?"home.hintScoped":"home.hintDefault");return}var a=_a(t);ce.innerHTML=a.map(function(r){var o=r.documents.map(Yr).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(Gr(jr(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(""),Wt.hidden=!1,ct.hidden=!0,requestAnimationFrame(function(){Kr(ce)})}}function Kr(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 $t(){var e={order:fe,collapsed:xe};try{localStorage.setItem(Ba,JSON.stringify(e))}catch{}i&&i.postMessage&&i.postMessage({type:"saveLibraryGroups",libraryGroups:e})}function _a(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 Jt(e){if(D){He=Array.isArray(e)?e:[];var t=_a(He);if(oe){Zr(t);return}D.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(Va(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 Zr(e){D.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 Qt(e){oe=!!e,bt&&bt.classList.toggle("active",oe),Oa&&(Oa.hidden=!oe),Jt(He)}function It(e){!_t||!yt||(_t.classList.toggle("open",!!e),_t.setAttribute("aria-hidden",e?"false":"true"),yt.hidden=!e,e?xt():oe&&Qt(!1))}function $r(){if(!(!me||!D)){me.classList.remove("dragging"),Array.prototype.forEach.call(D.querySelectorAll(".library-group.drag-over"),function(t){t.classList.remove("drag-over")}),fe=Array.prototype.map.call(D.querySelectorAll('.library-group[data-draggable="true"]'),function(t){return t.getAttribute("data-library-group-id")}).filter(Boolean),Mt(qt);var e=qe||{};Array.prototype.forEach.call(D.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,$t()},0)}}function Jr(){G&&G.ghost&&G.ghost.parentNode&&G.ghost.parentNode.removeChild(G.ghost)}function ja(e,t){var a=G;!a||!a.ghost||(a.ghost.style.left=e-a.offsetX+"px",a.ghost.style.top=t-a.offsetY+"px")}function Qr(e){var t=G;if(!(!t||t.active)){t.active=!0,me=e,qe={},oe||Array.prototype.forEach.call(D.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),ja(t.startX,t.startY)}}function en(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(D.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;D.insertBefore(me,o?r.nextSibling:r)}}}function Ga(){var e=G;e&&(e.active&&(Jr(),$r(),jt=!0,setTimeout(function(){jt=!1},0)),G=null)}Da&&Da.addEventListener("click",function(){It(!0)}),Pa&&Pa.addEventListener("click",function(){It(!1)}),yt&&yt.addEventListener("click",function(){It(!1)}),bt&&bt.addEventListener("click",function(){Qt(!oe)}),Ra&&Ra.addEventListener("click",function(){Qt(!1)}),D&&D.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||(It(!1),Ye=!0,c(n("status.opening")),ea(a))}),D&&(D.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,$t())}},!0),D.addEventListener("click",function(e){if(jt){var t=e.target&&e.target.closest?e.target.closest(".library-group summary"):null;t&&(e.preventDefault(),e.stopPropagation())}},!0),D.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&&(G={group:t,startX:e.clientX,startY:e.clientY,active:!1,ghost:null,offsetX:0,offsetY:0})}}),window.addEventListener("pointermove",function(e){var t=G;if(t){if(!t.active){if(Math.abs(e.clientX-t.startX)<4&&Math.abs(e.clientY-t.startY)<4)return;Qr(t.group)}e.preventDefault(),ja(e.clientX,e.clientY),en(e.clientX,e.clientY)}}),window.addEventListener("pointerup",function(){Ga()}),window.addEventListener("pointercancel",function(){Ga()}));var Ye=!1,Lt="";function ea(e){!e||!i||!i.postMessage||(Lt=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&&(Ye=!0,c(n("status.opening")),ea(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 Ke(){Nt.hidden=L(),document.body.classList.toggle("has-document",L()),Be&&(Be.hidden=!N),!Nt.hidden&&Ct&&xt()}function Fe(){Rr.classList.toggle("active",v?L():C==="edit"),Ht.classList.toggle("active",v?L():C==="preview"),(v||C==="edit")&&p&&requestAnimationFrame(function(){p.layout()})}function Xa(e){v||!i||!i.panel||!i.panel.setTitle||i.panel.setTitle(e||n("home.title")).catch(function(){})}function tn(e){return e?"document:"+encodeURIComponent(e):""}function Ya(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 Ka(e){!e||e===m||!i||!i.postMessage||(Te=e,ea(e))}function we(){if(!(!v||!i||!i.appView||!i.appView.breadcrumb)){var e=L()&&m?[{id:tn(m),title:V||n("common.markdownDocDefault"),icon:"file-text"}]:[];i.appView.breadcrumb.set(e).catch(function(){})}}function an(){Wa||!i||!i.appView||!i.appView.breadcrumb||(Wa=!0,i.appView.breadcrumb.onNavigate(function(e){if(!e.id){L()&&ot().then(we);return}var t=Ya(e.id);t?Ka(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()&&ot().then(we);return}var a=t.length===1&&Ya(t[0].id);if(!a){i.appView.breadcrumb.set([]).catch(function(){}),L()&&ot().then(we);return}Ka(a)}))}function rn(){var e=[{id:"style:kami",label:"Kami"},{id:"style:bauhaus",label:"Bauhaus"},{id:"style:blueprint",label:"Blueprint"},{id:"style:botanical",label:"Botanical"},{id:"style:newsprint",label:"Newsprint"},{id:"style:retro",label:"Retro"},{id:"style:sketch",label:"Sketch"},{id:"style:terminal",label:"Terminal"},{id:"style-sep",label:"",separator:!0}],t=I==="custom"&&!!R&&!H.some(function(s){return s&&s.css===R});if(t){for(var a=0;a<3;a++)e.push({id:"style:slot-save:"+a,label:n("aiStyle.saveToSlot",{n:a+1})});e.push({id:"style-save-sep",label:"",separator:!0})}for(var r=0;r<3;r++){var o=H[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 nn(){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=$a(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:_e?"ext:markdown-editor-icons/hourglass":"ext:markdown-editor-icons/swatch-book",label:n("toolbar.mode.label"),tooltip:n(r?_e?"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:rn()},{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:U==="character"},{id:"word-count:word",label:n("wordCount.mode.word"),icon:"ext:markdown-editor-icons/whole-word",checked:U==="word"}]},{id:"focus",icon:"ext:markdown-editor-icons/feather",tooltip:n(r?F?"toolbar.focus.tooltipOn":"toolbar.focus.tooltipOff":"toolbar.needDoc"),checked:F,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:!B},{id:"comfort:write",label:n("toolbar.comfort.write"),checked:B},{id:"font-comfort-sep",label:"",separator:!0},{id:"font-size:14",label:n("toolbar.fontSize.small"),checked:z===14},{id:"font-size:16",label:n("toolbar.fontSize.medium"),checked:z===16},{id:"font-size:18",label:n("toolbar.fontSize.large"),checked:z===18},{id:"font-sep",label:"",separator:!0},{id:"font-family:rounded",label:n("toolbar.fontFamily.default"),checked:$==="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:!ge},{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 A(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 Za(){if(pt){var e=["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"],t=e.map(function(s){return A("style:"+s,s[0].toUpperCase()+s.slice(1),I===s)}).join("")+"<hr>",a=I==="custom"&&!!R&&!H.some(function(s){return s&&s.css===R});a&&(t+=[0,1,2].map(function(s){return A("style:slot-save:"+s,n("aiStyle.saveToSlot",{n:s+1}),!1)}).join("")+"<hr>");for(var r=0;r<3;r++){var o=H[r];t+=o?A("style:slot-use:"+r,n("toolbar.style.customSlot",{n:r+1,label:o.label}),I==="custom"&&R===o.css):A("style:slot-use:"+r,n("toolbar.style.customSlotEmpty",{n:r+1}),!1)}pt.innerHTML=t}gt&&(gt.innerHTML=A("word-count:character",n("wordCount.mode.character"),U==="character")+A("word-count:word",n("wordCount.mode.word"),U==="word")),vt&&(vt.innerHTML=A("comfort:read",n("toolbar.comfort.read"),!B)+A("comfort:write",n("toolbar.comfort.write"),B)+"<hr>"+A("font-size:14",n("toolbar.fontSize.small"),z===14)+A("font-size:16",n("toolbar.fontSize.medium"),z===16)+A("font-size:18",n("toolbar.fontSize.large"),z===18)+"<hr>"+A("font-family:rounded",n("toolbar.fontFamily.default"),$==="rounded")+A("font-family:songti",n("toolbar.fontFamily.serif"),$==="songti")),ht&&(ht.innerHTML=A("reload",n("toolbar.more.reload"),!1)+A("reveal",n("toolbar.more.reveal"),!1)+A("recentSession",n("toolbar.more.recentSession"),!1,!ge)+"<hr>"+A("about",n("toolbar.more.about"),!1))}function on(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=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==="&"?"&amp;":t==="<"?"&lt;":t===">"?"&gt;":"&quot;"})}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,`
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 $a(e,t){var a=U==="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=on(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 sn(){return U==="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(ft){var e=$a(h,L());Ta&&(Ta.textContent=e.label),mt&&mt.getAttribute("data-mode")!==U&&(mt.innerHTML=sn(),mt.setAttribute("data-mode",U)),ft.setAttribute("data-tooltip",e.tooltip),ft.setAttribute("aria-label",e.tooltip)}}function cn(){if(v){var e=L();if(Fa&&(Fa.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",F);var o=n(F?"appview.focusExit":"appview.focus");pe.setAttribute("data-tooltip",o),pe.setAttribute("aria-label",o)}We&&(We.disabled=!e,We.classList.toggle("checked",X)),ut&&(ut.disabled=K),dt&&(dt.disabled=!e||!X,dt.setAttribute("data-tooltip",n(X?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),Vt&&(Vt.disabled=!e),Za()}}function S(){v?cn():i&&i.postMessage({type:"setToolbar",toolbar:nn()})}function Ze(e){if(T(),v){C="edit",Fe(),Y(),S();return}C=e,Fe(),S(),C==="preview"&&Y()}function un(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=++Ur;ve[u]={resolve:t,reject:a},setTimeout(function(){ve[u]&&(delete ve[u],a(new Error(n("status.pasteImageTimeout"))))},15e3),i.postMessage({type:"pasteImage",data:l,mimeType:e.type,requestId:u})},r.onerror=function(){a(new Error("Could not read pasted image."))},r.readAsDataURL(e)})}var p=window.MarkdownCodeMirror.create({parent:Ce,value:h,onChange:function(e){h=e,T(),Ke(),Re(!0),vr(),bn()},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:un,onAiHintTrigger:Bn,onAiWorkingCancel:function(){!v||!q||!m||!i||!i.postMessage||i.postMessage({type:"cancelRewrite",path:m,sessionId:q.sessionId,turnId:q.turnId})}});p.setFontSize(z),p.setFontFamily(Ie[$]),p.setComfortWriting(B),p.setFocusMode(F),document.body.classList.toggle("focus-mode",F);var Ja=0;p.scrollDOM.addEventListener("scroll",function(){T(),p.scrollDOM.classList.add("cm-scrollbar-active"),window.clearTimeout(Ja),Ja=window.setTimeout(function(){p.scrollDOM.classList.remove("cm-scrollbar-active")},800)});function dn(){return I==="custom"?R:""}var Qa="user-content-mdl-",ta=0,aa={side:"",value:-1,at:0},$e={editor:!1,preview:!1},Pe=[];function pn(e){if(!v)return e;for(var t=e.split(`
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 Qa(e,t){var a=V==="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=ln(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 cn(){return V==="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 un(){if(mt){var e=Qa(h,L());Oa&&(Oa.textContent=e.label),vt&&vt.getAttribute("data-mode")!==V&&(vt.innerHTML=cn(),vt.setAttribute("data-mode",V)),mt.setAttribute("data-tooltip",e.tooltip),mt.setAttribute("aria-label",e.tooltip)}}function dn(){if(v){var e=L();if(Pa&&(Pa.hidden=!e),un(),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)),dt&&(dt.disabled=K),pt&&(pt.disabled=!e||!R,pt.setAttribute("data-tooltip",n(R?"toolbar.style.tooltip":"toolbar.style.tooltipNeedsPreview"))),_t&&(_t.disabled=!e),Ja()}}function S(){v?dn():i&&i.postMessage({type:"setToolbar",toolbar:sn()})}function $e(e){if(T(),v){C="edit",Fe(),Y(),S();return}C=e,Fe(),S(),C==="preview"&&Y()}function pn(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=++_r;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:Ce,value:h,onChange:function(e){h=e,T(),Ze(),Re(!0),yr(),Sn()},onOpenLink:function(e){i&&i.postMessage&&i.postMessage({type:"openLink",url:e})},onOpenImage:function(e){if(!(!i||!i.postMessage)){try{var t=new URL(e);if(t.protocol==="finch-file:"&&t.hostname==="local"){var a=t.searchParams.get("path");if(a){i.postMessage({type:"openImage",path:a});return}}}catch{}i.postMessage({type:"openImage",url:e})}},onPasteImage:pn,onAiHintTrigger:Wn,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 er=0;p.scrollDOM.addEventListener("scroll",function(){T(),p.scrollDOM.classList.add("cm-scrollbar-active"),window.clearTimeout(er),er=window.setTimeout(function(){p.scrollDOM.classList.remove("cm-scrollbar-active")},800)});function fn(){return I==="custom"?B:""}var tr="user-content-mdl-",aa=0,ra={side:"",value:-1,at:0},Je={editor:!1,preview:!1},Pe=[];function mn(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 ra(){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^="'+Qa+'"]'),r=0;r<a.length;r++){var o=a[r].id,s=Number(o.slice(Qa.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 er(){var e=y.contentDocument;return e&&e.scrollingElement?e.scrollingElement.scrollTop:0}function fn(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||(aa={side:"preview",value:r,at:Date.now()},a.scrollTop=r)}}function mn(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 gn(){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=mn(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 vn(){var e=y.contentDocument,t=e&&e.scrollingElement;return!t||!p||!p.scrollDOM?null:!Q||Q.pHeight!==t.scrollHeight||Q.eHeight!==p.scrollDOM.scrollHeight?gn():Q}function tr(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 ar(e){$e[e]=!0,!ta&&(ta=requestAnimationFrame(function(){ta=0,hn()}))}function rr(e){var t=aa;if(t.side!==e||Date.now()-t.at>300)return!1;var a=e==="editor"?p.scrollDOM.scrollTop:er();return!(Math.abs(t.value-a)>2)}function hn(){var e=$e.editor,t=$e.preview;if($e.editor=!1,$e.preview=!1,!(!v||!L()||!X)){var a=vn();if(a){if(e)fn(tr(a.e,a.p,p.scrollDOM.scrollTop));else if(t){var r=tr(a.p,a.e,er());aa={side:"editor",value:r,at:Date.now()},Math.abs(p.scrollDOM.scrollTop-r)>=1&&(p.scrollDOM.scrollTop=r)}}}}function yn(){rr("editor")||!v||!L()||!X||ar("editor")}function nr(){rr("preview")||!v||!L()||!X||ar("preview")}function bn(){v&&(wt&&clearTimeout(wt),wt=setTimeout(function(){wt=0,Y()},420))}function Y(){if(!(!h||!i)){var e=++qa;_e=!0,S(),i.postMessage({type:"renderBm",markdown:pn(h),markdownStyle:I==="custom"?"kami":I,customCss:dn(),requestId:e})}}function wn(){var e=y.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function Sn(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 kn(){try{return getComputedStyle(y).backgroundColor||""}catch{return""}}function Cn(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(W){u(W)}},d.onerror=function(){u(new Error("svg rasterize failed"))},d.src=s})}function or(){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 Cn(a,s,l).then(function(u){var d=e.createElement("img");d.src=u,d.alt=r&&r.classList.contains("figure-infographic")?"Infographic":"Mermaid diagram",d.style.display="block",d.style.width="100%",d.style.height="auto",a.replaceWith(d)}).catch(function(){})})).then(function(){e.body&&(N=e.body.innerHTML)})}}function ir(e){var t=wn(),a=y.contentDocument;N=e;var r=kn();if(Le&&a&&a.body){a.body.innerHTML=N,r&&(a.body.style.background=r),Sn(t),lr(),ra(),or();return}y.srcdoc='<!doctype html><meta charset="utf-8"><base target="_blank"><style>html,body{margin:0!important;padding:0!important;min-height:100%}body{background:'+(r||"transparent")+"}#bm-md{min-height:100dvh}</style><body>"+N}function sr(e,t,a){return{start:e.slice(0,t).split(`
18
+ `)}function na(){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^="'+tr+'"]'),r=0;r<a.length;r++){var o=a[r].id,s=Number(o.slice(tr.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 ar(){var e=y.contentDocument;return e&&e.scrollingElement?e.scrollingElement.scrollTop:0}function vn(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||(ra={side:"preview",value:r,at:Date.now()},a.scrollTop=r)}}function gn(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 hn(){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=gn(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 yn(){var e=y.contentDocument,t=e&&e.scrollingElement;return!t||!p||!p.scrollDOM?null:!Q||Q.pHeight!==t.scrollHeight||Q.eHeight!==p.scrollDOM.scrollHeight?hn():Q}function rr(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 nr(e){Je[e]=!0,!aa&&(aa=requestAnimationFrame(function(){aa=0,bn()}))}function or(e){var t=ra;if(t.side!==e||Date.now()-t.at>300)return!1;var a=e==="editor"?p.scrollDOM.scrollTop:ar();return!(Math.abs(t.value-a)>2)}function bn(){var e=Je.editor,t=Je.preview;if(Je.editor=!1,Je.preview=!1,!(!v||!L()||!R)){var a=yn();if(a){if(e)vn(rr(a.e,a.p,p.scrollDOM.scrollTop));else if(t){var r=rr(a.p,a.e,ar());ra={side:"editor",value:r,at:Date.now()},Math.abs(p.scrollDOM.scrollTop-r)>=1&&(p.scrollDOM.scrollTop=r)}}}}function wn(){or("editor")||!v||!L()||!R||nr("editor")}function ir(){or("preview")||!v||!L()||!R||nr("preview")}function Sn(){v&&(St&&clearTimeout(St),St=setTimeout(function(){St=0,Y()},420))}function Y(){if(!(!h||!i)){var e=++za;je=!0,S(),i.postMessage({type:"renderBm",markdown:mn(h),markdownStyle:I==="custom"?"kami":I,customCss:fn(),requestId:e})}}function kn(){var e=y.contentDocument,t=e&&e.scrollingElement;return t?{top:t.scrollTop}:null}function Cn(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 En(){try{return getComputedStyle(y).backgroundColor||""}catch{return""}}function xn(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 sr(){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 xn(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 lr(e){var t=kn(),a=y.contentDocument;W=e;var r=En();if(Le&&a&&a.body){a.body.innerHTML=W,r&&(a.body.style.background=r),Cn(t),ur(),na(),sr();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 cr(e,t,a){return{start:e.slice(0,t).split(`
19
19
  `).length,end:e.slice(0,a).split(`
20
- `).length}}function En(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 xn(e){var t="",a=[];function r(W,_){t+=W,a.push(_)}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 En(t,a)}function Mn(e,t){var a=e.indexOf(t);if(a>=0)return{start:a,end:a+t.length};var r=xn(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 In(e){return String(e||"").split(/[\\/]/).pop()||""}function lr(){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(_){return{top:u.top+_.top,left:u.left+_.left,width:_.width,height:_.height}}),f=l[0]||s.getBoundingClientRect(),b=l[l.length-1]||f,g=Mn(h,o),W=g?sr(h,g.start,g.end):null;ur(o,{startTop:u.top+f.top,startLeft:u.left+f.left,endBottom:u.top+b.bottom,endLeft:u.left+b.left},d,W,"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(),Ze("edit"))}),e.addEventListener("scroll",function(){Se(),T()},!0),y.contentWindow.addEventListener("scroll",function(){Se(),T()})}y.onload=function(){Le=!0,lr(),ra()};function cr(){p&&p.scrollDOM&&!p.scrollDOM.__scrollSyncBound&&(p.scrollDOM.__scrollSyncBound=!0,p.scrollDOM.addEventListener("scroll",yn,{passive:!0}));var e=y.contentDocument;if(e&&!e.__scrollSyncBound){e.__scrollSyncBound=!0;var t=e.scrollingElement||e.documentElement;t&&t.addEventListener("scroll",nr,{passive:!0}),e.defaultView&&e.defaultView.addEventListener("scroll",nr,{passive:!0})}}cr(),window.addEventListener("resize",function(){Q=null}),y.addEventListener("load",function(){requestAnimationFrame(function(){Le=!0,ra(),cr(),or()})});var At=0,na=[];function ur(e,t,a,r,o){Se(),At=setTimeout(function(){dr(e,t,a,r,o)},300)}function Se(){At&&(clearTimeout(At),At=0)}function dr(e,t,a,r,o,s){w.text=e,w.lines=r||null,w.origin=o||"",w.mode=s||"replace",Et(),M.classList.remove("hidden"),M.classList.toggle("popup-bar",!!(t&&t.width)),j.value="",An(a),requestAnimationFrame(function(){Ln(t),t&&t.focus&&j.focus()})}function Ln(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 An(e){pr(),(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),na.push(a)})}function pr(){na.forEach(function(e){e.remove()}),na=[]}var Dn=navigator.platform||navigator.userAgent||"",Dt=/Mac|iPhone|iPod|iPad/.test(Dn);document.body.classList.toggle("non-mac-platform",!Dt);function Fn(e){return String(e.key).toLowerCase()!=="e"||e.shiftKey?!1:Dt?e.metaKey&&e.ctrlKey&&!e.altKey:e.ctrlKey&&e.altKey&&!e.metaKey}(function(){if(xa){var t=Dt?["\u2318","\u2303","E"]:["Ctrl","Alt","E"],a=Dt?"":"+";xa.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",pr(),t&&requestAnimationFrame(function(){p.focus()})}Ea.onclick=mr;var fr=0;j.addEventListener("compositionend",function(){fr=Date.now()});function Tn(e){return e.isComposing||e.keyCode===229?!0:Date.now()-fr<100}j.addEventListener("keydown",function(e){if(e.key==="Enter"){if(Tn(e))return;mr()}e.key==="Escape"&&T(!0)}),j.addEventListener("focus",function(){M.classList.add("focused")}),j.addEventListener("blur",function(){requestAnimationFrame(function(){document.activeElement!==Ea&&M.classList.remove("focused")})}),document.addEventListener("keydown",function(e){e.key==="Escape"&&!M.classList.contains("hidden")&&T(!0)}),document.addEventListener("keydown",function(e){Fn(e)&&(M.classList.contains("hidden")||(e.preventDefault(),j.focus(),j.select()))}),document.addEventListener("mousedown",function(e){M.contains(e.target)||(Se(),T())}),window.addEventListener("resize",T);function Pn(){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 On(){return w.lines?w.lines.start+"-"+w.lines.end:n("annotate.lineCompactUnknown")}async function mr(){var e=j.value.trim(),t=w.mode==="continue",a=w.mode==="annotate-line";if(!(!w.text&&!t&&!a||!i)){if(O&&m){var r=await va();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:(V||"Markdown")+":"+On(),note:e||void 0,promptText:n("annotate.promptText",{lineLabel:Pn(),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 Rn(){var e=p.getSelection();if(!e)return!1;var t=e.text.trim();if(!t)return!1;var a=sr(p.getValue(),e.start,e.end);return ur(t,{startTop:e.startRect.top,startLeft:e.startRect.left,endBottom:e.rect.bottom,endLeft:e.rect.left},null,a,"editor"),!0}function gr(){ae&&Rn()}function Bn(e){if(!L()||!e)return!1;Se();var t=Ce.querySelector(".cm-line")||Ce.querySelector(".cm-content"),a=(t||Ce).getBoundingClientRect();return dr("",{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",gr),Ce.addEventListener("keyup",function(e){e.shiftKey&&gr()});var O=!1,Je=0,ie=null,oa=!1,Oe=!1,ia="",sa=null;function Nn(e){ia=e,sa=h,i.postMessage({type:"saveDraft",path:e,markdown:h,base:P})}function vr(){!m||!i||!i.postMessage||ia===m&&sa===h||Nn(m)}function la(){ia="",sa=null}function ca(e){la(),e&&i&&i.postMessage&&i.postMessage({type:"discardDraft",path:e})}function Re(e,t){O=e,je&&(clearTimeout(je),je=0),Oe=!O&&!!t,S(),!O&&t&&(je=setTimeout(function(){je=0,O||(Oe=!1,S())},3e3))}async function hr(e){if(ie)return br(),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(),kt=(await J.getFile()).lastModified,P=e,Re(h!==e,h===e),c(n(h===e?"status.saved":"status.savedWithNewChanges")),la(),!0}catch(r){return c(n("status.saveFailed",{err:String(r)}),!0),!1}if(m){var a=++Ha;return c(n("status.saving")),Xt[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(),Ze(C==="edit"?"preview":"edit"))});function yr(){De&&(clearInterval(De),De=0),J=null}var ua=null;function Qe(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),br(),!1;var l=P!==null&&(!a||!m||a===m);return l||(ae=!0),h=e,Ve=t,a&&(m=a),V=In(a||m)||t||"Markdown",P=typeof o=="string"?o:h,ua=l?p.applyExternalValue(h):null,ua||p.setValue(h),Re(!1),Xa(V),s||we(),Ke(),Fe(),(v||C==="preview")&&Y(),!0}async function br(){if(!(oa||!ie||!O)){var e=ie,t=P;if(h===t){ie=null,Qe(e.markdown,e.name,e.path,!0,e.diskBaseline);return}if(e.markdown===t){ie=null;return}oa=!0;var a=await no();if(oa=!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"){ca(m),Qe(e.markdown,e.name,e.path,!0,e.diskBaseline);return}a==="local"&&(P=typeof e.diskBaseline=="string"?e.diskBaseline:e.markdown,vr(),c("\u5DF2\u4FDD\u7559\u672C\u5730\u7F16\u8F91\uFF1BAI \u5199\u56DE\u7248\u672C\u4ECD\u5728\u78C1\u76D8\u4E0A\u3002"))}}}async function wr(e){Ve=e.name,kt=e.lastModified,typeof e.path=="string"&&e.path?(m=e.path,i&&i.postMessage({type:"watchPath",path:m})):m="",Qe(await e.text(),Ve,m,!0)}function Wn(){J&&(De&&clearInterval(De),De=setInterval(async function(){if(!(Yt||!J)){Yt=!0;try{var e=await J.getFile();if(e.lastModified!==kt){kt=e.lastModified;var t=await e.text();t!==P&&Qe(t,Ve,m)&&c(n("status.externalUpdateApplied"))}}catch{}Yt=!1}},800))}var K=!1,et=0;function tt(){et&&(clearTimeout(et),et=0)}function qn(){tt(),et=setTimeout(function(){et=0,K&&(K=!1,ze=!1,S(),c(n("status.pickerTimeout"),!0))},2e4)}async function da(){if(O){var e=await Dr(n("confirm.message",{file:V||n("common.markdownDocDefault")}));if(e==="cancel")return;if(e==="save"){var t=await va();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&ca(m)}if(yr(),ze&&i&&i.postMessage){if(K){tt(),ze=!1,K=!1,S(),await Sr();return}K=!0,qn(),S(),c(n("status.openingPicker")),i.postMessage({type:"requestOpen"});return}await Sr()}async function Sr(){if("showOpenFilePicker"in window)try{var e=await window.showOpenFilePicker({types:[{description:"Markdown",accept:{"text/markdown":[".md",".markdown"]}}],multiple:!1});J=e[0],await wr(await J.getFile()),Wn();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&&wr(a).catch(function(r){c(String(r),!0)})},t.click()}function Hn(){window.focus(),document.body.tabIndex=-1;try{document.body.focus({preventScroll:!0})}catch{document.body.focus()}}async function zn(e){for(var t=0;t<e;t++){if(Hn(),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 kr(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=++Vr;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 Un(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 Cr(e,t){if(document.hasFocus()||await zn(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 Vn(a)?"rich":_n(t)?"plain":"none"}function Vn(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 _n(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 jn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{var e=y.contentDocument&&y.contentDocument.body?y.contentDocument.body.innerText:N.replace(/<[^>]+>/g,""),t=await Cr(kr(N),e);t==="none"&&(await new Promise(function(a){setTimeout(a,200)}),t=await Cr(kr(N),e)),t==="rich"?c(n("status.copiedRich")):c(n(t==="plain"?"status.copiedPlainOnly":"status.copyFailed"),!0)}catch(a){c(n("status.richCopyFailed",{err:String(a)}),!0)}finally{C==="edit"&&requestAnimationFrame(function(){p.focus()})}}function Gn(){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 pa(){var e=Gn();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(W){u(W)}},d.onerror=function(){u(new Error(n("status.imageConversionFailed")))},d.src=s})}function fa(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 Er(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 Xn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}if(!window.ClipboardItem||!navigator.clipboard||!navigator.clipboard.write){c(n("status.clipboardUnsupported"),!0);return}c(n("status.generatingImage"));var e=pa().then(function(a){if(!a)throw new Error(n("status.previewNotReady"));return fa(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 Yn(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingImage"));var e=await pa();if(!e){c(n("status.exportImageFailedGeneric"),!0);return}var t=await fa(e.canvas,"image/png"),a=await t.arrayBuffer(),r=Er(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 Kn(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 ma(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 Zn(e,t,a,r,o){var s=ee(`%PDF-1.4
20
+ `).length}}function Mn(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 In(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 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
22
22
  %\xE2\xE3\xCF\xD3
23
- `),l=[s],u=[0],d=s.length;function f(Ot){u.push(d),l.push(Ot),d+=Ot.length}f(ee(`1 0 obj
23
+ `),l=[s],u=[0],d=s.length;function f(Rt){u.push(d),l.push(Rt),d+=Rt.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,18 +35,18 @@ stream
35
35
  `),g=ee(`
36
36
  endstream
37
37
  endobj
38
- `);f(ma([b,e,g]));var W="q "+r.toFixed(2)+" 0 0 "+o.toFixed(2)+" 0 0 cm /Im0 Do Q",_=ee(W);f(ma([ee(`5 0 obj
39
- << /Length `+_.length+` >>
38
+ `);f(va([b,e,g]));var q="q "+r.toFixed(2)+" 0 0 "+o.toFixed(2)+" 0 0 cm /Im0 Do Q",j=ee(q);f(va([ee(`5 0 obj
39
+ << /Length `+j.length+` >>
40
40
  stream
41
- `),_,ee(`
41
+ `),j,ee(`
42
42
  endstream
43
43
  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(Kn(u[re])+` 00000 n
48
- `);var Pt=`trailer
47
+ `],re=1;re<=5;re++)se.push($n(u[re])+` 00000 n
48
+ `);var Ot=`trailer
49
49
  << /Size 6 /Root 1 0 R >>
50
50
  startxref
51
51
  `+te+`
52
- %%EOF`;return l.push(ee(se.join("")+Pt)),ma(l)}async function $n(){if(!N){c(n("status.pleaseOpenArticle"),!0);return}try{c(n("status.generatingPdf"));var e=await pa();if(!e){c(n("status.exportPdfFailedGeneric"),!0);return}var t=await fa(e.canvas,"image/jpeg",.92),a=await t.arrayBuffer(),r=new Uint8Array(a),o=e.cssWidth*.75,s=e.cssHeight*.75,l=Zn(r,e.canvas.width,e.canvas.height,o,s),u=Er(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 at(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}))})}at(Br,jn),at(Nr,Xn),at(Wr,Yn),at(qr,$n),at(Ee,Jn);var xr="md-editor-actions-collapsed";(function(){var t=!1;try{t=localStorage.getItem(xr)==="1"}catch{}Be&&Be.classList.toggle("collapsed",t)})(),Ma&&Ma.addEventListener("click",function(e){e.preventDefault();var t=Be.classList.toggle("collapsed");try{localStorage.setItem(xr,t?"1":"0")}catch{}});function ga(){hr(h)}function Ft(e){if(zr=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 Mr(){if(!h||!m||!i||!i.postMessage){c(n("status.pleaseOpenArticle"),!0);return}i.postMessage({type:"requestStyleSession",path:m,baseStyle:I}),Ft(!0),c(n("aiStyle.appViewDesigning"))}async function Jn(){if(!h){c(n("status.pleaseOpenArticle"),!0);return}if(v||!i||!i.composer){Mr();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{Mr()}}function Qn(){return{fontSize:z,fontFamily:$,comfortWriting:B,style:I,customCss:I==="custom"?R:"",customStyleLabel:I==="custom"?Me:""}}function ke(){i&&i.postMessage&&i.postMessage({type:"saveWritingPreferences",preferences:Qn()})}function eo(e){return!e||typeof e!="object"?!1:((e.fontSize===14||e.fontSize===16||e.fontSize===18)&&(z=e.fontSize),Ie[e.fontFamily]&&($=e.fontFamily),B=e.comfortWriting===!0,e.style==="custom"&&typeof e.customCss=="string"&&e.customCss?(I="custom",R=e.customCss,Me=typeof e.customStyleLabel=="string"?e.customStyleLabel:""):["kami","bauhaus","blueprint","botanical","newsprint","retro","sketch","terminal"].indexOf(e.style)!==-1&&(I=e.style,R="",Me=""),p.setFontSize(z),p.setFontFamily(Ie[$]),p.setComfortWriting(B),!0)}function to(e){I=e,ke(),(v||C==="preview")&&Y(),S()}function ao(e){if(!(e!==14&&e!==16&&e!==18)){z=e,p.setFontSize(e);try{localStorage.setItem("md-editor-font-size",String(e))}catch{}ke(),S()}}function ro(e){if(Ie[e]){$=e,p.setFontFamily(Ie[e]);try{localStorage.setItem("md-editor-font-family",e)}catch{}ke(),S()}}function Ir(e){B=!!e,p.setComfortWriting(B);try{localStorage.setItem("md-editor-comfort-writing",B?"1":"0")}catch{}ke(),S(),c(n(B?"status.comfortWrite":"status.comfortRead"))}function Lr(e){if(!(e!=="character"&&e!=="word"||U===e)){U=e;try{localStorage.setItem("md-editor-word-count-mode",U)}catch{}S()}}function Ar(){F=!F,F&&ae?(ae=!1,T()):!F&&!ae&&(ae=!0),p.setFocusMode(F),document.body.classList.toggle("focus-mode",F);try{localStorage.setItem("md-editor-focus-mode",F?"1":"0")}catch{}S(),c(n(F?"status.focusOn":"status.focusOff"))}var rt=null;function nt(e){de.hidden=!0;var t=rt;rt=null,t&&t(e)}function Dr(e){return new Promise(function(t){rt=t,Ia.textContent=e,de.hidden=!1,Ne.focus()})}async function no(){Ia.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",zt.textContent="\u7A0D\u540E\u5904\u7406",Ut.textContent="\u4FDD\u7559\u672C\u5730",Ne.textContent="\u91C7\u7528 AI \u7248\u672C";var e=await new Promise(function(t){rt=t,de.hidden=!1,Ne.focus()});return Bt(de),e==="save"?"remote":e==="discard"?"local":"later"}zt&&zt.addEventListener("click",function(){nt("cancel")}),Ut&&Ut.addEventListener("click",function(){nt("discard")}),Ne&&Ne.addEventListener("click",function(){nt("save")}),de&&de.addEventListener("click",function(e){e.target===de&&nt("cancel")}),document.addEventListener("keydown",function(e){e.key==="Escape"&&rt&&nt("cancel")});async function va(){return await hr(h)}function oo(){yr(),la(),T(),h="",Ve="",V="",m="",P=null,ge=null,N="",ae=!1,C="edit",p&&p.setValue(""),Xa(n("home.title")),we(),ir(""),i&&i.postMessage&&i.postMessage({type:"goHome"}),Ke(),Fe(),Re(!1),c("")}async function ot(){if(O){var e=await Dr(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 va();if(!t){c(n("status.saveFailedNoReturn"),!0);return}}else e==="discard"&&ca(m)}oo()}function Fr(e){if(i&&i.postMessage&&i.postMessage({type:"clientLog",message:"finch:menu received, itemId="+e}),e==="home"){ot();return}if(e==="open"){da();return}if(e==="mode"){Ze(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"){ge&&i&&i.navigation&&i.navigation.openSession&&i.navigation.openSession(ge);return}if(e&&e.indexOf("font-size:")===0){ao(Number(e.slice(10)));return}if(e&&e.indexOf("font-family:")===0){ro(e.slice(12));return}if(e==="comfort:read"){Ir(!1);return}if(e==="comfort:write"){Ir(!0);return}if(e==="word-count:character"){Lr("character");return}if(e==="word-count:word"){Lr("word");return}if(e==="focus"){Ar();return}if(e==="about"){_r();return}if(e&&e.indexOf("style:slot-use:")===0){so(+e.slice(15));return}if(e&&e.indexOf("style:slot-save:")===0){Pr(+e.slice(16));return}if(e&&e.indexOf("style:")===0){to(e.slice(6));return}}function ha(){[pt,gt,vt,ht].forEach(function(e){e&&(e.hidden=!0)})}function io(e){if(e){var t=e.hidden;ha(),e.hidden=!t}}function Tt(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&&(Fr(o),ha())}})}Aa&&Aa.addEventListener("click",ot),ut&&ut.addEventListener("click",da),ne&&ne.addEventListener("click",ga),pe&&pe.addEventListener("click",Ar),We&&We.addEventListener("click",function(){X=!X,document.body.classList.toggle("preview-hidden",!X),S(),X&&requestAnimationFrame(function(){p.layout(),Y()})}),Tt(dt,pt),Tt(ft,gt),Tt(Vt,vt),Tt(Hr,ht),document.addEventListener("click",ha);var ya=370,ba=560,Tr=480;ue&&ue.addEventListener("mousedown",function(e){e.preventDefault();var t=ue.parentElement;if(!t)return;var a=e.clientX,r=Ht?Ht.getBoundingClientRect().width:Tr;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(ya,Math.min(ba,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"))||Tr;(t>ba||t<ya)&&e.style.setProperty("--preview-width",Math.max(ya,Math.min(ba,t))+"px")}}});function so(e){var t=H[e];t&&(R=t.css,Me=t.label,I="custom",ke(),c(n("status.appliedStyleSlot",{label:t.label})),C==="preview"?Y():Ze("preview"),S())}function Pr(e){if(I!=="custom"||!R){c(n("status.needCustomStyleFirst"),!0);return}var t=Me||n("common.customStyleDefault");i&&i.postMessage&&i.postMessage({type:"saveStyleSlot",slot:e,css:R,label:t,path:m})}function lo(){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=H[t];r&&(a.title=r.label),a.addEventListener("click",function(){Pr(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(ze=!!e.pickFileSupported,H=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],eo(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&&Jt(He)):(fe.length||Object.keys(xe).length)&&$t(),typeof e.locale=="string"&&e.locale){var t=/^zh/i.test(e.locale);t!==st&&(st=t,Bt(),Et())}e.assistantName&&(Xe=e.assistantName,Et()),Ua(),e.homeDir&&(be=e.homeDir,Xr()),S();return}if(e.type==="styleSlots"){H=Array.isArray(e.styleSlots)?e.styleSlots:[null,null,null],typeof e.savedSlot=="number"&&H[e.savedSlot]&&c(n("status.savedToSlot",{slot:e.savedSlot+1,label:H[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(Un(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=ve[e.requestId];l&&(delete ve[e.requestId],l.resolve(e.url));return}if(e.type==="pasteImageError"){var u=ve[e.requestId];u&&(delete ve[e.requestId],u.reject(new Error(e.message||n("status.pasteImageFailedDefault")))),c(n("status.pasteImageFailed",{msg:e.message||""}));return}if(e.type==="finch:env"){v=e.view==="appView",v&&(i&&i.panel&&i.panel.setTitle&&i.panel.setTitle(n("home.title")).catch(function(){}),we(),an()),v&&!Na&&(Na=!0,X=!1,document.body.classList.add("preview-hidden")),document.body.classList.toggle("app-view",v),La&&(La.hidden=!v),p.setAiHint(n("appview.hintSpace"),n("appview.hintSpaceCode"));var d=e.cwd||"",f=e.sessionId||"",b=e.spaceId||"";(d!==Ge||f!==Kt||b!==Zt||!Ct)&&(Ge=d,Kt=f,Zt=b,Ct=!0,Mt([])),Fe(),we(),S(),v&&L()&&Y(),(!Nt.hidden||v)&&xt();return}if(e.type==="recentDocuments"){if(!e.library&&(e.cwd||"")!==Ge)return;Mt(e.documents),e.library&&Jt(e.documents);return}if(e.type==="status"){c(e.message);return}if(e.type==="rewriteSessionStarted"){q=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"){q&&q.turnId===e.turnId&&(q.cancelling=!0),ye(n("appview.cancelling"),!1,e.sessionId,0);return}if(e.type==="rewriteSessionFinished"){q=null,p.setAiWorkingLines(0,0),ye(n("appview.rewriteDone"),!1,e.sessionId,5e3);return}if(e.type==="rewriteSessionFailed"){var g=q&&q.turnId===e.turnId&&q.cancelling;q=null,p.setAiWorkingLines(0,0),ye(g?n("appview.cancelled"):e.message||"Rewrite failed.",!g,e.sessionId,5e3);return}if(e.type==="styleSessionStarted"){Ft(!0),ye(n("aiStyle.appViewDesigning"),!1,e.sessionId,0);return}if(e.type==="styleSessionFinished"){Ft(!1),ye(e.message||n("aiStyle.appViewDone"),!1,e.sessionId,5e3);return}if(e.type==="styleSessionFailed"){Ft(!1),ye(e.message||n("aiStyle.appViewFailed"),!0,e.sessionId,5e3);return}if(e.type!=="lastFileUnavailable"){if(e.type==="lastSessionInfo"){ge=e.sessionId||null,S(),Za();return}if(e.type==="finch:menu"){Fr(e.itemId);return}if(e.type==="document"){var W=K;K=!1,tt();var _=e.markdown||"",te=e.path||"",se=Number(e.revision)||0;if(te&&te===m&&se&&se<=Je)return;var re=!!te&&!!m&&te!==m;if((re||P===null)&&(ge=null),re&&Lt&&te!==Lt){Te===te&&(Te="");return}if(!re&&_===P){se&&(Je=Math.max(Je,se)),S();return}var Pt=P===null,Ot=Ye;Ye=!1;var co=!!te&&Te===te;Te="";var uo=Qe(_,e.title||n("common.markdownDocDefault"),e.path||m,W||Pt||re,e.diskMarkdown,co);if(!uo){S();return}if(Je=se||(re?0:Je),e.draftRestored)Re(!0),c(n("status.draftRestored"));else if(e.draftConflict)c(n("status.draftConflict"),!0);else if(Ot)c(n("status.opened",{file:V}));else if(!Pt){var Z=ua;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!==qa)return;ir(e.html||""),Ke(),_e=!1,S(),c("");return}if(e.type==="savedMarkdown"){var it=Xt[e.requestId];delete Xt[e.requestId];var Rt=Ae[e.requestId];if(delete Ae[e.requestId],e.requestId!==Ha||typeof it!="string"){Rt&&Rt(!1);return}P=it,Re(h!==it,h===it),c(n(h===it?"status.saved":"status.savedWithNewChanges")),Rt&&Rt(!0);return}if(e.type==="customStyleSet"){R=e.css||"",Me=e.label||n("common.customStyleDefault"),I="custom",ke(),typeof e.savedSlot=="number"?(H=Array.isArray(e.styleSlots)?e.styleSlots:H,c(n("status.savedAppliedToSlot",{labelPrefix:e.label?e.label+" \xB7 ":"",slot:e.savedSlot+1}))):lo(),C==="preview"?Y():Ze("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,tt(),S(),c("");return}if(e.type==="error"){Ye=!1,Lt="",Te="",Object.keys(Ae).forEach(function(le){var Or=Ae[le];delete Ae[le],Or&&Or(!1)}),K=!1,tt(),e.fallback&&(ze=!1),_e=!1,S(),c(e.message,!0);return}}}}}),i&&i.postMessage&&i.postMessage({type:"panelReady"}),setTimeout(function(){!L()&&i&&i.postMessage&&i.postMessage({type:"requestLastFile"}),za||xt()},400),Bt(),Ua(),Et(),Ke(),Fe()})();})();
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()})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "finch-markdown-editor",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "A Markdown editor and WeChat Official Account style preview, with selection-based AI edits and AI-generated custom styles.",
5
5
  "author": {
6
6
  "name": "PuterJam",
@@ -197,7 +197,7 @@
197
197
  "devDependencies": {
198
198
  "@finchtoys/minitool-api": "^0.3.5",
199
199
  "@types/node": "^26.1.0",
200
- "bmmd": "0.3.2",
200
+ "bmmd": "^0.3.4",
201
201
  "esbuild": "^0.28.1",
202
202
  "typescript": "^6.0.3"
203
203
  },