finch-markdown-editor 0.2.3 → 0.2.5

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