UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

634 lines (633 loc) 24.5 kB
/** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */ function v(t) { return Array.isArray ? Array.isArray(t) : Fe(t) === "[object Array]"; } function L(t) { return typeof t == "string"; } function Ce(t) { return typeof t == "number"; } function me(t) { return typeof t == "object"; } function F(t) { return t != null; } function te(t) { return !t.trim().length; } function Fe(t) { return t == null ? t === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(t); } const le = Object.prototype.hasOwnProperty; class Ie { constructor(e) { this._keys = [], this._keyMap = {}; let s = 0; e.forEach((i) => { let n = Me(i); this._keys.push(n), this._keyMap[n.id] = n, s += n.weight; }), this._keys.forEach((i) => { i.weight /= s; }); } get(e) { return this._keyMap[e]; } keys() { return this._keys; } toJSON() { return JSON.stringify(this._keys); } } function Me(t) { let e = null, s = null, i = null, n = 1, r = null; if (L(t) || v(t)) i = t, e = de(t), s = ie(t); else { if (!le.call(t, "name")) throw new Error("Missing name property in key"); const u = t.name; if (i = u, le.call(t, "weight") && (n = t.weight, n <= 0)) throw new Error(`Property 'weight' in key '${u}' must be a positive integer`); e = de(u), s = ie(u), r = t.getFn; } return { path: e, id: s, weight: n, src: i, getFn: r }; } function de(t) { return v(t) ? t : t.split("."); } function ie(t) { return v(t) ? t.join(".") : t; } var l = { isCaseSensitive: !1, ignoreDiacritics: !1, includeScore: !1, keys: [], shouldSort: !0, sortFn: (t, e) => t.score === e.score ? t.idx < e.idx ? -1 : 1 : t.score < e.score ? -1 : 1, includeMatches: !1, findAllMatches: !1, minMatchCharLength: 1, location: 0, threshold: 0.6, distance: 100, useExtendedSearch: !1, getFn: function(t, e) { let s = [], i = !1; const n = (r, u, h) => { if (F(r)) if (u[h]) { const a = r[u[h]]; if (!F(a)) return; if (h === u.length - 1 && (L(a) || Ce(a) || function(o) { return o === !0 || o === !1 || me(d = o) && d !== null && Fe(o) == "[object Boolean]"; var d; }(a))) s.push((c = a) == null ? "" : function(o) { if (typeof o == "string") return o; let d = o + ""; return d == "0" && 1 / o == -1 / 0 ? "-0" : d; }(c)); else if (v(a)) { i = !0; for (let o = 0, d = a.length; o < d; o += 1) n(a[o], u, h + 1); } else u.length && n(a, u, h + 1); } else s.push(r); var c; }; return n(t, L(e) ? e.split(".") : e, 0), i ? s : s[0]; }, ignoreLocation: !1, ignoreFieldNorm: !1, fieldNormWeight: 1 }; const we = /[^ ]+/g; class ce { constructor({ getFn: e = l.getFn, fieldNormWeight: s = l.fieldNormWeight } = {}) { this.norm = function(i = 1, n = 3) { const r = /* @__PURE__ */ new Map(), u = Math.pow(10, n); return { get(h) { const c = h.match(we).length; if (r.has(c)) return r.get(c); const a = 1 / Math.pow(c, 0.5 * i), o = parseFloat(Math.round(a * u) / u); return r.set(c, o), o; }, clear() { r.clear(); } }; }(s, 3), this.getFn = e, this.isCreated = !1, this.setIndexRecords(); } setSources(e = []) { this.docs = e; } setIndexRecords(e = []) { this.records = e; } setKeys(e = []) { this.keys = e, this._keysMap = {}, e.forEach((s, i) => { this._keysMap[s.id] = i; }); } create() { !this.isCreated && this.docs.length && (this.isCreated = !0, L(this.docs[0]) ? this.docs.forEach((e, s) => { this._addString(e, s); }) : this.docs.forEach((e, s) => { this._addObject(e, s); }), this.norm.clear()); } add(e) { const s = this.size(); L(e) ? this._addString(e, s) : this._addObject(e, s); } removeAt(e) { this.records.splice(e, 1); for (let s = e, i = this.size(); s < i; s += 1) this.records[s].i -= 1; } getValueForItemAtKeyId(e, s) { return e[this._keysMap[s]]; } size() { return this.records.length; } _addString(e, s) { if (!F(e) || te(e)) return; let i = { v: e, i: s, n: this.norm.get(e) }; this.records.push(i); } _addObject(e, s) { let i = { i: s, $: {} }; this.keys.forEach((n, r) => { let u = n.getFn ? n.getFn(e) : this.getFn(e, n.path); if (F(u)) { if (v(u)) { let h = []; const c = [{ nestedArrIndex: -1, value: u }]; for (; c.length; ) { const { nestedArrIndex: a, value: o } = c.pop(); if (F(o)) if (L(o) && !te(o)) { let d = { v: o, i: a, n: this.norm.get(o) }; h.push(d); } else v(o) && o.forEach((d, f) => { c.push({ nestedArrIndex: f, value: d }); }); } i.$[r] = h; } else if (L(u) && !te(u)) { let h = { v: u, n: this.norm.get(u) }; i.$[r] = h; } } }), this.records.push(i); } toJSON() { return { keys: this.keys, records: this.records }; } } function Ee(t, e, { getFn: s = l.getFn, fieldNormWeight: i = l.fieldNormWeight } = {}) { const n = new ce({ getFn: s, fieldNormWeight: i }); return n.setKeys(t.map(Me)), n.setSources(e), n.create(), n; } function X(t, { errors: e = 0, currentLocation: s = 0, expectedLocation: i = 0, distance: n = l.distance, ignoreLocation: r = l.ignoreLocation } = {}) { const u = e / t.length; if (r) return u; const h = Math.abs(i - s); return n ? u + h / n : h ? 1 : u; } const z = 32; function $e(t) { let e = {}; for (let s = 0, i = t.length; s < i; s += 1) { const n = t.charAt(s); e[n] = (e[n] || 0) | 1 << i - s - 1; } return e; } const Y = String.prototype.normalize ? (t) => t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "") : (t) => t; class De { constructor(e, { location: s = l.location, threshold: i = l.threshold, distance: n = l.distance, includeMatches: r = l.includeMatches, findAllMatches: u = l.findAllMatches, minMatchCharLength: h = l.minMatchCharLength, isCaseSensitive: c = l.isCaseSensitive, ignoreDiacritics: a = l.ignoreDiacritics, ignoreLocation: o = l.ignoreLocation } = {}) { if (this.options = { location: s, threshold: i, distance: n, includeMatches: r, findAllMatches: u, minMatchCharLength: h, isCaseSensitive: c, ignoreDiacritics: a, ignoreLocation: o }, e = c ? e : e.toLowerCase(), e = a ? Y(e) : e, this.pattern = e, this.chunks = [], !this.pattern.length) return; const d = (g, p) => { this.chunks.push({ pattern: g, alphabet: $e(g), startIndex: p }); }, f = this.pattern.length; if (f > z) { let g = 0; const p = f % z, A = f - p; for (; g < A; ) d(this.pattern.substr(g, z), g), g += z; if (p) { const m = f - z; d(this.pattern.substr(m), m); } } else d(this.pattern, 0); } searchIn(e) { const { isCaseSensitive: s, ignoreDiacritics: i, includeMatches: n } = this.options; if (e = s ? e : e.toLowerCase(), e = i ? Y(e) : e, this.pattern === e) { let A = { isMatch: !0, score: 0 }; return n && (A.indices = [[0, e.length - 1]]), A; } const { location: r, distance: u, threshold: h, findAllMatches: c, minMatchCharLength: a, ignoreLocation: o } = this.options; let d = [], f = 0, g = !1; this.chunks.forEach(({ pattern: A, alphabet: m, startIndex: _ }) => { const { isMatch: N, score: w, indices: S } = function(k, $, Le, { location: ke = l.location, distance: J = l.distance, threshold: ve = l.threshold, findAllMatches: _e = l.findAllMatches, minMatchCharLength: he = l.minMatchCharLength, includeMatches: ae = l.includeMatches, ignoreLocation: V = l.ignoreLocation } = {}) { if ($.length > z) throw new Error("Pattern length exceeds max of 32."); const R = $.length, K = k.length, y = Math.max(0, Math.min(ke, K)); let O = ve, b = y; const Q = he > 1 || ae, Z = Q ? Array(K) : []; let U; for (; (U = k.indexOf($, b)) > -1; ) { let M = X($, { currentLocation: U, expectedLocation: y, distance: J, ignoreLocation: V }); if (O = Math.min(M, O), b = U + R, Q) { let E = 0; for (; E < R; ) Z[U + E] = 1, E += 1; } } b = -1; let G = [], H = 1, T = R + K; const Se = 1 << R - 1; for (let M = 0; M < R; M += 1) { let E = 0, B = T; for (; E < B; ) X($, { errors: M, currentLocation: y + B, expectedLocation: y, distance: J, ignoreLocation: V }) <= O ? E = B : T = B, B = Math.floor((T - E) / 2 + E); T = B; let j = Math.max(1, y - B + 1), D = _e ? K : Math.min(y + B, K) + R, x = Array(D + 2); x[D + 1] = (1 << M) - 1; for (let C = D; C >= j; C -= 1) { let W = C - 1, P = Le[k.charAt(W)]; if (Q && (Z[W] = +!!P), x[C] = (x[C + 1] << 1 | 1) & P, M && (x[C] |= (G[C + 1] | G[C]) << 1 | 1 | G[C + 1]), x[C] & Se && (H = X($, { errors: M, currentLocation: W, expectedLocation: y, distance: J, ignoreLocation: V }), H <= O)) { if (O = H, b = W, b <= y) break; j = Math.max(1, 2 * y - b); } } if (X($, { errors: M + 1, currentLocation: y, expectedLocation: y, distance: J, ignoreLocation: V }) > O) break; G = x; } const ee = { isMatch: b >= 0, score: Math.max(1e-3, H) }; if (Q) { const M = function(E = [], B = l.minMatchCharLength) { let j = [], D = -1, x = -1, C = 0; for (let W = E.length; C < W; C += 1) { let P = E[C]; P && D === -1 ? D = C : P || D === -1 || (x = C - 1, x - D + 1 >= B && j.push([D, x]), D = -1); } return E[C - 1] && C - D >= B && j.push([D, C - 1]), j; }(Z, he); M.length ? ae && (ee.indices = M) : ee.isMatch = !1; } return ee; }(e, A, m, { location: r + _, distance: u, threshold: h, findAllMatches: c, minMatchCharLength: a, includeMatches: n, ignoreLocation: o }); N && (g = !0), f += w, N && S && (d = [...d, ...S]); }); let p = { isMatch: g, score: g ? f / this.chunks.length : 1 }; return g && n && (p.indices = d), p; } } class I { constructor(e) { this.pattern = e; } static isMultiMatch(e) { return ge(e, this.multiRegex); } static isSingleMatch(e) { return ge(e, this.singleRegex); } search() { } } function ge(t, e) { const s = t.match(e); return s ? s[1] : null; } class ye extends I { constructor(e, { location: s = l.location, threshold: i = l.threshold, distance: n = l.distance, includeMatches: r = l.includeMatches, findAllMatches: u = l.findAllMatches, minMatchCharLength: h = l.minMatchCharLength, isCaseSensitive: c = l.isCaseSensitive, ignoreDiacritics: a = l.ignoreDiacritics, ignoreLocation: o = l.ignoreLocation } = {}) { super(e), this._bitapSearch = new De(e, { location: s, threshold: i, distance: n, includeMatches: r, findAllMatches: u, minMatchCharLength: h, isCaseSensitive: c, ignoreDiacritics: a, ignoreLocation: o }); } static get type() { return "fuzzy"; } static get multiRegex() { return /^"(.*)"$/; } static get singleRegex() { return /^(.*)$/; } search(e) { return this._bitapSearch.searchIn(e); } } class Be extends I { constructor(e) { super(e); } static get type() { return "include"; } static get multiRegex() { return /^'"(.*)"$/; } static get singleRegex() { return /^'(.*)$/; } search(e) { let s, i = 0; const n = [], r = this.pattern.length; for (; (s = e.indexOf(this.pattern, i)) > -1; ) i = s + r, n.push([s, i - 1]); const u = !!n.length; return { isMatch: u, score: u ? 0 : 1, indices: n }; } } const ne = [class extends I { constructor(t) { super(t); } static get type() { return "exact"; } static get multiRegex() { return /^="(.*)"$/; } static get singleRegex() { return /^=(.*)$/; } search(t) { const e = t === this.pattern; return { isMatch: e, score: e ? 0 : 1, indices: [0, this.pattern.length - 1] }; } }, Be, class extends I { constructor(t) { super(t); } static get type() { return "prefix-exact"; } static get multiRegex() { return /^\^"(.*)"$/; } static get singleRegex() { return /^\^(.*)$/; } search(t) { const e = t.startsWith(this.pattern); return { isMatch: e, score: e ? 0 : 1, indices: [0, this.pattern.length - 1] }; } }, class extends I { constructor(t) { super(t); } static get type() { return "inverse-prefix-exact"; } static get multiRegex() { return /^!\^"(.*)"$/; } static get singleRegex() { return /^!\^(.*)$/; } search(t) { const e = !t.startsWith(this.pattern); return { isMatch: e, score: e ? 0 : 1, indices: [0, t.length - 1] }; } }, class extends I { constructor(t) { super(t); } static get type() { return "inverse-suffix-exact"; } static get multiRegex() { return /^!"(.*)"\$$/; } static get singleRegex() { return /^!(.*)\$$/; } search(t) { const e = !t.endsWith(this.pattern); return { isMatch: e, score: e ? 0 : 1, indices: [0, t.length - 1] }; } }, class extends I { constructor(t) { super(t); } static get type() { return "suffix-exact"; } static get multiRegex() { return /^"(.*)"\$$/; } static get singleRegex() { return /^(.*)\$$/; } search(t) { const e = t.endsWith(this.pattern); return { isMatch: e, score: e ? 0 : 1, indices: [t.length - this.pattern.length, t.length - 1] }; } }, class extends I { constructor(t) { super(t); } static get type() { return "inverse-exact"; } static get multiRegex() { return /^!"(.*)"$/; } static get singleRegex() { return /^!(.*)$/; } search(t) { const e = t.indexOf(this.pattern) === -1; return { isMatch: e, score: e ? 0 : 1, indices: [0, t.length - 1] }; } }, ye], fe = ne.length, be = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, Ne = /* @__PURE__ */ new Set([ye.type, Be.type]), re = []; function ue(t, e) { for (let s = 0, i = re.length; s < i; s += 1) { let n = re[s]; if (n.condition(t, e)) return new n(t, e); } return new De(t, e); } const oe = "$and", Ae = "$path", se = (t) => !(!t[oe] && !t.$or), pe = (t) => ({ [oe]: Object.keys(t).map((e) => ({ [e]: t[e] })) }); function xe(t, e, { auto: s = !0 } = {}) { const i = (n) => { let r = Object.keys(n); const u = !!n[Ae]; if (!u && r.length > 1 && !se(n)) return i(pe(n)); if (((c) => !v(c) && me(c) && !se(c))(n)) { const c = u ? n[Ae] : r[0], a = u ? n.$val : n[c]; if (!L(a)) throw new Error(`Invalid value for key ${c}`); const o = { keyId: ie(c), pattern: a }; return s && (o.searcher = ue(a, e)), o; } let h = { children: [], operator: r[0] }; return r.forEach((c) => { const a = n[c]; v(a) && a.forEach((o) => { h.children.push(i(o)); }); }), h; }; return se(t) || (t = pe(t)), i(t); } function Re(t, e) { const s = t.matches; e.matches = [], F(s) && s.forEach((i) => { if (!F(i.indices) || !i.indices.length) return; const { indices: n, value: r } = i; let u = { indices: n, value: r }; i.key && (u.key = i.key.src), i.idx > -1 && (u.refIndex = i.idx), e.matches.push(u); }); } function Oe(t, e) { e.score = t.score; } class q { constructor(e, s = {}, i) { this.options = { ...l, ...s }, this.options.useExtendedSearch, this._keyStore = new Ie(this.options.keys), this.setCollection(e, i); } setCollection(e, s) { if (this._docs = e, s && !(s instanceof ce)) throw new Error("Incorrect 'index' type"); this._myIndex = s || Ee(this.options.keys, this._docs, { getFn: this.options.getFn, fieldNormWeight: this.options.fieldNormWeight }); } add(e) { F(e) && (this._docs.push(e), this._myIndex.add(e)); } remove(e = () => !1) { const s = []; for (let i = 0, n = this._docs.length; i < n; i += 1) { const r = this._docs[i]; e(r, i) && (this.removeAt(i), i -= 1, n -= 1, s.push(r)); } return s; } removeAt(e) { this._docs.splice(e, 1), this._myIndex.removeAt(e); } getIndex() { return this._myIndex; } search(e, { limit: s = -1 } = {}) { const { includeMatches: i, includeScore: n, shouldSort: r, sortFn: u, ignoreFieldNorm: h } = this.options; let c = L(e) ? L(this._docs[0]) ? this._searchStringList(e) : this._searchObjectList(e) : this._searchLogical(e); return function(a, { ignoreFieldNorm: o = l.ignoreFieldNorm }) { a.forEach((d) => { let f = 1; d.matches.forEach(({ key: g, norm: p, score: A }) => { const m = g ? g.weight : null; f *= Math.pow(A === 0 && m ? Number.EPSILON : A, (m || 1) * (o ? 1 : p)); }), d.score = f; }); }(c, { ignoreFieldNorm: h }), r && c.sort(u), Ce(s) && s > -1 && (c = c.slice(0, s)), function(a, o, { includeMatches: d = l.includeMatches, includeScore: f = l.includeScore } = {}) { const g = []; return d && g.push(Re), f && g.push(Oe), a.map((p) => { const { idx: A } = p, m = { item: o[A], refIndex: A }; return g.length && g.forEach((_) => { _(p, m); }), m; }); }(c, this._docs, { includeMatches: i, includeScore: n }); } _searchStringList(e) { const s = ue(e, this.options), { records: i } = this._myIndex, n = []; return i.forEach(({ v: r, i: u, n: h }) => { if (!F(r)) return; const { isMatch: c, score: a, indices: o } = s.searchIn(r); c && n.push({ item: r, idx: u, matches: [{ score: a, value: r, norm: h, indices: o }] }); }), n; } _searchLogical(e) { const s = xe(e, this.options), i = (h, c, a) => { if (!h.children) { const { keyId: d, searcher: f } = h, g = this._findMatches({ key: this._keyStore.get(d), value: this._myIndex.getValueForItemAtKeyId(c, d), searcher: f }); return g && g.length ? [{ idx: a, item: c, matches: g }] : []; } const o = []; for (let d = 0, f = h.children.length; d < f; d += 1) { const g = h.children[d], p = i(g, c, a); if (p.length) o.push(...p); else if (h.operator === oe) return []; } return o; }, n = this._myIndex.records, r = {}, u = []; return n.forEach(({ $: h, i: c }) => { if (F(h)) { let a = i(s, h, c); a.length && (r[c] || (r[c] = { idx: c, item: h, matches: [] }, u.push(r[c])), a.forEach(({ matches: o }) => { r[c].matches.push(...o); })); } }), u; } _searchObjectList(e) { const s = ue(e, this.options), { keys: i, records: n } = this._myIndex, r = []; return n.forEach(({ $: u, i: h }) => { if (!F(u)) return; let c = []; i.forEach((a, o) => { c.push(...this._findMatches({ key: a, value: u[o], searcher: s })); }), c.length && r.push({ idx: h, item: u, matches: c }); }), r; } _findMatches({ key: e, value: s, searcher: i }) { if (!F(s)) return []; let n = []; if (v(s)) s.forEach(({ v: r, i: u, n: h }) => { if (!F(r)) return; const { isMatch: c, score: a, indices: o } = i.searchIn(r); c && n.push({ score: a, key: e, value: r, idx: u, norm: h, indices: o }); }); else { const { v: r, n: u } = s, { isMatch: h, score: c, indices: a } = i.searchIn(r); h && n.push({ score: c, key: e, value: r, norm: u, indices: a }); } return n; } } q.version = "7.1.0", q.createIndex = Ee, q.parseIndex = function(t, { getFn: e = l.getFn, fieldNormWeight: s = l.fieldNormWeight } = {}) { const { keys: i, records: n } = t, r = new ce({ getFn: e, fieldNormWeight: s }); return r.setKeys(i), r.setIndexRecords(n), r; }, q.config = l, q.parseQuery = xe, function(...t) { re.push(...t); }(class { constructor(t, { isCaseSensitive: e = l.isCaseSensitive, ignoreDiacritics: s = l.ignoreDiacritics, includeMatches: i = l.includeMatches, minMatchCharLength: n = l.minMatchCharLength, ignoreLocation: r = l.ignoreLocation, findAllMatches: u = l.findAllMatches, location: h = l.location, threshold: c = l.threshold, distance: a = l.distance } = {}) { this.query = null, this.options = { isCaseSensitive: e, ignoreDiacritics: s, includeMatches: i, minMatchCharLength: n, findAllMatches: u, ignoreLocation: r, location: h, threshold: c, distance: a }, t = e ? t : t.toLowerCase(), t = s ? Y(t) : t, this.pattern = t, this.query = function(o, d = {}) { return o.split("|").map((f) => { let g = f.trim().split(be).filter((A) => A && !!A.trim()), p = []; for (let A = 0, m = g.length; A < m; A += 1) { const _ = g[A]; let N = !1, w = -1; for (; !N && ++w < fe; ) { const S = ne[w]; let k = S.isMultiMatch(_); k && (p.push(new S(k, d)), N = !0); } if (!N) for (w = -1; ++w < fe; ) { const S = ne[w]; let k = S.isSingleMatch(_); if (k) { p.push(new S(k, d)); break; } } } return p; }); }(this.pattern, this.options); } static condition(t, e) { return e.useExtendedSearch; } searchIn(t) { const e = this.query; if (!e) return { isMatch: !1, score: 1 }; const { includeMatches: s, isCaseSensitive: i, ignoreDiacritics: n } = this.options; t = i ? t : t.toLowerCase(), t = n ? Y(t) : t; let r = 0, u = [], h = 0; for (let c = 0, a = e.length; c < a; c += 1) { const o = e[c]; u.length = 0, r = 0; for (let d = 0, f = o.length; d < f; d += 1) { const g = o[d], { isMatch: p, indices: A, score: m } = g.search(t); if (!p) { h = 0, r = 0, u.length = 0; break; } if (r += 1, h += m, s) { const _ = g.constructor.type; Ne.has(_) ? u = [...u, ...A] : u.push(A); } } if (r) { let d = { isMatch: !0, score: h / r }; return s && (d.indices = u), d; } } return { isMatch: !1, score: 1 }; } }); export { q as default };