dobo 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/workflows/repo-lockdown.yml +24 -0
  3. package/.jsdoc.conf.json +45 -0
  4. package/LICENSE +1 -1
  5. package/README.md +38 -19
  6. package/docs/Dobo.html +26 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +7 -0
  12. package/docs/index.html +3 -0
  13. package/docs/index.js.html +578 -0
  14. package/docs/lib_collect-connections.js.html +39 -0
  15. package/docs/lib_collect-drivers.js.html +52 -0
  16. package/docs/lib_collect-features.js.html +36 -0
  17. package/docs/lib_collect-schemas.js.html +94 -0
  18. package/docs/lib_index.js.html +6 -0
  19. package/docs/method_model_create.js.html +35 -0
  20. package/docs/method_model_drop.js.html +34 -0
  21. package/docs/method_model_exists.js.html +40 -0
  22. package/docs/method_record_count.js.html +69 -0
  23. package/docs/method_record_create.js.html +114 -0
  24. package/docs/method_record_find-all.js.html +44 -0
  25. package/docs/method_record_find-one.js.html +73 -0
  26. package/docs/method_record_find.js.html +118 -0
  27. package/docs/method_record_get.js.html +92 -0
  28. package/docs/method_record_remove.js.html +75 -0
  29. package/docs/method_record_update.js.html +107 -0
  30. package/docs/method_record_upsert.js.html +54 -0
  31. package/docs/method_sanitize_body.js.html +88 -0
  32. package/docs/method_sanitize_date.js.html +30 -0
  33. package/docs/method_sanitize_id.js.html +20 -0
  34. package/docs/method_validate.js.html +249 -0
  35. package/docs/module-Lib.html +3 -0
  36. package/docs/scripts/core.js +725 -0
  37. package/docs/scripts/core.min.js +23 -0
  38. package/docs/scripts/resize.js +90 -0
  39. package/docs/scripts/search.js +265 -0
  40. package/docs/scripts/search.min.js +6 -0
  41. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  42. package/docs/scripts/third-party/fuse.js +9 -0
  43. package/docs/scripts/third-party/hljs-line-num-original.js +366 -0
  44. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  45. package/docs/scripts/third-party/hljs-original.js +5164 -0
  46. package/docs/scripts/third-party/hljs.js +1 -0
  47. package/docs/scripts/third-party/popper.js +5 -0
  48. package/docs/scripts/third-party/tippy.js +1 -0
  49. package/docs/scripts/third-party/tocbot.js +671 -0
  50. package/docs/scripts/third-party/tocbot.min.js +1 -0
  51. package/docs/static/bitcoin.jpeg +0 -0
  52. package/docs/static/home.md +25 -0
  53. package/docs/static/logo-ecosystem.png +0 -0
  54. package/docs/static/logo.png +0 -0
  55. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  56. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  57. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  58. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  59. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  60. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  61. package/extend/bajo/intl/en-US.json +69 -30
  62. package/extend/bajo/intl/id.json +58 -29
  63. package/extend/bajoCli/applet/clear-record.js +22 -0
  64. package/extend/bajoCli/applet/connection.js +5 -5
  65. package/extend/bajoCli/applet/count-record.js +27 -0
  66. package/extend/bajoCli/applet/create-aggregate.js +33 -0
  67. package/extend/bajoCli/applet/create-histogram.js +33 -0
  68. package/extend/bajoCli/applet/create-record.js +39 -0
  69. package/extend/bajoCli/applet/find-record.js +27 -0
  70. package/extend/bajoCli/applet/get-record.js +27 -0
  71. package/extend/bajoCli/applet/lib/post-process.js +25 -26
  72. package/extend/bajoCli/applet/model.js +22 -0
  73. package/extend/bajoCli/applet/rebuild-model.js +91 -0
  74. package/extend/bajoCli/applet/remove-record.js +27 -0
  75. package/extend/bajoCli/applet/update-record.js +44 -0
  76. package/extend/bajoCli/applet.js +0 -0
  77. package/extend/dobo/driver/memory.js +170 -0
  78. package/extend/dobo/feature/created-at.js +10 -8
  79. package/extend/dobo/feature/dt.js +0 -0
  80. package/extend/dobo/feature/immutable.js +30 -0
  81. package/extend/dobo/feature/int-id.js +0 -0
  82. package/extend/dobo/feature/removed-at.js +35 -57
  83. package/extend/dobo/feature/updated-at.js +14 -12
  84. package/extend/waibuMpa/route/attachment/@model/@id/@field/@file.js +5 -9
  85. package/extend/waibuStatic/virtual.json +0 -0
  86. package/index.js +420 -337
  87. package/lib/collect-connections.js +60 -21
  88. package/lib/collect-drivers.js +29 -35
  89. package/lib/collect-features.js +40 -0
  90. package/lib/collect-models.js +319 -0
  91. package/lib/factory/action.js +161 -0
  92. package/lib/factory/connection.js +62 -0
  93. package/lib/factory/driver.js +358 -0
  94. package/lib/factory/feature.js +33 -0
  95. package/lib/factory/model/_util.js +402 -0
  96. package/lib/factory/model/build.js +15 -0
  97. package/lib/factory/model/clear-record.js +17 -0
  98. package/lib/factory/model/count-record.js +17 -0
  99. package/lib/factory/model/create-aggregate.js +17 -0
  100. package/lib/factory/model/create-attachment.js +29 -0
  101. package/lib/factory/model/create-histogram.js +17 -0
  102. package/lib/factory/model/create-record.js +35 -0
  103. package/lib/factory/model/drop.js +15 -0
  104. package/lib/factory/model/exists.js +21 -0
  105. package/lib/factory/model/find-all-record.js +71 -0
  106. package/lib/factory/model/find-attachment.js +29 -0
  107. package/lib/factory/model/find-one-record.js +19 -0
  108. package/lib/factory/model/find-record.js +103 -0
  109. package/lib/factory/model/get-attachment.js +15 -0
  110. package/lib/factory/model/get-record.js +79 -0
  111. package/lib/factory/model/list-attachment.js +37 -0
  112. package/lib/{add-fixtures.js → factory/model/load-fixtures.js} +69 -67
  113. package/lib/factory/model/remove-attachment.js +15 -0
  114. package/lib/factory/model/remove-record.js +59 -0
  115. package/lib/factory/model/sanitize-body.js +62 -0
  116. package/lib/factory/model/sanitize-id.js +7 -0
  117. package/lib/factory/model/sanitize-record.js +26 -0
  118. package/lib/factory/model/update-attachment.js +9 -0
  119. package/lib/factory/model/update-record.js +81 -0
  120. package/lib/factory/model/upsert-record.js +95 -0
  121. package/lib/factory/model/validate.js +232 -0
  122. package/lib/factory/model.js +150 -0
  123. package/lib/index.js +3 -0
  124. package/package.json +45 -36
  125. package/wiki/APPLETS.md +57 -0
  126. package/wiki/CHANGES.md +46 -0
  127. package/wiki/CONFIG.md +25 -0
  128. package/wiki/CONTRIBUTING.md +5 -0
  129. package/wiki/DEV-GUIDE.md +1 -0
  130. package/wiki/ECOSYSTEM.md +20 -0
  131. package/wiki/GETTING-STARTED.md +166 -0
  132. package/{docs/query-language.md → wiki/QUERY-LANGUAGE.md} +0 -0
  133. package/wiki/USER-GUIDE.md +1 -0
  134. package/extend/bajoCli/applet/model-clear.js +0 -11
  135. package/extend/bajoCli/applet/model-rebuild.js +0 -101
  136. package/extend/bajoCli/applet/record-create.js +0 -41
  137. package/extend/bajoCli/applet/record-find.js +0 -27
  138. package/extend/bajoCli/applet/record-get.js +0 -24
  139. package/extend/bajoCli/applet/record-remove.js +0 -24
  140. package/extend/bajoCli/applet/record-update.js +0 -47
  141. package/extend/bajoCli/applet/schema.js +0 -22
  142. package/extend/bajoCli/applet/stat-count.js +0 -24
  143. package/lib/build-bulk-action.js +0 -12
  144. package/lib/check-unique.js +0 -39
  145. package/lib/collect-feature.js +0 -25
  146. package/lib/collect-schemas.js +0 -83
  147. package/lib/exec-feature-hook.js +0 -13
  148. package/lib/exec-validation.js +0 -21
  149. package/lib/generic-prop-sanitizer.js +0 -31
  150. package/lib/handle-attachment-upload.js +0 -16
  151. package/lib/mem-db/conn-sanitizer.js +0 -8
  152. package/lib/mem-db/instantiate.js +0 -41
  153. package/lib/mem-db/method/model/clear.js +0 -6
  154. package/lib/mem-db/method/model/create.js +0 -5
  155. package/lib/mem-db/method/model/drop.js +0 -5
  156. package/lib/mem-db/method/model/exists.js +0 -5
  157. package/lib/mem-db/method/record/create.js +0 -12
  158. package/lib/mem-db/method/record/find.js +0 -20
  159. package/lib/mem-db/method/record/get.js +0 -9
  160. package/lib/mem-db/method/record/remove.js +0 -13
  161. package/lib/mem-db/method/record/update.js +0 -15
  162. package/lib/mem-db/method/stat/count.js +0 -11
  163. package/lib/mem-db/start.js +0 -25
  164. package/lib/merge-attachment-info.js +0 -16
  165. package/lib/multi-rel-rows.js +0 -42
  166. package/lib/resolve-method.js +0 -16
  167. package/lib/sanitize-schema.js +0 -197
  168. package/lib/single-rel-rows.js +0 -38
  169. package/method/attachment/copy-uploaded.js +0 -34
  170. package/method/attachment/create.js +0 -29
  171. package/method/attachment/find.js +0 -27
  172. package/method/attachment/get-path.js +0 -12
  173. package/method/attachment/get.js +0 -12
  174. package/method/attachment/pre-check.js +0 -9
  175. package/method/attachment/remove.js +0 -11
  176. package/method/attachment/update.js +0 -7
  177. package/method/bulk/create.js +0 -46
  178. package/method/model/clear.js +0 -22
  179. package/method/model/create.js +0 -19
  180. package/method/model/drop.js +0 -19
  181. package/method/model/exists.js +0 -24
  182. package/method/record/clear.js +0 -24
  183. package/method/record/count.js +0 -44
  184. package/method/record/create.js +0 -71
  185. package/method/record/find-all.js +0 -25
  186. package/method/record/find-one.js +0 -56
  187. package/method/record/find.js +0 -52
  188. package/method/record/get.js +0 -47
  189. package/method/record/remove.js +0 -41
  190. package/method/record/update.js +0 -63
  191. package/method/record/upsert.js +0 -35
  192. package/method/sanitize/body.js +0 -70
  193. package/method/sanitize/date.js +0 -14
  194. package/method/sanitize/id.js +0 -7
  195. package/method/stat/aggregate.js +0 -23
  196. package/method/stat/histogram.js +0 -26
  197. package/method/validate.js +0 -157
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Fuse.js v6.4.6 - Lightweight fuzzy-search (http://fusejs.io)
3
+ *
4
+ * Copyright (c) 2021 Kiro Risk (http://kiro.me)
5
+ * All Rights Reserved. Apache Software License 2.0
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ */
9
+ let e, t; e = this, t = function () { 'use strict'; function e (t) { return (e = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (e) { return typeof e } : function (e) { return e && typeof Symbol === 'function' && e.constructor === Symbol && e !== Symbol.prototype ? 'symbol' : typeof e })(t) } function t (e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function') } function n (e, t) { for (let n = 0; n < t.length; n++) { const r = t[n]; r.enumerable = r.enumerable || !1, r.configurable = !0, 'value' in r && (r.writable = !0), Object.defineProperty(e, r.key, r) } } function r (e, t, r) { return t && n(e.prototype, t), r && n(e, r), e } function i (e, t, n) { return t in e ? Object.defineProperty(e, t, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = n, e } function o (e, t) { const n = Object.keys(e); if (Object.getOwnPropertySymbols) { let r = Object.getOwnPropertySymbols(e); t && (r = r.filter(function (t) { return Object.getOwnPropertyDescriptor(e, t).enumerable })), n.push.apply(n, r) } return n } function c (e) { for (let t = 1; t < arguments.length; t++) { var n = arguments[t] != null ? arguments[t] : {}; t % 2 ? o(Object(n), !0).forEach(function (t) { i(e, t, n[t]) }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : o(Object(n)).forEach(function (t) { Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t)) }) } return e } function a (e, t) { if (typeof t !== 'function' && t !== null) throw new TypeError('Super expression must either be null or a function'); e.prototype = Object.create(t && t.prototype, { constructor: { value: e, writable: !0, configurable: !0 } }), t && u(e, t) } function s (e) { return (s = Object.setPrototypeOf ? Object.getPrototypeOf : function (e) { return e.__proto__ || Object.getPrototypeOf(e) })(e) } function u (e, t) { return (u = Object.setPrototypeOf || function (e, t) { return e.__proto__ = t, e })(e, t) } function h (e, t) { return !t || typeof t !== 'object' && typeof t !== 'function' ? (function (e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e }(e)) : t } function f (e) { const t = (function () { if (typeof Reflect === 'undefined' || !Reflect.construct) return !1; if (Reflect.construct.sham) return !1; if (typeof Proxy === 'function') return !0; try { return Date.prototype.toString.call(Reflect.construct(Date, [], function () {})), !0 } catch (e) { return !1 } }()); return function () { let n; const r = s(e); if (t) { const i = s(this).constructor; n = Reflect.construct(r, arguments, i) } else n = r.apply(this, arguments); return h(this, n) } } function l (e) { return (function (e) { if (Array.isArray(e)) return d(e) }(e)) || (function (e) { if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(e)) return Array.from(e) }(e)) || (function (e, t) { if (e) { if (typeof e === 'string') return d(e, t); let n = Object.prototype.toString.call(e).slice(8, -1); return n === 'Object' && e.constructor && (n = e.constructor.name), n === 'Map' || n === 'Set' ? Array.from(e) : n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? d(e, t) : void 0 } }(e)) || (function () { throw new TypeError('Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.') }()) } function d (e, t) { (t == null || t > e.length) && (t = e.length); for (var n = 0, r = new Array(t); n < t; n++)r[n] = e[n]; return r } function v (e) { return Array.isArray ? Array.isArray(e) : b(e) === '[object Array]' } function g (e) { return typeof e === 'string' } function y (e) { return typeof e === 'number' } function p (e) { return !0 === e || !1 === e || (function (e) { return m(e) && e !== null }(e)) && b(e) == '[object Boolean]' } function m (t) { return e(t) === 'object' } function k (e) { return e != null } function M (e) { return !e.trim().length } function b (e) { return e == null ? void 0 === e ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(e) } const x = function (e) { return 'Invalid value for key '.concat(e) }; const L = function (e) { return 'Pattern length exceeds max of '.concat(e, '.') }; const S = Object.prototype.hasOwnProperty; const w = (function () { function e (n) { const r = this; t(this, e), this._keys = [], this._keyMap = {}; let i = 0; n.forEach(function (e) { const t = _(e); i += t.weight, r._keys.push(t), r._keyMap[t.id] = t, i += t.weight }), this._keys.forEach(function (e) { e.weight /= i }) } return r(e, [{ key: 'get', value: function (e) { return this._keyMap[e] } }, { key: 'keys', value: function () { return this._keys } }, { key: 'toJSON', value: function () { return JSON.stringify(this._keys) } }]), e }()); function _ (e) { let t = null; let n = null; let r = null; let i = 1; if (g(e) || v(e))r = e, t = O(e), n = j(e); else { if (!S.call(e, 'name')) throw new Error(function (e) { return 'Missing '.concat(e, ' property in key') }('name')); const o = e.name; if (r = o, S.call(e, 'weight') && (i = e.weight) <= 0) throw new Error(function (e) { return "Property 'weight' in key '".concat(e, "' must be a positive integer") }(o)); t = O(o), n = j(o) } return { path: t, id: n, weight: i, src: r } } function O (e) { return v(e) ? e : e.split('.') } function j (e) { return v(e) ? e.join('.') : e } const A = c({}, { isCaseSensitive: !1, includeScore: !1, keys: [], shouldSort: !0, sortFn: function (e, t) { return e.score === t.score ? e.idx < t.idx ? -1 : 1 : e.score < t.score ? -1 : 1 } }, {}, { includeMatches: !1, findAllMatches: !1, minMatchCharLength: 1 }, {}, { location: 0, threshold: 0.6, distance: 100 }, {}, { useExtendedSearch: !1, getFn: function (e, t) { const n = []; let r = !1; return (function e (t, i, o) { if (k(t)) if (i[o]) { const c = t[i[o]]; if (!k(c)) return; if (o === i.length - 1 && (g(c) || y(c) || p(c)))n.push(function (e) { return e == null ? '' : (function (e) { if (typeof e === 'string') return e; const t = e + ''; return t == '0' && 1 / e == -1 / 0 ? '-0' : t }(e)) }(c)); else if (v(c)) { r = !0; for (let a = 0, s = c.length; a < s; a += 1)e(c[a], i, o + 1) } else i.length && e(c, i, o + 1) } else n.push(t) }(e, g(t) ? t.split('.') : t, 0)), r ? n : n[0] }, ignoreLocation: !1, ignoreFieldNorm: !1 }); const I = /[^ ]+/g; function C () { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 3; const t = new Map(); const n = Math.pow(10, e); return { get: function (e) { const r = e.match(I).length; if (t.has(r)) return t.get(r); const i = 1 / Math.sqrt(r); const o = parseFloat(Math.round(i * n) / n); return t.set(r, o), o }, clear: function () { t.clear() } } } const E = (function () { function e () { const n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; const r = n.getFn; const i = void 0 === r ? A.getFn : r; t(this, e), this.norm = C(3), this.getFn = i, this.isCreated = !1, this.setIndexRecords() } return r(e, [{ key: 'setSources', value: function () { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : []; this.docs = e } }, { key: 'setIndexRecords', value: function () { const e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : []; this.records = e } }, { key: 'setKeys', value: function () { const e = this; const t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : []; this.keys = t, this._keysMap = {}, t.forEach(function (t, n) { e._keysMap[t.id] = n }) } }, { key: 'create', value: function () { const e = this; !this.isCreated && this.docs.length && (this.isCreated = !0, g(this.docs[0]) ? this.docs.forEach(function (t, n) { e._addString(t, n) }) : this.docs.forEach(function (t, n) { e._addObject(t, n) }), this.norm.clear()) } }, { key: 'add', value: function (e) { const t = this.size(); g(e) ? this._addString(e, t) : this._addObject(e, t) } }, { key: 'removeAt', value: function (e) { this.records.splice(e, 1); for (let t = e, n = this.size(); t < n; t += 1) this.records[t].i -= 1 } }, { key: 'getValueForItemAtKeyId', value: function (e, t) { return e[this._keysMap[t]] } }, { key: 'size', value: function () { return this.records.length } }, { key: '_addString', value: function (e, t) { if (k(e) && !M(e)) { const n = { v: e, i: t, n: this.norm.get(e) }; this.records.push(n) } } }, { key: '_addObject', value: function (e, t) { const n = this; const r = { i: t, $: {} }; this.keys.forEach(function (t, i) { const o = n.getFn(e, t.path); if (k(o)) if (v(o))!(function () { for (var e = [], t = [{ nestedArrIndex: -1, value: o }]; t.length;) { const c = t.pop(); const a = c.nestedArrIndex; const s = c.value; if (k(s)) if (g(s) && !M(s)) { const u = { v: s, i: a, n: n.norm.get(s) }; e.push(u) } else v(s) && s.forEach(function (e, n) { t.push({ nestedArrIndex: n, value: e }) }) }r.$[i] = e }()); else if (!M(o)) { const c = { v: o, n: n.norm.get(o) }; r.$[i] = c } }), this.records.push(r) } }, { key: 'toJSON', value: function () { return { keys: this.keys, records: this.records } } }]), e }()); function $ (e, t) { const n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}; const r = n.getFn; const i = void 0 === r ? A.getFn : r; const o = new E({ getFn: i }); return o.setKeys(e.map(_)), o.setSources(t), o.create(), o } function R (e) { const t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const n = t.errors; const r = void 0 === n ? 0 : n; const i = t.currentLocation; const o = void 0 === i ? 0 : i; const c = t.expectedLocation; const a = void 0 === c ? 0 : c; const s = t.distance; const u = void 0 === s ? A.distance : s; const h = t.ignoreLocation; const f = void 0 === h ? A.ignoreLocation : h; const l = r / e.length; if (f) return l; const d = Math.abs(a - o); return u ? l + d / u : d ? 1 : l } function F () { for (var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [], t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : A.minMatchCharLength, n = [], r = -1, i = -1, o = 0, c = e.length; o < c; o += 1) { const a = e[o]; a && r === -1 ? r = o : a || r === -1 || ((i = o - 1) - r + 1 >= t && n.push([r, i]), r = -1) } return e[o - 1] && o - r >= t && n.push([r, o - 1]), n } function P (e) { for (var t = {}, n = 0, r = e.length; n < r; n += 1) { const i = e.charAt(n); t[i] = (t[i] || 0) | 1 << r - n - 1 } return t } const N = (function () { function e (n) { const r = this; const i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const o = i.location; const c = void 0 === o ? A.location : o; const a = i.threshold; const s = void 0 === a ? A.threshold : a; const u = i.distance; const h = void 0 === u ? A.distance : u; const f = i.includeMatches; const l = void 0 === f ? A.includeMatches : f; const d = i.findAllMatches; const v = void 0 === d ? A.findAllMatches : d; const g = i.minMatchCharLength; const y = void 0 === g ? A.minMatchCharLength : g; const p = i.isCaseSensitive; const m = void 0 === p ? A.isCaseSensitive : p; const k = i.ignoreLocation; const M = void 0 === k ? A.ignoreLocation : k; if (t(this, e), this.options = { location: c, threshold: s, distance: h, includeMatches: l, findAllMatches: v, minMatchCharLength: y, isCaseSensitive: m, ignoreLocation: M }, this.pattern = m ? n : n.toLowerCase(), this.chunks = [], this.pattern.length) { const b = function (e, t) { r.chunks.push({ pattern: e, alphabet: P(e), startIndex: t }) }; const x = this.pattern.length; if (x > 32) { for (var L = 0, S = x % 32, w = x - S; L < w;)b(this.pattern.substr(L, 32), L), L += 32; if (S) { const _ = x - 32; b(this.pattern.substr(_), _) } } else b(this.pattern, 0) } } return r(e, [{ key: 'searchIn', value: function (e) { const t = this.options; const n = t.isCaseSensitive; const r = t.includeMatches; if (n || (e = e.toLowerCase()), this.pattern === e) { const i = { isMatch: !0, score: 0 }; return r && (i.indices = [[0, e.length - 1]]), i } const o = this.options; const c = o.location; const a = o.distance; const s = o.threshold; const u = o.findAllMatches; const h = o.minMatchCharLength; const f = o.ignoreLocation; let d = []; let v = 0; let g = !1; this.chunks.forEach(function (t) { const n = t.pattern; const i = t.alphabet; const o = t.startIndex; const y = (function (e, t, n) { const r = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}; const i = r.location; const o = void 0 === i ? A.location : i; const c = r.distance; const a = void 0 === c ? A.distance : c; const s = r.threshold; const u = void 0 === s ? A.threshold : s; const h = r.findAllMatches; const f = void 0 === h ? A.findAllMatches : h; const l = r.minMatchCharLength; const d = void 0 === l ? A.minMatchCharLength : l; const v = r.includeMatches; const g = void 0 === v ? A.includeMatches : v; const y = r.ignoreLocation; const p = void 0 === y ? A.ignoreLocation : y; if (t.length > 32) throw new Error(L(32)); for (var m, k = t.length, M = e.length, b = Math.max(0, Math.min(o, M)), x = u, S = b, w = d > 1 || g, _ = w ? Array(M) : []; (m = e.indexOf(t, S)) > -1;) { const O = R(t, { currentLocation: m, expectedLocation: b, distance: a, ignoreLocation: p }); if (x = Math.min(O, x), S = m + k, w) for (let j = 0; j < k;)_[m + j] = 1, j += 1 }S = -1; for (var I = [], C = 1, E = k + M, $ = 1 << k - 1, P = 0; P < k; P += 1) { for (var N = 0, D = E; N < D;) { const z = R(t, { errors: P, currentLocation: b + D, expectedLocation: b, distance: a, ignoreLocation: p }); z <= x ? N = D : E = D, D = Math.floor((E - N) / 2 + N) }E = D; let K = Math.max(1, b - D + 1); const q = f ? M : Math.min(b + D, M) + k; const W = Array(q + 2); W[q + 1] = (1 << P) - 1; for (let J = q; J >= K; J -= 1) { const T = J - 1; const U = n[e.charAt(T)]; if (w && (_[T] = +!!U), W[J] = (W[J + 1] << 1 | 1) & U, P && (W[J] |= (I[J + 1] | I[J]) << 1 | 1 | I[J + 1]), W[J] & $ && (C = R(t, { errors: P, currentLocation: T, expectedLocation: b, distance: a, ignoreLocation: p })) <= x) { if (x = C, (S = T) <= b) break; K = Math.max(1, 2 * b - S) } } const V = R(t, { errors: P + 1, currentLocation: b, expectedLocation: b, distance: a, ignoreLocation: p }); if (V > x) break; I = W } const B = { isMatch: S >= 0, score: Math.max(0.001, C) }; if (w) { const G = F(_, d); G.length ? g && (B.indices = G) : B.isMatch = !1 } return B }(e, n, i, { location: c + o, distance: a, threshold: s, findAllMatches: u, minMatchCharLength: h, includeMatches: r, ignoreLocation: f })); const p = y.isMatch; const m = y.score; const k = y.indices; p && (g = !0), v += m, p && k && (d = [].concat(l(d), l(k))) }); const y = { isMatch: g, score: g ? v / this.chunks.length : 1 }; return g && r && (y.indices = d), y } }]), e }()); const D = (function () { function e (n) { t(this, e), this.pattern = n } return r(e, [{ key: 'search', value: function () {} }], [{ key: 'isMultiMatch', value: function (e) { return z(e, this.multiRegex) } }, { key: 'isSingleMatch', value: function (e) { return z(e, this.singleRegex) } }]), e }()); function z (e, t) { const n = e.match(t); return n ? n[1] : null } const K = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = e === this.pattern; return { isMatch: t, score: t ? 0 : 1, indices: [0, this.pattern.length - 1] } } }], [{ key: 'type', get: function () { return 'exact' } }, { key: 'multiRegex', get: function () { return /^="(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^=(.*)$/ } }]), i }(D)); const q = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = e.indexOf(this.pattern) === -1; return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] } } }], [{ key: 'type', get: function () { return 'inverse-exact' } }, { key: 'multiRegex', get: function () { return /^!"(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^!(.*)$/ } }]), i }(D)); const W = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = e.startsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, this.pattern.length - 1] } } }], [{ key: 'type', get: function () { return 'prefix-exact' } }, { key: 'multiRegex', get: function () { return /^\^"(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^\^(.*)$/ } }]), i }(D)); const J = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = !e.startsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] } } }], [{ key: 'type', get: function () { return 'inverse-prefix-exact' } }, { key: 'multiRegex', get: function () { return /^!\^"(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^!\^(.*)$/ } }]), i }(D)); const T = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = e.endsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [e.length - this.pattern.length, e.length - 1] } } }], [{ key: 'type', get: function () { return 'suffix-exact' } }, { key: 'multiRegex', get: function () { return /^"(.*)"\$$/ } }, { key: 'singleRegex', get: function () { return /^(.*)\$$/ } }]), i }(D)); const U = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { const t = !e.endsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] } } }], [{ key: 'type', get: function () { return 'inverse-suffix-exact' } }, { key: 'multiRegex', get: function () { return /^!"(.*)"\$$/ } }, { key: 'singleRegex', get: function () { return /^!(.*)\$$/ } }]), i }(D)); const V = (function (e) { a(i, e); const n = f(i); function i (e) { let r; const o = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const c = o.location; const a = void 0 === c ? A.location : c; const s = o.threshold; const u = void 0 === s ? A.threshold : s; const h = o.distance; const f = void 0 === h ? A.distance : h; const l = o.includeMatches; const d = void 0 === l ? A.includeMatches : l; const v = o.findAllMatches; const g = void 0 === v ? A.findAllMatches : v; const y = o.minMatchCharLength; const p = void 0 === y ? A.minMatchCharLength : y; const m = o.isCaseSensitive; const k = void 0 === m ? A.isCaseSensitive : m; const M = o.ignoreLocation; const b = void 0 === M ? A.ignoreLocation : M; return t(this, i), (r = n.call(this, e))._bitapSearch = new N(e, { location: a, threshold: u, distance: f, includeMatches: d, findAllMatches: g, minMatchCharLength: p, isCaseSensitive: k, ignoreLocation: b }), r } return r(i, [{ key: 'search', value: function (e) { return this._bitapSearch.searchIn(e) } }], [{ key: 'type', get: function () { return 'fuzzy' } }, { key: 'multiRegex', get: function () { return /^"(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^(.*)$/ } }]), i }(D)); const B = (function (e) { a(i, e); const n = f(i); function i (e) { return t(this, i), n.call(this, e) } return r(i, [{ key: 'search', value: function (e) { for (var t, n = 0, r = [], i = this.pattern.length; (t = e.indexOf(this.pattern, n)) > -1;)n = t + i, r.push([t, n - 1]); const o = !!r.length; return { isMatch: o, score: o ? 0 : 1, indices: r } } }], [{ key: 'type', get: function () { return 'include' } }, { key: 'multiRegex', get: function () { return /^'"(.*)"$/ } }, { key: 'singleRegex', get: function () { return /^'(.*)$/ } }]), i }(D)); const G = [K, B, W, J, U, T, q, V]; const H = G.length; const Q = / +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/; function X (e) { const t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; return e.split('|').map(function (e) { for (var n = e.trim().split(Q).filter(function (e) { return e && !!e.trim() }), r = [], i = 0, o = n.length; i < o; i += 1) { for (var c = n[i], a = !1, s = -1; !a && ++s < H;) { const u = G[s]; const h = u.isMultiMatch(c); h && (r.push(new u(h, t)), a = !0) } if (!a) for (s = -1; ++s < H;) { const f = G[s]; const l = f.isSingleMatch(c); if (l) { r.push(new f(l, t)); break } } } return r }) } const Y = new Set([V.type, B.type]); const Z = (function () { function e (n) { const r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const i = r.isCaseSensitive; const o = void 0 === i ? A.isCaseSensitive : i; const c = r.includeMatches; const a = void 0 === c ? A.includeMatches : c; const s = r.minMatchCharLength; const u = void 0 === s ? A.minMatchCharLength : s; const h = r.ignoreLocation; const f = void 0 === h ? A.ignoreLocation : h; const l = r.findAllMatches; const d = void 0 === l ? A.findAllMatches : l; const v = r.location; const g = void 0 === v ? A.location : v; const y = r.threshold; const p = void 0 === y ? A.threshold : y; const m = r.distance; const k = void 0 === m ? A.distance : m; t(this, e), this.query = null, this.options = { isCaseSensitive: o, includeMatches: a, minMatchCharLength: u, findAllMatches: d, ignoreLocation: f, location: g, threshold: p, distance: k }, this.pattern = o ? n : n.toLowerCase(), this.query = X(this.pattern, this.options) } return r(e, [{ key: 'searchIn', value: function (e) { const t = this.query; if (!t) return { isMatch: !1, score: 1 }; const n = this.options; const r = n.includeMatches; e = n.isCaseSensitive ? e : e.toLowerCase(); for (let i = 0, o = [], c = 0, a = 0, s = t.length; a < s; a += 1) { const u = t[a]; o.length = 0, i = 0; for (let h = 0, f = u.length; h < f; h += 1) { const d = u[h]; const v = d.search(e); const g = v.isMatch; const y = v.indices; const p = v.score; if (!g) { c = 0, i = 0, o.length = 0; break } if (i += 1, c += p, r) { const m = d.constructor.type; Y.has(m) ? o = [].concat(l(o), l(y)) : o.push(y) } } if (i) { const k = { isMatch: !0, score: c / i }; return r && (k.indices = o), k } } return { isMatch: !1, score: 1 } } }], [{ key: 'condition', value: function (e, t) { return t.useExtendedSearch } }]), e }()); const ee = []; function te (e, t) { for (let n = 0, r = ee.length; n < r; n += 1) { const i = ee[n]; if (i.condition(e, t)) return new i(e, t) } return new N(e, t) } const ne = '$and'; const re = '$or'; const ie = '$path'; const oe = '$val'; const ce = function (e) { return !(!e[ne] && !e[re]) }; const ae = function (e) { return !!e[ie] }; const se = function (e) { return !v(e) && m(e) && !ce(e) }; const ue = function (e) { return i({}, ne, Object.keys(e).map(function (t) { return i({}, t, e[t]) })) }; function he (e, t) { const n = t.ignoreFieldNorm; const r = void 0 === n ? A.ignoreFieldNorm : n; e.forEach(function (e) { let t = 1; e.matches.forEach(function (e) { const n = e.key; const i = e.norm; const o = e.score; const c = n ? n.weight : null; t *= Math.pow(o === 0 && c ? Number.EPSILON : o, (c || 1) * (r ? 1 : i)) }), e.score = t }) } function fe (e, t) { const n = e.matches; t.matches = [], k(n) && n.forEach(function (e) { if (k(e.indices) && e.indices.length) { const n = { indices: e.indices, value: e.value }; e.key && (n.key = e.key.src), e.idx > -1 && (n.refIndex = e.idx), t.matches.push(n) } }) } function le (e, t) { t.score = e.score } function de (e, t) { const n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}; const r = n.includeMatches; const i = void 0 === r ? A.includeMatches : r; const o = n.includeScore; const c = void 0 === o ? A.includeScore : o; const a = []; return i && a.push(fe), c && a.push(le), e.map(function (e) { const n = e.idx; const r = { item: t[n], refIndex: n }; return a.length && a.forEach(function (t) { t(e, r) }), r }) } const ve = (function () { function e (n) { const r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const i = arguments.length > 2 ? arguments[2] : void 0; t(this, e), this.options = c({}, A, {}, r), this.options.useExtendedSearch, this._keyStore = new w(this.options.keys), this.setCollection(n, i) } return r(e, [{ key: 'setCollection', value: function (e, t) { if (this._docs = e, t && !(t instanceof E)) throw new Error("Incorrect 'index' type"); this._myIndex = t || $(this.options.keys, this._docs, { getFn: this.options.getFn }) } }, { key: 'add', value: function (e) { k(e) && (this._docs.push(e), this._myIndex.add(e)) } }, { key: 'remove', value: function () { for (var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : function () { return !1 }, t = [], n = 0, r = this._docs.length; n < r; n += 1) { const i = this._docs[n]; e(i, n) && (this.removeAt(n), n -= 1, r -= 1, t.push(i)) } return t } }, { key: 'removeAt', value: function (e) { this._docs.splice(e, 1), this._myIndex.removeAt(e) } }, { key: 'getIndex', value: function () { return this._myIndex } }, { key: 'search', value: function (e) { const t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const n = t.limit; const r = void 0 === n ? -1 : n; const i = this.options; const o = i.includeMatches; const c = i.includeScore; const a = i.shouldSort; const s = i.sortFn; const u = i.ignoreFieldNorm; let h = g(e) ? g(this._docs[0]) ? this._searchStringList(e) : this._searchObjectList(e) : this._searchLogical(e); return he(h, { ignoreFieldNorm: u }), a && h.sort(s), y(r) && r > -1 && (h = h.slice(0, r)), de(h, this._docs, { includeMatches: o, includeScore: c }) } }, { key: '_searchStringList', value: function (e) { const t = te(e, this.options); const n = this._myIndex.records; const r = []; return n.forEach(function (e) { const n = e.v; const i = e.i; const o = e.n; if (k(n)) { const c = t.searchIn(n); const a = c.isMatch; const s = c.score; const u = c.indices; a && r.push({ item: n, idx: i, matches: [{ score: s, value: n, norm: o, indices: u }] }) } }), r } }, { key: '_searchLogical', value: function (e) { const t = this; const n = (function (e, t) { const n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}; const r = n.auto; const i = void 0 === r || r; const o = function e (n) { const r = Object.keys(n); const o = ae(n); if (!o && r.length > 1 && !ce(n)) return e(ue(n)); if (se(n)) { const c = o ? n[ie] : r[0]; const a = o ? n[oe] : n[c]; if (!g(a)) throw new Error(x(c)); const s = { keyId: j(c), pattern: a }; return i && (s.searcher = te(a, t)), s } const u = { children: [], operator: r[0] }; return r.forEach(function (t) { const r = n[t]; v(r) && r.forEach(function (t) { u.children.push(e(t)) }) }), u }; return ce(e) || (e = ue(e)), o(e) }(e, this.options)); const r = this._myIndex.records; const i = {}; const o = []; return r.forEach(function (e) { const r = e.$; const c = e.i; if (k(r)) { const a = (function e (n, r, i) { if (!n.children) { const o = n.keyId; const c = n.searcher; const a = t._findMatches({ key: t._keyStore.get(o), value: t._myIndex.getValueForItemAtKeyId(r, o), searcher: c }); return a && a.length ? [{ idx: i, item: r, matches: a }] : [] } switch (n.operator) { case ne:for (var s = [], u = 0, h = n.children.length; u < h; u += 1) { const f = e(n.children[u], r, i); if (!f.length) return []; s.push.apply(s, l(f)) } return s; case re:for (var d = [], v = 0, g = n.children.length; v < g; v += 1) { const y = e(n.children[v], r, i); if (y.length) { d.push.apply(d, l(y)); break } } return d } }(n, r, c)); a.length && (i[c] || (i[c] = { idx: c, item: r, matches: [] }, o.push(i[c])), a.forEach(function (e) { let t; const n = e.matches; (t = i[c].matches).push.apply(t, l(n)) })) } }), o } }, { key: '_searchObjectList', value: function (e) { const t = this; const n = te(e, this.options); const r = this._myIndex; const i = r.keys; const o = r.records; const c = []; return o.forEach(function (e) { const r = e.$; const o = e.i; if (k(r)) { const a = []; i.forEach(function (e, i) { a.push.apply(a, l(t._findMatches({ key: e, value: r[i], searcher: n }))) }), a.length && c.push({ idx: o, item: r, matches: a }) } }), c } }, { key: '_findMatches', value: function (e) { const t = e.key; const n = e.value; const r = e.searcher; if (!k(n)) return []; const i = []; if (v(n))n.forEach(function (e) { const n = e.v; const o = e.i; const c = e.n; if (k(n)) { const a = r.searchIn(n); const s = a.isMatch; const u = a.score; const h = a.indices; s && i.push({ score: u, key: t, value: n, idx: o, norm: c, indices: h }) } }); else { const o = n.v; const c = n.n; const a = r.searchIn(o); const s = a.isMatch; const u = a.score; const h = a.indices; s && i.push({ score: u, key: t, value: o, norm: c, indices: h }) } return i } }]), e }()); return ve.version = '6.4.6', ve.createIndex = $, ve.parseIndex = function (e) { const t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; const n = t.getFn; const r = void 0 === n ? A.getFn : n; const i = e.keys; const o = e.records; const c = new E({ getFn: r }); return c.setKeys(i), c.setIndexRecords(o), c }, ve.config = A, (function () { ee.push.apply(ee, arguments) }(Z)), ve }, typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = t() : typeof define === 'function' && define.amd ? define(t) : (e = e || self).Fuse = t()
@@ -0,0 +1,366 @@
1
+ // jshint multistr:true
2
+
3
+ (function (w, d) {
4
+ 'use strict'
5
+
6
+ const TABLE_NAME = 'hljs-ln'
7
+ const LINE_NAME = 'hljs-ln-line'
8
+ const CODE_BLOCK_NAME = 'hljs-ln-code'
9
+ const NUMBERS_BLOCK_NAME = 'hljs-ln-numbers'
10
+ const NUMBER_LINE_NAME = 'hljs-ln-n'
11
+ const DATA_ATTR_NAME = 'data-line-number'
12
+ const BREAK_LINE_REGEXP = /\r\n|\r|\n/g
13
+
14
+ if (w.hljs) {
15
+ w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad
16
+ w.hljs.lineNumbersBlock = lineNumbersBlock
17
+ w.hljs.lineNumbersValue = lineNumbersValue
18
+
19
+ addStyles()
20
+ } else {
21
+ w.console.error('highlight.js not detected!')
22
+ }
23
+
24
+ function isHljsLnCodeDescendant (domElt) {
25
+ let curElt = domElt
26
+ while (curElt) {
27
+ if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
28
+ return true
29
+ }
30
+ curElt = curElt.parentNode
31
+ }
32
+ return false
33
+ }
34
+
35
+ function getHljsLnTable (hljsLnDomElt) {
36
+ let curElt = hljsLnDomElt
37
+ while (curElt.nodeName !== 'TABLE') {
38
+ curElt = curElt.parentNode
39
+ }
40
+ return curElt
41
+ }
42
+
43
+ // Function to workaround a copy issue with Microsoft Edge.
44
+ // Due to hljs-ln wrapping the lines of code inside a <table> element,
45
+ // itself wrapped inside a <pre> element, window.getSelection().toString()
46
+ // does not contain any line breaks. So we need to get them back using the
47
+ // rendered code in the DOM as reference.
48
+ function edgeGetSelectedCodeLines (selection) {
49
+ // current selected text without line breaks
50
+ const selectionText = selection.toString()
51
+
52
+ // get the <td> element wrapping the first line of selected code
53
+ let tdAnchor = selection.anchorNode
54
+ while (tdAnchor.nodeName !== 'TD') {
55
+ tdAnchor = tdAnchor.parentNode
56
+ }
57
+
58
+ // get the <td> element wrapping the last line of selected code
59
+ let tdFocus = selection.focusNode
60
+ while (tdFocus.nodeName !== 'TD') {
61
+ tdFocus = tdFocus.parentNode
62
+ }
63
+
64
+ // extract line numbers
65
+ let firstLineNumber = parseInt(tdAnchor.dataset.lineNumber)
66
+ let lastLineNumber = parseInt(tdFocus.dataset.lineNumber)
67
+
68
+ // multi-lines copied case
69
+ if (firstLineNumber != lastLineNumber) {
70
+ let firstLineText = tdAnchor.textContent
71
+ let lastLineText = tdFocus.textContent
72
+
73
+ // if the selection was made backward, swap values
74
+ if (firstLineNumber > lastLineNumber) {
75
+ let tmp = firstLineNumber
76
+ firstLineNumber = lastLineNumber
77
+ lastLineNumber = tmp
78
+ tmp = firstLineText
79
+ firstLineText = lastLineText
80
+ lastLineText = tmp
81
+ }
82
+
83
+ // discard not copied characters in first line
84
+ while (selectionText.indexOf(firstLineText) !== 0) {
85
+ firstLineText = firstLineText.slice(1)
86
+ }
87
+
88
+ // discard not copied characters in last line
89
+ while (selectionText.lastIndexOf(lastLineText) === -1) {
90
+ lastLineText = lastLineText.slice(0, -1)
91
+ }
92
+
93
+ // reconstruct and return the real copied text
94
+ let selectedText = firstLineText
95
+ const hljsLnTable = getHljsLnTable(tdAnchor)
96
+ for (let i = firstLineNumber + 1; i < lastLineNumber; ++i) {
97
+ const codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i])
98
+ const codeLineElt = hljsLnTable.querySelector(codeLineSel)
99
+ selectedText += '\n' + codeLineElt.textContent
100
+ }
101
+ selectedText += '\n' + lastLineText
102
+ return selectedText
103
+ // single copied line case
104
+ } else {
105
+ return selectionText
106
+ }
107
+ }
108
+
109
+ // ensure consistent code copy/paste behavior across all browsers
110
+ // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
111
+ document.addEventListener('copy', function (e) {
112
+ // get current selection
113
+ const selection = window.getSelection()
114
+ // override behavior when one wants to copy line of codes
115
+ if (isHljsLnCodeDescendant(selection.anchorNode)) {
116
+ let selectionText
117
+ // workaround an issue with Microsoft Edge as copied line breaks
118
+ // are removed otherwise from the selection string
119
+ if (window.navigator.userAgent.indexOf('Edge') !== -1) {
120
+ selectionText = edgeGetSelectedCodeLines(selection)
121
+ } else {
122
+ // other browsers can directly use the selection string
123
+ selectionText = selection.toString()
124
+ }
125
+ e.clipboardData.setData(
126
+ 'text/plain',
127
+ selectionText
128
+ .replace(/(^\t)/gm, '')
129
+ )
130
+ e.preventDefault()
131
+ }
132
+ })
133
+
134
+ function addStyles () {
135
+ const css = d.createElement('style')
136
+ css.type = 'text/css'
137
+ css.innerHTML = format(
138
+ '.{0}{border-collapse:collapse}' +
139
+ '.{0} td{padding:0}' +
140
+ '.{1}:before{content:attr({2})}',
141
+ [
142
+ TABLE_NAME,
143
+ NUMBER_LINE_NAME,
144
+ DATA_ATTR_NAME
145
+ ])
146
+ d.getElementsByTagName('head')[0].appendChild(css)
147
+ }
148
+
149
+ function initLineNumbersOnLoad (options) {
150
+ if (d.readyState === 'interactive' || d.readyState === 'complete') {
151
+ documentReady(options)
152
+ } else {
153
+ w.addEventListener('DOMContentLoaded', function () {
154
+ documentReady(options)
155
+ })
156
+ }
157
+ }
158
+
159
+ function documentReady (options) {
160
+ try {
161
+ const blocks = d.querySelectorAll('code.hljs,code.nohighlight')
162
+
163
+ for (const i in blocks) {
164
+ if (blocks.hasOwnProperty(i)) {
165
+ if (!isPluginDisabledForBlock(blocks[i])) {
166
+ lineNumbersBlock(blocks[i], options)
167
+ }
168
+ }
169
+ }
170
+ } catch (e) {
171
+ w.console.error('LineNumbers error: ', e)
172
+ }
173
+ }
174
+
175
+ function isPluginDisabledForBlock (element) {
176
+ return element.classList.contains('nohljsln')
177
+ }
178
+
179
+ function lineNumbersBlock (element, options) {
180
+ if (typeof element !== 'object') return
181
+
182
+ async(function () {
183
+ element.innerHTML = lineNumbersInternal(element, options)
184
+ })
185
+ }
186
+
187
+ function lineNumbersValue (value, options) {
188
+ if (typeof value !== 'string') return
189
+
190
+ const element = document.createElement('code')
191
+ element.innerHTML = value
192
+
193
+ return lineNumbersInternal(element, options)
194
+ }
195
+
196
+ function lineNumbersInternal (element, options) {
197
+ const internalOptions = mapOptions(element, options)
198
+
199
+ duplicateMultilineNodes(element)
200
+
201
+ return addLineNumbersBlockFor(element.innerHTML, internalOptions)
202
+ }
203
+
204
+ function addLineNumbersBlockFor (inputHtml, options) {
205
+ const lines = getLines(inputHtml)
206
+
207
+ // if last line contains only carriage return remove it
208
+ if (lines[lines.length - 1].trim() === '') {
209
+ lines.pop()
210
+ }
211
+
212
+ if (lines.length > 1 || options.singleLine) {
213
+ let html = ''
214
+
215
+ for (let i = 0, l = lines.length; i < l; i++) {
216
+ html += format(
217
+ '<tr>' +
218
+ '<td class="{0} {1}" {3}="{5}">' +
219
+ '</td>' +
220
+ '<td class="{0} {4}" {3}="{5}">' +
221
+ '{6}' +
222
+ '</td>' +
223
+ '</tr>',
224
+ [
225
+ LINE_NAME,
226
+ NUMBERS_BLOCK_NAME,
227
+ NUMBER_LINE_NAME,
228
+ DATA_ATTR_NAME,
229
+ CODE_BLOCK_NAME,
230
+ i + options.startFrom,
231
+ lines[i].length > 0 ? lines[i] : ' '
232
+ ])
233
+ }
234
+
235
+ return format('<table class="{0}">{1}</table>', [TABLE_NAME, html])
236
+ }
237
+
238
+ return inputHtml
239
+ }
240
+
241
+ /**
242
+ * @param {HTMLElement} element Code block.
243
+ * @param {Object} options External API options.
244
+ * @returns {Object} Internal API options.
245
+ */
246
+ function mapOptions (element, options) {
247
+ options = options || {}
248
+ return {
249
+ singleLine: getSingleLineOption(options),
250
+ startFrom: getStartFromOption(element, options)
251
+ }
252
+ }
253
+
254
+ function getSingleLineOption (options) {
255
+ const defaultValue = false
256
+ if (options.singleLine) {
257
+ return options.singleLine
258
+ }
259
+ return defaultValue
260
+ }
261
+
262
+ function getStartFromOption (element, options) {
263
+ const defaultValue = 1
264
+ let startFrom = defaultValue
265
+
266
+ if (isFinite(options.startFrom)) {
267
+ startFrom = options.startFrom
268
+ }
269
+
270
+ // can be overridden because local option is priority
271
+ const value = getAttribute(element, 'data-ln-start-from')
272
+ if (value !== null) {
273
+ startFrom = toNumber(value, defaultValue)
274
+ }
275
+
276
+ return startFrom
277
+ }
278
+
279
+ /**
280
+ * Recursive method for fix multi-line elements implementation in highlight.js
281
+ * Doing deep passage on child nodes.
282
+ * @param {HTMLElement} element
283
+ */
284
+ function duplicateMultilineNodes (element) {
285
+ const nodes = element.childNodes
286
+ for (const node in nodes) {
287
+ if (nodes.hasOwnProperty(node)) {
288
+ const child = nodes[node]
289
+ if (getLinesCount(child.textContent) > 0) {
290
+ if (child.childNodes.length > 0) {
291
+ duplicateMultilineNodes(child)
292
+ } else {
293
+ duplicateMultilineNode(child.parentNode)
294
+ }
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Method for fix multi-line elements implementation in highlight.js
302
+ * @param {HTMLElement} element
303
+ */
304
+ function duplicateMultilineNode (element) {
305
+ const className = element.className
306
+
307
+ if (!/hljs-/.test(className)) return
308
+
309
+ const lines = getLines(element.innerHTML)
310
+
311
+ for (var i = 0, result = ''; i < lines.length; i++) {
312
+ const lineText = lines[i].length > 0 ? lines[i] : ' '
313
+ result += format('<span class="{0}">{1}</span>\n', [className, lineText])
314
+ }
315
+
316
+ element.innerHTML = result.trim()
317
+ }
318
+
319
+ function getLines (text) {
320
+ if (text.length === 0) return []
321
+ return text.split(BREAK_LINE_REGEXP)
322
+ }
323
+
324
+ function getLinesCount (text) {
325
+ return (text.trim().match(BREAK_LINE_REGEXP) || []).length
326
+ }
327
+
328
+ ///
329
+ /// HELPERS
330
+ ///
331
+
332
+ function async (func) {
333
+ w.setTimeout(func, 0)
334
+ }
335
+
336
+ /**
337
+ * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
338
+ * @param {string} format
339
+ * @param {array} args
340
+ */
341
+ function format (format, args) {
342
+ return format.replace(/\{(\d+)\}/g, function (m, n) {
343
+ return args[n] !== undefined ? args[n] : m
344
+ })
345
+ }
346
+
347
+ /**
348
+ * @param {HTMLElement} element Code block.
349
+ * @param {String} attrName Attribute name.
350
+ * @returns {String} Attribute value or empty.
351
+ */
352
+ function getAttribute (element, attrName) {
353
+ return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null
354
+ }
355
+
356
+ /**
357
+ * @param {String} str Source string.
358
+ * @param {Number} fallback Fallback value.
359
+ * @returns Parsed number or fallback value.
360
+ */
361
+ function toNumber (str, fallback) {
362
+ if (!str) return fallback
363
+ const number = Number(str)
364
+ return isFinite(number) ? number : fallback
365
+ }
366
+ }(window, document))
@@ -0,0 +1 @@
1
+ !(function (r, o) { 'use strict'; let e; const l = 'hljs-ln'; const s = 'hljs-ln-line'; const f = 'hljs-ln-code'; const c = 'hljs-ln-numbers'; const u = 'hljs-ln-n'; const h = 'data-line-number'; const n = /\r\n|\r|\n/g; function t (e) { for (var n = e.toString(), t = e.anchorNode; t.nodeName !== 'TD';)t = t.parentNode; for (var r = e.focusNode; r.nodeName !== 'TD';)r = r.parentNode; var e = parseInt(t.dataset.lineNumber); let o = parseInt(r.dataset.lineNumber); if (e == o) return n; let a; let i = t.textContent; let l = r.textContent; for (o < e && (a = e, e = o, o = a, a = i, i = l, l = a); n.indexOf(i) !== 0;)i = i.slice(1); for (;n.lastIndexOf(l) === -1;)l = l.slice(0, -1); for (var s = i, c = (function (e) { for (var n = e; n.nodeName !== 'TABLE';)n = n.parentNode; return n }(t)), u = e + 1; u < o; ++u) { const d = v('.{0}[{1}="{2}"]', [f, h, u]); s += '\n' + c.querySelector(d).textContent } return s += '\n' + l } function a (e) { try { let n; const t = o.querySelectorAll('code.hljs,code.nohighlight'); for (n in t)!t.hasOwnProperty(n) || t[n].classList.contains('nohljsln') || i(t[n], e) } catch (e) { r.console.error('LineNumbers error: ', e) } } function i (e, n) { typeof e === 'object' && r.setTimeout(function () { e.innerHTML = d(e, n) }, 0) } function d (e, n) { var n = { singleLine: (function (e) { return e.singleLine || !1 }(n = (n = n) || {})), startFrom: (function (e, n) { let t = 1; isFinite(n.startFrom) && (t = n.startFrom); n = (function (e, n) { return e.hasAttribute(n) ? e.getAttribute(n) : null }(e, 'data-ln-start-from')); n !== null && (t = (function (e, n) { if (!e) return n; e = Number(e); return isFinite(e) ? e : n }(n, 1))); return t }(e, n)) }; var e = (!(function e (n) { const t = n.childNodes; for (let r in t)!t.hasOwnProperty(r) || p((r = t[r]).textContent) > 0 && (r.childNodes.length > 0 ? e(r) : m(r.parentNode)) }(e)), e.innerHTML); const t = n; const r = g(e); if (r[r.length - 1].trim() === '' && r.pop(), r.length > 1 || t.singleLine) { for (var o = '', a = 0, i = r.length; a < i; a++)o += v('<tr><td class="{0} {1}" {3}="{5}"></td><td class="{0} {4}" {3}="{5}">{6}</td></tr>', [s, c, u, h, f, a + t.startFrom, r[a].length > 0 ? r[a] : ' ']); return v('<table class="{0}">{1}</table>', [l, o]) } return e } function m (e) { const n = e.className; if (/hljs-/.test(n)) { for (var t = g(e.innerHTML), r = 0, o = ''; r < t.length; r++)o += v('<span class="{0}">{1}</span>\n', [n, t[r].length > 0 ? t[r] : ' ']); e.innerHTML = o.trim() } } function g (e) { return e.length === 0 ? [] : e.split(n) } function p (e) { return (e.trim().match(n) || []).length } function v (e, t) { return e.replace(/\{(\d+)\}/g, function (e, n) { return void 0 !== t[n] ? t[n] : e }) }r.hljs ? (r.hljs.initLineNumbersOnLoad = function (e) { o.readyState === 'interactive' || o.readyState === 'complete' ? a(e) : r.addEventListener('DOMContentLoaded', function () { a(e) }) }, r.hljs.lineNumbersBlock = i, r.hljs.lineNumbersValue = function (e, n) { let t; if (typeof e === 'string') return (t = document.createElement('code')).innerHTML = e, d(t, n) }, (e = o.createElement('style')).type = 'text/css', e.innerHTML = v('.{0}{border-collapse:collapse}.{0} td{padding:0}.{1}:before{content:attr({2})}', [l, u, h]), o.getElementsByTagName('head')[0].appendChild(e)) : r.console.error('highlight.js not detected!'), document.addEventListener('copy', function (e) { let n = window.getSelection(); !(function (e) { for (let n = e; n;) { if (n.className && n.className.indexOf('hljs-ln-code') !== -1) return 1; n = n.parentNode } }(n.anchorNode)) || (n = window.navigator.userAgent.indexOf('Edge') !== -1 ? t(n) : n.toString(), e.clipboardData.setData('text/plain', n.replace(/(^\t)/gm, '')), e.preventDefault()) }) }(window, document))