search.min.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. !(function () {
  2. var u = {},
  3. m = { EXPIRE_KEY: 'docsify.search.expires', INDEX_KEY: 'docsify.search.index' }
  4. function p(e) {
  5. var n = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }
  6. return String(e).replace(/[&<>"']/g, function (e) {
  7. return n[e]
  8. })
  9. }
  10. function h(e) {
  11. return (
  12. e.text ||
  13. 'table' !== e.type ||
  14. (e.cells.unshift(e.header),
  15. (e.text = e.cells
  16. .map(function (e) {
  17. return e.join(' | ')
  18. })
  19. .join(' |\n '))),
  20. e.text
  21. )
  22. }
  23. function f(e) {
  24. return e.text || 'list' !== e.type || (e.text = e.raw), e.text
  25. }
  26. function g(i, e, r, o) {
  27. void 0 === e && (e = '')
  28. var s,
  29. e = window.marked.lexer(e),
  30. c = window.Docsify.slugify,
  31. d = {},
  32. l = ''
  33. return (
  34. e.forEach(function (e, n) {
  35. if ('heading' === e.type && e.depth <= o) {
  36. var t = (function (e) {
  37. void 0 === e && (e = '')
  38. var a = {}
  39. return {
  40. str: (e =
  41. e &&
  42. e
  43. .replace(/^('|")/, '')
  44. .replace(/('|")$/, '')
  45. .replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, function (e, n, t) {
  46. return -1 === n.indexOf(':') ? ((a[n] = (t && t.replace(/&quot;/g, '')) || !0), '') : e
  47. })
  48. .trim()),
  49. config: a,
  50. }
  51. })(e.text),
  52. a = t.str,
  53. t = t.config
  54. ;(s = t.id ? r.toURL(i, { id: c(t.id) }) : r.toURL(i, { id: c(p(e.text)) })),
  55. a &&
  56. (l = a
  57. .replace(/<!-- {docsify-ignore} -->/, '')
  58. .replace(/{docsify-ignore}/, '')
  59. .replace(/<!-- {docsify-ignore-all} -->/, '')
  60. .replace(/{docsify-ignore-all}/, '')
  61. .trim()),
  62. (d[s] = { slug: s, title: l, body: '' })
  63. } else {
  64. if ((0 === n && ((s = r.toURL(i)), (d[s] = { slug: s, title: '/' !== i ? i.slice(1) : 'Home Page', body: e.text || '' })), !s)) return
  65. d[s]
  66. ? d[s].body
  67. ? ((e.text = h(e)), (e.text = f(e)), (d[s].body += '\n' + (e.text || '')))
  68. : ((e.text = h(e)), (e.text = f(e)), (d[s].body = d[s].body ? d[s].body + e.text : e.text))
  69. : (d[s] = { slug: s, title: '', body: '' })
  70. }
  71. }),
  72. c.clear(),
  73. d
  74. )
  75. }
  76. function y(e) {
  77. return e && e.normalize ? e.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : e
  78. }
  79. function r(i, r) {
  80. var t,
  81. a,
  82. n,
  83. e,
  84. o = 'auto' === i.paths,
  85. s = o
  86. ? ((t = r.router),
  87. (a = []),
  88. Docsify.dom.findAll('.sidebar-nav a:not(.section-link):not([data-nosearch])').forEach(function (e) {
  89. var n = e.href,
  90. e = e.getAttribute('href'),
  91. n = t.parse(n).path
  92. n && -1 === a.indexOf(n) && !Docsify.util.isAbsolutePath(e) && a.push(n)
  93. }),
  94. a)
  95. : i.paths,
  96. c = ''
  97. s.length && o && i.pathNamespaces
  98. ? ((n = s[0]),
  99. Array.isArray(i.pathNamespaces)
  100. ? (c =
  101. i.pathNamespaces.filter(function (e) {
  102. return n.slice(0, e.length) === e
  103. })[0] || c)
  104. : i.pathNamespaces instanceof RegExp && (d = n.match(i.pathNamespaces)) && (c = d[0]),
  105. (e = -1 === s.indexOf(c + '/')),
  106. (d = -1 === s.indexOf(c + '/README')),
  107. e && d && s.unshift(c + '/'))
  108. : -1 === s.indexOf('/') && -1 === s.indexOf('/README') && s.unshift('/')
  109. var d,
  110. l = ((d = i.namespace) ? m.EXPIRE_KEY + '/' + d : m.EXPIRE_KEY) + c,
  111. p = ((d = i.namespace) ? m.INDEX_KEY + '/' + d : m.INDEX_KEY) + c,
  112. c = localStorage.getItem(l) < Date.now()
  113. if (((u = JSON.parse(localStorage.getItem(p))), c)) u = {}
  114. else if (!o) return
  115. var h = s.length,
  116. f = 0
  117. s.forEach(function (a) {
  118. return u[a]
  119. ? f++
  120. : void Docsify.get(r.router.getFile(a), !1, r.config.requestHeaders).then(function (e) {
  121. var n, t
  122. ;(u[a] = g(a, e, r.router, i.depth)), h === ++f && ((n = i.maxAge), (t = l), (e = p), localStorage.setItem(t, Date.now() + n), localStorage.setItem(e, JSON.stringify(u)))
  123. })
  124. })
  125. }
  126. var o,
  127. s = ''
  128. function c(e) {
  129. var n = Docsify.dom.find('div.search'),
  130. t = Docsify.dom.find(n, '.results-panel'),
  131. a = Docsify.dom.find(n, '.clear-button'),
  132. i = Docsify.dom.find('.sidebar-nav'),
  133. n = Docsify.dom.find('.app-name')
  134. if (!e)
  135. return t.classList.remove('show'), a.classList.remove('show'), (t.innerHTML = ''), void (o.hideOtherSidebarContent && (i && i.classList.remove('hide'), n && n.classList.remove('hide')))
  136. var e = (function (e) {
  137. var n = [],
  138. t = []
  139. Object.keys(u).forEach(function (n) {
  140. t = t.concat(
  141. Object.keys(u[n]).map(function (e) {
  142. return u[n][e]
  143. })
  144. )
  145. })
  146. var a = (e = e.trim()).split(/[\s\-,\\/]+/)
  147. 1 !== a.length && (a = [].concat(e, a))
  148. for (var i = 0; i < t.length; i++)
  149. !(function (e) {
  150. var e = t[e],
  151. r = 0,
  152. o = '',
  153. s = '',
  154. c = '',
  155. d = e.title && e.title.trim(),
  156. l = e.body && e.body.trim(),
  157. e = e.slug || ''
  158. d &&
  159. (a.forEach(function (e) {
  160. var n,
  161. t = new RegExp(p(y(e)).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'), 'gi'),
  162. a = -1,
  163. i = -1
  164. ;(s = d ? p(y(d)) : d),
  165. (c = l ? p(y(l)) : l),
  166. (a = d ? s.search(t) : -1),
  167. (i = l ? c.search(t) : -1),
  168. (0 <= a || 0 <= i) &&
  169. ((r += 0 <= a ? 3 : 0 <= i ? 2 : 0),
  170. i < 0 && (i = 0),
  171. (a = (a = n = 0) == (n = i < 11 ? 0 : i - 10) ? 70 : i + e.length + 60),
  172. l && a > l.length && (a = l.length),
  173. (t =
  174. '...' +
  175. c.substring(n, a).replace(t, function (e) {
  176. return '<em class="search-keyword">' + e + '</em>'
  177. }) +
  178. '...'),
  179. (o += t))
  180. }),
  181. 0 < r && ((e = { title: s, content: l ? o : '', url: e, score: r }), n.push(e)))
  182. })(i)
  183. return n.sort(function (e, n) {
  184. return n.score - e.score
  185. })
  186. })(e),
  187. r = ''
  188. e.forEach(function (e) {
  189. r += '<div class="matching-post">\n<a href="' + e.url + '">\n<h2>' + e.title + '</h2>\n<p>' + e.content + '</p>\n</a>\n</div>'
  190. }),
  191. t.classList.add('show'),
  192. a.classList.add('show'),
  193. (t.innerHTML = r || '<p class="empty">' + s + '</p>'),
  194. o.hideOtherSidebarContent && (i && i.classList.add('hide'), n && n.classList.add('hide'))
  195. }
  196. function d(e) {
  197. o = e
  198. }
  199. function l(e, n) {
  200. var t,
  201. a,
  202. i = n.router.parse().query.s
  203. d(e),
  204. Docsify.dom.style(
  205. '\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .input-wrap {\n display: flex;\n align-items: center;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 0 7px;\n line-height: 36px;\n font-size: 14px;\n border: 1px solid transparent;\n}\n\n.search input:focus {\n box-shadow: 0 0 5px var(--theme-color, #42b983);\n border: 1px solid var(--theme-color, #42b983);\n}\n\n.search input::-webkit-search-decoration,\n.search input::-webkit-search-cancel-button,\n.search input {\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n.search .clear-button {\n cursor: pointer;\n width: 36px;\n text-align: right;\n display: none;\n}\n\n.search .clear-button.show {\n display: block;\n}\n\n.search .clear-button svg {\n transform: scale(.5);\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}\n\n.app-name.hide, .sidebar-nav.hide {\n display: none;\n}'
  206. ),
  207. (function (e) {
  208. void 0 === e && (e = '')
  209. var n =
  210. '<div class="input-wrap">\n <input type="search" value="' +
  211. e +
  212. '" aria-label="Search text" />\n <div class="clear-button">\n <svg width="26" height="24">\n <circle cx="12" cy="12" r="11" fill="#ccc" />\n <path stroke="white" stroke-width="2" d="M8.25,8.25,15.75,15.75" />\n <path stroke="white" stroke-width="2"d="M8.25,15.75,15.75,8.25" />\n </svg>\n </div>\n </div>\n <div class="results-panel"></div>\n </div>',
  213. e = Docsify.dom.create('div', n),
  214. n = Docsify.dom.find('aside')
  215. Docsify.dom.toggleClass(e, 'search'), Docsify.dom.before(n, e)
  216. })(i),
  217. (n = Docsify.dom.find('div.search')),
  218. (a = Docsify.dom.find(n, 'input')),
  219. (e = Docsify.dom.find(n, '.input-wrap')),
  220. Docsify.dom.on(n, 'click', function (e) {
  221. return -1 === ['A', 'H2', 'P', 'EM'].indexOf(e.target.tagName) && e.stopPropagation()
  222. }),
  223. Docsify.dom.on(a, 'input', function (n) {
  224. clearTimeout(t),
  225. (t = setTimeout(function (e) {
  226. return c(n.target.value.trim())
  227. }, 100))
  228. }),
  229. Docsify.dom.on(e, 'click', function (e) {
  230. 'INPUT' !== e.target.tagName && ((a.value = ''), c())
  231. }),
  232. i &&
  233. setTimeout(function (e) {
  234. return c(i)
  235. }, 500)
  236. }
  237. function v(e, n) {
  238. var t, a, i, r, o
  239. d(e),
  240. (t = e.placeholder),
  241. (a = n.route.path),
  242. (r = Docsify.dom.getNode('.search input[type="search"]')) &&
  243. ('string' == typeof t
  244. ? (r.placeholder = t)
  245. : ((i = Object.keys(t).filter(function (e) {
  246. return -1 < a.indexOf(e)
  247. })[0]),
  248. (r.placeholder = t[i]))),
  249. (e = e.noData),
  250. (o = n.route.path),
  251. (s =
  252. 'string' == typeof e
  253. ? e
  254. : e[
  255. Object.keys(e).filter(function (e) {
  256. return -1 < o.indexOf(e)
  257. })[0]
  258. ])
  259. }
  260. var b = { placeholder: 'Type to search', noData: 'No Results!', paths: 'auto', depth: 2, maxAge: 864e5, hideOtherSidebarContent: !1, namespace: void 0, pathNamespaces: void 0 }
  261. $docsify.plugins = [].concat(function (e, n) {
  262. var t = Docsify.util,
  263. a = n.config.search || b
  264. Array.isArray(a)
  265. ? (b.paths = a)
  266. : 'object' == typeof a &&
  267. ((b.paths = Array.isArray(a.paths) ? a.paths : 'auto'),
  268. (b.maxAge = (t.isPrimitive(a.maxAge) ? a : b).maxAge),
  269. (b.placeholder = a.placeholder || b.placeholder),
  270. (b.noData = a.noData || b.noData),
  271. (b.depth = a.depth || b.depth),
  272. (b.hideOtherSidebarContent = a.hideOtherSidebarContent || b.hideOtherSidebarContent),
  273. (b.namespace = a.namespace || b.namespace),
  274. (b.pathNamespaces = a.pathNamespaces || b.pathNamespaces))
  275. var i = 'auto' === b.paths
  276. e.mounted(function (e) {
  277. l(b, n), i || r(b, n)
  278. }),
  279. e.doneEach(function (e) {
  280. v(b, n), i && r(b, n)
  281. })
  282. }, $docsify.plugins)
  283. })()