(function(global, factory) { typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react/jsx-runtime")) : typeof define === "function" && define.amd ? define(["exports", "react", "react/jsx-runtime"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["react-fzf"] = {}, global.React, global.reactJsxRuntime)); })(this, function(exports2, react, jsxRuntime) { "use strict"; /** @license * fzf v0.5.1 * Copyright (c) 2021-2022 Ajit * Licensed under BSD 3-Clause */ const t = { 216: "O", 223: "s", 248: "o", 273: "d", 295: "h", 305: "i", 320: "l", 322: "l", 359: "t", 383: "s", 384: "b", 385: "B", 387: "b", 390: "O", 392: "c", 393: "D", 394: "D", 396: "d", 398: "E", 400: "E", 402: "f", 403: "G", 407: "I", 409: "k", 410: "l", 412: "M", 413: "N", 414: "n", 415: "O", 421: "p", 427: "t", 429: "t", 430: "T", 434: "V", 436: "y", 438: "z", 477: "e", 485: "g", 544: "N", 545: "d", 549: "z", 564: "l", 565: "n", 566: "t", 567: "j", 570: "A", 571: "C", 572: "c", 573: "L", 574: "T", 575: "s", 576: "z", 579: "B", 580: "U", 581: "V", 582: "E", 583: "e", 584: "J", 585: "j", 586: "Q", 587: "q", 588: "R", 589: "r", 590: "Y", 591: "y", 592: "a", 593: "a", 595: "b", 596: "o", 597: "c", 598: "d", 599: "d", 600: "e", 603: "e", 604: "e", 605: "e", 606: "e", 607: "j", 608: "g", 609: "g", 610: "G", 613: "h", 614: "h", 616: "i", 618: "I", 619: "l", 620: "l", 621: "l", 623: "m", 624: "m", 625: "m", 626: "n", 627: "n", 628: "N", 629: "o", 633: "r", 634: "r", 635: "r", 636: "r", 637: "r", 638: "r", 639: "r", 640: "R", 641: "R", 642: "s", 647: "t", 648: "t", 649: "u", 651: "v", 652: "v", 653: "w", 654: "y", 655: "Y", 656: "z", 657: "z", 663: "c", 665: "B", 666: "e", 667: "G", 668: "H", 669: "j", 670: "k", 671: "L", 672: "q", 686: "h", 867: "a", 868: "e", 869: "i", 870: "o", 871: "u", 872: "c", 873: "d", 874: "h", 875: "m", 876: "r", 877: "t", 878: "v", 879: "x", 7424: "A", 7427: "B", 7428: "C", 7429: "D", 7431: "E", 7432: "e", 7433: "i", 7434: "J", 7435: "K", 7436: "L", 7437: "M", 7438: "N", 7439: "O", 7440: "O", 7441: "o", 7442: "o", 7443: "o", 7446: "o", 7447: "o", 7448: "P", 7449: "R", 7450: "R", 7451: "T", 7452: "U", 7453: "u", 7454: "u", 7455: "m", 7456: "V", 7457: "W", 7458: "Z", 7522: "i", 7523: "r", 7524: "u", 7525: "v", 7834: "a", 7835: "s", 8305: "i", 8341: "h", 8342: "k", 8343: "l", 8344: "m", 8345: "n", 8346: "p", 8347: "s", 8348: "t", 8580: "c" }; for (let at = "\u0300".codePointAt(0); at <= "\u036F".codePointAt(0); ++at) { const e2 = String.fromCodePoint(at); for (const n2 of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") { const r2 = (n2 + e2).normalize().codePointAt(0); r2 > 126 && (t[r2] = n2); } } const e = { a: [7844, 7863], e: [7870, 7879], o: [7888, 7907], u: [7912, 7921] }; for (const at of Object.keys(e)) { const n2 = at.toUpperCase(); for (let r2 = e[at][0]; r2 <= e[at][1]; ++r2) t[r2] = r2 % 2 == 0 ? n2 : at; } function n(e2) { if (e2 < 192 || e2 > 8580) return e2; const n2 = t[e2]; return void 0 !== n2 ? n2.codePointAt(0) : e2; } function r(t2, e2) { return t2 > e2 ? t2 : e2; } const s = (t2) => t2.split("").map((t3) => t3.codePointAt(0)), o = (t2) => t2.map((t3) => String.fromCodePoint(t3)).join(""), i = new Set(" \f\n\r \v\xA0\u1680\u2028\u2029\u202F\u205F\u3000\uFEFF".split("").map((t2) => t2.codePointAt(0))); for (let at = "\u2000".codePointAt(0); at <= "\u200A".codePointAt(0); at++) i.add(at); const l = (t2) => i.has(t2), c = (t2) => { let e2 = 0; for (const n2 of t2) { if (!l(n2)) break; e2++; } return e2; }, a = (t2) => { let e2 = 0; for (let n2 = t2.length - 1; n2 >= 0 && l(t2[n2]); n2--) e2++; return e2; }, u = "\x7F".codePointAt(0), f = "A".codePointAt(0), h = "Z".codePointAt(0), d = "a".codePointAt(0), g = "z".codePointAt(0), m = "0".codePointAt(0), p = "9".codePointAt(0); function b(t2, e2, n2) { return n2 ? t2 : e2 - t2 - 1; } var y, P; function w(t2) { return t2 ? /* @__PURE__ */ new Set() : null; } function z(t2, e2, n2) { if (null !== e2 && e2.i16.length > t2 + n2) { return [t2 + n2, e2.i16.subarray(t2, t2 + n2)]; } return [t2, new Int16Array(n2)]; } function L(t2, e2, n2) { if (null !== e2 && e2.i32.length > t2 + n2) { return [t2 + n2, e2.i32.subarray(t2, t2 + n2)]; } return [t2, new Int32Array(n2)]; } function S(t2) { return t2 >= d && t2 <= g ? 1 : t2 >= f && t2 <= h ? 2 : t2 >= m && t2 <= p ? 4 : 0; } function A(t2) { const e2 = String.fromCodePoint(t2); return e2 !== e2.toUpperCase() ? 1 : e2 !== e2.toLowerCase() ? 2 : null !== e2.match(/\p{Number}/gu) ? 4 : null !== e2.match(/\p{Letter}/gu) ? 3 : 0; } function C(t2) { return t2 <= u ? S(t2) : A(t2); } function v(t2, e2) { return 0 === t2 && 0 !== e2 ? 8 : 1 === t2 && 2 === e2 || 4 !== t2 && 4 === e2 ? 7 : 0 === e2 ? 8 : 0; } function k(t2, e2, n2, r2) { let s2 = t2.slice(r2), o2 = s2.indexOf(n2); if (0 === o2) return r2; if (!e2 && n2 >= d && n2 <= g) { o2 > 0 && (s2 = s2.slice(0, o2)); const t3 = s2.indexOf(n2 - 32); t3 >= 0 && (o2 = t3); } return o2 < 0 ? -1 : r2 + o2; } function x(t2) { for (const e2 of t2) if (e2 >= 128) return false; return true; } function E(t2, e2, n2) { if (!x(t2)) return 0; if (!x(e2)) return -1; let r2 = 0, s2 = 0; for (let o2 = 0; o2 < e2.length; o2++) { if (s2 = k(t2, n2, e2[o2], s2), s2 < 0) return -1; 0 === o2 && s2 > 0 && (r2 = s2 - 1), s2++; } return r2; } (P = y || (y = {}))[P.NonWord = 0] = "NonWord", P[P.Lower = 1] = "Lower", P[P.Upper = 2] = "Upper", P[P.Letter = 3] = "Letter", P[P.Number = 4] = "Number"; const N = (t2, e2, s2, o2, i2, l2, c2) => { const a2 = i2.length; if (0 === a2) return [{ start: 0, end: 0, score: 0 }, w(l2)]; const f2 = o2.length; if (null !== c2 && f2 * a2 > c2.i16.length) return O(t2, e2, s2, o2, i2, l2); const h2 = E(o2, i2, t2); if (h2 < 0) return [{ start: -1, end: -1, score: 0 }, null]; let d2 = 0, g2 = 0, m2 = null, p2 = null, b2 = null, y2 = null; [d2, m2] = z(d2, c2, f2), [d2, p2] = z(d2, c2, f2), [d2, b2] = z(d2, c2, f2), [g2, y2] = L(g2, c2, a2); const [, P2] = L(g2, c2, f2); for (let n2 = 0; n2 < P2.length; n2++) P2[n2] = o2[n2]; let C2 = 0, k2 = 0, x2 = 0, N2 = 0; const F2 = i2[0]; let R2 = i2[0], q2 = 0, I2 = 0, W2 = false, j2 = P2.subarray(h2), M2 = m2.subarray(h2).subarray(0, j2.length), B2 = p2.subarray(h2).subarray(0, j2.length), U2 = b2.subarray(h2).subarray(0, j2.length); for (let [w2, z2] of j2.entries()) { let o3 = null; z2 <= u ? (o3 = S(z2), t2 || 2 !== o3 || (z2 += 32)) : (o3 = A(z2), t2 || 2 !== o3 || (z2 = String.fromCodePoint(z2).toLowerCase().codePointAt(0)), e2 && (z2 = n(z2))), j2[w2] = z2; const l3 = v(I2, o3); if (U2[w2] = l3, I2 = o3, z2 === R2 && (x2 < a2 && (y2[x2] = h2 + w2, x2++, R2 = i2[Math.min(x2, a2 - 1)]), N2 = h2 + w2), z2 === F2) { const t3 = 16 + 2 * l3; if (M2[w2] = t3, B2[w2] = 1, 1 === a2 && (s2 && t3 > C2 || !s2 && t3 >= C2) && (C2 = t3, k2 = h2 + w2, s2 && 8 === l3)) break; W2 = false; } else M2[w2] = r(W2 ? q2 + -1 : q2 + -3, 0), B2[w2] = 0, W2 = true; q2 = M2[w2]; } if (x2 !== a2) return [{ start: -1, end: -1, score: 0 }, null]; if (1 === a2) { const t3 = { start: k2, end: k2 + 1, score: C2 }; if (!l2) return [t3, null]; const e3 = /* @__PURE__ */ new Set(); return e3.add(k2), [t3, e3]; } const T2 = y2[0], D2 = N2 - T2 + 1; let G2 = null; [d2, G2] = z(d2, c2, D2 * a2); { const t3 = m2.subarray(T2, N2 + 1); for (const [e3, n2] of t3.entries()) G2[e3] = n2; } let [, V2] = z(d2, c2, D2 * a2); { const t3 = p2.subarray(T2, N2 + 1); for (const [e3, n2] of t3.entries()) V2[e3] = n2; } const J2 = y2.subarray(1), Y2 = i2.slice(1).slice(0, J2.length); for (const [n2, u2] of J2.entries()) { let t3 = false; const e3 = Y2[n2], o3 = n2 + 1, i3 = o3 * D2, l3 = P2.subarray(u2, N2 + 1), c3 = b2.subarray(u2).subarray(0, l3.length), f3 = V2.subarray(i3 + u2 - T2).subarray(0, l3.length), h3 = V2.subarray(i3 + u2 - T2 - 1 - D2).subarray(0, l3.length), d3 = G2.subarray(i3 + u2 - T2).subarray(0, l3.length), g3 = G2.subarray(i3 + u2 - T2 - 1 - D2).subarray(0, l3.length), m3 = G2.subarray(i3 + u2 - T2 - 1).subarray(0, l3.length); m3[0] = 0; for (const [n3, p3] of l3.entries()) { const i4 = n3 + u2; let l4 = 0, y3 = 0, P3 = 0; if (y3 = t3 ? m3[n3] + -1 : m3[n3] + -3, e3 === p3) { l4 = g3[n3] + 16; let t4 = c3[n3]; P3 = h3[n3] + 1, 8 === t4 ? P3 = 1 : P3 > 1 && (t4 = r(t4, r(4, b2[i4 - P3 + 1]))), l4 + t4 < y3 ? (l4 += c3[n3], P3 = 0) : l4 += t4; } f3[n3] = P3, t3 = l4 < y3; const w2 = r(r(l4, y3), 0); o3 === a2 - 1 && (s2 && w2 > C2 || !s2 && w2 >= C2) && (C2 = w2, k2 = i4), d3[n3] = w2; } } const Z = w(l2); let H = T2; if (l2 && null !== Z) { let t3 = a2 - 1; H = k2; let e3 = true; for (; ; ) { const n2 = t3 * D2, r2 = H - T2, s3 = G2[n2 + r2]; let o3 = 0, i3 = 0; if (t3 > 0 && H >= y2[t3] && (o3 = G2[n2 - D2 + r2 - 1]), H > y2[t3] && (i3 = G2[n2 + r2 - 1]), s3 > o3 && (s3 > i3 || s3 === i3 && e3)) { if (Z.add(H), 0 === t3) break; t3--; } e3 = V2[n2 + r2] > 1 || n2 + D2 + r2 + 1 < V2.length && V2[n2 + D2 + r2 + 1] > 0, H--; } } return [{ start: H, end: k2 + 1, score: C2 }, Z]; }; function F(t2, e2, s2, o2, i2, l2, c2) { let a2 = 0, d2 = 0, g2 = false, m2 = 0, p2 = 0; const b2 = w(c2); let y2 = 0; i2 > 0 && (y2 = C(s2[i2 - 1])); for (let P2 = i2; P2 < l2; P2++) { let i3 = s2[P2]; const l3 = C(i3); if (t2 || (i3 >= f && i3 <= h ? i3 += 32 : i3 > u && (i3 = String.fromCodePoint(i3).toLowerCase().codePointAt(0))), e2 && (i3 = n(i3)), i3 === o2[a2]) { c2 && null !== b2 && b2.add(P2), d2 += 16; let t3 = v(y2, l3); 0 === m2 ? p2 = t3 : (8 === t3 && (p2 = t3), t3 = r(r(t3, p2), 4)), d2 += 0 === a2 ? 2 * t3 : t3, g2 = false, m2++, a2++; } else d2 += g2 ? -1 : -3, g2 = true, m2 = 0, p2 = 0; y2 = l3; } return [d2, b2]; } const O = (t2, e2, r2, s2, o2, i2, l2) => { if (0 === o2.length) return [{ start: 0, end: 0, score: 0 }, null]; if (E(s2, o2, t2) < 0) return [{ start: -1, end: -1, score: 0 }, null]; let c2 = 0, a2 = -1, d2 = -1; const g2 = s2.length, m2 = o2.length; for (let p2 = 0; p2 < g2; p2++) { let i3 = s2[b(p2, g2, r2)]; t2 || (i3 >= f && i3 <= h ? i3 += 32 : i3 > u && (i3 = String.fromCodePoint(i3).toLowerCase().codePointAt(0))), e2 && (i3 = n(i3)); if (i3 === o2[b(c2, m2, r2)] && (a2 < 0 && (a2 = p2), c2++, c2 === m2)) { d2 = p2 + 1; break; } } if (a2 >= 0 && d2 >= 0) { c2--; for (let e3 = d2 - 1; e3 >= a2; e3--) { let n3 = s2[b(e3, g2, r2)]; t2 || (n3 >= f && n3 <= h ? n3 += 32 : n3 > u && (n3 = String.fromCodePoint(n3).toLowerCase().codePointAt(0))); if (n3 === o2[b(c2, m2, r2)] && (c2--, c2 < 0)) { a2 = e3; break; } } if (!r2) { const t3 = a2; a2 = g2 - d2, d2 = g2 - t3; } const [n2, l3] = F(t2, e2, s2, o2, a2, d2, i2); return [{ start: a2, end: d2, score: n2 }, l3]; } return [{ start: -1, end: -1, score: 0 }, null]; }, R = (t2, e2, r2, s2, o2, i2, l2) => { if (0 === o2.length) return [{ start: 0, end: 0, score: 0 }, null]; const c2 = s2.length, a2 = o2.length; if (c2 < a2) return [{ start: -1, end: -1, score: 0 }, null]; if (E(s2, o2, t2) < 0) return [{ start: -1, end: -1, score: 0 }, null]; let d2 = 0, g2 = -1, m2 = 0, p2 = -1; for (let w2 = 0; w2 < c2; w2++) { const i3 = b(w2, c2, r2); let l3 = s2[i3]; t2 || (l3 >= f && l3 <= h ? l3 += 32 : l3 > u && (l3 = String.fromCodePoint(l3).toLowerCase().codePointAt(0))), e2 && (l3 = n(l3)); const z2 = b(d2, a2, r2); if (o2[z2] === l3) { if (0 === z2 && (y2 = s2, m2 = 0 === (P2 = i3) ? 8 : v(C(y2[P2 - 1]), C(y2[P2]))), d2++, d2 === a2) { if (m2 > p2 && (g2 = w2, p2 = m2), 8 === m2) break; w2 -= d2 - 1, d2 = 0, m2 = 0; } } else w2 -= d2, d2 = 0, m2 = 0; } var y2, P2; if (g2 >= 0) { let n2 = 0, i3 = 0; r2 ? (n2 = g2 - a2 + 1, i3 = g2 + 1) : (n2 = c2 - (g2 + 1), i3 = c2 - (g2 - a2 + 1)); const [l3] = F(t2, e2, s2, o2, n2, i3, false); return [{ start: n2, end: i3, score: l3 }, null]; } return [{ start: -1, end: -1, score: 0 }, null]; }; const q = (I = 2048, { i16: new Int16Array(102400), i32: new Int32Array(I) }); var I, W, j; (j = W || (W = {}))[j.Fuzzy = 0] = "Fuzzy", j[j.Exact = 1] = "Exact", j[j.Prefix = 2] = "Prefix", j[j.Suffix = 3] = "Suffix", j[j.Equal = 4] = "Equal"; const M = { 0: N, 1: R, 2: (t2, e2, r2, s2, o2, i2, a2) => { if (0 === o2.length) return [{ start: 0, end: 0, score: 0 }, null]; let u2 = 0; if (l(o2[0]) || (u2 = c(s2)), s2.length - u2 < o2.length) return [{ start: -1, end: -1, score: 0 }, null]; for (const [l2, c2] of o2.entries()) { let r3 = s2[u2 + l2]; if (t2 || (r3 = String.fromCodePoint(r3).toLowerCase().codePointAt(0)), e2 && (r3 = n(r3)), r3 !== c2) return [{ start: -1, end: -1, score: 0 }, null]; } const f2 = o2.length, [h2] = F(t2, e2, s2, o2, u2, u2 + f2, false); return [{ start: u2, end: u2 + f2, score: h2 }, null]; }, 3: (t2, e2, r2, s2, o2, i2, c2) => { let u2 = s2.length; if (0 !== o2.length && l(o2[o2.length - 1]) || (u2 -= a(s2)), 0 === o2.length) return [{ start: u2, end: u2, score: 0 }, null]; const f2 = u2 - o2.length; if (f2 < 0) return [{ start: -1, end: -1, score: 0 }, null]; for (const [l2, a2] of o2.entries()) { let r3 = s2[l2 + f2]; if (t2 || (r3 = String.fromCodePoint(r3).toLowerCase().codePointAt(0)), e2 && (r3 = n(r3)), r3 !== a2) return [{ start: -1, end: -1, score: 0 }, null]; } const h2 = u2 - o2.length, d2 = u2, [g2] = F(t2, e2, s2, o2, h2, d2, false); return [{ start: h2, end: d2, score: g2 }, null]; }, 4: (t2, e2, r2, s2, i2, u2, f2) => { const h2 = i2.length; if (0 === h2) return [{ start: -1, end: -1, score: 0 }, null]; let d2 = 0; l(i2[0]) || (d2 = c(s2)); let g2 = 0; if (l(i2[h2 - 1]) || (g2 = a(s2)), s2.length - d2 - g2 != h2) return [{ start: -1, end: -1, score: 0 }, null]; let m2 = true; if (e2) { const e3 = s2; for (const [r3, s3] of i2.entries()) { let o2 = e3[d2 + r3]; if (t2 || (o2 = String.fromCodePoint(o2).toLowerCase().codePointAt(0)), n(s3) !== n(o2)) { m2 = false; break; } } } else { let e3 = o(s2).substring(d2, s2.length - g2); t2 || (e3 = e3.toLowerCase()), m2 = e3 === o(i2); } return m2 ? [{ start: d2, end: d2 + h2, score: 24 * h2 + 8 }, null] : [{ start: -1, end: -1, score: 0 }, null]; } }; function B(t2, e2, r2, i2) { let l2 = true; { const t3 = (i2 = i2.trimLeft()).trimRight(); i2 = t3.endsWith("\\") && " " === i2[t3.length] ? t3 + " " : t3; } let c2 = false, a2 = []; a2 = function(t3, e3, r3, i3) { const l3 = (i3 = i3.replace(/\\ /g, " ")).split(/ +/), c3 = []; let a3 = [], u2 = false, f2 = false; for (const h2 of l3) { let i4 = 0, l4 = false, d2 = h2.replace(/\t/g, " "); const g2 = d2.toLowerCase(), m2 = "case-sensitive" === e3 || "smart-case" === e3 && d2 !== g2, p2 = r3 && g2 === o(s(g2).map(n)); if (m2 || (d2 = g2), t3 || (i4 = 1), a3.length > 0 && !f2 && "|" === d2) u2 = false, f2 = true; else if (f2 = false, d2.startsWith("!") && (l4 = true, i4 = 1, d2 = d2.substring(1)), "$" !== d2 && d2.endsWith("$") && (i4 = 3, d2 = d2.substring(0, d2.length - 1)), d2.startsWith("'") ? (i4 = t3 && !l4 ? 1 : 0, d2 = d2.substring(1)) : d2.startsWith("^") && (i4 = 3 === i4 ? 4 : 2, d2 = d2.substring(1)), d2.length > 0) { u2 && (c3.push(a3), a3 = []); let t4 = s(d2); p2 && (t4 = t4.map(n)), a3.push({ typ: i4, inv: l4, text: t4, caseSensitive: m2, normalize: p2 }), u2 = true; } } a3.length > 0 && c3.push(a3); return c3; }(t2, e2, r2, i2); t: for (const n2 of a2) for (const [e3, r3] of n2.entries()) if (r3.inv || (c2 = true), (!l2 || e3 > 0 || r3.inv || t2 && 0 !== r3.typ || !t2 && 1 !== r3.typ) && (l2 = false, c2)) break t; return { str: i2, termSets: a2, sortable: c2, cacheable: l2, fuzzy: t2 }; } const U = (t2, e2, r2) => { let o2 = false; switch (e2) { case "smart-case": t2.toLowerCase() !== t2 && (o2 = true); break; case "case-sensitive": o2 = true; break; case "case-insensitive": t2 = t2.toLowerCase(), o2 = false; } let i2 = s(t2); return r2 && (i2 = i2.map(n)), { queryRunes: i2, caseSensitive: o2 }; }; function T(t2, e2, n2, r2, s2, o2, i2) { for (const l2 of e2) { const [e3, c2] = t2(n2, r2, s2, l2.text, o2, true, i2); if (e3.start >= 0) { const t3 = e3.start + l2.prefixLength, n3 = e3.end + l2.prefixLength; if (null !== c2) { const r3 = /* @__PURE__ */ new Set(); return c2.forEach((t4) => r3.add(l2.prefixLength + t4)), [[t3, n3], e3.score, r3]; } return [[t3, n3], e3.score, c2]; } } return [[-1, -1], 0, null]; } function D(t2, e2) { const n2 = Object.keys(t2).map((t3) => parseInt(t3, 10)).sort((t3, e3) => e3 - t3); let r2 = []; for (const s2 of n2) if (r2 = r2.concat(t2[s2]), r2.length >= e2) break; return r2; } function G(t2, e2, n2) { return (r2) => { const s2 = this.runesList[r2]; if (e2.length > s2.length) return; let [o2, i2] = this.algoFn(n2, this.opts.normalize, this.opts.forward, s2, e2, true, q); if (-1 === o2.start) return; if (false === this.opts.fuzzy) { i2 = /* @__PURE__ */ new Set(); for (let t3 = o2.start; t3 < o2.end; ++t3) i2.add(t3); } const l2 = this.opts.sort ? o2.score : 0; void 0 === t2[l2] && (t2[l2] = []), t2[l2].push({ item: this.items[r2], ...o2, positions: null != i2 ? i2 : /* @__PURE__ */ new Set() }); }; } function V(t2, e2) { return (n2) => { const r2 = function(t3, e3, n3, r3) { const s3 = [{ text: t3, prefixLength: 0 }], o3 = []; let i3 = 0; const l2 = /* @__PURE__ */ new Set(); for (const c2 of e3.termSets) { let t4 = [0, 0], e4 = 0, a2 = false; for (const o4 of c2) { let i4 = M[o4.typ]; o4.typ === W.Fuzzy && (i4 = n3); const [c3, u2, f2] = T(i4, s3, o4.caseSensitive, o4.normalize, r3, o4.text, q); if (c3[0] >= 0) { if (o4.inv) continue; if (t4 = c3, e4 = u2, a2 = true, null !== f2) f2.forEach((t5) => l2.add(t5)); else for (let t5 = c3[0]; t5 < c3[1]; ++t5) l2.add(t5); break; } o4.inv && (t4 = [0, 0], e4 = 0, a2 = true); } a2 && (o3.push(t4), i3 += e4); } return { offsets: o3, totalScore: i3, allPos: l2 }; }(this.runesList[n2], e2, this.algoFn, this.opts.forward); if (r2.offsets.length !== e2.termSets.length) return; let s2 = -1, o2 = -1; r2.allPos.size > 0 && (s2 = Math.min(...r2.allPos), o2 = Math.max(...r2.allPos) + 1); const i2 = this.opts.sort ? r2.totalScore : 0; void 0 === t2[i2] && (t2[i2] = []), t2[i2].push({ score: r2.totalScore, item: this.items[n2], positions: r2.allPos, start: s2, end: o2 }); }; } function J(t2) { const { queryRunes: e2, caseSensitive: n2 } = U(t2, this.opts.casing, this.opts.normalize), r2 = {}, s2 = G.bind(this)(r2, e2, n2); for (let o2 = 0, i2 = this.runesList.length; o2 < i2; ++o2) s2(o2); return D(r2, this.opts.limit); } function Y(t2) { const e2 = B(Boolean(this.opts.fuzzy), this.opts.casing, this.opts.normalize, t2), n2 = {}, r2 = V.bind(this)(n2, e2); for (let s2 = 0, o2 = this.runesList.length; s2 < o2; ++s2) r2(s2); return D(n2, this.opts.limit); } const $ = { limit: 1 / 0, selector: (t2) => t2, casing: "smart-case", normalize: true, fuzzy: "v2", tiebreakers: [], sort: true, forward: true }; class X { constructor(t2, ...e2) { switch (this.opts = { ...$, ...e2[0] }, this.items = t2, this.runesList = t2.map((t3) => s(this.opts.selector(t3).normalize())), this.algoFn = R, this.opts.fuzzy) { case "v2": this.algoFn = N; break; case "v1": this.algoFn = O; } } } const _ = { ...$, match: J }; class tt extends X { constructor(t2, ...e2) { super(t2, ...e2), this.opts = { ..._, ...e2[0] }; } find(t2) { if (0 === t2.length || 0 === this.items.length) return this.items.slice(0, this.opts.limit).map(rt); return t2 = t2.normalize(), st(this.opts.match.bind(this)(t2), this.opts); } } const rt = (t2) => ({ item: t2, start: -1, end: -1, score: 0, positions: /* @__PURE__ */ new Set() }); function st(t2, e2) { if (e2.sort) { const { selector: n2 } = e2; t2.sort((t3, r2) => { if (t3.score === r2.score) for (const s2 of e2.tiebreakers) { const e3 = s2(t3, r2, n2); if (0 !== e3) return e3; } return 0; }); } return Number.isFinite(e2.limit) && t2.splice(e2.limit), t2; } function ot(t2, e2, n2) { return n2(t2.item).length - n2(e2.item).length; } function it(t2, e2) { return t2.start - e2.start; } class lt { constructor(t2, ...e2) { this.finder = new tt(t2, ...e2), this.find = this.finder.find.bind(this.finder); } } function FzfHighlight({ as, highlight, ...props }) { const Component = as != null ? as : "strong"; return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: highlight.characters.map((char, index) => { return highlight.positions.has(index) ? /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props, children: char }, index) : /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: char }, index); }) }); } function useFzf({ items, itemToString, query, ...fzfOptions }) { const highlights = react.useRef([]); const fzf = react.useMemo(() => { const options = fzfOptions; if (itemToString) { options.selector = itemToString; } return new lt(items, fzfOptions); }, [fzfOptions, items, itemToString]); const getFzfHighlightProps = react.useCallback(({ index, item, ...props }) => { const highlight = highlights.current[getHighlightIndex(highlights.current, item, index)]; if (!highlight) { throw new Error(`getFzfHighlightProps: Unable to find highlight for item '${JSON.stringify(item)}'.`); } return { ...props, highlight }; }, []); const results = react.useMemo(() => { highlights.current = []; return fzf.find(query).map((result) => { let characters = ""; if (itemToString) { characters = itemToString(result.item); } else if (typeof result.item === "string") { characters = result.item; } else if (typeof result.item !== "string") { throw new TypeError("react-fzf: the `itemToString` option is required for non-string items."); } highlights.current.push({ ...result, characters: [...characters] }); return result.item; }); }, [fzf, itemToString, query]); return { getFzfHighlightProps, results }; } function getHighlightIndex(highlights, item, index) { if (index !== void 0) { return index; } if (highlights.length === 0) { return -1; } return highlights.findIndex((highlight) => highlight.item === item); } exports2.FzfHighlight = FzfHighlight; exports2.basicMatch = J; exports2.byLengthAsc = ot; exports2.byStartAsc = it; exports2.extendedMatch = Y; exports2.useFzf = useFzf; Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); });