1 |
- {"version":3,"sources":["../src/helper.js"],"names":["isFunction","isUrl","arrayToObject","htmlEncode","renderContent","addImageProcess","functionToCheck","toString","call","userInput","regexp","res","match","array","keyField","reduce","obj","item","str","replace","i","charCodeAt","content","onClick","newContent","indexOf","IMAGE_SPLIT","split","pop","join","innerUrl","data","REGEXP","a","b","src","slice","console","log","emoji","JSON","parse","sessionStorage","getItem","title","protocol","hasProtocol","test","url","options","small","IMAGE_PROCESS_SMALL","large","IMAGE_PROCESS_LARGE","IMAGE_PROCESS"],"mappings":";;;;;QAWgBA,U,GAAAA,U;QAMAC,K,GAAAA,K;QAaAC,a,GAAAA,a;QAYAC,U,GAAAA,U;QAYAC,a,GAAAA,a;QAuCAC,e,GAAAA,e;;AA7FhB;;AAOA;;AAEA;;AAEO,SAASL,UAAT,CAAoBM,eAApB,EAAqC;AAC1C,SACEA,mBAAmB,GAAGC,QAAH,CAAYC,IAAZ,CAAiBF,eAAjB,MAAsC,mBAD3D;AAGD;;AAEM,SAASL,KAAT,CAAeQ,SAAf,EAA0B;AAC/B;AACA,MAAMC,SAAS,sGAAf;AACA,MAAIC,MAAMF,UAAUG,KAAV,CAAgBF,MAAhB,CAAV;AACA,MAAIC,QAAQ,IAAZ,EAAkB,OAAO,KAAP,CAAlB,KACK,OAAO,IAAP;AACN;;AAED;;;;;AAKO,SAAST,aAAT,CAAuBW,KAAvB,EAA8BC,QAA9B,EAAwC;AAC7C,SAAOD,MAAME,MAAN,CAAa,UAACC,GAAD,EAAMC,IAAN,EAAe;AACjCD,QAAIC,KAAKH,QAAL,CAAJ,IAAsBG,IAAtB;AACA,WAAOD,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID;;AAED;;;;;AAKO,SAASb,UAAT,CAAoBe,GAApB,EAAyB;AAC9B,MAAI,CAACA,GAAL,EAAU,OAAO,EAAP;AACV,SAAOA,IAAIC,OAAJ,CAAY,SAAZ,EAAuB,UAASC,CAAT,EAAY;AACxC,WAAO,OAAOA,EAAEC,UA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AOY,IAAP;AACD;;AAEM,SAAS1B,eAAT,CAAyB2C,GAAzB,EAA4C;AAAA,MAAdC,OAAc,uEAAJ,EAAI;;AACjD,MAAIA,QAAQC,KAAZ,EAAmB;AACjB,WAAOF,MAAMG,6BAAb;AACD;AACD,MAAIF,QAAQG,KAAZ,EAAmB;AACjB,WAAOJ,MAAMK,6BAAb;AACD;AACD,SAAOL,MAAMM,uBAAb;AACD","file":"helper.js","sourcesContent":["import {\n REGEXP,\n IMAGE_SPLIT,\n IMAGE_PROCESS_SMALL,\n IMAGE_PROCESS_LARGE,\n IMAGE_PROCESS\n} from \"./constant\";\n// import emoji, { prefixUrl } from \"./emoji\";\n\n// const emojiObejct = arrayToObject(emoji, \"title\");\n\nexport function isFunction(functionToCheck) {\n return (\n functionToCheck && {}.toString.call(functionToCheck) === \"[object Function]\"\n );\n}\n\nexport function isUrl(userInput) {\n // 需完整匹配\n const regexp = /^((http(s)?:)?\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\n var res = userInput.match(regexp);\n if (res === null) return false;\n else return true;\n}\n\n/**\n * 将对象数组转换为对象\n * @param {array} array Array of Objects\n * @param {string} keyField string\n */\nexport function arrayToObject(array, keyField) {\n return array.reduce((obj, item) => {\n obj[item[keyField]] = item;\n return obj;\n }, {});\n}\n\n/**\n * HTML 编码\n * 将 < > 等字符串进行编码\n * @param {string} str 文本\n */\nexport function htmlEncode(str) {\n if (!str) return \"\";\n return str.replace(/[<>]/gim, function(i) {\n return \"&#\" + i.charCodeAt(0) + \";\";\n });\n}\n\n/**\n * 渲染编辑器\n * [x] => <img src=\"x\" />\n * @param {strig} content\n */\nexport function renderContent(content, onClick) {\n let newContent = content;\n if (newContent.indexOf(IMAGE_SPLIT) !== -1) {\n newContent = newContent.split(IMAGE_SPLIT);\n newContent.pop();\n newContent = newContent.join(\"\");\n }\n // 不包含在标签内的链接\n const innerUrl = /((http(s)?:)?\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[com|net|org|cn|edu|top|gov]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)(?![^<>]*>|[^\"]*?<\\/a)/g;\n const data = htmlEncode(newContent)\n .replace(REGEXP, function(a, b) {\n const src = a.slice(1, -1);\n\n // 兼容旧的评\n // 因为旧的评论用 [img url] 方式存储的\n if (isUrl(src)) {\n return `<a href=\"${src}\" rel=\"noopener noreferrer\" target=\"_blank\"><img class=\"comment-img\" src=\"${src}\" alt=\"${src}\" /></a>`;\n }\n // 如果不存在对应的表情, 则返回原文\n // const emoji = emojiObejct[src];\n console.log(src);\n const emoji = JSON.parse(sessionStorage.getItem(\"emojiMap\"))[src];\n if (emoji) {\n return `<img class=\"comment-emoji\" src=\"${emoji}\" alt=\"${emoji.title}\" />`;\n }\n return `[${src}]`;\n })\n .replace(innerUrl, function(a, b) {\n const protocol = /^(https?:)?\\/\\//;\n const hasProtocol = protocol.test(a);\n const url = hasProtocol ? a : `//${a}`;\n // target=\"_blank\" 存在安全性问题\n // return `<a href=\"${url}\" target=\"_blank\" rel=\"noopener noreferrer\" >${a}</a>`;\n return `<a href=\"${url}\">${a}</a>`;\n })\n .replace(/\\n/g, \"<br />\");\n return data;\n}\n\nexport function addImageProcess(url, options = {}) {\n if (options.small) {\n return url + IMAGE_PROCESS_SMALL;\n }\n if (options.large) {\n return url + IMAGE_PROCESS_LARGE;\n }\n return url + IMAGE_PROCESS;\n}\n"]}
|