@eox/itemfilter 0.0.1

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.
@@ -0,0 +1,1405 @@
1
+ var ut = Object.defineProperty;
2
+ var ft = (s, t, e) =>
3
+ t in s
4
+ ? ut(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e })
5
+ : (s[t] = e);
6
+ var A = (s, t, e) => (ft(s, typeof t != "symbol" ? t + "" : t, e), e);
7
+ function I(s) {
8
+ return Array.isArray ? Array.isArray(s) : st(s) === "[object Array]";
9
+ }
10
+ const dt = 1 / 0;
11
+ function gt(s) {
12
+ if (typeof s == "string") return s;
13
+ let t = s + "";
14
+ return t == "0" && 1 / s == -dt ? "-0" : t;
15
+ }
16
+ function pt(s) {
17
+ return s == null ? "" : gt(s);
18
+ }
19
+ function x(s) {
20
+ return typeof s == "string";
21
+ }
22
+ function tt(s) {
23
+ return typeof s == "number";
24
+ }
25
+ function mt(s) {
26
+ return s === !0 || s === !1 || (yt(s) && st(s) == "[object Boolean]");
27
+ }
28
+ function et(s) {
29
+ return typeof s == "object";
30
+ }
31
+ function yt(s) {
32
+ return et(s) && s !== null;
33
+ }
34
+ function y(s) {
35
+ return s != null;
36
+ }
37
+ function H(s) {
38
+ return !s.trim().length;
39
+ }
40
+ function st(s) {
41
+ return s == null
42
+ ? s === void 0
43
+ ? "[object Undefined]"
44
+ : "[object Null]"
45
+ : Object.prototype.toString.call(s);
46
+ }
47
+ const Mt = "Incorrect 'index' type",
48
+ Et = (s) => `Invalid value for key ${s}`,
49
+ xt = (s) => `Pattern length exceeds max of ${s}.`,
50
+ St = (s) => `Missing ${s} property in key`,
51
+ At = (s) => `Property 'weight' in key '${s}' must be a positive integer`,
52
+ Q = Object.prototype.hasOwnProperty;
53
+ class It {
54
+ constructor(t) {
55
+ (this._keys = []), (this._keyMap = {});
56
+ let e = 0;
57
+ t.forEach((n) => {
58
+ let r = rt(n);
59
+ (e += r.weight),
60
+ this._keys.push(r),
61
+ (this._keyMap[r.id] = r),
62
+ (e += r.weight);
63
+ }),
64
+ this._keys.forEach((n) => {
65
+ n.weight /= e;
66
+ });
67
+ }
68
+ get(t) {
69
+ return this._keyMap[t];
70
+ }
71
+ keys() {
72
+ return this._keys;
73
+ }
74
+ toJSON() {
75
+ return JSON.stringify(this._keys);
76
+ }
77
+ }
78
+ function rt(s) {
79
+ let t = null,
80
+ e = null,
81
+ n = null,
82
+ r = 1,
83
+ i = null;
84
+ if (x(s) || I(s)) (n = s), (t = X(s)), (e = K(s));
85
+ else {
86
+ if (!Q.call(s, "name")) throw new Error(St("name"));
87
+ const c = s.name;
88
+ if (((n = c), Q.call(s, "weight") && ((r = s.weight), r <= 0)))
89
+ throw new Error(At(c));
90
+ (t = X(c)), (e = K(c)), (i = s.getFn);
91
+ }
92
+ return { path: t, id: e, weight: r, src: n, getFn: i };
93
+ }
94
+ function X(s) {
95
+ return I(s) ? s : s.split(".");
96
+ }
97
+ function K(s) {
98
+ return I(s) ? s.join(".") : s;
99
+ }
100
+ function _t(s, t) {
101
+ let e = [],
102
+ n = !1;
103
+ const r = (i, c, o) => {
104
+ if (y(i))
105
+ if (!c[o]) e.push(i);
106
+ else {
107
+ let a = c[o];
108
+ const h = i[a];
109
+ if (!y(h)) return;
110
+ if (o === c.length - 1 && (x(h) || tt(h) || mt(h))) e.push(pt(h));
111
+ else if (I(h)) {
112
+ n = !0;
113
+ for (let l = 0, u = h.length; l < u; l += 1) r(h[l], c, o + 1);
114
+ } else c.length && r(h, c, o + 1);
115
+ }
116
+ };
117
+ return r(s, x(t) ? t.split(".") : t, 0), n ? e : e[0];
118
+ }
119
+ const wt = {
120
+ // Whether the matches should be included in the result set. When `true`, each record in the result
121
+ // set will include the indices of the matched characters.
122
+ // These can consequently be used for highlighting purposes.
123
+ includeMatches: !1,
124
+ // When `true`, the matching function will continue to the end of a search pattern even if
125
+ // a perfect match has already been located in the string.
126
+ findAllMatches: !1,
127
+ // Minimum number of characters that must be matched before a result is considered a match
128
+ minMatchCharLength: 1,
129
+ },
130
+ Lt = {
131
+ // When `true`, the algorithm continues searching to the end of the input even if a perfect
132
+ // match is found before the end of the same input.
133
+ isCaseSensitive: !1,
134
+ // When true, the matching function will continue to the end of a search pattern even if
135
+ includeScore: !1,
136
+ // List of properties that will be searched. This also supports nested properties.
137
+ keys: [],
138
+ // Whether to sort the result list, by score
139
+ shouldSort: !0,
140
+ // Default sort function: sort by ascending score, ascending index
141
+ sortFn: (s, t) =>
142
+ s.score === t.score
143
+ ? s.idx < t.idx
144
+ ? -1
145
+ : 1
146
+ : s.score < t.score
147
+ ? -1
148
+ : 1,
149
+ },
150
+ bt = {
151
+ // Approximately where in the text is the pattern expected to be found?
152
+ location: 0,
153
+ // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
154
+ // (of both letters and location), a threshold of '1.0' would match anything.
155
+ threshold: 0.6,
156
+ // Determines how close the match must be to the fuzzy location (specified above).
157
+ // An exact letter match which is 'distance' characters away from the fuzzy location
158
+ // would score as a complete mismatch. A distance of '0' requires the match be at
159
+ // the exact location specified, a threshold of '1000' would require a perfect match
160
+ // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
161
+ distance: 100,
162
+ },
163
+ Rt = {
164
+ // When `true`, it enables the use of unix-like search commands
165
+ useExtendedSearch: !1,
166
+ // The get function to use when fetching an object's properties.
167
+ // The default will search nested paths *ie foo.bar.baz*
168
+ getFn: _t,
169
+ // When `true`, search will ignore `location` and `distance`, so it won't matter
170
+ // where in the string the pattern appears.
171
+ // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
172
+ ignoreLocation: !1,
173
+ // When `true`, the calculation for the relevance score (used for sorting) will
174
+ // ignore the field-length norm.
175
+ // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
176
+ ignoreFieldNorm: !1,
177
+ // The weight to determine how much field length norm effects scoring.
178
+ fieldNormWeight: 1,
179
+ };
180
+ var d = {
181
+ ...Lt,
182
+ ...wt,
183
+ ...bt,
184
+ ...Rt,
185
+ };
186
+ const kt = /[^ ]+/g;
187
+ function Tt(s = 1, t = 3) {
188
+ const e = /* @__PURE__ */ new Map(),
189
+ n = Math.pow(10, t);
190
+ return {
191
+ get(r) {
192
+ const i = r.match(kt).length;
193
+ if (e.has(i)) return e.get(i);
194
+ const c = 1 / Math.pow(i, 0.5 * s),
195
+ o = parseFloat(Math.round(c * n) / n);
196
+ return e.set(i, o), o;
197
+ },
198
+ clear() {
199
+ e.clear();
200
+ },
201
+ };
202
+ }
203
+ class Y {
204
+ constructor({
205
+ getFn: t = d.getFn,
206
+ fieldNormWeight: e = d.fieldNormWeight,
207
+ } = {}) {
208
+ (this.norm = Tt(e, 3)),
209
+ (this.getFn = t),
210
+ (this.isCreated = !1),
211
+ this.setIndexRecords();
212
+ }
213
+ setSources(t = []) {
214
+ this.docs = t;
215
+ }
216
+ setIndexRecords(t = []) {
217
+ this.records = t;
218
+ }
219
+ setKeys(t = []) {
220
+ (this.keys = t),
221
+ (this._keysMap = {}),
222
+ t.forEach((e, n) => {
223
+ this._keysMap[e.id] = n;
224
+ });
225
+ }
226
+ create() {
227
+ this.isCreated ||
228
+ !this.docs.length ||
229
+ ((this.isCreated = !0),
230
+ x(this.docs[0])
231
+ ? this.docs.forEach((t, e) => {
232
+ this._addString(t, e);
233
+ })
234
+ : this.docs.forEach((t, e) => {
235
+ this._addObject(t, e);
236
+ }),
237
+ this.norm.clear());
238
+ }
239
+ // Adds a doc to the end of the index
240
+ add(t) {
241
+ const e = this.size();
242
+ x(t) ? this._addString(t, e) : this._addObject(t, e);
243
+ }
244
+ // Removes the doc at the specified index of the index
245
+ removeAt(t) {
246
+ this.records.splice(t, 1);
247
+ for (let e = t, n = this.size(); e < n; e += 1) this.records[e].i -= 1;
248
+ }
249
+ getValueForItemAtKeyId(t, e) {
250
+ return t[this._keysMap[e]];
251
+ }
252
+ size() {
253
+ return this.records.length;
254
+ }
255
+ _addString(t, e) {
256
+ if (!y(t) || H(t)) return;
257
+ let n = {
258
+ v: t,
259
+ i: e,
260
+ n: this.norm.get(t),
261
+ };
262
+ this.records.push(n);
263
+ }
264
+ _addObject(t, e) {
265
+ let n = { i: e, $: {} };
266
+ this.keys.forEach((r, i) => {
267
+ let c = r.getFn ? r.getFn(t) : this.getFn(t, r.path);
268
+ if (y(c)) {
269
+ if (I(c)) {
270
+ let o = [];
271
+ const a = [{ nestedArrIndex: -1, value: c }];
272
+ for (; a.length; ) {
273
+ const { nestedArrIndex: h, value: l } = a.pop();
274
+ if (y(l))
275
+ if (x(l) && !H(l)) {
276
+ let u = {
277
+ v: l,
278
+ i: h,
279
+ n: this.norm.get(l),
280
+ };
281
+ o.push(u);
282
+ } else
283
+ I(l) &&
284
+ l.forEach((u, f) => {
285
+ a.push({
286
+ nestedArrIndex: f,
287
+ value: u,
288
+ });
289
+ });
290
+ }
291
+ n.$[i] = o;
292
+ } else if (x(c) && !H(c)) {
293
+ let o = {
294
+ v: c,
295
+ n: this.norm.get(c),
296
+ };
297
+ n.$[i] = o;
298
+ }
299
+ }
300
+ }),
301
+ this.records.push(n);
302
+ }
303
+ toJSON() {
304
+ return {
305
+ keys: this.keys,
306
+ records: this.records,
307
+ };
308
+ }
309
+ }
310
+ function nt(
311
+ s,
312
+ t,
313
+ { getFn: e = d.getFn, fieldNormWeight: n = d.fieldNormWeight } = {}
314
+ ) {
315
+ const r = new Y({ getFn: e, fieldNormWeight: n });
316
+ return r.setKeys(s.map(rt)), r.setSources(t), r.create(), r;
317
+ }
318
+ function $t(
319
+ s,
320
+ { getFn: t = d.getFn, fieldNormWeight: e = d.fieldNormWeight } = {}
321
+ ) {
322
+ const { keys: n, records: r } = s,
323
+ i = new Y({ getFn: t, fieldNormWeight: e });
324
+ return i.setKeys(n), i.setIndexRecords(r), i;
325
+ }
326
+ function v(
327
+ s,
328
+ {
329
+ errors: t = 0,
330
+ currentLocation: e = 0,
331
+ expectedLocation: n = 0,
332
+ distance: r = d.distance,
333
+ ignoreLocation: i = d.ignoreLocation,
334
+ } = {}
335
+ ) {
336
+ const c = t / s.length;
337
+ if (i) return c;
338
+ const o = Math.abs(n - e);
339
+ return r ? c + o / r : o ? 1 : c;
340
+ }
341
+ function Nt(s = [], t = d.minMatchCharLength) {
342
+ let e = [],
343
+ n = -1,
344
+ r = -1,
345
+ i = 0;
346
+ for (let c = s.length; i < c; i += 1) {
347
+ let o = s[i];
348
+ o && n === -1
349
+ ? (n = i)
350
+ : !o &&
351
+ n !== -1 &&
352
+ ((r = i - 1), r - n + 1 >= t && e.push([n, r]), (n = -1));
353
+ }
354
+ return s[i - 1] && i - n >= t && e.push([n, i - 1]), e;
355
+ }
356
+ const k = 32;
357
+ function Ot(
358
+ s,
359
+ t,
360
+ e,
361
+ {
362
+ location: n = d.location,
363
+ distance: r = d.distance,
364
+ threshold: i = d.threshold,
365
+ findAllMatches: c = d.findAllMatches,
366
+ minMatchCharLength: o = d.minMatchCharLength,
367
+ includeMatches: a = d.includeMatches,
368
+ ignoreLocation: h = d.ignoreLocation,
369
+ } = {}
370
+ ) {
371
+ if (t.length > k) throw new Error(xt(k));
372
+ const l = t.length,
373
+ u = s.length,
374
+ f = Math.max(0, Math.min(n, u));
375
+ let g = i,
376
+ p = f;
377
+ const m = o > 1 || a,
378
+ b = m ? Array(u) : [];
379
+ let S;
380
+ for (; (S = s.indexOf(t, p)) > -1; ) {
381
+ let M = v(t, {
382
+ currentLocation: S,
383
+ expectedLocation: f,
384
+ distance: r,
385
+ ignoreLocation: h,
386
+ });
387
+ if (((g = Math.min(M, g)), (p = S + l), m)) {
388
+ let _ = 0;
389
+ for (; _ < l; ) (b[S + _] = 1), (_ += 1);
390
+ }
391
+ }
392
+ p = -1;
393
+ let T = [],
394
+ R = 1,
395
+ O = l + u;
396
+ const lt = 1 << (l - 1);
397
+ for (let M = 0; M < l; M += 1) {
398
+ let _ = 0,
399
+ w = O;
400
+ for (; _ < w; )
401
+ v(t, {
402
+ errors: M,
403
+ currentLocation: f + w,
404
+ expectedLocation: f,
405
+ distance: r,
406
+ ignoreLocation: h,
407
+ }) <= g
408
+ ? (_ = w)
409
+ : (O = w),
410
+ (w = Math.floor((O - _) / 2 + _));
411
+ O = w;
412
+ let G = Math.max(1, f - w + 1),
413
+ j = c ? u : Math.min(f + w, u) + l,
414
+ $ = Array(j + 2);
415
+ $[j + 1] = (1 << M) - 1;
416
+ for (let E = j; E >= G; E -= 1) {
417
+ let C = E - 1,
418
+ U = e[s.charAt(C)];
419
+ if (
420
+ (m && (b[C] = +!!U),
421
+ ($[E] = (($[E + 1] << 1) | 1) & U),
422
+ M && ($[E] |= ((T[E + 1] | T[E]) << 1) | 1 | T[E + 1]),
423
+ $[E] & lt &&
424
+ ((R = v(t, {
425
+ errors: M,
426
+ currentLocation: C,
427
+ expectedLocation: f,
428
+ distance: r,
429
+ ignoreLocation: h,
430
+ })),
431
+ R <= g))
432
+ ) {
433
+ if (((g = R), (p = C), p <= f)) break;
434
+ G = Math.max(1, 2 * f - p);
435
+ }
436
+ }
437
+ if (
438
+ v(t, {
439
+ errors: M + 1,
440
+ currentLocation: f,
441
+ expectedLocation: f,
442
+ distance: r,
443
+ ignoreLocation: h,
444
+ }) > g
445
+ )
446
+ break;
447
+ T = $;
448
+ }
449
+ const P = {
450
+ isMatch: p >= 0,
451
+ // Count exact matches (those with a score of 0) to be "almost" exact
452
+ score: Math.max(1e-3, R),
453
+ };
454
+ if (m) {
455
+ const M = Nt(b, o);
456
+ M.length ? a && (P.indices = M) : (P.isMatch = !1);
457
+ }
458
+ return P;
459
+ }
460
+ function Ct(s) {
461
+ let t = {};
462
+ for (let e = 0, n = s.length; e < n; e += 1) {
463
+ const r = s.charAt(e);
464
+ t[r] = (t[r] || 0) | (1 << (n - e - 1));
465
+ }
466
+ return t;
467
+ }
468
+ class it {
469
+ constructor(
470
+ t,
471
+ {
472
+ location: e = d.location,
473
+ threshold: n = d.threshold,
474
+ distance: r = d.distance,
475
+ includeMatches: i = d.includeMatches,
476
+ findAllMatches: c = d.findAllMatches,
477
+ minMatchCharLength: o = d.minMatchCharLength,
478
+ isCaseSensitive: a = d.isCaseSensitive,
479
+ ignoreLocation: h = d.ignoreLocation,
480
+ } = {}
481
+ ) {
482
+ if (
483
+ ((this.options = {
484
+ location: e,
485
+ threshold: n,
486
+ distance: r,
487
+ includeMatches: i,
488
+ findAllMatches: c,
489
+ minMatchCharLength: o,
490
+ isCaseSensitive: a,
491
+ ignoreLocation: h,
492
+ }),
493
+ (this.pattern = a ? t : t.toLowerCase()),
494
+ (this.chunks = []),
495
+ !this.pattern.length)
496
+ )
497
+ return;
498
+ const l = (f, g) => {
499
+ this.chunks.push({
500
+ pattern: f,
501
+ alphabet: Ct(f),
502
+ startIndex: g,
503
+ });
504
+ },
505
+ u = this.pattern.length;
506
+ if (u > k) {
507
+ let f = 0;
508
+ const g = u % k,
509
+ p = u - g;
510
+ for (; f < p; ) l(this.pattern.substr(f, k), f), (f += k);
511
+ if (g) {
512
+ const m = u - k;
513
+ l(this.pattern.substr(m), m);
514
+ }
515
+ } else l(this.pattern, 0);
516
+ }
517
+ searchIn(t) {
518
+ const { isCaseSensitive: e, includeMatches: n } = this.options;
519
+ if ((e || (t = t.toLowerCase()), this.pattern === t)) {
520
+ let p = {
521
+ isMatch: !0,
522
+ score: 0,
523
+ };
524
+ return n && (p.indices = [[0, t.length - 1]]), p;
525
+ }
526
+ const {
527
+ location: r,
528
+ distance: i,
529
+ threshold: c,
530
+ findAllMatches: o,
531
+ minMatchCharLength: a,
532
+ ignoreLocation: h,
533
+ } = this.options;
534
+ let l = [],
535
+ u = 0,
536
+ f = !1;
537
+ this.chunks.forEach(({ pattern: p, alphabet: m, startIndex: b }) => {
538
+ const {
539
+ isMatch: S,
540
+ score: T,
541
+ indices: R,
542
+ } = Ot(t, p, m, {
543
+ location: r + b,
544
+ distance: i,
545
+ threshold: c,
546
+ findAllMatches: o,
547
+ minMatchCharLength: a,
548
+ includeMatches: n,
549
+ ignoreLocation: h,
550
+ });
551
+ S && (f = !0), (u += T), S && R && (l = [...l, ...R]);
552
+ });
553
+ let g = {
554
+ isMatch: f,
555
+ score: f ? u / this.chunks.length : 1,
556
+ };
557
+ return f && n && (g.indices = l), g;
558
+ }
559
+ }
560
+ class L {
561
+ constructor(t) {
562
+ this.pattern = t;
563
+ }
564
+ static isMultiMatch(t) {
565
+ return J(t, this.multiRegex);
566
+ }
567
+ static isSingleMatch(t) {
568
+ return J(t, this.singleRegex);
569
+ }
570
+ search() {}
571
+ }
572
+ function J(s, t) {
573
+ const e = s.match(t);
574
+ return e ? e[1] : null;
575
+ }
576
+ class vt extends L {
577
+ constructor(t) {
578
+ super(t);
579
+ }
580
+ static get type() {
581
+ return "exact";
582
+ }
583
+ static get multiRegex() {
584
+ return /^="(.*)"$/;
585
+ }
586
+ static get singleRegex() {
587
+ return /^=(.*)$/;
588
+ }
589
+ search(t) {
590
+ const e = t === this.pattern;
591
+ return {
592
+ isMatch: e,
593
+ score: e ? 0 : 1,
594
+ indices: [0, this.pattern.length - 1],
595
+ };
596
+ }
597
+ }
598
+ class Ft extends L {
599
+ constructor(t) {
600
+ super(t);
601
+ }
602
+ static get type() {
603
+ return "inverse-exact";
604
+ }
605
+ static get multiRegex() {
606
+ return /^!"(.*)"$/;
607
+ }
608
+ static get singleRegex() {
609
+ return /^!(.*)$/;
610
+ }
611
+ search(t) {
612
+ const n = t.indexOf(this.pattern) === -1;
613
+ return {
614
+ isMatch: n,
615
+ score: n ? 0 : 1,
616
+ indices: [0, t.length - 1],
617
+ };
618
+ }
619
+ }
620
+ class Pt extends L {
621
+ constructor(t) {
622
+ super(t);
623
+ }
624
+ static get type() {
625
+ return "prefix-exact";
626
+ }
627
+ static get multiRegex() {
628
+ return /^\^"(.*)"$/;
629
+ }
630
+ static get singleRegex() {
631
+ return /^\^(.*)$/;
632
+ }
633
+ search(t) {
634
+ const e = t.startsWith(this.pattern);
635
+ return {
636
+ isMatch: e,
637
+ score: e ? 0 : 1,
638
+ indices: [0, this.pattern.length - 1],
639
+ };
640
+ }
641
+ }
642
+ class jt extends L {
643
+ constructor(t) {
644
+ super(t);
645
+ }
646
+ static get type() {
647
+ return "inverse-prefix-exact";
648
+ }
649
+ static get multiRegex() {
650
+ return /^!\^"(.*)"$/;
651
+ }
652
+ static get singleRegex() {
653
+ return /^!\^(.*)$/;
654
+ }
655
+ search(t) {
656
+ const e = !t.startsWith(this.pattern);
657
+ return {
658
+ isMatch: e,
659
+ score: e ? 0 : 1,
660
+ indices: [0, t.length - 1],
661
+ };
662
+ }
663
+ }
664
+ class Ht extends L {
665
+ constructor(t) {
666
+ super(t);
667
+ }
668
+ static get type() {
669
+ return "suffix-exact";
670
+ }
671
+ static get multiRegex() {
672
+ return /^"(.*)"\$$/;
673
+ }
674
+ static get singleRegex() {
675
+ return /^(.*)\$$/;
676
+ }
677
+ search(t) {
678
+ const e = t.endsWith(this.pattern);
679
+ return {
680
+ isMatch: e,
681
+ score: e ? 0 : 1,
682
+ indices: [t.length - this.pattern.length, t.length - 1],
683
+ };
684
+ }
685
+ }
686
+ class Kt extends L {
687
+ constructor(t) {
688
+ super(t);
689
+ }
690
+ static get type() {
691
+ return "inverse-suffix-exact";
692
+ }
693
+ static get multiRegex() {
694
+ return /^!"(.*)"\$$/;
695
+ }
696
+ static get singleRegex() {
697
+ return /^!(.*)\$$/;
698
+ }
699
+ search(t) {
700
+ const e = !t.endsWith(this.pattern);
701
+ return {
702
+ isMatch: e,
703
+ score: e ? 0 : 1,
704
+ indices: [0, t.length - 1],
705
+ };
706
+ }
707
+ }
708
+ class ct extends L {
709
+ constructor(
710
+ t,
711
+ {
712
+ location: e = d.location,
713
+ threshold: n = d.threshold,
714
+ distance: r = d.distance,
715
+ includeMatches: i = d.includeMatches,
716
+ findAllMatches: c = d.findAllMatches,
717
+ minMatchCharLength: o = d.minMatchCharLength,
718
+ isCaseSensitive: a = d.isCaseSensitive,
719
+ ignoreLocation: h = d.ignoreLocation,
720
+ } = {}
721
+ ) {
722
+ super(t),
723
+ (this._bitapSearch = new it(t, {
724
+ location: e,
725
+ threshold: n,
726
+ distance: r,
727
+ includeMatches: i,
728
+ findAllMatches: c,
729
+ minMatchCharLength: o,
730
+ isCaseSensitive: a,
731
+ ignoreLocation: h,
732
+ }));
733
+ }
734
+ static get type() {
735
+ return "fuzzy";
736
+ }
737
+ static get multiRegex() {
738
+ return /^"(.*)"$/;
739
+ }
740
+ static get singleRegex() {
741
+ return /^(.*)$/;
742
+ }
743
+ search(t) {
744
+ return this._bitapSearch.searchIn(t);
745
+ }
746
+ }
747
+ class ot extends L {
748
+ constructor(t) {
749
+ super(t);
750
+ }
751
+ static get type() {
752
+ return "include";
753
+ }
754
+ static get multiRegex() {
755
+ return /^'"(.*)"$/;
756
+ }
757
+ static get singleRegex() {
758
+ return /^'(.*)$/;
759
+ }
760
+ search(t) {
761
+ let e = 0,
762
+ n;
763
+ const r = [],
764
+ i = this.pattern.length;
765
+ for (; (n = t.indexOf(this.pattern, e)) > -1; )
766
+ (e = n + i), r.push([n, e - 1]);
767
+ const c = !!r.length;
768
+ return {
769
+ isMatch: c,
770
+ score: c ? 0 : 1,
771
+ indices: r,
772
+ };
773
+ }
774
+ }
775
+ const B = [vt, ot, Pt, jt, Kt, Ht, Ft, ct],
776
+ q = B.length,
777
+ Bt = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,
778
+ Dt = "|";
779
+ function Wt(s, t = {}) {
780
+ return s.split(Dt).map((e) => {
781
+ let n = e
782
+ .trim()
783
+ .split(Bt)
784
+ .filter((i) => i && !!i.trim()),
785
+ r = [];
786
+ for (let i = 0, c = n.length; i < c; i += 1) {
787
+ const o = n[i];
788
+ let a = !1,
789
+ h = -1;
790
+ for (; !a && ++h < q; ) {
791
+ const l = B[h];
792
+ let u = l.isMultiMatch(o);
793
+ u && (r.push(new l(u, t)), (a = !0));
794
+ }
795
+ if (!a)
796
+ for (h = -1; ++h < q; ) {
797
+ const l = B[h];
798
+ let u = l.isSingleMatch(o);
799
+ if (u) {
800
+ r.push(new l(u, t));
801
+ break;
802
+ }
803
+ }
804
+ }
805
+ return r;
806
+ });
807
+ }
808
+ const zt = /* @__PURE__ */ new Set([ct.type, ot.type]);
809
+ class Vt {
810
+ constructor(
811
+ t,
812
+ {
813
+ isCaseSensitive: e = d.isCaseSensitive,
814
+ includeMatches: n = d.includeMatches,
815
+ minMatchCharLength: r = d.minMatchCharLength,
816
+ ignoreLocation: i = d.ignoreLocation,
817
+ findAllMatches: c = d.findAllMatches,
818
+ location: o = d.location,
819
+ threshold: a = d.threshold,
820
+ distance: h = d.distance,
821
+ } = {}
822
+ ) {
823
+ (this.query = null),
824
+ (this.options = {
825
+ isCaseSensitive: e,
826
+ includeMatches: n,
827
+ minMatchCharLength: r,
828
+ findAllMatches: c,
829
+ ignoreLocation: i,
830
+ location: o,
831
+ threshold: a,
832
+ distance: h,
833
+ }),
834
+ (this.pattern = e ? t : t.toLowerCase()),
835
+ (this.query = Wt(this.pattern, this.options));
836
+ }
837
+ static condition(t, e) {
838
+ return e.useExtendedSearch;
839
+ }
840
+ searchIn(t) {
841
+ const e = this.query;
842
+ if (!e)
843
+ return {
844
+ isMatch: !1,
845
+ score: 1,
846
+ };
847
+ const { includeMatches: n, isCaseSensitive: r } = this.options;
848
+ t = r ? t : t.toLowerCase();
849
+ let i = 0,
850
+ c = [],
851
+ o = 0;
852
+ for (let a = 0, h = e.length; a < h; a += 1) {
853
+ const l = e[a];
854
+ (c.length = 0), (i = 0);
855
+ for (let u = 0, f = l.length; u < f; u += 1) {
856
+ const g = l[u],
857
+ { isMatch: p, indices: m, score: b } = g.search(t);
858
+ if (p) {
859
+ if (((i += 1), (o += b), n)) {
860
+ const S = g.constructor.type;
861
+ zt.has(S) ? (c = [...c, ...m]) : c.push(m);
862
+ }
863
+ } else {
864
+ (o = 0), (i = 0), (c.length = 0);
865
+ break;
866
+ }
867
+ }
868
+ if (i) {
869
+ let u = {
870
+ isMatch: !0,
871
+ score: o / i,
872
+ };
873
+ return n && (u.indices = c), u;
874
+ }
875
+ }
876
+ return {
877
+ isMatch: !1,
878
+ score: 1,
879
+ };
880
+ }
881
+ }
882
+ const D = [];
883
+ function Yt(...s) {
884
+ D.push(...s);
885
+ }
886
+ function W(s, t) {
887
+ for (let e = 0, n = D.length; e < n; e += 1) {
888
+ let r = D[e];
889
+ if (r.condition(s, t)) return new r(s, t);
890
+ }
891
+ return new it(s, t);
892
+ }
893
+ const F = {
894
+ AND: "$and",
895
+ OR: "$or",
896
+ },
897
+ z = {
898
+ PATH: "$path",
899
+ PATTERN: "$val",
900
+ },
901
+ V = (s) => !!(s[F.AND] || s[F.OR]),
902
+ Gt = (s) => !!s[z.PATH],
903
+ Ut = (s) => !I(s) && et(s) && !V(s),
904
+ Z = (s) => ({
905
+ [F.AND]: Object.keys(s).map((t) => ({
906
+ [t]: s[t],
907
+ })),
908
+ });
909
+ function at(s, t, { auto: e = !0 } = {}) {
910
+ const n = (r) => {
911
+ let i = Object.keys(r);
912
+ const c = Gt(r);
913
+ if (!c && i.length > 1 && !V(r)) return n(Z(r));
914
+ if (Ut(r)) {
915
+ const a = c ? r[z.PATH] : i[0],
916
+ h = c ? r[z.PATTERN] : r[a];
917
+ if (!x(h)) throw new Error(Et(a));
918
+ const l = {
919
+ keyId: K(a),
920
+ pattern: h,
921
+ };
922
+ return e && (l.searcher = W(h, t)), l;
923
+ }
924
+ let o = {
925
+ children: [],
926
+ operator: i[0],
927
+ };
928
+ return (
929
+ i.forEach((a) => {
930
+ const h = r[a];
931
+ I(h) &&
932
+ h.forEach((l) => {
933
+ o.children.push(n(l));
934
+ });
935
+ }),
936
+ o
937
+ );
938
+ };
939
+ return V(s) || (s = Z(s)), n(s);
940
+ }
941
+ function Qt(s, { ignoreFieldNorm: t = d.ignoreFieldNorm }) {
942
+ s.forEach((e) => {
943
+ let n = 1;
944
+ e.matches.forEach(({ key: r, norm: i, score: c }) => {
945
+ const o = r ? r.weight : null;
946
+ n *= Math.pow(c === 0 && o ? Number.EPSILON : c, (o || 1) * (t ? 1 : i));
947
+ }),
948
+ (e.score = n);
949
+ });
950
+ }
951
+ function Xt(s, t) {
952
+ const e = s.matches;
953
+ (t.matches = []),
954
+ y(e) &&
955
+ e.forEach((n) => {
956
+ if (!y(n.indices) || !n.indices.length) return;
957
+ const { indices: r, value: i } = n;
958
+ let c = {
959
+ indices: r,
960
+ value: i,
961
+ };
962
+ n.key && (c.key = n.key.src),
963
+ n.idx > -1 && (c.refIndex = n.idx),
964
+ t.matches.push(c);
965
+ });
966
+ }
967
+ function Jt(s, t) {
968
+ t.score = s.score;
969
+ }
970
+ function qt(
971
+ s,
972
+ t,
973
+ {
974
+ includeMatches: e = d.includeMatches,
975
+ includeScore: n = d.includeScore,
976
+ } = {}
977
+ ) {
978
+ const r = [];
979
+ return (
980
+ e && r.push(Xt),
981
+ n && r.push(Jt),
982
+ s.map((i) => {
983
+ const { idx: c } = i,
984
+ o = {
985
+ item: t[c],
986
+ refIndex: c,
987
+ };
988
+ return (
989
+ r.length &&
990
+ r.forEach((a) => {
991
+ a(i, o);
992
+ }),
993
+ o
994
+ );
995
+ })
996
+ );
997
+ }
998
+ class N {
999
+ constructor(t, e = {}, n) {
1000
+ (this.options = { ...d, ...e }),
1001
+ this.options.useExtendedSearch,
1002
+ (this._keyStore = new It(this.options.keys)),
1003
+ this.setCollection(t, n);
1004
+ }
1005
+ setCollection(t, e) {
1006
+ if (((this._docs = t), e && !(e instanceof Y))) throw new Error(Mt);
1007
+ this._myIndex =
1008
+ e ||
1009
+ nt(this.options.keys, this._docs, {
1010
+ getFn: this.options.getFn,
1011
+ fieldNormWeight: this.options.fieldNormWeight,
1012
+ });
1013
+ }
1014
+ add(t) {
1015
+ y(t) && (this._docs.push(t), this._myIndex.add(t));
1016
+ }
1017
+ remove(t = () => !1) {
1018
+ const e = [];
1019
+ for (let n = 0, r = this._docs.length; n < r; n += 1) {
1020
+ const i = this._docs[n];
1021
+ t(i, n) && (this.removeAt(n), (n -= 1), (r -= 1), e.push(i));
1022
+ }
1023
+ return e;
1024
+ }
1025
+ removeAt(t) {
1026
+ this._docs.splice(t, 1), this._myIndex.removeAt(t);
1027
+ }
1028
+ getIndex() {
1029
+ return this._myIndex;
1030
+ }
1031
+ search(t, { limit: e = -1 } = {}) {
1032
+ const {
1033
+ includeMatches: n,
1034
+ includeScore: r,
1035
+ shouldSort: i,
1036
+ sortFn: c,
1037
+ ignoreFieldNorm: o,
1038
+ } = this.options;
1039
+ let a = x(t)
1040
+ ? x(this._docs[0])
1041
+ ? this._searchStringList(t)
1042
+ : this._searchObjectList(t)
1043
+ : this._searchLogical(t);
1044
+ return (
1045
+ Qt(a, { ignoreFieldNorm: o }),
1046
+ i && a.sort(c),
1047
+ tt(e) && e > -1 && (a = a.slice(0, e)),
1048
+ qt(a, this._docs, {
1049
+ includeMatches: n,
1050
+ includeScore: r,
1051
+ })
1052
+ );
1053
+ }
1054
+ _searchStringList(t) {
1055
+ const e = W(t, this.options),
1056
+ { records: n } = this._myIndex,
1057
+ r = [];
1058
+ return (
1059
+ n.forEach(({ v: i, i: c, n: o }) => {
1060
+ if (!y(i)) return;
1061
+ const { isMatch: a, score: h, indices: l } = e.searchIn(i);
1062
+ a &&
1063
+ r.push({
1064
+ item: i,
1065
+ idx: c,
1066
+ matches: [{ score: h, value: i, norm: o, indices: l }],
1067
+ });
1068
+ }),
1069
+ r
1070
+ );
1071
+ }
1072
+ _searchLogical(t) {
1073
+ const e = at(t, this.options),
1074
+ n = (o, a, h) => {
1075
+ if (!o.children) {
1076
+ const { keyId: u, searcher: f } = o,
1077
+ g = this._findMatches({
1078
+ key: this._keyStore.get(u),
1079
+ value: this._myIndex.getValueForItemAtKeyId(a, u),
1080
+ searcher: f,
1081
+ });
1082
+ return g && g.length
1083
+ ? [
1084
+ {
1085
+ idx: h,
1086
+ item: a,
1087
+ matches: g,
1088
+ },
1089
+ ]
1090
+ : [];
1091
+ }
1092
+ const l = [];
1093
+ for (let u = 0, f = o.children.length; u < f; u += 1) {
1094
+ const g = o.children[u],
1095
+ p = n(g, a, h);
1096
+ if (p.length) l.push(...p);
1097
+ else if (o.operator === F.AND) return [];
1098
+ }
1099
+ return l;
1100
+ },
1101
+ r = this._myIndex.records,
1102
+ i = {},
1103
+ c = [];
1104
+ return (
1105
+ r.forEach(({ $: o, i: a }) => {
1106
+ if (y(o)) {
1107
+ let h = n(e, o, a);
1108
+ h.length &&
1109
+ (i[a] || ((i[a] = { idx: a, item: o, matches: [] }), c.push(i[a])),
1110
+ h.forEach(({ matches: l }) => {
1111
+ i[a].matches.push(...l);
1112
+ }));
1113
+ }
1114
+ }),
1115
+ c
1116
+ );
1117
+ }
1118
+ _searchObjectList(t) {
1119
+ const e = W(t, this.options),
1120
+ { keys: n, records: r } = this._myIndex,
1121
+ i = [];
1122
+ return (
1123
+ r.forEach(({ $: c, i: o }) => {
1124
+ if (!y(c)) return;
1125
+ let a = [];
1126
+ n.forEach((h, l) => {
1127
+ a.push(
1128
+ ...this._findMatches({
1129
+ key: h,
1130
+ value: c[l],
1131
+ searcher: e,
1132
+ })
1133
+ );
1134
+ }),
1135
+ a.length &&
1136
+ i.push({
1137
+ idx: o,
1138
+ item: c,
1139
+ matches: a,
1140
+ });
1141
+ }),
1142
+ i
1143
+ );
1144
+ }
1145
+ _findMatches({ key: t, value: e, searcher: n }) {
1146
+ if (!y(e)) return [];
1147
+ let r = [];
1148
+ if (I(e))
1149
+ e.forEach(({ v: i, i: c, n: o }) => {
1150
+ if (!y(i)) return;
1151
+ const { isMatch: a, score: h, indices: l } = n.searchIn(i);
1152
+ a &&
1153
+ r.push({
1154
+ score: h,
1155
+ key: t,
1156
+ value: i,
1157
+ idx: c,
1158
+ norm: o,
1159
+ indices: l,
1160
+ });
1161
+ });
1162
+ else {
1163
+ const { v: i, n: c } = e,
1164
+ { isMatch: o, score: a, indices: h } = n.searchIn(i);
1165
+ o && r.push({ score: a, key: t, value: i, norm: c, indices: h });
1166
+ }
1167
+ return r;
1168
+ }
1169
+ }
1170
+ N.version = "6.6.2";
1171
+ N.createIndex = nt;
1172
+ N.parseIndex = $t;
1173
+ N.config = d;
1174
+ N.parseQuery = at;
1175
+ Yt(Vt);
1176
+ const Zt = `
1177
+ <style>
1178
+ :host {
1179
+ display: block;
1180
+ }
1181
+ </style>
1182
+ <div>
1183
+ <slot></slot>
1184
+ <ul id="filters"></ul>
1185
+ <input type="text" />
1186
+ <ul id="results"></ul>
1187
+ </div>
1188
+ `,
1189
+ te = `
1190
+ <li>
1191
+ <label>
1192
+ <input type="checkbox" />
1193
+ <span class="title">FILTERITEMTITLE</span>
1194
+ </label>
1195
+ </li>
1196
+ `,
1197
+ ee = `
1198
+ <details open>
1199
+ <summary>TITLE</summar>
1200
+ <ul></ul>
1201
+ </details>
1202
+ `,
1203
+ se = (s, t = "highlight") => {
1204
+ const e = (r, i, c) => {
1205
+ const o = i.split(".");
1206
+ let a;
1207
+ for (a = 0; a < o.length - 1; a++) r = r[o[a]];
1208
+ r[o[a]] = c;
1209
+ },
1210
+ n = (r, i = []) => {
1211
+ let c = "",
1212
+ o = 0;
1213
+ return (
1214
+ i.forEach((a) => {
1215
+ const h = a[1] + 1;
1216
+ (c += [
1217
+ r.substring(o, a[0]),
1218
+ `<mark class="${t}">`,
1219
+ r.substring(a[0], h),
1220
+ "</mark>",
1221
+ ].join("")),
1222
+ (o = h);
1223
+ }),
1224
+ (c += r.substring(o)),
1225
+ c
1226
+ );
1227
+ };
1228
+ return s
1229
+ .filter(({ matches: r }) => r && r.length)
1230
+ .map(({ item: r, matches: i }) => {
1231
+ const c = { ...r };
1232
+ return (
1233
+ i.forEach((o) => {
1234
+ o.key === "name" && e(c, o.key, n(o.value, o.indices));
1235
+ }),
1236
+ c
1237
+ );
1238
+ });
1239
+ },
1240
+ ht = document.createElement("template");
1241
+ ht.innerHTML = Zt;
1242
+ class re extends HTMLElement {
1243
+ constructor() {
1244
+ super();
1245
+ A(this, "shadowRoot");
1246
+ /**
1247
+ * Apply JSON items to itemfilter.
1248
+ * @param json
1249
+ */
1250
+ A(this, "apply");
1251
+ /**
1252
+ * The filter properties.
1253
+ * @param filterProperties
1254
+ */
1255
+ A(this, "filterProperties");
1256
+ A(this, "items");
1257
+ A(this, "fuse");
1258
+ // TODO proper typing
1259
+ A(this, "filters");
1260
+ A(this, "aggregateBy");
1261
+ /**
1262
+ * Native fuse.js config override
1263
+ */
1264
+ A(this, "fuseConfig");
1265
+ this.filters = {};
1266
+ const e = this.getAttribute("aggregateResults") || !1;
1267
+ (this.shadowRoot = this.attachShadow({ mode: "open" })),
1268
+ this.shadowRoot.appendChild(ht.content.cloneNode(!0)),
1269
+ (this.apply = (i) => {
1270
+ (this.items = i),
1271
+ (this.fuse = new N(this.items, {
1272
+ minMatchCharLength: 1,
1273
+ includeMatches: !0,
1274
+ // Search in same fields as specified by filter properties, plus name
1275
+ // @ts-ignore
1276
+ keys: ["name", ...this.filterProperties],
1277
+ useExtendedSearch: !0,
1278
+ ...this.fuseConfig,
1279
+ })),
1280
+ this.filterProperties.forEach((c) => {
1281
+ const o = [
1282
+ ...new Set(this.items.reduce((h, l) => h.concat(l[c]), [])),
1283
+ ].sort(),
1284
+ a = this.shadowRoot.querySelector("ul#filters");
1285
+ o.forEach((h) => {
1286
+ const l = document.createElement("template");
1287
+ l.innerHTML = te;
1288
+ const u = l.content.cloneNode(!0);
1289
+ u
1290
+ .querySelector("input[type='checkbox']")
1291
+ .setAttribute("data-filter-key", c),
1292
+ u
1293
+ .querySelector("input[type='checkbox']")
1294
+ .setAttribute("data-filter-value", h),
1295
+ (u.querySelector("span.title").innerHTML = h),
1296
+ a.appendChild(u);
1297
+ }),
1298
+ e === c && (this.aggregateBy = o);
1299
+ }),
1300
+ n();
1301
+ });
1302
+ const n = () => {
1303
+ this.shadowRoot
1304
+ .querySelectorAll("input[type='checkbox']")
1305
+ .forEach((i) => {
1306
+ i.addEventListener("click", (c) => {
1307
+ const o = c.target,
1308
+ a = o.getAttribute("data-filter-key"),
1309
+ h = o.getAttribute("data-filter-value");
1310
+ o.checked
1311
+ ? (this.filters[a] || (this.filters[a] = []),
1312
+ this.filters[a].push(h))
1313
+ : (this.filters[a].splice(
1314
+ // @ts-ignore
1315
+ this.filters[a].indexOf(h),
1316
+ 1
1317
+ ),
1318
+ this.filters[a].length === 0 && delete this.filters[a]),
1319
+ r(
1320
+ // @ts-ignore
1321
+ this.shadowRoot.querySelector("input[type='text']").value
1322
+ );
1323
+ });
1324
+ });
1325
+ },
1326
+ r = (i, c = this.filters) => {
1327
+ const o = Object.entries(c).reduce((l, [u, f]) => {
1328
+ const g = (p) => {
1329
+ const m = {};
1330
+ (m[u] = `=${p}`), l.push(m);
1331
+ };
1332
+ return Array.isArray(f) ? f.forEach((p) => g(p)) : g(f), l;
1333
+ }, []),
1334
+ a = se(
1335
+ this.fuse.search({
1336
+ ...(i.length && Object.keys(o).length
1337
+ ? {
1338
+ $and: [
1339
+ { name: i },
1340
+ {
1341
+ $or: o,
1342
+ },
1343
+ ],
1344
+ }
1345
+ : {
1346
+ $or: [
1347
+ { name: i },
1348
+ {
1349
+ $or: o,
1350
+ },
1351
+ ],
1352
+ }),
1353
+ })
1354
+ ),
1355
+ h = this.shadowRoot.querySelector("ul#results");
1356
+ if (((h.innerHTML = ""), e)) {
1357
+ const l = document.createElement("template");
1358
+ (l.innerHTML = ee),
1359
+ this.aggregateBy.forEach((u) => {
1360
+ if (
1361
+ // @ts-ignore
1362
+ !a.find((g) =>
1363
+ Array.isArray(g[e]) ? g[e].includes(u) : g[e] === u
1364
+ )
1365
+ )
1366
+ return;
1367
+ const f = l.content.cloneNode(!0);
1368
+ (f.querySelector("summary").innerHTML = u),
1369
+ f.querySelector("details").setAttribute("data-aggregate", u),
1370
+ h.appendChild(f);
1371
+ });
1372
+ }
1373
+ a.forEach((l) => {
1374
+ if (this.aggregateBy) {
1375
+ const u = l[e];
1376
+ if (Array.isArray(u))
1377
+ u.forEach((f) => {
1378
+ const g = document.createElement("li");
1379
+ (g.innerHTML = l.name),
1380
+ this.shadowRoot
1381
+ .querySelector(`details[data-aggregate=${f}]`)
1382
+ .appendChild(g);
1383
+ });
1384
+ else {
1385
+ const f = document.createElement("li");
1386
+ (f.innerHTML = l.name),
1387
+ this.shadowRoot
1388
+ .querySelector(`details[data-aggregate=${u}]`)
1389
+ .appendChild(f);
1390
+ }
1391
+ } else {
1392
+ const u = document.createElement("li");
1393
+ (u.innerHTML = l.name), h.appendChild(u);
1394
+ }
1395
+ });
1396
+ };
1397
+ this.shadowRoot
1398
+ .querySelector("input[type='text']")
1399
+ .addEventListener("input", (i) => {
1400
+ r(i.target.value);
1401
+ });
1402
+ }
1403
+ }
1404
+ customElements.define("eox-itemfilter", re);
1405
+ export { re as EOxItemFilter };