md/js/app.05d7455c.js
2020-09-04 01:47:08 +00:00

4 lines
58 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(e){function t(t){for(var o,a,s=t[0],c=t[1],l=t[2],d=0,f=[];d<s.length;d++)a=s[d],Object.prototype.hasOwnProperty.call(i,a)&&i[a]&&f.push(i[a][0]),i[a]=0;for(o in c)Object.prototype.hasOwnProperty.call(c,o)&&(e[o]=c[o]);u&&u(t);while(f.length)f.shift()();return r.push.apply(r,l||[]),n()}function n(){for(var e,t=0;t<r.length;t++){for(var n=r[t],o=!0,s=1;s<n.length;s++){var c=n[s];0!==i[c]&&(o=!1)}o&&(r.splice(t--,1),e=a(a.s=n[0]))}return e}var o={},i={app:0},r=[];function a(t){if(o[t])return o[t].exports;var n=o[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=o,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)a.d(n,o,function(t){return e[t]}.bind(null,o));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="/md/";var s=window["webpackJsonp"]=window["webpackJsonp"]||[],c=s.push.bind(s);s.push=t,s=s.slice();for(var l=0;l<s.length;l++)t(s[l]);var u=c;r.push([0,"chunk-vendors"]),n()})({0:function(e,t,n){e.exports=n("56d7")},"0a43":function(e,t,n){},1:function(e,t){},"38c7":function(e,t,n){},"3a5e":function(e,t,n){"use strict";var o=n("7268"),i=n("cb57"),r=(n("f6be"),n("2877")),a=Object(r["a"])(i["default"],o["a"],o["b"],!1,null,"31c61828",null);t["default"]=a.exports},"56d7":function(e,t,n){"use strict";n.r(t);n("e260"),n("e6cf"),n("cca6"),n("a79d");var o=n("2b0e"),i=function(){var e=this,t=e.$createElement,n=e._self._c||t;return e.loading?n("transition",{attrs:{name:"fade"}},[n("loading")],1):n("codemirror-editor")},r=[],a=n("3a5e"),s=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"container",class:{container_night:e.nightMode}},[n("el-container",[n("el-header",{staticClass:"editor__header"},[n("editor-header",{ref:"header",on:{refresh:e.onEditorRefresh,cssChanged:e.cssChanged,downLoad:e.downloadEditorContent,showCssEditor:function(t){e.showCssEditor=!e.showCssEditor},showAboutDialog:function(t){e.aboutDialogVisible=!0},showDialogForm:function(t){e.dialogFormVisible=!0},showDialogUploadImg:function(t){e.dialogUploadImgVisible=!0},startCopy:function(t){e.isCoping=!0,e.backLight=!0},endCopy:e.endCopy}})],1),n("el-main",{staticClass:"main-body"},[n("el-row",{staticClass:"main-section"},[n("el-col",{attrs:{span:12},nativeOn:{contextmenu:function(t){return t.preventDefault(),e.openMenu(t)}}},[n("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)}}})]),n("el-col",{ref:"preview",staticClass:"preview-wrapper",class:{"preview-wrapper_night":e.nightMode&&e.isCoping},attrs:{span:12,id:"preview"}},[n("section",{class:{output_night:e.nightMode&&!e.backLight},attrs:{id:"output-wrapper"}},[n("div",{staticClass:"preview"},[n("section",{attrs:{id:"output"},domProps:{innerHTML:e._s(e.output)}}),e.nightMode&&e.isCoping?n("div",{staticClass:"loading-mask"},[n("div",{staticClass:"loading__img"}),n("span",[e._v("正在生成")])]):e._e()])])]),n("transition",{attrs:{name:"custom-classes-transition","enter-active-class":"bounceInRight"}},[n("el-col",{directives:[{name:"show",rawName:"v-show",value:e.showCssEditor,expression:"showCssEditor"}],attrs:{id:"cssBox",span:12}},[n("textarea",{attrs:{id:"cssEditor",type:"textarea",placeholder:"Your custom css here."}})])],1)],1)],1)],1),n("upload-img-dialog",{on:{close:function(t){e.dialogUploadImgVisible=!1},uploaded:e.uploaded},model:{value:e.dialogUploadImgVisible,callback:function(t){e.dialogUploadImgVisible=t},expression:"dialogUploadImgVisible"}}),n("about-dialog",{model:{value:e.aboutDialogVisible,callback:function(t){e.aboutDialogVisible=t},expression:"aboutDialogVisible"}}),n("insert-form-dialog",{model:{value:e.dialogFormVisible,callback:function(t){e.dialogFormVisible=t},expression:"dialogFormVisible"}}),n("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"}})],1)},c=[],l=(n("ac1f"),n("5319"),n("5530")),u=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-container",{staticClass:"top is-dark"},[n("el-tooltip",{attrs:{effect:e.effect,content:"上传图片",placement:"bottom-start"}},[n("i",{staticClass:"el-icon-upload",attrs:{size:"medium"},on:{click:function(t){return e.$emit("showDialogUploadImg")}}})]),n("el-tooltip",{staticClass:"header__item",attrs:{effect:e.effect,content:"下载编辑框Markdown文档",placement:"bottom-start"}},[n("i",{staticClass:"el-icon-download",attrs:{size:"medium"},on:{click:function(t){return e.$emit("downLoad")}}})]),n("el-tooltip",{staticClass:"header__item",attrs:{effect:e.effect,content:"重置页面",placement:"bottom-start"}},[n("i",{staticClass:"el-icon-refresh",attrs:{size:"medium"},on:{click:function(t){e.showResetConfirm=!0}}})]),n("el-tooltip",{staticClass:"header__item header__item_last",attrs:{effect:e.effect,content:"插入表格",placement:"bottom-start"}},[n("i",{staticClass:"el-icon-s-grid",attrs:{size:"medium"},on:{click:function(t){return e.$emit("showDialogForm")}}})]),n("el-form",{staticClass:"ctrl",attrs:{size:"mini",inline:!0}},[n("el-form-item",[n("el-select",{attrs:{size:"mini",placeholder:"选择字体",clearable:""},on:{change:e.fontChanged},model:{value:e.selectFont,callback:function(t){e.selectFont=t},expression:"selectFont"}},e._l(e.config.builtinFonts,(function(t){return n("el-option",{key:t.value,style:{fontFamily:t.value},attrs:{label:t.label,value:t.value}},[n("span",{staticClass:"select-item-left"},[e._v(e._s(t.label))]),n("span",{staticClass:"select-item-right"},[e._v("Abc")])])})),1)],1),n("el-form-item",[n("el-select",{attrs:{size:"mini",placeholder:"选择段落字号",clearable:""},on:{change:e.sizeChanged},model:{value:e.selectSize,callback:function(t){e.selectSize=t},expression:"selectSize"}},e._l(e.config.sizeOption,(function(t){return n("el-option",{key:t.value,attrs:{label:t.label,value:t.value}},[n("span",{staticClass:"select-item-left"},[e._v(e._s(t.label))]),n("span",{staticClass:"select-item-right"},[e._v(e._s(t.desc))])])})),1)],1),n("el-form-item",[n("el-select",{attrs:{size:"mini",placeholder:"选择颜色",clearable:""},on:{change:e.colorChanged},model:{value:e.selectColor,callback:function(t){e.selectColor=t},expression:"selectColor"}},e._l(e.config.colorOption,(function(t){return n("el-option",{key:t.value,attrs:{label:t.label,value:t.value}},[n("span",{staticClass:"select-item-left"},[e._v(e._s(t.label))]),n("span",{staticClass:"select-item-right"},[e._v(e._s(t.desc))])])})),1)],1),n("el-tooltip",{attrs:{content:"自定义颜色",effect:e.effect,placement:"top"}},[n("el-color-picker",{attrs:{size:"mini","show-alpha":""},on:{change:e.colorChanged},model:{value:e.selectColor,callback:function(t){e.selectColor=t},expression:"selectColor"}})],1),n("el-tooltip",{attrs:{content:"微信外链自动转为文末引用",effect:e.effect,placement:"top"}},[n("el-switch",{staticClass:"header__switch",attrs:{"active-color":"#67c23a","inactive-color":"#dcdfe6"},on:{change:e.statusChanged},model:{value:e.citeStatus,callback:function(t){e.citeStatus=t},expression:"citeStatus"}})],1)],1),n("el-tooltip",{staticClass:"item",attrs:{effect:e.effect,content:"自定义CSS样式",placement:"left"}},[n("el-button",{attrs:{type:e.btnType,plain:"",size:"medium",icon:"el-icon-setting"},on:{click:e.customStyle}})],1),n("el-button",{attrs:{type:e.btnType,plain:"",size:"medium",placement:"bottom-start"},on:{click:e.copy}},[e._v("复制")]),n("el-button",{staticClass:"about",attrs:{type:e.btnType,plain:"",size:"medium"},on:{click:function(t){return e.$emit("showAboutDialog")}}},[e._v("关于")]),n("el-tooltip",{attrs:{content:e.btnContent,effect:e.effect,placement:"bottom-start"}},[e.nightMode?n("div",{staticClass:"mode__switch mode__switch_black",on:{click:e.themeChanged}}):n("div",{staticClass:"mode__switch",on:{click:e.themeChanged}})]),n("resetDialog",{attrs:{showResetConfirm:e.showResetConfirm},on:{confirm:e.confirmReset,close:e.cancelReset}})],1)},d=[],f=(n("96cf"),n("1da1")),p=(n("4de4"),n("4160"),n("c975"),n("d81d"),n("fb6a"),n("b64b"),n("d3b7"),n("3ca3"),n("1276"),n("498a"),n("9911"),n("159b"),n("ddb0"),n("2b3d"),{BASE:{"text-align":"left",color:"#3f3f3f","line-height":"1.75"},BASE_BLOCK:{margin:"1em 8px"},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)"},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)"},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"},blockquote:{"font-style":"normal","border-left":"none",padding:"1em","border-radius":"4px",color:"#FEEEED",background:"rgba(27,31,35,.05)",margin:"2em 8px"},blockquote_p:{"letter-spacing":"0.1em",color:"rgb(80, 80, 80)","font-family":"PingFangSC-light, PingFangTC-light, Open Sans, Helvetica Neue, sans-serif","font-size":"1em",display:"block"},code:{"font-size":"80%",overflow:"auto",color:"#333","white-space":"pre",background:"rgb(247, 247, 247)","border-radius":"2px",padding:"10px","line-height":"1.5",border:"1px solid rgb(236,236,236)",margin:"20px 0"},image:{"border-radius":"4px",display:"block",margin:"0.1em auto 0.5em",width:"100% !important"},image_org:{"border-radius":"4px",display:"block"},ol:{"margin-left":"0","padding-left":"1em"},ul:{"margin-left":"0","padding-left":"1em","list-style":"circle"},footnotes:{margin:"0.5em 8px","font-size":"80%"},figure:{margin:"1.5em 8px"}},inline:{listitem:{"text-indent":"-1em",display:"block",margin:"0.2em 8px"},codespan:{"font-size":"90%","white-space":"pre",color:"#d14",background:"rgba(27,31,35,.05)",padding:"3px 5px","border-radius":"4px"},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"},thead:{background:"rgba(0, 0, 0, 0.05)","font-weight":"bold"},td:{border:"1px solid #dfdfdf",padding:"0.25em 0.5em"},footnote:{"font-size":"12px"},figcaption:{"text-align":"center",color:"#888","font-size":"0.8em"}}}),g=n("325b"),m=n.n(g),h=n("4fc3"),b=n.n(h);function v(e){return function(t){var n=JSON.parse(JSON.stringify(e));return n.block.h1["border-bottom"]="2px solid ".concat(t),n.block.h2["background"]=t,n.block.h3["border-left"]="3px solid ".concat(t),n.block.h4["color"]=t,n.inline.strong["color"]=t,n}}var C=function(e,t){var n=JSON.parse(JSON.stringify(e));return n.block.h1["border-bottom"]="2px solid ".concat(t),n.block.h2["background"]=t,n.block.h3["border-left"]="3px solid ".concat(t),n.block.h4["color"]=t,n.inline.strong["color"]=t,n};function k(e){return function(t){var n=JSON.parse(JSON.stringify(e));return n.block.h1["font-size"]="".concat(1.14*t,"px"),n.block.h2["font-size"]="".concat(1.1*t,"px"),n.block.h3["font-size"]="".concat(t,"px"),n.block.h4["font-size"]="".concat(t,"px"),n}}var w=v(p),y=k(p);function x(e,t,n){var o=JSON.parse(JSON.stringify(n));return o.block.h1["border-bottom"]="2px solid ".concat(t),o.block.h2["background"]=t,o.block.h3["border-left"]="3px solid ".concat(t),o.block.h4["color"]=t,o.inline.strong["color"]=t,o.block.h1=Object.assign(o.block.h1,e.h1),o.block.h2=Object.assign(o.block.h2,e.h2),o.block.h3=Object.assign(o.block.h3,e.h3),o.block.h4=Object.assign(o.block.h4,e.h4),o.block.p=Object.assign(o.block.p,e.p),o.block.blockquote=Object.assign(o.block.blockquote,e.blockquote),o.block.blockquote_p=Object.assign(o.block.blockquote_p,e.blockquote_p),o.block.image=Object.assign(o.block.image,e.image),o.inline.strong=Object.assign(o.inline.strong,e.strong),o.inline.codespan=Object.assign(o.inline.codespan,e.codespan),o.inline.link=Object.assign(o.inline.link,e.link),o.inline.wx_link=Object.assign(o.inline.wx_link,e.wx_link),o}function _(e){var t,n;while(-1!==(t=e.indexOf("/*"))&&-1!==(n=e.indexOf("*/")))e=e.substring(0,t)+e.substring(n+2);var o={},i=function(){var t=e.indexOf("{"),n=e.indexOf("}");function i(e){var t={};return e.forEach((function(e){var n=e.indexOf(":"),o=e.substring(0,n).trim(),i=e.substring(n+1).trim();t[o]=i})),t}var r=e.substring(t+1,n).split(";").map((function(e){return e.trim()})).filter((function(e){return e.length>0}));r=i(r);var a=e.substring(0,t).split(",").map((function(e){return e.trim()}));a.forEach((function(e){o[e]||(o[e]={}),Object.keys(r).forEach((function(t){o[e][t]=r[t]}))})),e=e.slice(n+1).trim()};while(e.length>0&&-1!==e.indexOf("{")&&-1!==e.indexOf("}"))i();return o}function S(e,t){var n=e.getValue(0);n?localStorage.setItem(t,n):localStorage.removeItem(t)}function O(e){var t=m.a.format(e,{parser:"markdown",plugins:[b.a]});return t}function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"pre",t=document.getElementsByClassName("code__pre");t.length>0&&t.forEach((function(t){t.style.whiteSpace=e}))}function T(e){var t=document.createElement("a");t.download="content.md",t.style.display="none";var n=new Blob([e]);t.href=URL.createObjectURL(n),document.body.appendChild(t),t.click(),document.body.removeChild(t)}var R=n("466b"),M=n.n(R);function j(){for(var e=document.getElementById("output"),t=e.getElementsByTagName("img"),n=0;n<t.length;n++){var o=t[n],i=o.getAttribute("width"),r=o.getAttribute("height");o.removeAttribute("width"),o.removeAttribute("height"),o.style.width=i,o.style.height=r}}function I(){var e=document.getElementById("output-wrapper"),t=e.innerHTML,n="";return n=M.a.inlineContent(t,{inlinePseudoElements:!0,preserveImportant:!0}),n}var $={builtinFonts:[{label:"无衬线",value:"-apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif"},{label:"衬线",value:"Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif"}],sizeOption:[{label:"12px",value:"12px",desc:"更小"},{label:"13px",value:"13px",desc:"稍小"},{label:"14px",value:"14px",desc:"推荐"},{label:"15px",value:"15px",desc:"稍大"},{label:"16px",value:"16px",desc:"更大"}],colorOption:[{label:"经典蓝",value:"rgba(15, 76, 129, 1)",desc:"最新流行"},{label:"翡翠绿",value:"rgba(0, 152, 116, 1)",desc:"优雅清新"},{label:"活力橘",value:"rgba(250, 81, 81, 1)",desc:"热情活泼"}],codeThemeOption:[{label:"微信",value:"wechat",desc:"默认样式"},{label:"GitHub",value:"github",desc:"精简风格"}],form:{rows:1,cols:1}},z="/*\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/* 行内代码样式 */\ncodespan {\n}\n/* 粗体样式 */\nstrong {\n}\n/* 链接样式 */\nlink {\n}\n/* 微信链接样式 */\nwx_link {\n}\n",G=z,F=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-dialog",{staticClass:"reset__dialog",attrs:{title:"提示",visible:e.showResetConfirm},on:{close:function(t){return e.$emit("close")}}},[n("div",{staticClass:"text"},[e._v(" 此操作将丢失本地缓存的文本和自定义样式,是否继续? ")]),n("div",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{attrs:{type:e.btnType,plain:""},on:{click:function(t){return e.$emit("close")}}},[e._v("取 消")]),n("el-button",{attrs:{type:e.btnType,plain:""},on:{click:function(t){return e.$emit("confirm")}}},[e._v("确 定")])],1)])},H=[],D=n("2f62"),P={props:{showResetConfirm:{type:Boolean,default:!1}},computed:Object(l["a"])({btnType:function(){return this.nightMode?"default":"primary"}},Object(D["c"])({nightMode:function(e){return e.nightMode}}))},V=P,A=(n("5b3a"),n("2877")),N=Object(A["a"])(V,F,H,!1,null,"0facc8d4",null),L=N.exports,B={name:"editor-header",data:function(){return{config:$,citeStatus:!1,showResetConfirm:!1,selectFont:"",selectSize:"",selectColor:"",selectCodeTheme:"github"}},components:{resetDialog:L},computed:Object(l["a"])({effect:function(){return this.nightMode?"dark":"light"},btnContent:function(){return this.nightMode?"浅色模式":"暗黑模式"},btnType:function(){return this.nightMode?"default":"primary"}},Object(D["c"])({output:function(e){return e.output},editor:function(e){return e.editor},cssEditor:function(e){return e.cssEditor},currentFont:function(e){return e.currentFont},currentSize:function(e){return e.currentSize},currentColor:function(e){return e.currentColor},codeTheme:function(e){return e.codeTheme},nightMode:function(e){return e.nightMode}})),methods:Object(l["a"])({fontChanged:function(e){this.setWxRendererOptions({fonts:e}),this.setCurrentFont(e),this.$emit("refresh")},sizeChanged:function(e){var t=y(e.replace("px",""));t=C(t,this.currentColor),this.setWxRendererOptions({size:e,theme:t}),this.setCurrentSize(e),this.$emit("refresh")},colorChanged:function(e){var t=y(this.currentSize.replace("px",""));t=C(t,e),this.setWxRendererOptions({theme:t}),this.setCurrentColor(e),this.$emit("refresh")},codeThemeChanged:function(e){this.setCurrentCodeTheme(e),this.$emit("refresh")},statusChanged:function(e){this.setCiteStatus(e),this.$emit("refresh")},copy:function(e){var t=this;this.$emit("startCopy"),setTimeout((function(){var e=document.getElementById("output");j(),E(),I(),e.focus(),window.getSelection().removeAllRanges();var n=document.createRange();n.setStartBefore(e.firstChild),n.setEndAfter(e.lastChild),window.getSelection().addRange(n),document.execCommand("copy"),window.getSelection().removeAllRanges(),E("normal"),e.innerHTML=t.output,t.$notify({showClose:!0,message:"已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴",offset:80,duration:1600,type:"success"}),t.$emit("refresh"),t.$emit("endCopy")}),350),e.target.blur()},customStyle:function(){var e=this;return Object(f["a"])(regeneratorRuntime.mark((function t(){var n;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return e.$emit("showCssEditor"),e.$nextTick((function(){e.cssEditor||e.cssEditor.refresh()})),setTimeout((function(){e.cssEditor.refresh()}),50),t.next=5,localStorage.getItem("__css_content");case 5:n=t.sent,n||e.setCssEditorValue(G);case 7:case"end":return t.stop()}}),t)})))()},confirmReset:function(){localStorage.clear(),this.clearEditorToDefault(),this.editor.focus(),this.citeStatus=!1,this.statusChanged(!1),this.fontChanged(this.config.builtinFonts[0].value),this.colorChanged(this.config.colorOption[1].value),this.sizeChanged(this.config.sizeOption[2].value),this.$emit("cssChanged"),this.selectFont=this.currentFont,this.selectSize=this.currentSize,this.selectColor=this.currentColor,this.showResetConfirm=!1},cancelReset:function(){this.showResetConfirm=!1,this.editor.focus()}},Object(D["b"])(["clearEditorToDefault","setCurrentColor","setCiteStatus","themeChanged","setCurrentFont","setCurrentSize","setCssEditorValue","setCurrentCodeTheme","setWxRendererOptions"])),mounted:function(){this.selectFont=this.currentFont,this.selectSize=this.currentSize,this.selectColor=this.currentColor,this.selectCodeTheme=this.codeTheme}},q=B,U=(n("706c"),Object(A["a"])(q,u,d,!1,null,"96e5a094",null)),J=U.exports,W=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-dialog",{staticClass:"about__dialog",attrs:{title:"关于",visible:e.value,width:"30%",center:""},on:{close:function(t){return e.$emit("input",!1)}}},[n("div",{staticStyle:{"text-align":"center"}},[n("h3",[e._v("一款高度简洁的微信 Markdown 编辑器")])]),n("div",{staticStyle:{"text-align":"center","margin-top":"10px"}},[n("p",[e._v("扫码关注我的公众号,原创技术文章第一时间推送!")]),n("img",{staticStyle:{width:"40%",display:"block",margin:"20px auto 10px"},attrs:{src:"https://gitee.com/yanglbme/resource/raw/master/doocs-md/qrcode.png"}})]),n("span",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{attrs:{type:"primary",plain:""},on:{click:function(t){return e.onRedirect("https://github.com/doocs/md")}}},[e._v("GitHub 仓库")]),n("el-button",{attrs:{type:"primary",plain:""},on:{click:function(t){return e.onRedirect("https://gitee.com/doocs/md")}}},[e._v("Gitee 仓库")])],1)])},K=[],Y={props:{value:{type:Boolean,default:!1}},methods:{onRedirect:function(e){window.open(e)}}},Q=Y,Z=Object(A["a"])(Q,W,K,!1,null,"7f87549e",null),X=Z.exports,ee=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-dialog",{staticClass:"insert__dialog",attrs:{title:"插入表格",visible:e.value,border:""},on:{close:function(t){return e.$emit("input",!1)}}},[n("el-row",{staticClass:"tb-options",attrs:{type:"flex",align:"middle",gutter:10}},[n("el-col",{attrs:{span:6}},[e._v(" 行数 "),n("el-input-number",{attrs:{"controls-position":"right",min:1,max:100,size:"small"},on:{change:function(t){return e.handleChange(t,"row")}},model:{value:e.rowNum,callback:function(t){e.rowNum=t},expression:"rowNum"}})],1),n("el-col",{attrs:{span:6}},[e._v(" 列数 "),n("el-input-number",{attrs:{"controls-position":"right",min:1,max:100,size:"small"},on:{change:function(t){return e.handleChange(t,"col")}},model:{value:e.colNum,callback:function(t){e.colNum=t},expression:"colNum"}})],1)],1),n("table",{staticClass:"input-table",staticStyle:{"border-collapse":"collapse"}},e._l(e.rowNum+1,(function(t){return n("tr",{key:t,class:{"head-style":1===t}},e._l(e.colNum,(function(o){return n("td",{key:o},[n("el-input",{attrs:{align:"center",placeholder:1===t?"表头":""},model:{value:e.tableData["k_"+(t-1)+"_"+(o-1)],callback:function(n){e.$set(e.tableData,"k_"+(t-1)+"_"+(o-1),n)},expression:"tableData[`k_${row-1}_${col-1}`]"}})],1)})),0)})),0),n("div",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{attrs:{type:e.btnType,plain:""},on:{click:function(t){return e.$emit("input",!1)}}},[e._v("取 消")]),n("el-button",{attrs:{type:e.btnType,plain:""},on:{click:e.insertTable}},[e._v("确 定")])],1)],1)},te=[],ne=(n("99af"),n("a15b"),{props:{value:{type:Boolean,default:!1}},data:function(){return{config:$,rowNum:1,colNum:1,tableData:{}}},computed:Object(l["a"])({btnType:function(){return this.nightMode?"default":"primary"}},Object(D["c"])({nightMode:function(e){return e.nightMode},editor:function(e){return e.editor}})),methods:Object(l["a"])(Object(l["a"])({insertTable:function(){this.editor.getCursor();for(var e=this.rowNum,t=this.colNum,n="",o=[],i=0;i<e+2;++i){n+="|\t",o=[];for(var r=0;r<t;++r){var a=i>1?i-1:i;1===i?o.push("---\t"):o.push(this.tableData["k_".concat(a,"_").concat(r)]||"")}n+=o.join("\t|\t"),n+="\t|\n"}this.tableData={},this.rowNum=1,this.colNum=1,this.editor.replaceSelection("\n".concat(n,"\n"),"end"),this.$emit("input",!1),this.editorRefresh()}},Object(D["b"])(["editorRefresh"])),{},{handleChange:function(e,t){}})}),oe=ne,ie=(n("9656"),Object(A["a"])(oe,ee,te,!1,null,"fa0d7a10",null)),re=ie.exports,ae=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("ul",{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.list,(function(t){return n("li",{key:t.key,staticClass:"menu_item",on:{mousedown:function(n){return e.onMouseDown(t.key)}}},[n("span",[e._v(e._s(t.text))])])})),0)},se=[],ce=(n("a9e3"),n("b0c0"),n("25f0"),n("4d90"),n("bc3a")),le=n.n(ce),ue=le.a.create({baseURL:"",timeout:1e4});ue.interceptors.request.use((function(e){return/^(post)|(put)|(delete)$/i.test(e.method)&&e.data&&e.data.upload&&(e.headers["Content-Type"]="multipart/form-data"),e}),(function(e){Promise.reject(e)})),ue.interceptors.response.use((function(e){return e.data?e.data:Promise.reject(e)}),(function(e){return Promise.reject(e)}));var de=ue,fe=n("ec26"),pe={username:"filess",repo:"images",accessToken:["7715d7ca67b5d3837cfdoocsmde8c38421815aa423510af","c411415bf95dbe39625doocsmd5047ba9b7a2a6c9642abe","2821cd8819fa345c053doocsmdca86ac653f8bc20db1f1b","445f0dae46ef1f2a4d6doocsmdc797301e94797b4750a4c","cc1d0c1426d0fd0902bdoocsmdd2d7184b14da61b86ec46","b67e9d15cb6f910492fdoocsmdac6b44d379c953bb19eff","618c4dc2244ccbbc088doocsmd125d17fd31b7d06a50cf3","a4b581732e1c1507458doocsmdc5b223b27dae5e2e16a55"]};function ge(){var e=localStorage.getItem("ImgHost")||"default",t=pe.accessToken[Math.floor(Math.random()*pe.accessToken.length)].replace("doocsmd",""),n=pe.username,o=pe.repo;if("github"===e&&localStorage.getItem("GitHubConfig")){var i=JSON.parse(localStorage.getItem("GitHubConfig")),r=i.repo.replace("https://github.com/","").replace("http://github.com/","").replace("github.com/","").split("/");t=i.accessToken,n=r[0],o=r[1]}return{username:n,repo:o,token:t}}function me(e,t){var n=new Date,o=n.getFullYear()+"/"+(n.getMonth()+1).toString().padStart(2,"0")+"/"+n.getDate().toString().padStart(2,"0"),i=Object(fe["a"])(),r=(new Date).getTime()+"-"+i+"."+t.split(".")[1],a=ge(),s=a.username,c=a.repo,l=a.token,u="https://api.github.com/repos/".concat(s,"/").concat(c,"/contents/").concat(o,"/").concat(r);return de({url:u,method:"put",headers:{Authorization:"token "+l},data:{message:"Upload image by https://doocs.github.io/md",content:e}})}var he={fileUpload:me},be="raw.githubusercontent.com/filess/images/master/",ve="cdn.jsdelivr.net/gh/filess/images/";function Ce(e){return new Promise((function(t,n){var o=ke(e);if(o)n(o);else{var i=new FileReader;i.readAsDataURL(e),i.onload=function(){var n=this.result.split(",").pop();he.fileUpload(n,e.name).then((function(e){var n=e.content.download_url.replace(be,ve);t(n)})).catch((function(e){console.log(e.message)}))}}}))}function ke(e){return/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(e.name)?e.size>5242880&&"由于公众号限制,图片大小不能超过 5.0M":"请上传 JPG/PNG/GIF 格式的图片"}var we={props:{value:{type:Boolean,default:!1},top:{type:Number,default:0},left:{type:Number,default:0}},data:function(){return{list:[{text:"上传图片",key:"insertPic"},{text:"插入表格",key:"insertTable"},{text:"页面重置",key:"pageReset"},{text:"下载MD文档",key:"downLoad"}]}},methods:{closeCB:function(){this.$emit("input",!1)},onMouseDown:function(e){this.$emit("menuTick",e),this.$emit("closeMenu",!1)}}},ye=we,xe=(n("afb2"),Object(A["a"])(ye,ae,se,!1,null,"26fb3bc3",null)),_e=xe.exports,Se=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-dialog",{staticClass:"upload__dialog",attrs:{title:"插入图片",visible:e.value},on:{close:function(t){return e.$emit("close")}}},[n("el-tabs",{attrs:{type:"card",value:"upload"}},[n("el-tab-pane",{staticClass:"upload-panel",attrs:{label:"选择上传",name:"upload"}},[n("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 n("el-option",{key:e.value,attrs:{label:e.label,value:e.value}})})),1),n("el-upload",{directives:[{name:"loading",rawName:"v-loading",value:e.uploadingImg,expression:"uploadingImg"}],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.beforeUpload}},[n("i",{staticClass:"el-icon-upload"}),n("div",{staticClass:"el-upload__text"},[e._v(" 将文件拖到此处,或 "),n("em",[e._v("点击上传")])])])],1),n("el-tab-pane",{staticClass:"github-panel",attrs:{label:"GitHub 图床",name:"github"}},[n("el-form",{ref:"form",staticClass:"setting-form",attrs:{model:e.formGitHub,"label-position":"right","label-width":"120px"}},[n("el-form-item",{attrs:{label:"GitHub 仓库",required:"true"}},[n("el-input",{attrs:{placeholder:"如github.com/yanglbme/resource"},model:{value:e.formGitHub.repo,callback:function(t){e.$set(e.formGitHub,"repo",t)},expression:"formGitHub.repo"}})],1),n("el-form-item",{attrs:{label:"token",required:"true"}},[n("el-input",{attrs:{placeholder:"如cc1d0c1426d0fd0902bd2d7184b14da61b8abc46"},model:{value:e.formGitHub.accessToken,callback:function(t){e.$set(e.formGitHub,"accessToken",t)},expression:"formGitHub.accessToken"}}),n("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),n("el-form-item",[n("el-button",{attrs:{type:"primary"},on:{click:e.onSubmit}},[e._v("保存配置")])],1)],1)],1)],1)],1)},Oe=[],Ee={props:{value:{type:Boolean,default:!1}},data:function(){return{formGitHub:{repo:"",accessToken:""},options:[{value:"default",label:"默认图床"},{value:"github",label:"GitHub"}],imgHost:"default",uploadingImg:!1}},created:function(){localStorage.getItem("GitHubConfig")&&(this.formGitHub=JSON.parse(localStorage.getItem("GitHubConfig"))),localStorage.getItem("ImgHost")&&(this.imgHost=localStorage.getItem("ImgHost"))},methods:{changeImgHost:function(){console.log("select img host:",this.imgHost),localStorage.setItem("ImgHost",this.imgHost)},onSubmit:function(){if(this.formGitHub.repo&&this.formGitHub.accessToken)localStorage.setItem("GitHubConfig",JSON.stringify(this.formGitHub)),console.log("submit github params:",this.formGitHub),this.$message({message:"保存成功",type:"success"});else{var e=this.formGitHub.repo?"token":"GitHub 仓库";this.$message({showClose:!0,message:"参数「​".concat(e,"」不能为空"),type:"error"})}},beforeUpload:function(e){var t=this;if(this.validateConfig())return this.uploadingImg=!0,Ce(e).then((function(e){t.$emit("uploaded",e),t.uploadingImg=!1})).catch((function(e){t.uploadingImg=!1,t.$message({showClose:!0,message:e,type:"error"})})),!1},validateConfig:function(){switch(this.imgHost){case"github":var e=this.formGitHub,t=e.repo,n=e.accessToken;if(!t||!n)return this.$message.error("未配置 GitHub 参数"),!1}return!0}}},Te=Ee,Re=(n("8862"),Object(A["a"])(Te,Se,Oe,!1,null,"ccb3a454",null)),Me=Re.exports;n("f9d4");var je={data:function(){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:{editorHeader:J,aboutDialog:X,insertFormDialog:re,rightClickMenu:_e,uploadImgDialog:Me},computed:Object(l["a"])({},Object(D["c"])({wxRenderer:function(e){return e.wxRenderer},output:function(e){return e.output},editor:function(e){return e.editor},cssEditor:function(e){return e.cssEditor},currentSize:function(e){return e.currentSize},currentColor:function(e){return e.currentColor},nightMode:function(e){return e.nightMode},rightClickMenuVisible:function(e){return e.rightClickMenuVisible}})),created:function(){var e=this;this.initEditorState(),this.$nextTick((function(){e.initEditor(),e.initCssEditor(),e.onEditorRefresh()}))},methods:Object(l["a"])({initEditor:function(){var e=this;this.initEditorEntity(),this.editor.on("change",(function(t,n){e.changeTimer&&clearTimeout(e.changeTimer),e.changeTimer=setTimeout((function(){e.onEditorRefresh(),S(e.editor,"__editor_content")}),300)})),this.editor.on("paste",(function(t,n){if(n.clipboardData&&n.clipboardData.items&&!e.isImgLoading)for(var o=0,i=n.clipboardData.items.length;o<i;++o){var r=n.clipboardData.items[o];if("file"===r.kind){e.isImgLoading=!0;var a=r.getAsFile();Ce(a).then((function(t){e.uploaded(t)})).catch((function(t){e.$message({showClose:!0,message:t,type:"error"})})),e.isImgLoading=!1}}})),this.editor.on("mousedown",(function(){e.$store.commit("setRightClickMenuVisible",!1)})),this.editor.on("blur",(function(){
//!影响到右键菜单的点击事件右键菜单的点击事件在组件内通过mousedown触发
e.$store.commit("setRightClickMenuVisible",!1)})),this.editor.on("scroll",(function(){e.$store.commit("setRightClickMenuVisible",!1)}))},initCssEditor:function(){var e=this;this.initCssEditorEntity(),this.cssEditor.on("keyup",(function(e,t){(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode)&&e.showHint(t)})),this.cssEditor.on("update",(function(t){e.cssChanged(),S(e.cssEditor,"__css_content")}))},cssChanged:function(){var e=_(this.cssEditor.getValue(0)),t=y(this.currentSize.replace("px",""));t=x(e,this.currentColor,t),this.setWxRendererOptions({theme:t}),this.onEditorRefresh()},uploaded:function(e){if(e){this.dialogUploadImgVisible=!1;var t=this.editor.getCursor(),n=e,o="![](".concat(n,")");this.editor.replaceSelection("\n".concat(o,"\n"),t),this.$message({showClose:!0,message:"图片插入成功",type:"success"}),this.onEditorRefresh()}else this.$message({showClose:!0,message:"上传图片未知异常",type:"error"})},leftAndRightScroll:function(){var e=this,t=function(t){var i,r;clearTimeout(e.timeout),"preview"===t?(i=e.$refs.preview.$el,r=document.getElementsByClassName("CodeMirror-scroll")[0],e.editor.off("scroll",n),e.timeout=setTimeout((function(){e.editor.on("scroll",n)}),300)):"editor"===t&&(i=document.getElementsByClassName("CodeMirror-scroll")[0],r=e.$refs.preview.$el,r.removeEventListener("scroll",o,!1),e.timeout=setTimeout((function(){r.addEventListener("scroll",o,!1)}),300));var a=i.scrollTop/(i.scrollHeight-i.offsetHeight),s=a*(r.scrollHeight-r.offsetHeight);r.scrollTo(0,s)},n=function(){t("editor")},o=function(){t("preview")};this.$refs.preview.$el.addEventListener("scroll",o,!1),this.editor.on("scroll",n)},onEditorRefresh:function(){this.editorRefresh(),setTimeout((function(){return PR.prettyPrint()}),0)},endCopy:function(){var e=this;this.backLight=!1,setTimeout((function(){e.isCoping=!1}),800)},downloadEditorContent:function(){T(this.editor.getValue(0))},openMenu:function(e){var t=105,n=this.$el.getBoundingClientRect().left,o=this.$el.offsetWidth,i=o-t,r=e.clientX-n;this.mouseLeft=Math.min(i,r),this.mouseTop=e.clientY+10,this.$store.commit("setRightClickMenuVisible",!0)},closeRightClickMenu:function(){this.$store.commit("setRightClickMenuVisible",!1)},onMenuEvent:function(e){switch(e){case"pageReset":this.$refs.header.showResetConfirm=!0;break;case"insertPic":this.dialogUploadImgVisible=!0;break;case"downLoad":this.downloadEditorContent();break;case"insertTable":this.dialogFormVisible=!0;default:break}}},Object(D["b"])(["initEditorState","initEditorEntity","setWxRendererOptions","editorRefresh","initCssEditorEntity"])),mounted:function(){var e=this;setTimeout((function(){e.leftAndRightScroll(),PR.prettyPrint()}),300)}},Ie=je,$e=(n("db35"),n("85fe"),Object(A["a"])(Ie,s,c,!1,null,"26d55444",null)),ze=$e.exports,Ge={name:"App",components:{Loading:a["default"],CodemirrorEditor:ze},data:function(){return{loading:!0}},mounted:function(){var e=this;setTimeout((function(){e.loading=!1}),100)}},Fe=Ge,He=(n("c95f"),Object(A["a"])(Fe,i,r,!1,null,"6f36a3b6",null)),De=He.exports,Pe=n("e0c1"),Ve=n.n(Pe),Ae=function(e){var t=this;this.opts=e;var n=!0,o=[],i=0,r=null,a="Menlo, Operator Mono, Consolas, Monaco, monospace",s=function(e,t){return Object.assign({},e,t)};this.buildTheme=function(e){var n={},o=s(e.BASE,{"font-family":t.opts.fonts,"font-size":t.opts.size}),i=s(o,{});for(var r in e.inline)if(e.inline.hasOwnProperty(r)){var c=e.inline[r];"codespan"===r&&(c["font-family"]=a,c["white-space"]="normal"),n[r]=s(o,c)}for(var l in e.block)if(e.block.hasOwnProperty(l)){var u=e.block[l];"code"===l&&(u["font-family"]=a),n[l]=s(i,u)}return n};var c=function(e,t){var n=[],o=r[e];if(!o)return"";for(var i in o)n.push(i+":"+o[i]);return'style="'.concat(n.join(";")+(t||""),'"')},l=function(e,t){return o.push([++i,e,t]),i};this.buildFootnotes=function(){var e=o.map((function(e){return e[1]===e[2]?'<code style="font-size: 90%; opacity: 0.6;">['.concat(e[0],"]</code>: <i>").concat(e[1],"</i><br/>"):'<code style="font-size: 90%; opacity: 0.6;">['.concat(e[0],"]</code> ").concat(e[1],": <i>").concat(e[2],"</i><br/>")}));return"<h4 ".concat(c("h4"),">引用链接</h4><p ").concat(c("footnotes"),">").concat(e.join("\n"),"</p>")},this.buildAddition=function(){return'\n <style>\n .preview-wrapper pre::before {\n font-family: "SourceSansPro", "HelveticaNeue", Arial, sans-serif;\n position: absolute;\n top: 0;\n right: 0;\n color: #ccc;\n text-align: center;\n font-size: 0.8em;\n padding: 5px 10px 0;\n line-height: 15px;\n height: 15px;\n font-weight: 600;\n }\n </style>\n '},this.setOptions=function(e){t.opts=s(t.opts,e)},this.hasFootnotes=function(){return 0!==o.length},this.getRenderer=function(e){o=[],i=0,r=t.buildTheme(t.opts.theme);var a=new Ve.a.Renderer;return a.heading=function(e,t){switch(t){case 1:return"<h1 ".concat(c("h1"),">").concat(e,"</h1>");case 2:return"<h2 ".concat(c("h2"),">").concat(e,"</h2>");case 3:return"<h3 ".concat(c("h3"),">").concat(e,"</h3>");default:return"<h4 ".concat(c("h4"),">").concat(e,"</h4>")}},a.paragraph=function(e){return-1!=e.indexOf("<figure")&&-1!=e.indexOf("<img")?e:""===e.replace(/ /g,"")?"":"<p ".concat(c("p"),">").concat(e,"</p>")},a.blockquote=function(e){return e=e.replace(/<p.*?>/g,"<p ".concat(c("blockquote_p"),">")),"<blockquote ".concat(c("blockquote"),">").concat(e,"</blockquote>")},a.code=function(e,t){e=e.replace(/</g,"&lt;").replace(/>/g,"&gt;");var n=e.split("\n").map((function(e){return'<code class="prettyprint"><span class="code-snippet_outer">'.concat(e||"<br>","</span></code>")})),o="github";return'\n <section class="code-snippet__'.concat(o,'">\n <pre class="code__pre" data-lang="').concat(t,'">\n ').concat(n.join(""),"\n </pre>\n </section>\n ")},a.codespan=function(e,t){return"<code ".concat(c("codespan"),">").concat(e,"</code>")},a.listitem=function(e){return"<span ".concat(c("listitem"),'><span style="margin-right: 10px;"><%s/></span>').concat(e,"</span>")},a.list=function(e,t,n){e=e.replace(/<\/*p.*?>/g,"");var o=e.split("<%s/>");if(!t)return e=o.join("•"),"<p ".concat(c("ul"),">").concat(e,"</p>");e=o[0];for(var i=1;i<o.length;i++)e=e+i+"."+o[i];return"<p ".concat(c("ol"),">").concat(e,"</p>")},a.image=function(e,t,o){var i="";o&&(i="<figcaption ".concat(c("figcaption"),">").concat(o,"</figcaption>"));var r=c("figure"),a=c(n?"image":"image_org");return"<figure ".concat(r,"><img ").concat(a,' src="').concat(e,'" title="').concat(t,'" alt="').concat(o,'"/>').concat(i,"</figure>")},a.link=function(t,n,o){if(0===t.indexOf("https://mp.weixin.qq.com"))return'<a href="'.concat(t,'" title="').concat(n||o,'" ').concat(c("wx_link"),">").concat(o,"</a>");if(t===o||!e)return o;var i=l(n||o,t);return"<span ".concat(c("link"),">").concat(o,"<sup>[").concat(i,"]</sup></span>")},a.strong=function(e){return"<strong ".concat(c("strong"),">").concat(e,"</strong>")},a.em=function(e){return'<span style="font-style: italic;">'.concat(e,"</span>")},a.table=function(e,t){return'<section style="padding:0 8px;"><table class="preview-table"><thead '.concat(c("thead"),">").concat(e,"</thead><tbody>").concat(t,"</tbody></table></section>")},a.tablecell=function(e,t){return"<td ".concat(c("td"),">").concat(e,"</td>")},a.hr=function(){return'<hr style="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);">'},a}},Ne=Ae,Le=n("56b3"),Be=n.n(Le),qe='# 示例文章Google 搜索的即时自动补全功能究竟是如何“工作”的?\n> Google 搜索**自动补全功能**的强大,相信不少朋友都能感受到,它帮助我们更快地“补全”我们所要输入的搜索关键字。那么,它怎么知道我们要输入什么内容?它又是如何工作的?在这篇文章里,我们一起来看看。\n\n## 使用自动补全\nGoogle 搜索的自动补全功能可以在 Google 搜索应用的大多数位置使用,包括 [Google](https://www.google.com/) 主页、适用于 IOS 和 Android 的 Google 应用,我们只需要在 Google 搜索框上开始键入关键字,就可以看到联想词了。\n\n![](https://gitee.com/yanglbme/resource/raw/master/doocs-md/juejin.gif)\n\n在上图示例中我们可以看到输入关键字 `juej`Google 搜索会联想到“掘金”、“掘金小册”、“绝句”等等,好处就是,我们无须输入完整的关键字即可轻松完成针对这些 topics 的搜索。\n\n谷歌搜索的自动补全功能对于使用移动设备的用户来说特别有用用户可以轻松在难以键入的小屏幕上完成搜索。当然对于移动设备用户和台式机用户而言这都节省了大量的时间。根据 Google 官方报告,自动补全功能可以减少大约 25% 的打字,累积起来,预计每天可以节省 200 多年的打字时间。是的,每天!\n\n> 注意,本文所提到的“**联想词**”与“**预测**”,是同一个意思。\n\n## 基于“预测”而非“建议”\nGoogle 官方将自动补全功能称之为“预测”,而不是“建议”,为什么呢?其实是有充分理由的。自动补全功能是为了**帮助用户完成他们打算进行的搜索**,而不是建议用户要执行什么搜索。\n\n那么Google 是如何确定这些“预测”的其实Google 会根据趋势搜索 [trends](https://trends.google.com/trends/?geo=US) 给到我们这些“预测”。简单来说,哪个热门、哪个搜索频率高,就更可能推给我们。当然,这也与我们当前所处的位置以及我们的搜索历史相关。\n\n另外这些“预测”也会随着我们键入的关键字的变更而更改。例如当我们把键入的关键字从 `juej` 更改为 `juex` 时,与“掘金”相关的预测会“消失”,同时,与“觉醒”、“决心”相关联的词会出现。\n\n![](https://gitee.com/yanglbme/resource/raw/master/doocs-md/juex.gif)\n\n## 为什么看不到某些联想词?\n如果我们在输入某个关键字时看不到联想词那么表明 Google 的算法可能检测到:\n\n- 这个关键字不是热门字词;\n- 搜索的字词太新了,我们可能需要等待几天或几周才能看到联想词;\n- 这是一个侮辱性或敏感字词,这个搜索字词违反了 Google 的相关政策。更加详细的情况,可以了解 [Google 搜索自动补全政策](https://support.google.com/websearch/answer/7368877)。\n\n## 为什么会看到某些不当的联想词?\nGoogle 拥有专门设计的系统可以自动捕获不适当的预测结果而不显示出来。然而Google 每天需要处理数十亿次搜索,这意味着 Google 每天会显示数十亿甚至上百亿条预测。再好的系统,也可能存在缺陷,不正确的预测也可能随时会出现。\n\n我们作为 Google 搜索的用户,如果认定某条预测违反了相关的搜索自动补全政策,可以进行举报反馈,点击右下角“**举报不当的联想查询**”并勾选相关选项即可。\n\n![](https://gitee.com/yanglbme/resource/raw/master/doocs-md/report.gif)\n\n## 如何实现自动补全算法?\n目前Google 官方似乎并没有公开搜索自动补全的算法实现,但是业界在这方面已经有了不少研究。\n\n一个好的自动补全器必须是快速的并且在用户键入下一个字符后立即更新联想词列表。**自动补全器的核心是一个函数,它接受输入的前缀,并搜索以给定前缀开头的词汇或语句列表**。通常来说,只需要返回少量的数目即可。\n\n接下来我们先从一个简单且低效的实现开始并在此基础上逐步构建更高效的方法。\n\n### 词汇表实现\n一个**简单粗暴的实现方式**是:顺序查找词汇表,依次检查每个词汇,看它是否以给定的前缀开头。\n\n但是此方法需要将前缀与每个词汇进行匹配检查若词汇量较少这种方式可能勉强行得通。但是如果词汇量规模较大效率就太低了。\n\n一个**更好的实现方式是**:让词汇按字典顺序排序。借助二分搜索算法,可以快速搜索有序词汇表中的前缀。由于二分搜索的每一步都会将搜索的范围减半,因此,总的搜索时间与词汇表中单词数量的对数成正比,即时间复杂度是 `O(log N)`。二分搜索的性能很好,但有没有更好的实现呢?当然有,往下看。\n\n### 前缀树实现\n通常来说许多词汇都以相同的前缀开头比如 `need`、`nested` 都以 `ne` 开头,`seed`、`speed` 都以 `s` 开头。要是为每个单词分别存储公共前缀似乎很浪费。\n\n![](https://gitee.com/yanglbme/resource/raw/master/doocs-md/pretree.png)\n\n前缀树是一种利用公共前缀来加速补全速度的数据结构。前缀树在节点树中排列一组单词单词沿着从根节点到叶子节点的路径存储树的层次对应于前缀的字母位置。\n\n前缀的补全是顺着前缀定义的路径来查找的。例如在上图的前缀树中前缀 `ne` 对应于从子节点取左边缘 `N` 和唯一边缘 `E` 的路径。然后可以通过继续遍历从 `E` 节点可以达到的所有叶节点来生成补全列表。在图中,`ne` 的补全可以是两个分支:`-ed` 和 `-sted`。如果在数中找不到由前缀定义的路径,则说明词汇表中不包含以该前缀开头的单词。\n\n### 有限状态自动机(DFA)实现\n前缀树可以有效处理公共前缀但是对于其他共享词部分仍会分别存储在每个分支中。比如后缀 `ed`、`ing`、`tion` 在英文单词中特别常见。在上一个例子中,`e`、`d` 分别存放在了每一个分支上。\n\n有没有一种方法可以更加节省存储空间呢有的那就是 DFA。\n\n<center>\n<img src="https://gitee.com/yanglbme/resource/raw/master/doocs-md/dfa.gif" style="width: 50%;"></center>\n\n在上面的例子中单词 `need`、`nested`、`seed` 和 `speed` 仅由 9 个节点组成,而上一张图中的前缀树包含了 17 个节点。\n\n可以看出最小化前缀树 DFA 可以在很大程度上减少数据结构的大小。即使词汇量很大,最小化 DFA 通常也适合在内存中存储,避免昂贵的磁盘访问是实现快速自动补全的关键。\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- [阿里又一个 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<center>\n <img src="https://gitee.com/yanglbme/resource/raw/master/doocs-md/qrcode.png" style="width: 100px;">\n</center>\n\n',Ue=qe;o["default"].use(D["a"]);var Je={wxRenderer:null,output:"",html:"",editor:null,cssEditor:null,currentFont:"",currentSize:"",currentColor:"",citeStatus:0,nightMode:!1,codeTheme:"github",rightClickMenuVisible:!1},We={setEditorValue:function(e,t){e.editor.setValue(t)},setCssEditorValue:function(e,t){e.cssEditor.setValue(t)},setWxRendererOptions:function(e,t){e.wxRenderer.setOptions(t)},setCiteStatus:function(e,t){e.citeStatus=t,localStorage.setItem("citeStatus",t)},setCurrentFont:function(e,t){e.currentFont=t,localStorage.setItem("fonts",t)},setCurrentSize:function(e,t){e.currentSize=t,localStorage.setItem("size",t)},setCurrentColor:function(e,t){e.currentColor=t,localStorage.setItem("color",t)},setCurrentCodeTheme:function(e,t){e.codeTheme=t,localStorage.setItem("codeTheme",t)},setRightClickMenuVisible:function(e,t){e.rightClickMenuVisible=t},themeChanged:function(e){e.nightMode=!e.nightMode,localStorage.setItem("nightMode",e.nightMode)},initEditorState:function(e){e.currentFont=localStorage.getItem("fonts")||$.builtinFonts[0].value,e.currentColor=localStorage.getItem("color")||$.colorOption[1].value,e.currentSize=localStorage.getItem("size")||$.sizeOption[2].value,e.codeTheme=localStorage.getItem("codeTheme")||$.codeThemeOption[0].value,e.citeStatus="true"===localStorage.getItem("citeStatus"),e.nightMode="true"===localStorage.getItem("nightMode"),e.wxRenderer=new Ne({theme:w(e.currentColor),fonts:e.currentFont,size:e.currentSize,status:e.citeStatus})},initEditorEntity:function(e){e.editor=Be.a.fromTextArea(document.getElementById("editor"),{value:"",mode:"text/x-markdown",theme:"xq-light",lineNumbers:!1,lineWrapping:!0,styleActiveLine:!0,autoCloseBrackets:!0,extraKeys:{"Ctrl-F":function(e){var t=O(e.getValue(0));localStorage.setItem("__editor_content",t),e.setValue(t)},"Ctrl-S":function(e){}}}),e.editor.setValue(localStorage.getItem("__editor_content")||O(Ue))},initCssEditorEntity:function(e){e.cssEditor=Be.a.fromTextArea(document.getElementById("cssEditor"),{value:"",mode:"css",theme:"style-mirror",lineNumbers:!1,lineWrapping:!0,matchBrackets:!0,autofocus:!0,extraKeys:{"Ctrl-F":function(e){var t=e.lineCount();e.autoFormatRange({line:0,ch:0},{line:t})},"Ctrl-S":function(e){}}}),e.cssEditor.setValue(localStorage.getItem("__css_content")||G)},editorRefresh:function(e){var t=Ve()(e.editor.getValue(0),{renderer:e.wxRenderer.getRenderer(e.citeStatus)});t=t.replace(/(style=".*?)"/,'$1;margin-top: 0"'),e.citeStatus&&(t+=e.wxRenderer.buildFootnotes(),t+=e.wxRenderer.buildAddition()),e.output=t},clearEditorToDefault:function(e){var t=O(Ue);e.editor.setValue(t),e.cssEditor.setValue(G)}},Ke=new D["a"].Store({state:Je,mutations:We,actions:{},modules:{}}),Ye=n("5c96"),Qe=n.n(Ye);n("0fae");o["default"].use(Ye["Container"]),o["default"].use(Ye["Header"]),o["default"].use(Ye["Upload"]),o["default"].use(Ye["Tooltip"]),o["default"].use(Ye["Form"]),o["default"].use(Ye["FormItem"]),o["default"].use(Ye["Select"]),o["default"].use(Ye["Option"]),o["default"].use(Ye["ColorPicker"]),o["default"].use(Ye["Switch"]),o["default"].use(Ye["Button"]),o["default"].use(Ye["Main"]),o["default"].use(Ye["Col"]),o["default"].use(Ye["Row"]),o["default"].use(Ye["Dialog"]),o["default"].use(Ye["Loading"]),o["default"].component(Ye["Message"].name,Ye["Message"]),o["default"].prototype.$loading=Ye["Loading"].service,o["default"].prototype.$message=Ye["Message"];n("a7be"),n("0f7c"),n("8d7e"),n("7b00"),n("959b"),n("8c33"),n("31c5"),n("9b74"),n("111b"),n("90ba"),n("baa5");(function(){Be.a.extendMode("css",{commentStart:"/*",commentEnd:"*/",newlineAfterToken:function(e,t){return/^[;{}]$/.test(t)}}),Be.a.defineExtension("commentRange",(function(e,t,n){var o=this,i=Be.a.innerMode(o.getMode(),o.getTokenAt(t).state).mode;o.operation((function(){if(e)o.replaceRange(i.commentEnd,n),o.replaceRange(i.commentStart,t),t.line==n.line&&t.ch==n.ch&&o.setCursor(t.line,t.ch+i.commentStart.length);else{var r=o.getRange(t,n),a=r.indexOf(i.commentStart),s=r.lastIndexOf(i.commentEnd);a>-1&&s>-1&&s>a&&(r=r.substr(0,a)+r.substring(a+i.commentStart.length,s)+r.substr(s+i.commentEnd.length)),o.replaceRange(r,t,n)}}))})),Be.a.defineExtension("autoIndentRange",(function(e,t){var n=this;this.operation((function(){for(var o=e.line;o<=t.line;o++)n.indentLine(o,"smart")}))})),Be.a.defineExtension("autoFormatRange",(function(e,t){var n=this,o=n.getMode(),i=n.getRange(e,t).split("\n"),r=Be.a.copyState(o,n.getTokenAt(e).state),a=n.getOption("tabSize"),s="",c=0,l=0==e.ch;function u(){s+="\n",l=!0,++c}for(var d=0;d<i.length;++d){var f=new Be.a.StringStream(i[d],a);while(!f.eol()){var p=Be.a.innerMode(o,r),g=o.token(f,r),m=f.current();f.start=f.pos,l&&!/\S/.test(m)||(s+=m,l=!1),!l&&p.mode.newlineAfterToken&&p.mode.newlineAfterToken(g,m,f.string.slice(f.pos)||i[d+1]||"",p.state)&&u()}!f.pos&&o.blankLine&&o.blankLine(r),l||u()}n.operation((function(){n.replaceRange(s,e,t);for(var o=e.line+1,i=e.line+c;o<=i;++o)n.indentLine(o,"smart");n.setSelection(e,n.getCursor(!1))}))}))})();n("18a5");var Ze=n("53ca");(function(e){var t={pairs:"()[]{}''\"\"",closeBefore:")]}'\":;>",triples:"",explode:"[]{}"},n=e.Pos;function o(e,n){return"pairs"==n&&"string"==typeof e?e:"object"==Object(Ze["a"])(e)&&null!=e[n]?e[n]:t[n]}e.defineOption("autoCloseBrackets",!1,(function(t,n,a){a&&a!=e.Init&&(t.removeKeyMap(i),t.state.closeBrackets=null),n&&(r(o(n,"pairs")),t.state.closeBrackets=n,t.addKeyMap(i))}));var i={Backspace:c,Enter:l};function r(e){for(var t=0;t<e.length;t++){var n=e.charAt(t),o="'"+n+"'";i[o]||(i[o]=a(n))}}function a(e){return function(t){return d(t,e)}}function s(e){var t=e.state.closeBrackets;if(!t||t.override)return t;var n=e.getModeAt(e.getCursor());return n.closeBrackets||t}function c(t){var i=s(t);if(!i||t.getOption("disableInput"))return e.Pass;for(var r=o(i,"pairs"),a=t.listSelections(),c=0;c<a.length;c++){if(!a[c].empty())return e.Pass;var l=f(t,a[c].head);if(!l||r.indexOf(l)%2!=0)return e.Pass}for(c=a.length-1;c>=0;c--){var u=a[c].head;t.replaceRange("",n(u.line,u.ch-1),n(u.line,u.ch+1),"+delete")}}function l(t){var n=s(t),i=n&&o(n,"explode");if(!i||t.getOption("disableInput"))return e.Pass;for(var r=t.listSelections(),a=0;a<r.length;a++){if(!r[a].empty())return e.Pass;var c=f(t,r[a].head);if(!c||i.indexOf(c)%2!=0)return e.Pass}t.operation((function(){var e=t.lineSeparator()||"\n";t.replaceSelection(e+e,null),t.execCommand("goCharLeft"),r=t.listSelections();for(var n=0;n<r.length;n++){var o=r[n].head.line;t.indentLine(o,null,!0),t.indentLine(o+1,null,!0)}}))}function u(t){var o=e.cmpPos(t.anchor,t.head)>0;return{anchor:new n(t.anchor.line,t.anchor.ch+(o?-1:1)),head:new n(t.head.line,t.head.ch+(o?1:-1))}}function d(t,i){var r=s(t);if(!r||t.getOption("disableInput"))return e.Pass;var a=o(r,"pairs"),c=a.indexOf(i);if(-1==c)return e.Pass;for(var l,d=o(r,"closeBefore"),f=o(r,"triples"),g=a.charAt(c+1)==i,m=t.listSelections(),h=c%2==0,b=0;b<m.length;b++){var v,C=m[b],k=C.head,w=t.getRange(k,n(k.line,k.ch+1));if(h&&!C.empty())v="surround";else if(!g&&h||w!=i)if(g&&k.ch>1&&f.indexOf(i)>=0&&t.getRange(n(k.line,k.ch-2),k)==i+i){if(k.ch>2&&/\bstring/.test(t.getTokenTypeAt(n(k.line,k.ch-2))))return e.Pass;v="addFour"}else if(g){var y=0==k.ch?" ":t.getRange(n(k.line,k.ch-1),k);if(e.isWordChar(w)||y==i||e.isWordChar(y))return e.Pass;v="both"}else{if(!h||!(0===w.length||/\s/.test(w)||d.indexOf(w)>-1))return e.Pass;v="both"}else v=g&&p(t,k)?"both":f.indexOf(i)>=0&&t.getRange(k,n(k.line,k.ch+3))==i+i+i?"skipThree":"skip";if(l){if(l!=v)return e.Pass}else l=v}var x=c%2?a.charAt(c-1):i,_=c%2?i:a.charAt(c+1);t.operation((function(){if("skip"==l)t.execCommand("goCharRight");else if("skipThree"==l)for(var e=0;e<3;e++)t.execCommand("goCharRight");else if("surround"==l){var n=t.getSelections();for(e=0;e<n.length;e++)n[e]=x+n[e]+_;t.replaceSelections(n,"around"),n=t.listSelections().slice();for(e=0;e<n.length;e++)n[e]=u(n[e]);t.setSelections(n)}else"both"==l?(t.replaceSelection(x+_,null),t.triggerElectric(x+_),t.execCommand("goCharLeft")):"addFour"==l&&(t.replaceSelection(x+x+x+x,"before"),t.execCommand("goCharRight"))}))}function f(e,t){var o=e.getRange(n(t.line,t.ch-1),n(t.line,t.ch+1));return 2==o.length?o:null}function p(e,t){var o=e.getTokenAt(n(t.line,t.ch+1));return/\bstring/.test(o.type)&&o.start==t.ch&&(0==t.ch||!/\bstring/.test(e.getTokenTypeAt(t)))}r(t.pairs+"`")})(Be.a),o["default"].use(Qe.a),o["default"].config.productionTip=!1,new o["default"]({store:Ke,render:function(e){return e(De)}}).$mount("#app")},"595a":function(e,t,n){},"5b3a":function(e,t,n){"use strict";var o=n("595a"),i=n.n(o);i.a},6705:function(e,t,n){},"706c":function(e,t,n){"use strict";var o=n("a2d1"),i=n.n(o);i.a},7268:function(e,t,n){"use strict";n.d(t,"a",(function(){return o})),n.d(t,"b",(function(){return i}));var o=function(){var e=this,t=e.$createElement;e._self._c;return e._m(0)},i=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"loading",attrs:{id:"loading"}},[n("div",{staticClass:"loading-wrapper"},[n("div",{staticClass:"loading-anim"}),n("div",{staticClass:"loading-text"},[e._v("致力于让 Markdown 编辑更简单")])])])}]},"85fe":function(e,t,n){"use strict";var o=n("db6c"),i=n.n(o);i.a},8862:function(e,t,n){"use strict";var o=n("d58d"),i=n.n(o);i.a},"90ba":function(e,t,n){},9656:function(e,t,n){"use strict";var o=n("e5cc"),i=n.n(o);i.a},a2d1:function(e,t,n){},afb2:function(e,t,n){"use strict";var o=n("d037"),i=n.n(o);i.a},c95f:function(e,t,n){"use strict";var o=n("0a43"),i=n.n(o);i.a},cb57:function(e,t,n){"use strict";var o=n("eff7"),i=n.n(o);t["default"]=i.a},d037:function(e,t,n){},d58d:function(e,t,n){},db35:function(e,t,n){"use strict";var o=n("6705"),i=n.n(o);i.a},db6c:function(e,t,n){},e5cc:function(e,t,n){},eff7:function(e,t){},f6be:function(e,t,n){"use strict";var o=n("38c7"),i=n.n(o);i.a}});
//# sourceMappingURL=app.05d7455c.js.map