(function(e){function t(t){for(var i,r,a=t[0],l=t[1],c=t[2],u=0,m=[];u{d.subscribe({next:e=>{console.log(e)},error:e=>{t(e.message)},complete:t=>{e(`${r}/${t.key}`)}})})}async function aliOSSFileUpload(e,t){const o=getDateFilename(t),{region:i,bucket:n,accessKeyId:s,accessKeySecret:r,cdnHost:a,path:l}=JSON.parse(localStorage.getItem("aliOSSConfig")),c=buffer_from__WEBPACK_IMPORTED_MODULE_6___default()(e,"base64"),d=`${l}/${o}`,u=new ali_oss__WEBPACK_IMPORTED_MODULE_3___default.a({region:i,bucket:n,accessKeyId:s,accessKeySecret:r});try{const e=await u.put(d,c);return""===a?e.url:`${a}/${""===l?o:d}`}catch(m){return Promise.reject(m)}}async function txCOSFileUpload(e){const t=getDateFilename(e.name),{secretId:o,secretKey:i,bucket:n,region:s,path:r,cdnHost:a}=JSON.parse(localStorage.getItem("txCOSConfig")),l=new cos_js_sdk_v5__WEBPACK_IMPORTED_MODULE_5___default.a({SecretId:o,SecretKey:i});return new Promise((o,i)=>{l.putObject({Bucket:n,Region:s,Key:`${r}/${t}`,Body:e},(function(e,n){e?i(e):o(a?""==r?`${a}/${t}`:`${a}/${r}/${t}`:"https://"+n.Location)}))})}async function minioFileUpload(e,t){const o=getDateFilename(t),{endpoint:i,port:n,useSSL:s,bucket:r,accessKey:a,secretKey:l}=JSON.parse(localStorage.getItem("minioConfig")),c=buffer_from__WEBPACK_IMPORTED_MODULE_6___default()(e,"base64"),d={endPoint:i,useSSL:s,accessKey:a,secretKey:l},u=Number(n||0),m=u>0&&80!==u&&443!==u;return m&&(d.port=u),new Promise((e,t)=>{const a=new minio__WEBPACK_IMPORTED_MODULE_4__["Client"](d);try{a.putObject(r,o,c,(function(a){a&&t(a);const l=`${s?"https://":"http://"}${i}${m?":"+n:""}`,c=`${l}/${r}/${o}`;e(c)}))}catch(l){t(l)}})}async function formCustomUpload(content,file){const str=`\n async (CUSTOM_ARG) => {\n ${localStorage.getItem("formCustomConfig")}\n }\n `;return new Promise((resolve,reject)=>{const exportObj={content:content,file:file,util:{axios:_fetch__WEBPACK_IMPORTED_MODULE_0__["a"],CryptoJS:crypto_js__WEBPACK_IMPORTED_MODULE_2___default(),OSS:ali_oss__WEBPACK_IMPORTED_MODULE_3___default(),COS:cos_js_sdk_v5__WEBPACK_IMPORTED_MODULE_5___default(),Buffer:buffer_from__WEBPACK_IMPORTED_MODULE_6___default(),uuidv4:uuid__WEBPACK_IMPORTED_MODULE_7__["a"],qiniu:qiniu_js__WEBPACK_IMPORTED_MODULE_8__,tokenTools:_assets_scripts_tokenTools__WEBPACK_IMPORTED_MODULE_9__,getDir:getDir,getDateFilename:getDateFilename},okCb:resolve,errCb:reject};eval(str)(exportObj).catch(e=>{console.error(e),reject(e)})})}function fileUpload(e,t){const o=localStorage.getItem("imgHost");switch(!o&&localStorage.setItem("imgHost","default"),o){case"aliOSS":return aliOSSFileUpload(e,t.name);case"minio":return minioFileUpload(e,t.name);case"txCOS":return txCOSFileUpload(t);case"qiniu":return qiniuUpload(t);case"gitee":return giteeUpload(e,t.name);case"github":return ghFileUpload(e,t.name);case"formCustom":return formCustomUpload(e,t);default:return ghFileUpload(e,t.name)}}__webpack_exports__["a"]={fileUpload:fileUpload}},4:function(e,t){},"4e00":function(e,t,o){"use strict";function i(e){var t,o,i,n;for(t="",i=e.length,o=0;o=1&&n<=127?t+=e.charAt(o):n>2047?(t+=String.fromCharCode(224|n>>12&15),t+=String.fromCharCode(128|n>>6&63),t+=String.fromCharCode(128|n>>0&63)):(t+=String.fromCharCode(192|n>>6&31),t+=String.fromCharCode(128|n>>0&63));return t}function n(e){var t,o,i,n,s,r;t="",i=e.length,o=0;while(o>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=e.charAt(o-1);break;case 12:case 13:s=e.charCodeAt(o++),t+=String.fromCharCode((31&n)<<6|63&s);break;case 14:s=e.charCodeAt(o++),r=e.charCodeAt(o++),t+=String.fromCharCode((15&n)<<12|(63&s)<<6|(63&r)<<0);break}return t}o.r(t),o.d(t,"utf16to8",(function(){return i})),o.d(t,"utf8to16",(function(){return n})),o.d(t,"base64encode",(function(){return a})),o.d(t,"base64decode",(function(){return l})),o.d(t,"safe64",(function(){return c}));const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",r=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);function a(e){var t,o,i,n,r,a;i=e.length,o=0,t="";while(o>2),t+=s.charAt((3&n)<<4),t+="==";break}if(r=e.charCodeAt(o++),o==i){t+=s.charAt(n>>2),t+=s.charAt((3&n)<<4|(240&r)>>4),t+=s.charAt((15&r)<<2),t+="=";break}a=e.charCodeAt(o++),t+=s.charAt(n>>2),t+=s.charAt((3&n)<<4|(240&r)>>4),t+=s.charAt((15&r)<<2|(192&a)>>6),t+=s.charAt(63&a)}return t}function l(e){var t,o,i,n,s,a,l;a=e.length,s=0,l="";while(s>4);do{if(i=255&e.charCodeAt(s++),61==i)return l;i=r[i]}while(s>2);do{if(n=255&e.charCodeAt(s++),61==n)return l;n=r[n]}while(sObject.assign({},e,t);this.buildTheme=e=>{let t={},o=n(e.BASE,{"font-family":this.opts.fonts,"font-size":this.opts.size});for(let s in e.inline)if(e.inline.hasOwnProperty(s)){let o=e.inline[s];t[s]=n(e.BASE,o)}let i=n(o,{});for(let s in e.block)if(e.block.hasOwnProperty(s)){let o=e.block[s];t[s]=n(i,o)}return t};let s=(e,t)=>{let o=[],n=i[e];if(!n)return"";for(const i in n)o.push(i+":"+n[i]);return`style="${o.join(";")+(t||"")}"`},r=(e,i)=>(t.push([++o,e,i]),o);this.buildFootnotes=()=>{let e=t.map(e=>e[1]===e[2]?`[${e[0]}]
: ${e[1]}
`:`[${e[0]}]
${e[1]}: ${e[2]}
`);return e.length?`引用链接
${e.join("\n")}
`:""},this.buildAddition=()=>"\n \n ",this.setOptions=e=>{this.opts=n(this.opts,e)},this.hasFootnotes=()=>0!==t.length,this.getRenderer=e=>{t=[],o=0,i=this.buildTheme(this.opts.theme);let n=new m["Renderer"];return n.heading=(e,t)=>{switch(t){case 1:return`${e}
`;case 2:return`${e}
`;case 3:return`${e}
`;default:return`${e}
`}},n.paragraph=e=>-1!=e.indexOf("
`,n.blockquote=e=>(e=e.replace(//g,``),`
${e}
`),n.code=(e,t)=>(t=f.a.getLanguage(t)?t:"plaintext",e=f.a.highlight(e,{language:t}).value,e=e.replace(/\r\n/g,"
").replace(/\n/g,"
").replace(/(>[^<]+)|(^[^<]+)/g,(function(e){return e.replace(/\s/g," ")})),`${e}
`),n.codespan=(e,t)=>`${e}
`,n.listitem=e=>`<%s/>${e}`,n.list=(e,t,o)=>{e=e.replace(/<\/*p.*?>/g,"");let i=e.split("<%s/>");if(!t)return e=i.join("• "),``;e=i[0];for(let n=1;n${e}`},n.image=(e,t,o)=>{let i="";o&&(i=`${o}`);let n=s("figure"),r=s("image");return``},n.link=(t,o,i)=>{if(t.startsWith("https://mp.weixin.qq.com"))return`${i}`;if(t===i)return i;if(e){let e=r(o||i,t);return`${i}[${e}]`}return`${i}`},n.strong=e=>`${e}`,n.em=e=>`${e}`,n.table=(e,t)=>``,n.tablecell=(e,t)=>`${e} | `,n.hr=()=>`
`,n}}}var g=h,b=o("56b3"),_=o.n(b),C='# 示例文章:Google 搜索的即时自动补全功能究竟是如何“工作”的?\n\n> Google 搜索**自动补全功能**的强大,相信不少朋友都能感受到,它帮助我们更快地“补全”我们所要输入的搜索关键字。那么,它怎么知道我们要输入什么内容?它又是如何工作的?在这篇文章里,我们一起来看看。\n\n## 使用自动补全\n\nGoogle 搜索的自动补全功能可以在 Google 搜索应用的大多数位置使用,包括 [Google](https://www.google.com/) 主页、适用于 IOS 和 Android 的 Google 应用,我们只需要在 Google 搜索框上开始键入关键字,就可以看到联想词了。\n\n![](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/md/images/1648303019705-c161ce00-d245-446a-b81c-42ec91474a40.gif)\n\n在上图示例中,我们可以看到,输入关键字 `juej`,Google 搜索会联想到“掘金”、“掘金小册”、“绝句”等等,好处就是,我们无须输入完整的关键字即可轻松完成针对这些 topics 的搜索。\n\n谷歌搜索的自动补全功能对于使用移动设备的用户来说特别有用,用户可以轻松在难以键入的小屏幕上完成搜索。当然,对于移动设备用户和台式机用户而言,这都节省了大量的时间。根据 Google 官方报告,自动补全功能可以减少大约 25% 的打字,累积起来,预计每天可以节省 200 多年的打字时间。是的,每天!\n\n> 注意,本文所提到的“**联想词**”与“**预测**”,是同一个意思。\n\n## 基于“预测”而非“建议”\n\nGoogle 官方将自动补全功能称之为“预测”,而不是“建议”,为什么呢?其实是有充分理由的。自动补全功能是为了**帮助用户完成他们打算进行的搜索**,而不是建议用户要执行什么搜索。\n\n那么,Google 是如何确定这些“预测”的?其实,Google 会根据趋势搜索 [trends](https://trends.google.com/trends/?geo=US) 给到我们这些“预测”。简单来说,哪个热门、哪个搜索频率高,就更可能推给我们。当然,这也与我们当前所处的位置以及我们的搜索历史相关。\n\n另外,这些“预测”也会随着我们键入的关键字的变更而更改。例如,当我们把键入的关键字从 `juej` 更改为 `juex` 时,与“掘金”相关的预测会“消失”,同时,与“觉醒”、“决心”相关联的词会出现。\n\n![](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/md/images/1648303068169-386a99cb-143b-4ded-a859-1b7a4c4b5bd3.gif)\n\n## 为什么看不到某些联想词?\n\n如果我们在输入某个关键字时看不到联想词,那么表明 Google 的算法可能检测到:\n\n- 这个关键字不是热门字词;\n- 搜索的字词太新了,我们可能需要等待几天或几周才能看到联想词;\n- 这是一个侮辱性或敏感字词,这个搜索字词违反了 Google 的相关政策。更加详细的情况,可以了解 [Google 搜索自动补全政策](https://support.google.com/websearch/answer/7368877)。\n\n## 为什么会看到某些不当的联想词?\n\nGoogle 拥有专门设计的系统,可以自动捕获不适当的预测结果而不显示出来。然而,Google 每天需要处理数十亿次搜索,这意味着 Google 每天会显示数十亿甚至上百亿条预测。再好的系统,也可能存在缺陷,不正确的预测也可能随时会出现。\n\n我们作为 Google 搜索的用户,如果认定某条预测违反了相关的搜索自动补全政策,可以进行举报反馈,点击右下角“**举报不当的联想查询**”并勾选相关选项即可。\n\n![](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/md/images/1648303098026-cac215dc-42c9-462a-a359-dcfb12ed3234.gif)\n\n## 如何实现自动补全算法?\n\n目前,Google 官方似乎并没有公开搜索自动补全的算法实现,但是业界在这方面已经有了不少研究。\n\n一个好的自动补全器必须是快速的,并且在用户键入下一个字符后立即更新联想词列表。**自动补全器的核心是一个函数,它接受输入的前缀,并搜索以给定前缀开头的词汇或语句列表**。通常来说,只需要返回少量的数目即可。\n\n接下来,我们先从一个简单且低效的实现开始,并在此基础上逐步构建更高效的方法。\n\n### 词汇表实现\n\n一个**简单粗暴的实现方式**是:顺序查找词汇表,依次检查每个词汇,看它是否以给定的前缀开头。\n\n但是,此方法需要将前缀与每个词汇进行匹配检查,若词汇量较少,这种方式可能勉强行得通。但是,如果词汇量规模较大,效率就太低了。\n\n一个**更好的实现方式是**:让词汇按字典顺序排序。借助二分搜索算法,可以快速搜索有序词汇表中的前缀。由于二分搜索的每一步都会将搜索的范围减半,因此,总的搜索时间与词汇表中单词数量的对数成正比,即时间复杂度是 `O(log N)`。二分搜索的性能很好,但有没有更好的实现呢?当然有,往下看。\n\n### 前缀树实现\n\n通常来说,许多词汇都以相同的前缀开头,比如 `need`、`nested` 都以 `ne` 开头,`seed`、`speed` 都以 `s` 开头。要是为每个单词分别存储公共前缀似乎很浪费。\n\n\n![](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/md/images/1648303128008-93cf798d-2662-4eec-8f80-2e07436aebfe.png)\n\n\n前缀树是一种利用公共前缀来加速补全速度的数据结构。前缀树在节点树中排列一组单词,单词沿着从根节点到叶子节点的路径存储,树的层次对应于前缀的字母位置。\n\n前缀的补全是顺着前缀定义的路径来查找的。例如,在上图的前缀树中,前缀 `ne` 对应于从子节点取左边缘 `N` 和唯一边缘 `E` 的路径。然后可以通过继续遍历从 `E` 节点可以达到的所有叶节点来生成补全列表。在图中,`ne` 的补全可以是两个分支:`-ed` 和 `-sted`。如果在数中找不到由前缀定义的路径,则说明词汇表中不包含以该前缀开头的单词。\n\n### 有限状态自动机(DFA)实现\n\n前缀树可以有效处理公共前缀,但是,对于其他共享词部分,仍会分别存储在每个分支中。比如,后缀 `ed`、`ing`、`tion` 在英文单词中特别常见。在上一个例子中,`e`、`d` 分别存放在了每一个分支上。\n\n有没有一种方法可以更加节省存储空间呢?有的,那就是 DFA。\n\n\n\n\n在上面的例子中,单词 `need`、`nested`、`seed` 和 `speed` 仅由 9 个节点组成,而上一张图中的前缀树包含了 17 个节点。\n\n可以看出,最小化前缀树 DFA 可以在很大程度上减少数据结构的大小。即使词汇量很大,最小化 DFA 通常也适合在内存中存储,避免昂贵的磁盘访问是实现快速自动补全的关键。\n\n### 一些扩展\n\n上面介绍了如何利用合理的数据结构实现基本的自动补全功能。这些数据结构可以通过多种方式进行扩展,从而改善用户体验。\n\n通常,满足特定前缀的词汇可能很多,而用户界面上能够显示的却不多,我们更希望能显示最常搜索或者最有价值的词汇。这通常可以通过为词汇表中的每个单词增加一个代表单词值的**权重** `weight`,并且按照权重高低来排序自动补全列表。\n\n- 对于排序后的词汇表来说,在词汇表每个元素上增加 `weight` 属性并不难;\n- 对于前缀树来说,将 `weight` 存储在叶子节点中,也是很简单的一个实现;\n- 对于 `DFA` 来说,则较为复杂。因为一个叶子节点可以通过多条路径到达。一种解决方案是将权重关联到路径而不是叶子节点。\n\n目前有不少开源库都提供了这个功能,比如主流的搜索引擎框架 [Elasticsearch](https://www.elastic.co/products/elasticsearch)、[Solr](https://lucene.apache.org/solr/) 等,基于此,我们可以实现高效而强大的自动补全功能。\n\n#### 推荐阅读\n\n- [阿里又一个 20k+ stars 开源项目诞生,恭喜 fastjson!](https://mp.weixin.qq.com/s/RNKDCK2KoyeuMeEs6GUrow)\n- [刷掉 90% 候选人的互联网大厂海量数据面试题(附题解 + 方法总结)](https://mp.weixin.qq.com/s/rjGqxUvrEqJNlo09GrT1Dw)\n- [好用!期待已久的文本块功能究竟如何在 Java 13 中发挥作用?](https://mp.weixin.qq.com/s/kalGv5T8AZGxTnLHr2wDsA)\n- [2019 GitHub 开源贡献排行榜新鲜出炉!微软谷歌领头,阿里跻身前 12!](https://mp.weixin.qq.com/s/_q812aGD1b9QvZ2WFI0Qgw)\n\n---\n\n欢迎关注我的公众号“**Doocs**”,原创技术文章第一时间推送。\n\n\n \n\n',k="/*\n 按Ctrl+F可格式化\n*/\n/* 一级标题样式 */\nh1 {\n}\n/* 二级标题样式 */\nh2 {\n}\n/* 三级标题样式 */\nh3 {\n}\n/* 四级标题样式 */\nh4 {\n}\n/* 图片样式 */\nimage {\n}\n/* 引用样式 */\nblockquote {\n}\n/* 引用段落样式 */\nblockquote_p {\n}\n/* 段落样式 */\np {\n}\n/* 分割线样式 */\nhr {\n}\n/* 行内代码样式 */\ncodespan {\n}\n/* 粗体样式 */\nstrong {\n}\n/* 链接样式 */\nlink {\n}\n/* 微信链接样式 */\nwx_link {\n}\n/* 有序列表样式 */\nol {\n}\n/* 无序列表样式 */\nul {\n}\n/* 列表项样式 */\nli {\n}\n/* 代码块样式 */\ncode {\n}\n",S=o("325b"),y=o.n(S),v=o("d238"),w=o.n(v),O=o("4fc3"),x=o.n(O);let $="#3f3f3f";var E={BASE:{"text-align":"left","line-height":"1.75"},block:{h1:{"font-size":"1.2em","text-align":"center","font-weight":"bold",display:"table",margin:"2em auto 1em",padding:"0 1em","border-bottom":"2px solid rgba(0, 152, 116, 0.9)",color:$},h2:{"font-size":"1.2em","text-align":"center","font-weight":"bold",display:"table",margin:"4em auto 2em",padding:"0 0.2em",background:"rgba(0, 152, 116, 0.9)",color:"#fff"},h3:{"font-weight":"bold","font-size":"1.1em",margin:"2em 8px 0.75em 0","line-height":"1.2","padding-left":"8px","border-left":"3px solid rgba(0, 152, 116, 0.9)",color:$},h4:{"font-weight":"bold","font-size":"1em",margin:"2em 8px 0.5em",color:"rgba(66, 185, 131, 0.9)"},p:{margin:"1.5em 8px","letter-spacing":"0.1em",color:$},blockquote:{"font-style":"normal","border-left":"none",padding:"1em","border-radius":"8px",color:"rgba(0,0,0,0.5)",background:"#f7f7f7",margin:"2em 8px"},blockquote_p:{"letter-spacing":"0.1em",color:"rgb(80, 80, 80)","font-size":"1em",display:"block"},code_pre:{"font-size":"14px","overflow-x":"auto","border-radius":"8px",padding:"1em","line-height":"1.5",margin:"10px 8px"},code:{margin:0,"white-space":"nowrap","font-family":"Menlo, Operator Mono, Consolas, Monaco, monospace"},image:{"border-radius":"4px",display:"block",margin:"0.1em auto 0.5em",width:"100% !important"},ol:{"margin-left":"0","padding-left":"1em",color:$},ul:{"margin-left":"0","padding-left":"1em","list-style":"circle",color:$},footnotes:{margin:"0.5em 8px","font-size":"80%",color:$},figure:{margin:"1.5em 8px",color:$},hr:{"border-style":"solid","border-width":"1px 0 0","border-color":"rgba(0,0,0,0.1)","-webkit-transform-origin":"0 0","-webkit-transform":"scale(1, 0.5)","transform-origin":"0 0",transform:"scale(1, 0.5)"}},inline:{listitem:{"text-indent":"-1em",display:"block",margin:"0.2em 8px",color:$},codespan:{"font-size":"90%",color:"#d14",background:"rgba(27,31,35,.05)",padding:"3px 5px","border-radius":"4px","word-break":"break-all"},link:{color:"#576b95"},wx_link:{color:"#576b95","text-decoration":"none"},strong:{color:"rgba(15, 76, 129, 0.9)","font-weight":"bold"},table:{"border-collapse":"collapse","text-align":"center",margin:"1em 8px",color:$},thead:{background:"rgba(0, 0, 0, 0.05)","font-weight":"bold",color:$},td:{border:"1px solid #dfdfdf",padding:"0.25em 0.5em",color:$},footnote:{"font-size":"12px",color:$},figcaption:{"text-align":"center",color:"#888","font-size":"0.8em"}}};const T=(e,t)=>{const o=JSON.parse(JSON.stringify(e));return o.block.h1["border-bottom"]="2px solid "+t,o.block.h2["background"]=t,o.block.h3["border-left"]="3px solid "+t,o.block.h4["color"]=t,o.inline.strong["color"]=t,o};function M(e){return t=>T(e,t)}function I(e,t){return T(e,t)}function D(e){return function(t){const o=JSON.parse(JSON.stringify(e));return o.block.h1["font-size"]=1.14*t+"px",o.block.h2["font-size"]=1.1*t+"px",o.block.h3["font-size"]=t+"px",o.block.h4["font-size"]=t+"px",o}}const A=M(E),P=D(E);function R(e,t,o){const i=T(o,t);return i.block.h1=Object.assign(i.block.h1,e.h1),i.block.h2=Object.assign(i.block.h2,e.h2),i.block.h3=Object.assign(i.block.h3,e.h3),i.block.h4=Object.assign(i.block.h4,e.h4),i.block.code=Object.assign(i.block.code,e.code),i.block.p=Object.assign(i.block.p,e.p),i.block.hr=Object.assign(i.block.hr,e.hr),i.block.blockquote=Object.assign(i.block.blockquote,e.blockquote),i.block.blockquote_p=Object.assign(i.block.blockquote_p,e.blockquote_p),i.block.image=Object.assign(i.block.image,e.image),i.inline.strong=Object.assign(i.inline.strong,e.strong),i.inline.codespan=Object.assign(i.inline.codespan,e.codespan),i.inline.link=Object.assign(i.inline.link,e.link),i.inline.wx_link=Object.assign(i.inline.wx_link,e.wx_link),i.block.ul=Object.assign(i.block.ul,e.ul),i.block.ol=Object.assign(i.block.ol,e.ol),i.inline.listitem=Object.assign(i.inline.listitem,e.li),i}function K(e){let t,o;while(-1!==(t=e.indexOf("/*"))&&-1!==(o=e.indexOf("*/")))e=e.substring(0,t)+e.substring(o+2);let i={};while(e.length>0&&-1!==e.indexOf("{")&&-1!==e.indexOf("}")){const t=e.indexOf("{"),o=e.indexOf("}");function n(e){let t={};return e.forEach(e=>{const o=e.indexOf(":"),i=e.substring(0,o).trim();t[i]=e.substring(o+1).trim()}),t}let s=e.substring(t+1,o).split(";").map(e=>e.trim()).filter(e=>e.length>0);s=n(s);let r=e.substring(0,t).split(",").map(e=>e.trim());r.forEach(e=>{i[e]||(i[e]={}),Object.keys(s).forEach(t=>{i[e][t]=s[t]})}),e=e.slice(o+1).trim()}return i}function j(e,t){const o=e.getValue(0);o?localStorage.setItem(t,o):localStorage.removeItem(t)}function L(e){return y.a.format(e,{parser:"markdown",plugins:[x.a]})}function U(e){return y.a.format(e,{parser:"css",plugins:[w.a]})}function q(e){const t=document.createElement("a");t.download="content.md",t.style.display="none";const o=new Blob([e]);t.href=URL.createObjectURL(o),document.body.appendChild(t),t.click(),document.body.removeChild(t)}function B(){const e=document.querySelector("#output");n(e);const t=e.innerHTML,o=document.createElement("a");o.download="content.html",o.style.display="none";let i=new Blob([`${t}
`]);function n(e){function t(e,t=["width","height"]){const o=getComputedStyle(e,null);return Object.entries(o).filter(([e])=>o.getPropertyValue(e)&&!t.includes(e)).map(([e,t])=>`${e}:${t};`).join("")}switch(!0){case o(e):case i(e):case s(e):e.setAttribute("style",t(e));default:}function o(e){return"PRE"===e.tagName&&Array.from(e.classList).includes("code__pre")}function i(e){return"CODE"===e.tagName&&Array.from(e.classList).includes("prettyprint")}function s(e){return"SPAN"===e.tagName&&(i(e.parentElement)||i(e.parentElement.parentElement))}e.children.length&&Array.from(e.children).forEach(e=>n(e))}o.href=URL.createObjectURL(i),document.body.appendChild(o),o.click(),document.body.removeChild(o)}function F({data:e,rows:t,cols:o}){let i="";for(let n=0;n1?n-1:n;t.push(1===n?"---":e[`k_${o}_${i}`]||" ")}i+=t.join(" | "),i+=" |\n"}return i}function z(e){return new Promise((t,o)=>{const i=new FileReader;i.readAsDataURL(e),i.onload=()=>t(i.result.split(",").pop()),i.onerror=e=>o(e)})}function H(e){const t=/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(e.name);if(!t)return{ok:!1,msg:"请上传 JPG/PNG/GIF 格式的图片"};const o=10,i=e.size/1024/1024<=o;return i?{ok:!0}:{ok:!1,msg:`由于公众号限制,图片大小不能超过 ${o}M`}}function G(e){const t=e.split("\n"),o=t.filter(e=>e.trim()).map(e=>e.match(/(^\s+)?/)[0].length).sort((e,t)=>e-t)[0];return t.map(e=>e.slice(o)).join("\n")}i["default"].use(d["a"]);const N={wxRenderer:null,output:"",html:"",editor:null,cssEditor:null,currentFont:"",currentSize:"",currentColor:"",citeStatus:0,nightMode:!1,codeTheme:u.codeThemeOption[0].value,rightClickMenuVisible:!1},V={setEditorValue(e,t){e.editor.setValue(t)},setCssEditorValue(e,t){e.cssEditor.setValue(t)},setWxRendererOptions(e,t){e.wxRenderer.setOptions(t)},setCiteStatus(e,t){e.citeStatus=t,localStorage.setItem("citeStatus",t)},setCurrentFont(e,t){e.currentFont=t,localStorage.setItem("fonts",t)},setCurrentSize(e,t){e.currentSize=t,localStorage.setItem("size",t)},setCurrentColor(e,t){e.currentColor=t,localStorage.setItem("color",t)},setCurrentCodeTheme(e,t){e.codeTheme=t,localStorage.setItem("codeTheme",t)},setRightClickMenuVisible(e,t){e.rightClickMenuVisible=t},themeChanged(e){e.nightMode=!e.nightMode,localStorage.setItem("nightMode",e.nightMode)},initEditorState(e){e.currentFont=localStorage.getItem("fonts")||u.builtinFonts[0].value,e.currentColor=localStorage.getItem("color")||u.colorOption[0].value,e.currentSize=localStorage.getItem("size")||u.sizeOption[2].value,e.codeTheme=localStorage.getItem("codeTheme")||u.codeThemeOption[0].value,e.citeStatus="true"===localStorage.getItem("citeStatus"),e.nightMode="true"===localStorage.getItem("nightMode"),e.wxRenderer=new g({theme:A(e.currentColor),fonts:e.currentFont,size:e.currentSize})},initEditorEntity(e){const t=document.getElementById("editor");t.value||(t.value=localStorage.getItem("__editor_content")||L(C)),e.editor=_.a.fromTextArea(t,{mode:"text/x-markdown",theme:"xq-light",lineNumbers:!1,lineWrapping:!0,styleActiveLine:!0,autoCloseBrackets:!0,extraKeys:{"Ctrl-F":function(e){const t=L(e.getValue(0));localStorage.setItem("__editor_content",t),e.setValue(t)},"Ctrl-S":function(e){},"Ctrl-B":function(e){const t=e.getSelection();e.replaceSelection(`**${t}**`)},"Ctrl-D":function(e){const t=e.getSelection();e.replaceSelection(`~~${t}~~`)},"Ctrl-I":function(e){const t=e.getSelection();e.replaceSelection(`*${t}*`)}}})},initCssEditorEntity(e){const t=document.getElementById("cssEditor");t.value||(t.value=localStorage.getItem("__css_content")||k),e.cssEditor=_.a.fromTextArea(t,{mode:"css",theme:"style-mirror",lineNumbers:!1,lineWrapping:!0,matchBrackets:!0,autofocus:!0,extraKeys:{"Ctrl-F":function(e){const t=U(e.getValue(0));localStorage.setItem("__css_content",t),e.setValue(t)},"Ctrl-S":function(e){}}})},editorRefresh(e){let t=e.wxRenderer.getRenderer(e.citeStatus);m["marked"].setOptions({renderer:t});let o=m["marked"].parse(e.editor.getValue(0));o=o.replace(/(style=".*?)"/,'$1;margin-top: 0"'),e.citeStatus&&(o+=e.wxRenderer.buildFootnotes(),o+=e.wxRenderer.buildAddition()),e.output=o}};var W=new d["a"].Store({state:N,mutations:V,actions:{}}),Q=o("5c96"),J=o.n(Q);o("0fae");i["default"].component(Q["Message"].name,Q["Message"]),i["default"].prototype.$loading=Q["Loading"].service,i["default"].prototype.$message=Q["Message"];o("a7be"),o("8d7e"),o("7b00"),o("959b"),o("10b2"),o("8c33"),o("31c5"),o("9b74"),o("111b");var Y=o("8c4f"),Z=function(){var e=this,t=e._self._c;return t("codemirror-editor")},X=[],ee=function(){var e=this,t=e._self._c;return t("div",{staticClass:"container",class:{container_night:e.nightMode},on:{keydown:[function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"k",void 0,t.key,void 0)?null:t.altKey&&t.shiftKey?void e.addFormat("[","]()"):null},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"u",void 0,t.key,void 0)?null:t.altKey&&t.shiftKey?e.addFormat("~~"):null},function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"l",void 0,t.key,void 0)?null:t.ctrlKey&&t.altKey?e.formatContent():null}]}},[t("el-container",[t("el-header",{staticClass:"editor__header"},[t("editor-header",{ref:"header",on:{addFormat:e.addFormat,formatContent:e.formatContent,refresh:e.onEditorRefresh,cssChanged:e.cssChanged,"import-md":e.importMD,download:e.downloadEditorContent,export:e.exportEditorContent,showCssEditor:function(t){e.showCssEditor=!e.showCssEditor},"show-about-dialog":function(t){e.aboutDialogVisible=!0},"show-dialog-form":function(t){e.dialogFormVisible=!0},"show-dialog-upload-img":function(t){e.dialogUploadImgVisible=!0},startCopy:function(t){e.isCoping=!0,e.backLight=!0},endCopy:e.endCopy}})],1),t("el-main",{staticClass:"main-body"},[t("el-row",{staticClass:"main-section"},[t("el-col",{ref:"codeMirrorWrapper",staticClass:"codeMirror-wrapper",attrs:{span:12},nativeOn:{contextmenu:function(t){return t.preventDefault(),e.openMenu(t)}}},[t("textarea",{directives:[{name:"model",rawName:"v-model",value:e.source,expression:"source"}],attrs:{id:"editor",type:"textarea",placeholder:"Your markdown text here."},domProps:{value:e.source},on:{input:function(t){t.target.composing||(e.source=t.target.value)}}})]),t("el-col",{ref:"preview",staticClass:"preview-wrapper",class:{"preview-wrapper_night":e.nightMode&&e.isCoping},attrs:{span:12,id:"preview"}},[t("section",{class:{output_night:e.nightMode&&!e.backLight},attrs:{id:"output-wrapper"}},[t("div",{staticClass:"preview"},[t("section",{attrs:{id:"output"},domProps:{innerHTML:e._s(e.output)}}),e.nightMode&&e.isCoping?t("div",{staticClass:"loading-mask"},[t("div",{staticClass:"loading__img"}),t("span",[e._v("正在生成")])]):e._e()])])]),t("transition",{attrs:{name:"custom-classes-transition","enter-active-class":"bounceInRight"}},[t("el-col",{directives:[{name:"show",rawName:"v-show",value:e.showCssEditor,expression:"showCssEditor"}],staticClass:"cssEditor-wrapper",attrs:{id:"cssBox",span:12}},[t("textarea",{attrs:{id:"cssEditor",type:"textarea",placeholder:"Your custom css here."}})])],1)],1)],1)],1),t("upload-img-dialog",{on:{close:function(t){e.dialogUploadImgVisible=!1},beforeUpload:e.beforeUpload,uploadImage:e.uploadImage,uploaded:e.uploaded},model:{value:e.dialogUploadImgVisible,callback:function(t){e.dialogUploadImgVisible=t},expression:"dialogUploadImgVisible"}}),t("about-dialog",{model:{value:e.aboutDialogVisible,callback:function(t){e.aboutDialogVisible=t},expression:"aboutDialogVisible"}}),t("insert-form-dialog",{model:{value:e.dialogFormVisible,callback:function(t){e.dialogFormVisible=t},expression:"dialogFormVisible"}}),t("right-click-menu",{attrs:{left:e.mouseLeft,top:e.mouseTop},on:{menuTick:e.onMenuEvent,closeMenu:e.closeRightClickMenu},model:{value:e.rightClickMenuVisible,callback:function(t){e.rightClickMenuVisible=t},expression:"rightClickMenuVisible"}}),t("run-loading")],1)},te=[],oe=(o("a1f0"),function(){var e=this,t=e._self._c;return t("el-container",{staticClass:"top is-dark"},[t("el-dialog",{attrs:{title:"发布",visible:e.form.dialogVisible},on:{"update:visible":function(t){return e.$set(e.form,"dialogVisible",t)}}},[t("div",{staticClass:"postInfo"},[t("el-form",{ref:"form",attrs:{model:e.form,"label-width":"80px"}},[t("el-form-item",{attrs:{label:"封面"}},[t("el-input",{attrs:{placeholder:"自动提取第一张图"},model:{value:e.form.thumb,callback:function(t){e.$set(e.form,"thumb",t)},expression:"form.thumb"}})],1),t("el-form-item",{attrs:{label:"标题"}},[t("el-input",{attrs:{placeholder:"自动提取第一个标题"},model:{value:e.form.title,callback:function(t){e.$set(e.form,"title",t)},expression:"form.title"}})],1),t("el-form-item",{attrs:{label:"描述"}},[t("el-input",{attrs:{type:"textarea",rows:4,placeholder:"自动提取第一个段落"},model:{value:e.form.desc,callback:function(t){e.$set(e.form,"desc",t)},expression:"form.desc"}})],1),t("el-form-item",[t("div",{staticClass:"info"},[e._v(" 注:此功能由第三方浏览器插件支持,本平台不保证安全性。 ")])])],1)],1),t("span",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[t("el-button",{on:{click:function(t){e.form.dialogVisible=!1}}},[e._v("取 消")]),t("el-button",{attrs:{type:"primary"},on:{click:e.post}},[e._v("确 定")])],1)]),t("div",{staticClass:"left-side"},[t("el-dropdown",[t("span",{staticClass:"el-dropdown-link"},[e._v(" 文件"),t("i",{staticClass:"el-icon-arrow-down el-icon--right"})]),t("el-dropdown-menu",{attrs:{slot:"dropdown"},slot:"dropdown"},[t("el-dropdown-item",{nativeOn:{click:function(t){return e.refClick.apply(null,arguments)}}},[t("i",{staticClass:"el-icon-upload2",attrs:{size:"medium"}}),e._v(" 导入 .md "),t("input",{ref:"fileInput",attrs:{hidden:"",type:"file",accept:".md"}})]),t("el-dropdown-item",{nativeOn:{click:function(t){return e.$emit("download")}}},[t("i",{staticClass:"el-icon-download",attrs:{size:"medium"}}),e._v(" 导出 .md ")]),t("el-dropdown-item",{nativeOn:{click:function(t){return e.$emit("export")}}},[t("i",{staticClass:"el-icon-document",attrs:{size:"medium"}}),e._v(" 导出 .html ")]),t("el-dropdown-item",{attrs:{divided:""},nativeOn:{click:function(t){return e.themeChanged.apply(null,arguments)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.nightMode?1:0}}),e._v(" 暗黑模式 ")])],1)],1),t("el-dropdown",[t("span",{staticClass:"el-dropdown-link"},[e._v(" 格式"),t("i",{staticClass:"el-icon-arrow-down el-icon--right"})]),t("el-dropdown-menu",{attrs:{slot:"dropdown"},slot:"dropdown"},[t("el-dropdown-item",{staticClass:"format-item",nativeOn:{click:function(t){return e.$emit("addFormat","**")}}},[e._v(" 加粗 "),t("kbd",[e._v(" Ctrl + B ")])]),t("el-dropdown-item",{staticClass:"format-item",nativeOn:{click:function(t){return e.$emit("addFormat","*")}}},[e._v(" 斜体 "),t("kbd",[e._v(" Ctrl + I ")])]),t("el-dropdown-item",{staticClass:"format-item",nativeOn:{click:function(t){return e.$emit("addFormat","~~")}}},[e._v(" 删除线 "),t("kbd",[e._v(" Alt + Shift + U ")])]),t("el-dropdown-item",{staticClass:"format-item",nativeOn:{click:function(t){e.$emit("addFormat","[","]()")}}},[e._v(" 超链接 "),t("kbd",[e._v(" Alt + Shift + K ")])]),t("el-dropdown-item",{staticClass:"format-item",nativeOn:{click:function(t){return e.$emit("formatContent")}}},[e._v(" 格式化 "),t("kbd",[e._v(" Ctrl + Alt + L ")])]),t("el-dropdown-item",{attrs:{divided:""},nativeOn:{click:function(t){return e.statusChanged.apply(null,arguments)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.citeStatus?1:0}}),e._v(" 微信外链转底部引用 ")])],1)],1),t("el-dropdown",[t("span",{staticClass:"el-dropdown-link"},[e._v(" 编辑"),t("i",{staticClass:"el-icon-arrow-down el-icon--right"})]),t("el-dropdown-menu",{attrs:{slot:"dropdown"},slot:"dropdown"},[t("el-dropdown-item",{nativeOn:{click:function(t){return e.$emit("show-dialog-upload-img")}}},[t("i",{staticClass:"el-icon-upload",attrs:{size:"medium"}}),e._v(" 上传图片 ")]),t("el-dropdown-item",{nativeOn:{click:function(t){return e.$emit("show-dialog-form")}}},[t("i",{staticClass:"el-icon-s-grid",attrs:{size:"medium"}}),e._v(" 插入表格 ")])],1)],1),t("el-dropdown",[t("span",{staticClass:"el-dropdown-link"},[e._v(" 样式"),t("i",{staticClass:"el-icon-arrow-down el-icon--right"})]),t("el-dropdown-menu",{attrs:{slot:"dropdown"},slot:"dropdown"},[t("el-dropdown-item",{staticClass:"padding-left-3"},[t("el-dropdown",{staticClass:"style-option-menu",attrs:{placement:"right"}},[t("div",{staticClass:"el-dropdown-link"},[e._v(" 字体 "),t("i",{staticClass:"el-icon-arrow-right el-icon--right"})]),t("el-dropdown-menu",{staticStyle:{width:"200px"},attrs:{slot:"dropdown"},slot:"dropdown"},e._l(e.config.builtinFonts,(function(o){return t("el-dropdown-item",{key:o.value,style:{fontFamily:o.value},attrs:{label:o.label,value:o.value},nativeOn:{click:function(t){return e.fontChanged(o.value)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.selectFont===o.value?1:0}}),t("span",[e._v(e._s(o.label))]),t("span",{staticClass:"select-item-right"},[e._v("Abc")])])})),1)],1)],1),t("el-dropdown-item",{staticClass:"padding-left-3"},[t("el-dropdown",{staticClass:"style-option-menu",attrs:{placement:"right"}},[t("div",{staticClass:"el-dropdown-link"},[e._v(" 字号 "),t("i",{staticClass:"el-icon-arrow-right el-icon--right"})]),t("el-dropdown-menu",{staticStyle:{width:"200px"},attrs:{slot:"dropdown"},slot:"dropdown"},e._l(e.config.sizeOption,(function(o){return t("el-dropdown-item",{key:o.value,attrs:{label:o.label,value:o.value},nativeOn:{click:function(t){return e.sizeChanged(o.value)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.selectSize===o.value?1:0}}),t("span",[e._v(e._s(o.label))]),t("span",{staticClass:"select-item-right"},[e._v(e._s(o.desc))])])})),1)],1)],1),t("el-dropdown-item",{staticClass:"padding-left-3"},[t("el-dropdown",{staticClass:"style-option-menu",attrs:{placement:"right"}},[t("div",{staticClass:"el-dropdown-link"},[e._v(" 颜色 "),t("i",{staticClass:"el-icon-arrow-right el-icon--right"})]),t("el-dropdown-menu",{staticStyle:{width:"200px"},attrs:{slot:"dropdown"},slot:"dropdown"},e._l(e.config.colorOption,(function(o){return t("el-dropdown-item",{key:o.value,attrs:{label:o.label,value:o.value},nativeOn:{click:function(t){return e.colorChanged(o.value)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.selectColor===o.value?1:0}}),t("span",[e._v(e._s(o.label))]),t("span",{staticClass:"select-item-right"},[e._v(e._s(o.desc))])])})),1)],1)],1),t("el-dropdown-item",{staticClass:"padding-left-3"},[t("el-dropdown",{staticClass:"style-option-menu",attrs:{placement:"right"}},[t("div",{staticClass:"el-dropdown-link"},[e._v(" 代码主题 "),t("i",{staticClass:"el-icon-arrow-right el-icon--right"})]),t("el-dropdown-menu",{staticStyle:{width:"200px"},attrs:{slot:"dropdown"},slot:"dropdown"},e._l(e.config.codeThemeOption,(function(o){return t("el-dropdown-item",{key:o.value,attrs:{label:o.label,value:o.value},nativeOn:{click:function(t){return e.codeThemeChanged(o.value)}}},[t("i",{staticClass:"el-icon-check",style:{opacity:e.selectCodeTheme===o.value?1:0}}),t("span",[e._v(e._s(o.label))]),t("span",{staticClass:"select-item-right"},[e._v(e._s(o.desc))])])})),1)],1)],1),t("el-dropdown-item",{staticClass:"padding-left-3",attrs:{divided:""},nativeOn:{click:function(t){return e.showPicker()}}},[e._v(" 自定义颜色 "),t("el-color-picker",{ref:"colorPicker",staticStyle:{float:"right","margin-top":"3px"},attrs:{"show-alpha":"",size:"mini"},on:{change:e.colorChanged},model:{value:e.selectColor,callback:function(t){e.selectColor=t},expression:"selectColor"}})],1),t("el-dropdown-item",{staticClass:"padding-left-3",nativeOn:{click:function(t){return e.customStyle.apply(null,arguments)}}},[e._v(" 自定义 CSS ")]),t("el-dropdown-item",{staticClass:"padding-left-3",attrs:{divided:""},nativeOn:{click:function(t){e.showResetConfirm=!0}}},[e._v(" 重置 ")])],1)],1),t("el-dropdown",[t("span",{staticClass:"el-dropdown-link"},[e._v(" 帮助"),t("i",{staticClass:"el-icon-arrow-down el-icon--right"})]),t("el-dropdown-menu",{attrs:{slot:"dropdown"},slot:"dropdown"},[t("el-dropdown-item",{nativeOn:{click:function(t){return e.$emit("show-about-dialog")}}},[e._v(" 关于 ")])],1)],1)],1),t("div",{staticClass:"right-side"},[t("el-button",{attrs:{type:e.btnType,plain:"",size:"medium",placement:"bottom-start"},on:{click:e.copy}},[e._v("复制 ")]),t("el-button",{attrs:{type:e.btnType,plain:"",size:"medium",placement:"bottom-start"},on:{click:e.prePost}},[e._v("发布 ")])],1),t("reset-dialog",{attrs:{showResetConfirm:e.showResetConfirm},on:{confirm:e.confirmReset,close:e.cancelReset}})],1)}),ie=[],ne=o("466b"),se=o.n(ne);function re(){const e=document.getElementById("output"),t=e.getElementsByTagName("img");for(let o=0;oe.nightMode})}},ue=de,me=(o("0d32"),Object(r["a"])(ue,le,ce,!1,null,"dab43504",null)),pe=me.exports,fe={name:"editor-header",data(){return{form:{dialogVisible:!1,title:"",desc:"",thumb:"",content:""},config:u,citeStatus:!1,showResetConfirm:!1,selectFont:"",selectSize:"",selectColor:"",selectCodeTheme:u.codeThemeOption[0].value}},components:{ResetDialog:pe},computed:{effect(){return this.nightMode?"dark":"light"},btnContent(){return this.nightMode?"浅色模式":"暗黑模式"},btnType(){return this.nightMode?"default":"primary"},...Object(d["c"])({output:e=>e.output,editor:e=>e.editor,cssEditor:e=>e.cssEditor,currentFont:e=>e.currentFont,currentSize:e=>e.currentSize,currentColor:e=>e.currentColor,codeTheme:e=>e.codeTheme,nightMode:e=>e.nightMode,currentCiteStatus:e=>e.citeStatus})},methods:{refClick(){this.$refs.fileInput.click()},showPicker(){this.$refs.colorPicker.showPicker=!0},prePost(){let e={};try{e={thumb:document.querySelector("#output img").src,title:[1,2,3,4,5,6].map(e=>document.querySelector("#output h"+e)).filter(e=>e)[0].innerText,desc:document.querySelector("#output p").innerText,content:this.output}}catch(t){console.log("error",t)}this.form={dialogVisible:!0,...e,auto:e}},post(){this.form.dialogVisible=!1,window.syncPost({title:this.form.title||this.form.auto.title,desc:this.form.desc||this.form.auto.desc,content:this.form.content||this.form.auto.content,thumb:this.form.thumb||this.form.auto.thumb})},fontChanged(e){this.setWxRendererOptions({fonts:e}),this.setCurrentFont(e),this.selectFont=e,this.$emit("refresh")},sizeChanged(e){let t=P(e.replace("px",""));t=I(t,this.currentColor),this.setWxRendererOptions({size:e,theme:t}),this.setCurrentSize(e),this.selectSize=e,this.$emit("refresh")},colorChanged(e){let t=P(this.currentSize.replace("px",""));t=I(t,e),this.setWxRendererOptions({theme:t}),this.setCurrentColor(e),this.selectColor=e,this.$emit("refresh")},codeThemeChanged(e){this.setCurrentCodeTheme(e),this.selectCodeTheme=e,this.$emit("refresh")},statusChanged(){this.citeStatus=!this.citeStatus,this.setCiteStatus(this.citeStatus),this.$emit("refresh")},copy(e){this.$emit("startCopy"),setTimeout(()=>{let e=document.getElementById("output");re(),ae(),e.focus(),window.getSelection().removeAllRanges();let t=document.createRange();t.setStartBefore(e.firstChild),t.setEndAfter(e.lastChild),window.getSelection().addRange(t),document.execCommand("copy"),window.getSelection().removeAllRanges(),e.innerHTML=this.output,this.$notify({showClose:!0,message:"已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴",offset:80,duration:1600,type:"success"}),this.$emit("refresh"),this.$emit("endCopy")},350)},async customStyle(){this.$emit("showCssEditor"),this.$nextTick(()=>{this.cssEditor||this.cssEditor.refresh()}),setTimeout(()=>{this.cssEditor.refresh()},50);let e=localStorage.getItem("__css_content");e||this.setCssEditorValue(k)},confirmReset(){localStorage.clear(),this.cssEditor.setValue(k),this.citeStatus=!1,this.statusChanged(!1),this.fontChanged(this.config.builtinFonts[0].value),this.colorChanged(this.config.colorOption[0].value),this.sizeChanged(this.config.sizeOption[2].value),this.codeThemeChanged(this.config.codeThemeOption[0].value),this.$emit("cssChanged"),this.selectFont=this.currentFont,this.selectSize=this.currentSize,this.selectColor=this.currentColor,this.showResetConfirm=!1,this.selectCodeTheme=this.codeTheme},cancelReset(){this.showResetConfirm=!1,this.editor.focus()},...Object(d["b"])(["setCurrentColor","setCiteStatus","themeChanged","setCurrentFont","setCurrentSize","setCssEditorValue","setCurrentCodeTheme","setWxRendererOptions"])},mounted(){this.selectFont=this.currentFont,this.selectSize=this.currentSize,this.selectColor=this.currentColor,this.selectCodeTheme=this.codeTheme,this.citeStatus=this.currentCiteStatus;const e=this.$refs.fileInput;e.onchange=()=>{const t=e.files[0];if(null==t)return;const o=new FileReader;o.readAsText(t),o.onload=()=>{this.$emit("import-md",o.result)}}}},he=fe,ge=(o("9271"),Object(r["a"])(he,oe,ie,!1,null,"b521a8fa",null)),be=ge.exports,_e=function(){var e=this,t=e._self._c;return t("el-dialog",{staticClass:"about__dialog",attrs:{title:"关于",visible:e.value,width:"30%",center:""},on:{close:function(t){return e.$emit("input",!1)}}},[t("div",{staticStyle:{"text-align":"center"}},[t("h3",[e._v("一款高度简洁的微信 Markdown 编辑器")]),t("p",[e._v("扫码关注公众号 Doocs,原创技术文章第一时间推送!")]),t("img",{staticStyle:{width:"40%"},attrs:{src:"https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/md/images/1648303220922-7e14aefa-816e-44c1-8604-ade709ca1c69.png"}})]),t("template",{slot:"footer"},[t("el-button",{attrs:{type:"primary",plain:""},on:{click:function(t){return e.onRedirect("https://github.com/doocs/md")}}},[e._v(" GitHub 仓库 ")]),t("el-button",{attrs:{type:"primary",plain:""},on:{click:function(t){return e.onRedirect("https://gitee.com/doocs/md")}}},[e._v(" Gitee 仓库 ")])],1)],2)},Ce=[],ke={props:{value:{type:Boolean,default:!1}},methods:{onRedirect(e){window.open(e)}}},Se=ke,ye=(o("ff58"),Object(r["a"])(Se,_e,Ce,!1,null,"50755400",null)),ve=ye.exports,we=function(){var e=this,t=e._self._c;return t("el-dialog",{staticClass:"insert__dialog",attrs:{title:"插入表格",visible:e.value,border:""},on:{close:function(t){return e.$emit("input",!1)}}},[t("el-row",{staticClass:"tb-options",attrs:{type:"flex",align:"middle",gutter:10}},[t("el-col",[e._v(" 行数: "),t("el-input-number",{attrs:{"controls-position":"right",min:1,max:100,size:"small"},model:{value:e.rowNum,callback:function(t){e.rowNum=t},expression:"rowNum"}})],1),t("el-col",[e._v(" 列数: "),t("el-input-number",{attrs:{"controls-position":"right",min:1,max:100,size:"small"},model:{value:e.colNum,callback:function(t){e.colNum=t},expression:"colNum"}})],1)],1),t("table",{staticClass:"input-table",staticStyle:{"border-collapse":"collapse"}},e._l(e.rowNum+1,(function(o){return t("tr",{key:o,class:{"head-style":1===o}},e._l(e.colNum,(function(i){return t("td",{key:i},[t("el-input",{attrs:{align:"center",placeholder:1===o?"表头":""},model:{value:e.tableData[`k_${o-1}_${i-1}`],callback:function(t){e.$set(e.tableData,`k_${o-1}_${i-1}`,t)},expression:"tableData[`k_${row - 1}_${col - 1}`]"}})],1)})),0)})),0),t("div",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[t("el-button",{attrs:{type:e.btnType,plain:""},on:{click:function(t){return e.$emit("input",!1)}}},[e._v(" 取 消 ")]),t("el-button",{attrs:{type:e.btnType,plain:""},on:{click:e.insertTable}},[e._v(" 确 定 ")])],1)],1)},Oe=[],xe={props:{value:{type:Boolean,default:!1}},data(){return{config:u,rowNum:3,colNum:3,tableData:{}}},computed:{btnType(){return this.nightMode?"default":"primary"},...Object(d["c"])({nightMode:e=>e.nightMode,editor:e=>e.editor})},methods:{insertTable(){this.editor.getCursor();const e=F({data:this.tableData,rows:this.rowNum,cols:this.colNum});this.tableData={},this.rowNum=3,this.colNum=3,this.editor.replaceSelection(`\n${e}\n`,"end"),this.$emit("input",!1),this.editorRefresh()},...Object(d["b"])(["editorRefresh"])}},$e=xe,Ee=(o("1663"),Object(r["a"])($e,we,Oe,!1,null,"0305ca08",null)),Te=Ee.exports,Me=function(){var e=this,t=e._self._c;return t("div",{directives:[{name:"show",rawName:"v-show",value:e.value,expression:"value"}],staticClass:"menu",style:`left: ${e.left}px;top: ${e.top}px;`,attrs:{id:"menu"}},e._l(e.menu,(function(o,i){return t("ul",{key:i,staticClass:"menu__group"},e._l(o,(function({key:o,text:i}){return t("li",{key:o,staticClass:"menu_item",on:{mousedown:function(t){return e.onMouseDown(o)}}},[e._v(" "+e._s(i)+" ")])})),0)})),0)},Ie=[],De={props:{value:{type:Boolean,default:!1},top:{type:Number,default:0},left:{type:Number,default:0}},data(){return{menu:[[{text:"上传图片",key:"insertPic"},{text:"插入表格",key:"insertTable"},{text:"恢复默认样式",key:"resetStyle"}],[{text:"导入 Markdown 文档",key:"importMarkdown"},{text:"导出 Markdown 文档",key:"download"},{text:"导出 HTML 页面",key:"export"},{text:"格式化 Markdown 文档",key:"formatMarkdown"}]]}},methods:{closeCB(){this.$emit("input",!1)},onMouseDown(e){this.$emit("menuTick",e),this.$emit("closeMenu",!1)}}},Ae=De,Pe=(o("d281"),Object(r["a"])(Ae,Me,Ie,!1,null,"6253096e",null)),Re=Pe.exports,Ke=function(){var e=this,t=e._self._c;return t("el-dialog",{staticClass:"upload__dialog",attrs:{title:"本地上传",visible:e.value},on:{close:function(t){return e.$emit("close")}}},[t("el-tabs",{attrs:{type:"activeName"},model:{value:e.activeName,callback:function(t){e.activeName=t},expression:"activeName"}},[t("el-tab-pane",{staticClass:"upload-panel",attrs:{label:"选择上传",name:"upload"}},[t("el-select",{attrs:{placeholder:"请选择",size:"small"},on:{change:e.changeImgHost},model:{value:e.imgHost,callback:function(t){e.imgHost=t},expression:"imgHost"}},e._l(e.options,(function(e){return t("el-option",{key:e.value,attrs:{label:e.label,value:e.value}})})),1),t("el-upload",{attrs:{drag:"",action:"",headers:{"Content-Type":"multipart/form-data"},"show-file-list":!1,multiple:!0,accept:".jpg, .jpeg, .png, .gif",name:"file","before-upload":e.beforeImageUpload,"http-request":e.uploadImage}},[t("i",{staticClass:"el-icon-upload"}),t("div",{staticClass:"el-upload__text"},[e._v(" 将图片拖到此处,或 "),t("em",[e._v("点击上传")])])])],1),t("el-tab-pane",{staticClass:"github-panel",attrs:{label:"GitHub 图床",name:"github"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.formGitHub,"label-position":"right","label-width":"140px"}},[t("el-form-item",{attrs:{label:"GitHub 仓库",required:!0}},[t("el-input",{attrs:{placeholder:"如:github.com/yanglbme/resource"},model:{value:e.formGitHub.repo,callback:function(t){e.$set(e.formGitHub,"repo","string"===typeof t?t.trim():t)},expression:"formGitHub.repo"}})],1),t("el-form-item",{attrs:{label:"分支"}},[t("el-input",{attrs:{placeholder:"如:release,可不填,默认 master"},model:{value:e.formGitHub.branch,callback:function(t){e.$set(e.formGitHub,"branch","string"===typeof t?t.trim():t)},expression:"formGitHub.branch"}})],1),t("el-form-item",{attrs:{label:"Token",required:!0}},[t("el-input",{attrs:{"show-password":"",placeholder:"如:cc1d0c1426d0fd0902bd2d7184b14da61b8abc46"},model:{value:e.formGitHub.accessToken,callback:function(t){e.$set(e.formGitHub,"accessToken","string"===typeof t?t.trim():t)},expression:"formGitHub.accessToken"}}),t("el-link",{attrs:{type:"primary",href:"https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token",target:"_blank"}},[e._v("如何获取 GitHub Token? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.saveGitHubConfiguration}},[e._v("保存配置 ")])],1)],1)],1),t("el-tab-pane",{staticClass:"github-panel",attrs:{label:"阿里云 OSS",name:"aliOSS"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.formAliOSS,"label-position":"right","label-width":"140px"}},[t("el-form-item",{attrs:{label:"AccessKey ID",required:!0}},[t("el-input",{attrs:{placeholder:"如:LTAI4GdoocsmdoxUf13ylbaNHk"},model:{value:e.formAliOSS.accessKeyId,callback:function(t){e.$set(e.formAliOSS,"accessKeyId","string"===typeof t?t.trim():t)},expression:"formAliOSS.accessKeyId"}})],1),t("el-form-item",{attrs:{label:"AccessKey Secret",required:!0}},[t("el-input",{attrs:{"show-password":"",placeholder:"如:cc1d0c142doocs0902bd2d7md4b14da6ylbabc46"},model:{value:e.formAliOSS.accessKeySecret,callback:function(t){e.$set(e.formAliOSS,"accessKeySecret","string"===typeof t?t.trim():t)},expression:"formAliOSS.accessKeySecret"}})],1),t("el-form-item",{attrs:{label:"Bucket",required:!0}},[t("el-input",{attrs:{placeholder:"如:doocs"},model:{value:e.formAliOSS.bucket,callback:function(t){e.$set(e.formAliOSS,"bucket","string"===typeof t?t.trim():t)},expression:"formAliOSS.bucket"}})],1),t("el-form-item",{attrs:{label:"Bucket 所在区域",required:!0}},[t("el-input",{attrs:{placeholder:"如:oss-cn-shenzhen"},model:{value:e.formAliOSS.region,callback:function(t){e.$set(e.formAliOSS,"region","string"===typeof t?t.trim():t)},expression:"formAliOSS.region"}})],1),t("el-form-item",{attrs:{label:"自定义 CDN 域名",required:!1}},[t("el-input",{attrs:{placeholder:"如:https://imagecdn.alidaodao.com,可不填"},model:{value:e.formAliOSS.cdnHost,callback:function(t){e.$set(e.formAliOSS,"cdnHost","string"===typeof t?t.trim():t)},expression:"formAliOSS.cdnHost"}})],1),t("el-form-item",{attrs:{label:"存储路径"}},[t("el-input",{attrs:{placeholder:"如:img,可不填,默认为根目录"},model:{value:e.formAliOSS.path,callback:function(t){e.$set(e.formAliOSS,"path","string"===typeof t?t.trim():t)},expression:"formAliOSS.path"}}),t("el-link",{attrs:{type:"primary",href:"https://help.aliyun.com/document_detail/31883.html",target:"_blank"}},[e._v("如何使用阿里云 OSS? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.saveAliOSSConfiguration}},[e._v(" 保存配置 ")])],1)],1)],1),t("el-tab-pane",{staticClass:"github-panel",attrs:{label:"腾讯云 COS",name:"txCOS"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.formTxCOS,"label-position":"right","label-width":"140px"}},[t("el-form-item",{attrs:{label:"SecretId",required:!0}},[t("el-input",{attrs:{placeholder:"如:AKIDnQp1w3DOOCSs8F5MDp9tdoocsmdUPonW3"},model:{value:e.formTxCOS.secretId,callback:function(t){e.$set(e.formTxCOS,"secretId","string"===typeof t?t.trim():t)},expression:"formTxCOS.secretId"}})],1),t("el-form-item",{attrs:{label:"SecretKey",required:!0}},[t("el-input",{attrs:{"show-password":"",placeholder:"如:ukLmdtEJ9271f3DOocsMDsCXdS3YlbW0"},model:{value:e.formTxCOS.secretKey,callback:function(t){e.$set(e.formTxCOS,"secretKey","string"===typeof t?t.trim():t)},expression:"formTxCOS.secretKey"}})],1),t("el-form-item",{attrs:{label:"Bucket",required:!0}},[t("el-input",{attrs:{placeholder:"如:doocs-3212520134"},model:{value:e.formTxCOS.bucket,callback:function(t){e.$set(e.formTxCOS,"bucket","string"===typeof t?t.trim():t)},expression:"formTxCOS.bucket"}})],1),t("el-form-item",{attrs:{label:"Bucket 所在区域",required:!0}},[t("el-input",{attrs:{placeholder:"如:ap-guangzhou"},model:{value:e.formTxCOS.region,callback:function(t){e.$set(e.formTxCOS,"region","string"===typeof t?t.trim():t)},expression:"formTxCOS.region"}})],1),t("el-form-item",{attrs:{label:"自定义 CDN 域名",required:!1}},[t("el-input",{attrs:{placeholder:"如:https://imagecdn.alidaodao.com,可不填"},model:{value:e.formTxCOS.cdnHost,callback:function(t){e.$set(e.formTxCOS,"cdnHost","string"===typeof t?t.trim():t)},expression:"formTxCOS.cdnHost"}})],1),t("el-form-item",{attrs:{label:"存储路径"}},[t("el-input",{attrs:{placeholder:"如:img,可不填,默认根目录"},model:{value:e.formTxCOS.path,callback:function(t){e.$set(e.formTxCOS,"path","string"===typeof t?t.trim():t)},expression:"formTxCOS.path"}}),t("el-link",{attrs:{type:"primary",href:"https://cloud.tencent.com/document/product/436/38484",target:"_blank"}},[e._v("如何使用腾讯云 COS? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.saveTxCOSConfiguration}},[e._v(" 保存配置 ")])],1)],1)],1),t("el-tab-pane",{staticClass:"github-panel",attrs:{label:"七牛云 Kodo",name:"qiniu"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.formQiniu,"label-position":"right","label-width":"140px"}},[t("el-form-item",{attrs:{label:"AccessKey",required:!0}},[t("el-input",{attrs:{placeholder:"如:6DD3VaLJ_SQgOdoocsyTV_YWaDmdnL2n8EGx7kG"},model:{value:e.formQiniu.accessKey,callback:function(t){e.$set(e.formQiniu,"accessKey","string"===typeof t?t.trim():t)},expression:"formQiniu.accessKey"}})],1),t("el-form-item",{attrs:{label:"SecretKey",required:!0}},[t("el-input",{attrs:{"show-password":"",placeholder:"如:qgZa5qrvDOOcsmdKStD1oCjZ9nB7MDvJUs_34SIm"},model:{value:e.formQiniu.secretKey,callback:function(t){e.$set(e.formQiniu,"secretKey","string"===typeof t?t.trim():t)},expression:"formQiniu.secretKey"}})],1),t("el-form-item",{attrs:{label:"Bucket",required:!0}},[t("el-input",{attrs:{placeholder:"如:md"},model:{value:e.formQiniu.bucket,callback:function(t){e.$set(e.formQiniu,"bucket","string"===typeof t?t.trim():t)},expression:"formQiniu.bucket"}})],1),t("el-form-item",{attrs:{label:"Bucket 对应域名",required:!0}},[t("el-input",{attrs:{placeholder:"如:https://images.123ylb.cn"},model:{value:e.formQiniu.domain,callback:function(t){e.$set(e.formQiniu,"domain","string"===typeof t?t.trim():t)},expression:"formQiniu.domain"}})],1),t("el-form-item",{attrs:{label:"存储区域",required:!0}},[t("el-input",{attrs:{placeholder:"如:z2"},model:{value:e.formQiniu.region,callback:function(t){e.$set(e.formQiniu,"region","string"===typeof t?t.trim():t)},expression:"formQiniu.region"}})],1),t("el-form-item",{attrs:{label:"存储路径",required:!1}},[t("el-input",{attrs:{placeholder:"如:img,可不填,默认为根目录"},model:{value:e.formQiniu.path,callback:function(t){e.$set(e.formQiniu,"path","string"===typeof t?t.trim():t)},expression:"formQiniu.path"}}),t("el-link",{attrs:{type:"primary",href:"https://developer.qiniu.com/kodo",target:"_blank"}},[e._v("如何使用七牛云 Kodo? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.saveQiniuConfiguration}},[e._v(" 保存配置 ")])],1)],1)],1),t("el-tab-pane",{staticClass:"github-panel",attrs:{label:"MinIO",name:"minio"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.minioOSS,"label-position":"right","label-width":"140px"}},[t("el-form-item",{attrs:{label:"Endpoint",required:!0}},[t("el-input",{attrs:{placeholder:"如:play.min.io"},model:{value:e.minioOSS.endpoint,callback:function(t){e.$set(e.minioOSS,"endpoint","string"===typeof t?t.trim():t)},expression:"minioOSS.endpoint"}})],1),t("el-form-item",{attrs:{label:"Port",required:!1}},[t("el-input",{attrs:{type:"number",placeholder:"如:9000,可不填,http 默认为 80,https 默认为 443"},model:{value:e.minioOSS.port,callback:function(t){e.$set(e.minioOSS,"port","string"===typeof t?t.trim():t)},expression:"minioOSS.port"}})],1),t("el-form-item",{attrs:{label:"UseSSL",required:!0}},[t("el-switch",{attrs:{"active-text":"是","inactive-text":"否"},model:{value:e.minioOSS.useSSL,callback:function(t){e.$set(e.minioOSS,"useSSL",t)},expression:"minioOSS.useSSL"}})],1),t("el-form-item",{attrs:{label:"Bucket",required:!0}},[t("el-input",{attrs:{placeholder:"如:doocs"},model:{value:e.minioOSS.bucket,callback:function(t){e.$set(e.minioOSS,"bucket","string"===typeof t?t.trim():t)},expression:"minioOSS.bucket"}})],1),t("el-form-item",{attrs:{label:"AccessKey",required:!0}},[t("el-input",{attrs:{placeholder:"如:zhangsan"},model:{value:e.minioOSS.accessKey,callback:function(t){e.$set(e.minioOSS,"accessKey","string"===typeof t?t.trim():t)},expression:"minioOSS.accessKey"}})],1),t("el-form-item",{attrs:{label:"SecretKey",required:!0}},[t("el-input",{attrs:{placeholder:"如:asdasdasd"},model:{value:e.minioOSS.secretKey,callback:function(t){e.$set(e.minioOSS,"secretKey","string"===typeof t?t.trim():t)},expression:"minioOSS.secretKey"}}),t("el-link",{attrs:{type:"primary",href:"http://docs.minio.org.cn/docs/master/minio-client-complete-guide",target:"_blank"}},[e._v("如何使用 MinIO? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.saveMinioOSSConfiguration}},[e._v(" 保存配置 ")])],1)],1)],1),t("el-tab-pane",{staticClass:"github-panel formCustom",attrs:{label:"自定义代码",name:"formCustom"}},[t("el-form",{staticClass:"setting-form",attrs:{model:e.formCustom,"label-position":"right"}},[t("el-form-item",{attrs:{label:"",required:!0}},[t("el-input",{ref:"formCustomElInput",staticClass:"formCustomElInput",attrs:{type:"textarea",resize:"none",placeholder:"Your custom code here."},model:{value:e.formCustom.code,callback:function(t){e.$set(e.formCustom,"code",t)},expression:"formCustom.code"}}),t("el-link",{attrs:{type:"primary",href:"https://github.com/doocs/md#自定义上传逻辑",target:"_blank"}},[e._v("参数详情? ")])],1),t("el-form-item",[t("el-button",{attrs:{type:"primary"},on:{click:e.formCustomSave}},[e._v(" 保存配置 ")])],1)],1)],1)],1)],1)},je=[],Le={props:{value:{type:Boolean,default:!1}},data(){return{activeName:"upload",formGitHub:{repo:"",branch:"",accessToken:""},formAliOSS:{accessKeyId:"",accessKeySecret:"",bucket:"",region:"",path:"",cdnHost:""},minioOSS:{endpoint:"",port:"",useSSL:!0,bucket:"",accessKey:"",secretKey:""},formTxCOS:{secretId:"",secretKey:"",bucket:"",region:"",path:"",cdnHost:""},formQiniu:{accessKey:"",secretKey:"",bucket:"",domain:"",region:""},formCustom:{code:localStorage.getItem("formCustomConfig")||G(`\n const {file, util, okCb, errCb} = CUSTOM_ARG\n const param = new FormData()\n param.append('file', file)\n util.axios.post('${window.location.origin}/upload', param, {\n headers: { 'Content-Type': 'multipart/form-data' }\n }).then(res => {\n okCb(res.url)\n }).catch(err => {\n errCb(err)\n })\n `).trim(),editor:void 0},options:[{value:"default",label:"默认"},{value:"github",label:"GitHub"},{value:"aliOSS",label:"阿里云"},{value:"txCOS",label:"腾讯云"},{value:"qiniu",label:"七牛云"},{value:"minio",label:"MinIO"},{value:"formCustom",label:"自定义代码"}],imgHost:"default"}},created(){localStorage.getItem("githubConfig")&&(this.formGitHub=JSON.parse(localStorage.getItem("githubConfig"))),localStorage.getItem("aliOSSConfig")&&(this.formAliOSS=JSON.parse(localStorage.getItem("aliOSSConfig"))),localStorage.getItem("minioConfig")&&(this.minioOSS=JSON.parse(localStorage.getItem("minioConfig"))),localStorage.getItem("txCOSConfig")&&(this.formTxCOS=JSON.parse(localStorage.getItem("txCOSConfig"))),localStorage.getItem("imgHost")&&(this.imgHost=localStorage.getItem("imgHost"))},methods:{changeImgHost(){localStorage.setItem("imgHost",this.imgHost),this.$message.success("已成功切换图床")},saveGitHubConfiguration(){if(this.formGitHub.repo&&this.formGitHub.accessToken)localStorage.setItem("githubConfig",JSON.stringify(this.formGitHub)),this.$message.success("保存成功");else{const e=this.formGitHub.repo?"token":"GitHub 仓库";this.$message.error(`参数「${e}」不能为空`)}},saveAliOSSConfiguration(){this.formAliOSS.accessKeyId&&this.formAliOSS.accessKeySecret&&this.formAliOSS.bucket&&this.formAliOSS.region?(localStorage.setItem("aliOSSConfig",JSON.stringify(this.formAliOSS)),this.$message.success("保存成功")):this.$message.error("阿里云 OSS 参数配置不全")},saveMinioOSSConfiguration(){this.minioOSS.endpoint&&this.minioOSS.bucket&&this.minioOSS.accessKey&&this.minioOSS.secretKey?(localStorage.setItem("minioConfig",JSON.stringify(this.minioOSS)),this.$message.success("保存成功")):this.$message.error("MinIO 参数配置不全")},saveTxCOSConfiguration(){this.formTxCOS.secretId&&this.formTxCOS.secretKey&&this.formTxCOS.bucket&&this.formTxCOS.region?(localStorage.setItem("txCOSConfig",JSON.stringify(this.formTxCOS)),this.$message.success("保存成功")):this.$message.error("腾讯云 COS 参数配置不全")},saveQiniuConfiguration(){this.formQiniu.accessKey&&this.formQiniu.secretKey&&this.formQiniu.bucket&&this.formQiniu.domain&&this.formQiniu.region?(localStorage.setItem("qiniuConfig",JSON.stringify(this.formQiniu)),this.$message.success("保存成功")):this.$message.error("七牛云 Kodo 参数配置不全")},formCustomSave(){const e=this.formCustom.editor.getValue();localStorage.setItem("formCustomConfig",e),this.$message.success("保存成功")},beforeImageUpload(e){const t=H(e);if(!t.ok)return this.$message.error(t.msg),!1;let o=localStorage.getItem("imgHost");o=o||"default",localStorage.setItem("imgHost",o);const i=localStorage.getItem(o+"Config"),n="default"==o||i;return!!n||(this.$message.error(`请先配置 ${o} 图床参数`),!1)},uploadImage(e){this.$emit("uploadImage",e.file)}},watch:{activeName:{immediate:!0,handler(e){"formCustom"===e&&this.$nextTick(()=>{const e=this.$refs.formCustomElInput.$el.querySelector("textarea");this.formCustom.editor=this.formCustom.editor||_.a.fromTextArea(e,{mode:"javascript"}),this.formCustom.editor.setValue(this.formCustom.code)})}}},mounted(){}},Ue=Le,qe=(o("ee3c"),Object(r["a"])(Ue,Ke,je,!1,null,"f93f6c70",null)),Be=qe.exports,Fe=function(){var e=this,t=e._self._c;return e.loading?t("transition",{attrs:{name:"fade"}},[t("div",{staticClass:"loading"},[t("div",{staticClass:"loading-wrapper"},[t("div",{staticClass:"loading-anim"}),t("div",{staticClass:"loading-text"},[e._v("致力于让 Markdown 编辑更简单")])])])]):e._e()},ze=[],He={name:"RunLoading",data(){return{loading:!0}},mounted(){setTimeout(()=>{this.loading=!1},100)}},Ge=He,Ne=(o("12ca"),Object(r["a"])(Ge,Fe,ze,!1,null,"0b991e35",null)),Ve=Ne.exports,We=o("3f5e");o("f9d4");var Qe={data(){return{showCssEditor:!1,aboutDialogVisible:!1,dialogUploadImgVisible:!1,dialogFormVisible:!1,isCoping:!1,isImgLoading:!1,backLight:!1,timeout:null,changeTimer:null,source:"",mouseLeft:0,mouseTop:0}},components:{RunLoading:Ve,EditorHeader:be,AboutDialog:ve,InsertFormDialog:Te,RightClickMenu:Re,UploadImgDialog:Be},computed:{...Object(d["c"])({wxRenderer:e=>e.wxRenderer,output:e=>e.output,editor:e=>e.editor,cssEditor:e=>e.cssEditor,currentSize:e=>e.currentSize,currentColor:e=>e.currentColor,nightMode:e=>e.nightMode,rightClickMenuVisible:e=>e.rightClickMenuVisible,codeTheme:e=>e.codeTheme})},created(){this.initEditorState(),this.$nextTick(()=>{this.initEditor(),this.initCssEditor(),this.onEditorRefresh(),this.mdLocalToRemote()})},methods:{mdLocalToRemote(){const e=this,t=this.$refs.codeMirrorWrapper.$el;async function o({list:e}){return new Promise((t,o)=>{const{path:i,file:n}=e.find(e=>e.path.match(/\.md$/)),s=new FileReader;s.readAsText(n,"UTF-8"),s.onload=e=>{t({str:e.target.result,file:n,path:i})}})}async function i({md:t,list:o}){const i=[...t.str.matchAll(/!\[(.*?)\]\((.*?)\)/gm)||[]].filter(e=>e),n=t.path.match(/.+?\//)[0],s=await Promise.all(i.map(t=>new Promise((i,s)=>{let[,,r]=t;r=r.replace(/^.\//,"");const{file:a}=o.find(e=>e.path===`${n}${r}`)||{};e.uploadImage(a,e=>{i({matchStr:r,url:e})})})));s.forEach(e=>{t.str=t.str.replace(`](./${e.matchStr})`,`](${e.url})`).replace(`](${e.matchStr})`,`](${e.url})`)}),e.editor.setValue(t.str),console.log("resList",s,t.str)}async function n(e){const t=[];let o="";try{const i=[e];for(const e of i){o+=e.name+"/";for await(const[,n]of e)"file"===n.kind?t.push({path:o+n.name,file:await n.getFile()}):(t.push({path:o+n.name+"/"}),i.push(n))}}catch(i){console.error(i)}return t}t.ondragover=e=>e.preventDefault(),t.ondrop=async e=>{e.preventDefault();for(const t of e.dataTransfer.items)t.getAsFileSystemHandle().then(async e=>{if("directory"===e.kind){const t=await n(e),s=await o({list:t});i({md:s,list:t})}else{const t=await e.getFile();console.log("file",t)}})}},initEditor(){this.initEditorEntity(),this.editor.on("change",(e,t)=>{this.changeTimer&&clearTimeout(this.changeTimer),this.changeTimer=setTimeout(()=>{this.onEditorRefresh(),j(this.editor,"__editor_content")},300)}),this.editor.on("paste",(e,t)=>{if(t.clipboardData&&t.clipboardData.items&&!this.isImgLoading)for(let o=0,i=t.clipboardData.items.length;o{this.$store.commit("setRightClickMenuVisible",!1)}),this.editor.on("blur",()=>{
//!影响到右键菜单的点击事件,右键菜单的点击事件在组件内通过mousedown触发
this.$store.commit("setRightClickMenuVisible",!1)}),this.editor.on("scroll",()=>{this.$store.commit("setRightClickMenuVisible",!1)})},initCssEditor(){this.initCssEditorEntity(),this.cssEditor.on("keyup",(e,t)=>{(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode)&&e.showHint(t)}),this.cssEditor.on("update",e=>{this.cssChanged(),j(this.cssEditor,"__css_content")})},cssChanged(){let e=K(this.cssEditor.getValue(0)),t=P(this.currentSize.replace("px",""));t=R(e,this.currentColor,t),this.setWxRendererOptions({theme:t}),this.onEditorRefresh()},codeThemeChanged(){let e=this.codeTheme,t=document.getElementById("hljs");if(void 0!=t)t.setAttribute("href",e);else{const t=document.createElement("link");t.setAttribute("type","text/css"),t.setAttribute("rel","stylesheet"),t.setAttribute("href",e),t.setAttribute("id","hljs"),document.head.appendChild(t)}},beforeUpload(e){const t=H(e);if(!t.ok)return this.$message.error(t.msg),!1;let o=localStorage.getItem("imgHost");o=o||"default",localStorage.setItem("imgHost",o);const i=localStorage.getItem(o+"Config"),n="default"==o||i;return!!n||(this.$message.error(`请先配置 ${o} 图床参数`),!1)},uploadImage(e,t){this.isImgLoading=!0,z(e).then(o=>{We["a"].fileUpload(o,e).then(e=>{console.log(e),t?t(e):this.uploaded(e)}).catch(e=>{this.$message.error(e.message)})}).catch(e=>{this.$message.error(e.message)}),this.isImgLoading=!1},uploaded(e){if(console.log("图片上传之后: ",e),!e)return void this.$message.error("上传图片未知异常");this.dialogUploadImgVisible=!1;const t=this.editor.getCursor(),o=e,i=`![](${o})`;this.editor.replaceSelection(`\n${i}\n`,t),this.$message.success("图片上传成功"),this.onEditorRefresh()},leftAndRightScroll(){const e=e=>{let i,n;clearTimeout(this.timeout),"preview"===e?(i=this.$refs.preview.$el,n=document.getElementsByClassName("CodeMirror-scroll")[0],this.editor.off("scroll",t),this.timeout=setTimeout(()=>{this.editor.on("scroll",t)},300)):"editor"===e&&(i=document.getElementsByClassName("CodeMirror-scroll")[0],n=this.$refs.preview.$el,n.removeEventListener("scroll",o,!1),this.timeout=setTimeout(()=>{n.addEventListener("scroll",o,!1)},300));let s=i.scrollTop/(i.scrollHeight-i.offsetHeight),r=s*(n.scrollHeight-n.offsetHeight);n.scrollTo(0,r)},t=()=>{e("editor")},o=()=>{e("preview")};this.$refs.preview.$el.addEventListener("scroll",o,!1),this.editor.on("scroll",t)},onEditorRefresh(){this.codeThemeChanged(this.codeTheme),this.editorRefresh(),setTimeout(()=>window.PR.prettyPrint(),0)},endCopy(){this.backLight=!1,setTimeout(()=>{this.isCoping=!1},800)},addFormat(e,t=e){const{head:o,anchor:i}=this.editor.doc.sel.ranges[0];let n,s;o.line===i.line?o.ch{B()})},importMarkdownContent(){let e=document.getElementById("menu"),t=document.createElement("input");t.type="file",t.name="filename",t.accept=".txt,.md",e.appendChild(t),t.onchange=()=>{if(!t.files)return;const e=t.files[0];if(!/\.(txt|TXT|MD|md)$/.test(e.name))return void this.$message.error("不支持的文档格式");const o=new FileReader;o.readAsText(e),o.onload=e=>{let t=e.target.result;t=L(t),t&&(localStorage.setItem("__editor_content",t),this.editor.setValue(t),this.$message.success("文档导入成功"))}},t.click(),e.removeChild(t)},formatContent(){const e=L(this.editor.getValue(0));localStorage.setItem("__editor_content",e),this.editor.setValue(e)},openMenu(e){const t=105,o=this.$el.getBoundingClientRect().left,i=this.$el.offsetWidth,n=i-t,s=e.clientX-o;this.mouseLeft=Math.min(n,s),this.mouseTop=e.clientY+10,this.$store.commit("setRightClickMenuVisible",!0)},closeRightClickMenu(){this.$store.commit("setRightClickMenuVisible",!1)},onMenuEvent(e,t={}){switch(e){case"resetStyle":this.$refs.header.showResetConfirm=!0;break;case"insertPic":this.dialogUploadImgVisible=!0;break;case"download":this.downloadEditorContent();break;case"export":this.exportEditorContent();break;case"insertTable":this.dialogFormVisible=!0;break;case"importMarkdown":this.importMarkdownContent();break;case"formatMarkdown":this.formatContent();break;default:break}},...Object(d["b"])(["initEditorState","initEditorEntity","setWxRendererOptions","editorRefresh","initCssEditorEntity"])},mounted(){setTimeout(()=>{this.leftAndRightScroll(),window.PR.prettyPrint()},300)}},Je=Qe,Ye=(o("ac56"),o("d902"),o("5e3c"),Object(r["a"])(Je,ee,te,!1,null,"a25a64ea",null)),Ze=Ye.exports,Xe={name:"App",components:{CodemirrorEditor:Ze}},et=Xe,tt=Object(r["a"])(et,Z,X,!1,null,"821a8f8c",null),ot=tt.exports;i["default"].use(Y["a"]);const it=[{path:"/",name:"index",component:ot}],nt=new Y["a"]({mode:"history",base:"/md/",routes:it});var st=nt;i["default"].use(J.a),i["default"].config.productionTip=!1,c.mpType="app";const rt=new i["default"]({router:st,store:W,...c});rt.$mount("#app")},"5e3c":function(e,t,o){"use strict";o("981b")},6:function(e,t){},"6af4":function(e,t,o){},7:function(e,t){},"744d":function(e,t,o){},"787f":function(e,t,o){},"7a33":function(e,t,o){},"7f2b":function(e,t,o){},8:function(e,t){},"846b":function(e,t,o){"use strict";o("ad1e")},9:function(e,t){},9271:function(e,t,o){"use strict";o("7a33")},"981b":function(e,t,o){},ac56:function(e,t,o){"use strict";o("07db")},ad1e:function(e,t,o){},d281:function(e,t,o){"use strict";o("0830")},d902:function(e,t,o){"use strict";o("7f2b")},da71:function(e,t,o){"use strict";o.d(t,"b",(function(){return i})),o.d(t,"a",(function(){return n}));const i={username:"filess",repoList:Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],e=>"img"+e),branch:"main",accessTokenList:["7715d7ca67b5d3837cfdoocsmde8c38421815aa423510af","c411415bf95dbe39625doocsmd5047ba9b7a2a6c9642abe","2821cd8819fa345c053doocsmdca86ac653f8bc20db1f1b","445f0dae46ef1f2a4d6doocsmdc797301e94797b4750a4c","cc1d0c1426d0fd0902bdoocsmdd2d7184b14da61b86ec46","b67e9d15cb6f910492fdoocsmdac6b44d379c953bb19eff","618c4dc2244ccbbc088doocsmd125d17fd31b7d06a50cf3","a4b581732e1c1507458doocsmdc5b223b27dae5e2e16a55","77904db41aee57ad79bdoocsmd760f848201dac9c96fd5e","02f251cb14ac62ab100doocsmdddbfc8527d773f1f04ce1","eb321079a95ba7028d9doocsmde2e84c502dac70de7cf08","22f74fcfb071a961fa2doocsmde28dabc746f0503a15e5d","85124c2bfe7abba0938doocsmd0af7f67918b99d085a5fd","0a561b4d4bbecb2de7edoocsmdd9ba3833d11dbc5e430f5","e8a01491188d8d5a097doocsmd03ede0aad1fe9e3af24e9","36e1f420d7e5bdebd67doocsmd65463562f5f25b20b8377"]},n={username:"filesss",repoList:Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],e=>"img"+e),branch:"main",accessTokenList:["ed5fc9866bd6c2fdoocsmddd433f806fd2f399c","5448ffebbbf1151doocsmdc4e337cf814fc8a62","25b05efd2557ca2doocsmd75b5c0835e3395911","11628c7a5aef015doocsmd2eeff9fb9566f0458","cb2f5145ed938dedoocsmdbd063b4ed244eecf8","d8c0b57500672c1doocsmd55f48b866b5ebcd98","78c56eadb88e453doocsmd43ddd95753351771a","03e1a688003948fdoocsmda16fcf41e6f03f1f0","c49121cf4d191fbdoocsmdd6a7877ed537e474a","adfeb2fadcdc4aadoocsmdfe1ee869ac9c968ff","116c94549ca4a0ddoocsmd192653af5c0694616","ecf30ed7f2eb184doocsmd51ea4ec8300371d9e","5837cf2bd5afd93doocsmd73904bed31934949e","b5b7e1c7d57e01fdoocsmd5266f552574297d78","684d55564ffbd0bdoocsmd7d747e5cc23aed6d6","3fc04a9d272ab71doocsmd010c56cb57d88d2ba"]}},ddc2:function(e,t,o){"use strict";o("0f67")},e1d2:function(e,t,o){"use strict";var i=o("bc3a"),n=o.n(i);const s=n.a.create({baseURL:"",timeout:3e4});s.interceptors.request.use(e=>(/^(post)|(put)|(delete)$/i.test(e.method)&&e.data&&e.data.upload&&(e.headers["Content-Type"]="multipart/form-data"),e),e=>{Promise.reject(e)}),s.interceptors.response.use(e=>e.data?e.data:Promise.reject(e),e=>Promise.reject(e)),t["a"]=s},ee3c:function(e,t,o){"use strict";o("787f")},ff58:function(e,t,o){"use strict";o("744d")}});