@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,1233 @@
1
+ (function (E, m) {
2
+ typeof exports == "object" && typeof module < "u"
3
+ ? m(exports)
4
+ : typeof define == "function" && define.amd
5
+ ? define(["exports"], m)
6
+ : ((E = typeof globalThis < "u" ? globalThis : E || self),
7
+ m((E["eox-itemfilter"] = {})));
8
+ })(this, function (E) {
9
+ "use strict";
10
+ var Ze = Object.defineProperty;
11
+ var et = (E, m, R) =>
12
+ m in E
13
+ ? Ze(E, m, { enumerable: !0, configurable: !0, writable: !0, value: R })
14
+ : (E[m] = R);
15
+ var _ = (E, m, R) => (et(E, typeof m != "symbol" ? m + "" : m, R), R);
16
+ function m(s) {
17
+ return Array.isArray ? Array.isArray(s) : J(s) === "[object Array]";
18
+ }
19
+ const R = 1 / 0;
20
+ function de(s) {
21
+ if (typeof s == "string") return s;
22
+ let e = s + "";
23
+ return e == "0" && 1 / s == -R ? "-0" : e;
24
+ }
25
+ function ge(s) {
26
+ return s == null ? "" : de(s);
27
+ }
28
+ function A(s) {
29
+ return typeof s == "string";
30
+ }
31
+ function Q(s) {
32
+ return typeof s == "number";
33
+ }
34
+ function pe(s) {
35
+ return s === !0 || s === !1 || (me(s) && J(s) == "[object Boolean]");
36
+ }
37
+ function X(s) {
38
+ return typeof s == "object";
39
+ }
40
+ function me(s) {
41
+ return X(s) && s !== null;
42
+ }
43
+ function M(s) {
44
+ return s != null;
45
+ }
46
+ function H(s) {
47
+ return !s.trim().length;
48
+ }
49
+ function J(s) {
50
+ return s == null
51
+ ? s === void 0
52
+ ? "[object Undefined]"
53
+ : "[object Null]"
54
+ : Object.prototype.toString.call(s);
55
+ }
56
+ const tt = "Extended search is not available",
57
+ ye = "Incorrect 'index' type",
58
+ Me = (s) => `Invalid value for key ${s}`,
59
+ Ee = (s) => `Pattern length exceeds max of ${s}.`,
60
+ xe = (s) => `Missing ${s} property in key`,
61
+ Se = (s) => `Property 'weight' in key '${s}' must be a positive integer`,
62
+ q = Object.prototype.hasOwnProperty;
63
+ class Ae {
64
+ constructor(e) {
65
+ (this._keys = []), (this._keyMap = {});
66
+ let t = 0;
67
+ e.forEach((r) => {
68
+ let n = Z(r);
69
+ (t += n.weight),
70
+ this._keys.push(n),
71
+ (this._keyMap[n.id] = n),
72
+ (t += n.weight);
73
+ }),
74
+ this._keys.forEach((r) => {
75
+ r.weight /= t;
76
+ });
77
+ }
78
+ get(e) {
79
+ return this._keyMap[e];
80
+ }
81
+ keys() {
82
+ return this._keys;
83
+ }
84
+ toJSON() {
85
+ return JSON.stringify(this._keys);
86
+ }
87
+ }
88
+ function Z(s) {
89
+ let e = null,
90
+ t = null,
91
+ r = null,
92
+ n = 1,
93
+ i = null;
94
+ if (A(s) || m(s)) (r = s), (e = ee(s)), (t = B(s));
95
+ else {
96
+ if (!q.call(s, "name")) throw new Error(xe("name"));
97
+ const c = s.name;
98
+ if (((r = c), q.call(s, "weight") && ((n = s.weight), n <= 0)))
99
+ throw new Error(Se(c));
100
+ (e = ee(c)), (t = B(c)), (i = s.getFn);
101
+ }
102
+ return { path: e, id: t, weight: n, src: r, getFn: i };
103
+ }
104
+ function ee(s) {
105
+ return m(s) ? s : s.split(".");
106
+ }
107
+ function B(s) {
108
+ return m(s) ? s.join(".") : s;
109
+ }
110
+ function Ie(s, e) {
111
+ let t = [],
112
+ r = !1;
113
+ const n = (i, c, o) => {
114
+ if (M(i))
115
+ if (!c[o]) t.push(i);
116
+ else {
117
+ let a = c[o];
118
+ const h = i[a];
119
+ if (!M(h)) return;
120
+ if (o === c.length - 1 && (A(h) || Q(h) || pe(h))) t.push(ge(h));
121
+ else if (m(h)) {
122
+ r = !0;
123
+ for (let l = 0, u = h.length; l < u; l += 1) n(h[l], c, o + 1);
124
+ } else c.length && n(h, c, o + 1);
125
+ }
126
+ };
127
+ return n(s, A(e) ? e.split(".") : e, 0), r ? t : t[0];
128
+ }
129
+ var f = {
130
+ ...{
131
+ isCaseSensitive: !1,
132
+ includeScore: !1,
133
+ keys: [],
134
+ shouldSort: !0,
135
+ sortFn: (s, e) =>
136
+ s.score === e.score
137
+ ? s.idx < e.idx
138
+ ? -1
139
+ : 1
140
+ : s.score < e.score
141
+ ? -1
142
+ : 1,
143
+ },
144
+ ...{ includeMatches: !1, findAllMatches: !1, minMatchCharLength: 1 },
145
+ ...{ location: 0, threshold: 0.6, distance: 100 },
146
+ ...{
147
+ useExtendedSearch: !1,
148
+ getFn: Ie,
149
+ ignoreLocation: !1,
150
+ ignoreFieldNorm: !1,
151
+ fieldNormWeight: 1,
152
+ },
153
+ };
154
+ const _e = /[^ ]+/g;
155
+ function we(s = 1, e = 3) {
156
+ const t = new Map(),
157
+ r = Math.pow(10, e);
158
+ return {
159
+ get(n) {
160
+ const i = n.match(_e).length;
161
+ if (t.has(i)) return t.get(i);
162
+ const c = 1 / Math.pow(i, 0.5 * s),
163
+ o = parseFloat(Math.round(c * r) / r);
164
+ return t.set(i, o), o;
165
+ },
166
+ clear() {
167
+ t.clear();
168
+ },
169
+ };
170
+ }
171
+ class K {
172
+ constructor({
173
+ getFn: e = f.getFn,
174
+ fieldNormWeight: t = f.fieldNormWeight,
175
+ } = {}) {
176
+ (this.norm = we(t, 3)),
177
+ (this.getFn = e),
178
+ (this.isCreated = !1),
179
+ this.setIndexRecords();
180
+ }
181
+ setSources(e = []) {
182
+ this.docs = e;
183
+ }
184
+ setIndexRecords(e = []) {
185
+ this.records = e;
186
+ }
187
+ setKeys(e = []) {
188
+ (this.keys = e),
189
+ (this._keysMap = {}),
190
+ e.forEach((t, r) => {
191
+ this._keysMap[t.id] = r;
192
+ });
193
+ }
194
+ create() {
195
+ this.isCreated ||
196
+ !this.docs.length ||
197
+ ((this.isCreated = !0),
198
+ A(this.docs[0])
199
+ ? this.docs.forEach((e, t) => {
200
+ this._addString(e, t);
201
+ })
202
+ : this.docs.forEach((e, t) => {
203
+ this._addObject(e, t);
204
+ }),
205
+ this.norm.clear());
206
+ }
207
+ add(e) {
208
+ const t = this.size();
209
+ A(e) ? this._addString(e, t) : this._addObject(e, t);
210
+ }
211
+ removeAt(e) {
212
+ this.records.splice(e, 1);
213
+ for (let t = e, r = this.size(); t < r; t += 1) this.records[t].i -= 1;
214
+ }
215
+ getValueForItemAtKeyId(e, t) {
216
+ return e[this._keysMap[t]];
217
+ }
218
+ size() {
219
+ return this.records.length;
220
+ }
221
+ _addString(e, t) {
222
+ if (!M(e) || H(e)) return;
223
+ let r = { v: e, i: t, n: this.norm.get(e) };
224
+ this.records.push(r);
225
+ }
226
+ _addObject(e, t) {
227
+ let r = { i: t, $: {} };
228
+ this.keys.forEach((n, i) => {
229
+ let c = n.getFn ? n.getFn(e) : this.getFn(e, n.path);
230
+ if (M(c)) {
231
+ if (m(c)) {
232
+ let o = [];
233
+ const a = [{ nestedArrIndex: -1, value: c }];
234
+ for (; a.length; ) {
235
+ const { nestedArrIndex: h, value: l } = a.pop();
236
+ if (M(l))
237
+ if (A(l) && !H(l)) {
238
+ let u = { v: l, i: h, n: this.norm.get(l) };
239
+ o.push(u);
240
+ } else
241
+ m(l) &&
242
+ l.forEach((u, d) => {
243
+ a.push({ nestedArrIndex: d, value: u });
244
+ });
245
+ }
246
+ r.$[i] = o;
247
+ } else if (A(c) && !H(c)) {
248
+ let o = { v: c, n: this.norm.get(c) };
249
+ r.$[i] = o;
250
+ }
251
+ }
252
+ }),
253
+ this.records.push(r);
254
+ }
255
+ toJSON() {
256
+ return { keys: this.keys, records: this.records };
257
+ }
258
+ }
259
+ function te(
260
+ s,
261
+ e,
262
+ { getFn: t = f.getFn, fieldNormWeight: r = f.fieldNormWeight } = {}
263
+ ) {
264
+ const n = new K({ getFn: t, fieldNormWeight: r });
265
+ return n.setKeys(s.map(Z)), n.setSources(e), n.create(), n;
266
+ }
267
+ function Le(
268
+ s,
269
+ { getFn: e = f.getFn, fieldNormWeight: t = f.fieldNormWeight } = {}
270
+ ) {
271
+ const { keys: r, records: n } = s,
272
+ i = new K({ getFn: e, fieldNormWeight: t });
273
+ return i.setKeys(r), i.setIndexRecords(n), i;
274
+ }
275
+ function v(
276
+ s,
277
+ {
278
+ errors: e = 0,
279
+ currentLocation: t = 0,
280
+ expectedLocation: r = 0,
281
+ distance: n = f.distance,
282
+ ignoreLocation: i = f.ignoreLocation,
283
+ } = {}
284
+ ) {
285
+ const c = e / s.length;
286
+ if (i) return c;
287
+ const o = Math.abs(r - t);
288
+ return n ? c + o / n : o ? 1 : c;
289
+ }
290
+ function be(s = [], e = f.minMatchCharLength) {
291
+ let t = [],
292
+ r = -1,
293
+ n = -1,
294
+ i = 0;
295
+ for (let c = s.length; i < c; i += 1) {
296
+ let o = s[i];
297
+ o && r === -1
298
+ ? (r = i)
299
+ : !o &&
300
+ r !== -1 &&
301
+ ((n = i - 1), n - r + 1 >= e && t.push([r, n]), (r = -1));
302
+ }
303
+ return s[i - 1] && i - r >= e && t.push([r, i - 1]), t;
304
+ }
305
+ const k = 32;
306
+ function Re(
307
+ s,
308
+ e,
309
+ t,
310
+ {
311
+ location: r = f.location,
312
+ distance: n = f.distance,
313
+ threshold: i = f.threshold,
314
+ findAllMatches: c = f.findAllMatches,
315
+ minMatchCharLength: o = f.minMatchCharLength,
316
+ includeMatches: a = f.includeMatches,
317
+ ignoreLocation: h = f.ignoreLocation,
318
+ } = {}
319
+ ) {
320
+ if (e.length > k) throw new Error(Ee(k));
321
+ const l = e.length,
322
+ u = s.length,
323
+ d = Math.max(0, Math.min(r, u));
324
+ let g = i,
325
+ p = d;
326
+ const y = o > 1 || a,
327
+ T = y ? Array(u) : [];
328
+ let I;
329
+ for (; (I = s.indexOf(e, p)) > -1; ) {
330
+ let x = v(e, {
331
+ currentLocation: I,
332
+ expectedLocation: d,
333
+ distance: n,
334
+ ignoreLocation: h,
335
+ });
336
+ if (((g = Math.min(x, g)), (p = I + l), y)) {
337
+ let L = 0;
338
+ for (; L < l; ) (T[I + L] = 1), (L += 1);
339
+ }
340
+ }
341
+ p = -1;
342
+ let N = [],
343
+ O = 1,
344
+ P = l + u;
345
+ const qe = 1 << (l - 1);
346
+ for (let x = 0; x < l; x += 1) {
347
+ let L = 0,
348
+ b = P;
349
+ for (; L < b; )
350
+ v(e, {
351
+ errors: x,
352
+ currentLocation: d + b,
353
+ expectedLocation: d,
354
+ distance: n,
355
+ ignoreLocation: h,
356
+ }) <= g
357
+ ? (L = b)
358
+ : (P = b),
359
+ (b = Math.floor((P - L) / 2 + L));
360
+ P = b;
361
+ let ue = Math.max(1, d - b + 1),
362
+ U = c ? u : Math.min(d + b, u) + l,
363
+ C = Array(U + 2);
364
+ C[U + 1] = (1 << x) - 1;
365
+ for (let S = U; S >= ue; S -= 1) {
366
+ let j = S - 1,
367
+ fe = t[s.charAt(j)];
368
+ if (
369
+ (y && (T[j] = +!!fe),
370
+ (C[S] = ((C[S + 1] << 1) | 1) & fe),
371
+ x && (C[S] |= ((N[S + 1] | N[S]) << 1) | 1 | N[S + 1]),
372
+ C[S] & qe &&
373
+ ((O = v(e, {
374
+ errors: x,
375
+ currentLocation: j,
376
+ expectedLocation: d,
377
+ distance: n,
378
+ ignoreLocation: h,
379
+ })),
380
+ O <= g))
381
+ ) {
382
+ if (((g = O), (p = j), p <= d)) break;
383
+ ue = Math.max(1, 2 * d - p);
384
+ }
385
+ }
386
+ if (
387
+ v(e, {
388
+ errors: x + 1,
389
+ currentLocation: d,
390
+ expectedLocation: d,
391
+ distance: n,
392
+ ignoreLocation: h,
393
+ }) > g
394
+ )
395
+ break;
396
+ N = C;
397
+ }
398
+ const G = { isMatch: p >= 0, score: Math.max(0.001, O) };
399
+ if (y) {
400
+ const x = be(T, o);
401
+ x.length ? a && (G.indices = x) : (G.isMatch = !1);
402
+ }
403
+ return G;
404
+ }
405
+ function ke(s) {
406
+ let e = {};
407
+ for (let t = 0, r = s.length; t < r; t += 1) {
408
+ const n = s.charAt(t);
409
+ e[n] = (e[n] || 0) | (1 << (r - t - 1));
410
+ }
411
+ return e;
412
+ }
413
+ class se {
414
+ constructor(
415
+ e,
416
+ {
417
+ location: t = f.location,
418
+ threshold: r = f.threshold,
419
+ distance: n = f.distance,
420
+ includeMatches: i = f.includeMatches,
421
+ findAllMatches: c = f.findAllMatches,
422
+ minMatchCharLength: o = f.minMatchCharLength,
423
+ isCaseSensitive: a = f.isCaseSensitive,
424
+ ignoreLocation: h = f.ignoreLocation,
425
+ } = {}
426
+ ) {
427
+ if (
428
+ ((this.options = {
429
+ location: t,
430
+ threshold: r,
431
+ distance: n,
432
+ includeMatches: i,
433
+ findAllMatches: c,
434
+ minMatchCharLength: o,
435
+ isCaseSensitive: a,
436
+ ignoreLocation: h,
437
+ }),
438
+ (this.pattern = a ? e : e.toLowerCase()),
439
+ (this.chunks = []),
440
+ !this.pattern.length)
441
+ )
442
+ return;
443
+ const l = (d, g) => {
444
+ this.chunks.push({ pattern: d, alphabet: ke(d), startIndex: g });
445
+ },
446
+ u = this.pattern.length;
447
+ if (u > k) {
448
+ let d = 0;
449
+ const g = u % k,
450
+ p = u - g;
451
+ for (; d < p; ) l(this.pattern.substr(d, k), d), (d += k);
452
+ if (g) {
453
+ const y = u - k;
454
+ l(this.pattern.substr(y), y);
455
+ }
456
+ } else l(this.pattern, 0);
457
+ }
458
+ searchIn(e) {
459
+ const { isCaseSensitive: t, includeMatches: r } = this.options;
460
+ if ((t || (e = e.toLowerCase()), this.pattern === e)) {
461
+ let p = { isMatch: !0, score: 0 };
462
+ return r && (p.indices = [[0, e.length - 1]]), p;
463
+ }
464
+ const {
465
+ location: n,
466
+ distance: i,
467
+ threshold: c,
468
+ findAllMatches: o,
469
+ minMatchCharLength: a,
470
+ ignoreLocation: h,
471
+ } = this.options;
472
+ let l = [],
473
+ u = 0,
474
+ d = !1;
475
+ this.chunks.forEach(({ pattern: p, alphabet: y, startIndex: T }) => {
476
+ const {
477
+ isMatch: I,
478
+ score: N,
479
+ indices: O,
480
+ } = Re(e, p, y, {
481
+ location: n + T,
482
+ distance: i,
483
+ threshold: c,
484
+ findAllMatches: o,
485
+ minMatchCharLength: a,
486
+ includeMatches: r,
487
+ ignoreLocation: h,
488
+ });
489
+ I && (d = !0), (u += N), I && O && (l = [...l, ...O]);
490
+ });
491
+ let g = { isMatch: d, score: d ? u / this.chunks.length : 1 };
492
+ return d && r && (g.indices = l), g;
493
+ }
494
+ }
495
+ class w {
496
+ constructor(e) {
497
+ this.pattern = e;
498
+ }
499
+ static isMultiMatch(e) {
500
+ return ne(e, this.multiRegex);
501
+ }
502
+ static isSingleMatch(e) {
503
+ return ne(e, this.singleRegex);
504
+ }
505
+ search() {}
506
+ }
507
+ function ne(s, e) {
508
+ const t = s.match(e);
509
+ return t ? t[1] : null;
510
+ }
511
+ class Te extends w {
512
+ constructor(e) {
513
+ super(e);
514
+ }
515
+ static get type() {
516
+ return "exact";
517
+ }
518
+ static get multiRegex() {
519
+ return /^="(.*)"$/;
520
+ }
521
+ static get singleRegex() {
522
+ return /^=(.*)$/;
523
+ }
524
+ search(e) {
525
+ const t = e === this.pattern;
526
+ return {
527
+ isMatch: t,
528
+ score: t ? 0 : 1,
529
+ indices: [0, this.pattern.length - 1],
530
+ };
531
+ }
532
+ }
533
+ class Oe extends w {
534
+ constructor(e) {
535
+ super(e);
536
+ }
537
+ static get type() {
538
+ return "inverse-exact";
539
+ }
540
+ static get multiRegex() {
541
+ return /^!"(.*)"$/;
542
+ }
543
+ static get singleRegex() {
544
+ return /^!(.*)$/;
545
+ }
546
+ search(e) {
547
+ const r = e.indexOf(this.pattern) === -1;
548
+ return { isMatch: r, score: r ? 0 : 1, indices: [0, e.length - 1] };
549
+ }
550
+ }
551
+ class $e extends w {
552
+ constructor(e) {
553
+ super(e);
554
+ }
555
+ static get type() {
556
+ return "prefix-exact";
557
+ }
558
+ static get multiRegex() {
559
+ return /^\^"(.*)"$/;
560
+ }
561
+ static get singleRegex() {
562
+ return /^\^(.*)$/;
563
+ }
564
+ search(e) {
565
+ const t = e.startsWith(this.pattern);
566
+ return {
567
+ isMatch: t,
568
+ score: t ? 0 : 1,
569
+ indices: [0, this.pattern.length - 1],
570
+ };
571
+ }
572
+ }
573
+ class Ne extends w {
574
+ constructor(e) {
575
+ super(e);
576
+ }
577
+ static get type() {
578
+ return "inverse-prefix-exact";
579
+ }
580
+ static get multiRegex() {
581
+ return /^!\^"(.*)"$/;
582
+ }
583
+ static get singleRegex() {
584
+ return /^!\^(.*)$/;
585
+ }
586
+ search(e) {
587
+ const t = !e.startsWith(this.pattern);
588
+ return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] };
589
+ }
590
+ }
591
+ class Ce extends w {
592
+ constructor(e) {
593
+ super(e);
594
+ }
595
+ static get type() {
596
+ return "suffix-exact";
597
+ }
598
+ static get multiRegex() {
599
+ return /^"(.*)"\$$/;
600
+ }
601
+ static get singleRegex() {
602
+ return /^(.*)\$$/;
603
+ }
604
+ search(e) {
605
+ const t = e.endsWith(this.pattern);
606
+ return {
607
+ isMatch: t,
608
+ score: t ? 0 : 1,
609
+ indices: [e.length - this.pattern.length, e.length - 1],
610
+ };
611
+ }
612
+ }
613
+ class ve extends w {
614
+ constructor(e) {
615
+ super(e);
616
+ }
617
+ static get type() {
618
+ return "inverse-suffix-exact";
619
+ }
620
+ static get multiRegex() {
621
+ return /^!"(.*)"\$$/;
622
+ }
623
+ static get singleRegex() {
624
+ return /^!(.*)\$$/;
625
+ }
626
+ search(e) {
627
+ const t = !e.endsWith(this.pattern);
628
+ return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] };
629
+ }
630
+ }
631
+ class re extends w {
632
+ constructor(
633
+ e,
634
+ {
635
+ location: t = f.location,
636
+ threshold: r = f.threshold,
637
+ distance: n = f.distance,
638
+ includeMatches: i = f.includeMatches,
639
+ findAllMatches: c = f.findAllMatches,
640
+ minMatchCharLength: o = f.minMatchCharLength,
641
+ isCaseSensitive: a = f.isCaseSensitive,
642
+ ignoreLocation: h = f.ignoreLocation,
643
+ } = {}
644
+ ) {
645
+ super(e),
646
+ (this._bitapSearch = new se(e, {
647
+ location: t,
648
+ threshold: r,
649
+ distance: n,
650
+ includeMatches: i,
651
+ findAllMatches: c,
652
+ minMatchCharLength: o,
653
+ isCaseSensitive: a,
654
+ ignoreLocation: h,
655
+ }));
656
+ }
657
+ static get type() {
658
+ return "fuzzy";
659
+ }
660
+ static get multiRegex() {
661
+ return /^"(.*)"$/;
662
+ }
663
+ static get singleRegex() {
664
+ return /^(.*)$/;
665
+ }
666
+ search(e) {
667
+ return this._bitapSearch.searchIn(e);
668
+ }
669
+ }
670
+ class ie extends w {
671
+ constructor(e) {
672
+ super(e);
673
+ }
674
+ static get type() {
675
+ return "include";
676
+ }
677
+ static get multiRegex() {
678
+ return /^'"(.*)"$/;
679
+ }
680
+ static get singleRegex() {
681
+ return /^'(.*)$/;
682
+ }
683
+ search(e) {
684
+ let t = 0,
685
+ r;
686
+ const n = [],
687
+ i = this.pattern.length;
688
+ for (; (r = e.indexOf(this.pattern, t)) > -1; )
689
+ (t = r + i), n.push([r, t - 1]);
690
+ const c = !!n.length;
691
+ return { isMatch: c, score: c ? 0 : 1, indices: n };
692
+ }
693
+ }
694
+ const D = [Te, ie, $e, Ne, ve, Ce, Oe, re],
695
+ ce = D.length,
696
+ Fe = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,
697
+ Pe = "|";
698
+ function je(s, e = {}) {
699
+ return s.split(Pe).map((t) => {
700
+ let r = t
701
+ .trim()
702
+ .split(Fe)
703
+ .filter((i) => i && !!i.trim()),
704
+ n = [];
705
+ for (let i = 0, c = r.length; i < c; i += 1) {
706
+ const o = r[i];
707
+ let a = !1,
708
+ h = -1;
709
+ for (; !a && ++h < ce; ) {
710
+ const l = D[h];
711
+ let u = l.isMultiMatch(o);
712
+ u && (n.push(new l(u, e)), (a = !0));
713
+ }
714
+ if (!a)
715
+ for (h = -1; ++h < ce; ) {
716
+ const l = D[h];
717
+ let u = l.isSingleMatch(o);
718
+ if (u) {
719
+ n.push(new l(u, e));
720
+ break;
721
+ }
722
+ }
723
+ }
724
+ return n;
725
+ });
726
+ }
727
+ const He = new Set([re.type, ie.type]);
728
+ class Be {
729
+ constructor(
730
+ e,
731
+ {
732
+ isCaseSensitive: t = f.isCaseSensitive,
733
+ includeMatches: r = f.includeMatches,
734
+ minMatchCharLength: n = f.minMatchCharLength,
735
+ ignoreLocation: i = f.ignoreLocation,
736
+ findAllMatches: c = f.findAllMatches,
737
+ location: o = f.location,
738
+ threshold: a = f.threshold,
739
+ distance: h = f.distance,
740
+ } = {}
741
+ ) {
742
+ (this.query = null),
743
+ (this.options = {
744
+ isCaseSensitive: t,
745
+ includeMatches: r,
746
+ minMatchCharLength: n,
747
+ findAllMatches: c,
748
+ ignoreLocation: i,
749
+ location: o,
750
+ threshold: a,
751
+ distance: h,
752
+ }),
753
+ (this.pattern = t ? e : e.toLowerCase()),
754
+ (this.query = je(this.pattern, this.options));
755
+ }
756
+ static condition(e, t) {
757
+ return t.useExtendedSearch;
758
+ }
759
+ searchIn(e) {
760
+ const t = this.query;
761
+ if (!t) return { isMatch: !1, score: 1 };
762
+ const { includeMatches: r, isCaseSensitive: n } = this.options;
763
+ e = n ? e : e.toLowerCase();
764
+ let i = 0,
765
+ c = [],
766
+ o = 0;
767
+ for (let a = 0, h = t.length; a < h; a += 1) {
768
+ const l = t[a];
769
+ (c.length = 0), (i = 0);
770
+ for (let u = 0, d = l.length; u < d; u += 1) {
771
+ const g = l[u],
772
+ { isMatch: p, indices: y, score: T } = g.search(e);
773
+ if (p) {
774
+ if (((i += 1), (o += T), r)) {
775
+ const I = g.constructor.type;
776
+ He.has(I) ? (c = [...c, ...y]) : c.push(y);
777
+ }
778
+ } else {
779
+ (o = 0), (i = 0), (c.length = 0);
780
+ break;
781
+ }
782
+ }
783
+ if (i) {
784
+ let u = { isMatch: !0, score: o / i };
785
+ return r && (u.indices = c), u;
786
+ }
787
+ }
788
+ return { isMatch: !1, score: 1 };
789
+ }
790
+ }
791
+ const W = [];
792
+ function Ke(...s) {
793
+ W.push(...s);
794
+ }
795
+ function z(s, e) {
796
+ for (let t = 0, r = W.length; t < r; t += 1) {
797
+ let n = W[t];
798
+ if (n.condition(s, e)) return new n(s, e);
799
+ }
800
+ return new se(s, e);
801
+ }
802
+ const F = { AND: "$and", OR: "$or" },
803
+ V = { PATH: "$path", PATTERN: "$val" },
804
+ Y = (s) => !!(s[F.AND] || s[F.OR]),
805
+ De = (s) => !!s[V.PATH],
806
+ We = (s) => !m(s) && X(s) && !Y(s),
807
+ oe = (s) => ({ [F.AND]: Object.keys(s).map((e) => ({ [e]: s[e] })) });
808
+ function ae(s, e, { auto: t = !0 } = {}) {
809
+ const r = (n) => {
810
+ let i = Object.keys(n);
811
+ const c = De(n);
812
+ if (!c && i.length > 1 && !Y(n)) return r(oe(n));
813
+ if (We(n)) {
814
+ const a = c ? n[V.PATH] : i[0],
815
+ h = c ? n[V.PATTERN] : n[a];
816
+ if (!A(h)) throw new Error(Me(a));
817
+ const l = { keyId: B(a), pattern: h };
818
+ return t && (l.searcher = z(h, e)), l;
819
+ }
820
+ let o = { children: [], operator: i[0] };
821
+ return (
822
+ i.forEach((a) => {
823
+ const h = n[a];
824
+ m(h) &&
825
+ h.forEach((l) => {
826
+ o.children.push(r(l));
827
+ });
828
+ }),
829
+ o
830
+ );
831
+ };
832
+ return Y(s) || (s = oe(s)), r(s);
833
+ }
834
+ function ze(s, { ignoreFieldNorm: e = f.ignoreFieldNorm }) {
835
+ s.forEach((t) => {
836
+ let r = 1;
837
+ t.matches.forEach(({ key: n, norm: i, score: c }) => {
838
+ const o = n ? n.weight : null;
839
+ r *= Math.pow(
840
+ c === 0 && o ? Number.EPSILON : c,
841
+ (o || 1) * (e ? 1 : i)
842
+ );
843
+ }),
844
+ (t.score = r);
845
+ });
846
+ }
847
+ function Ve(s, e) {
848
+ const t = s.matches;
849
+ (e.matches = []),
850
+ M(t) &&
851
+ t.forEach((r) => {
852
+ if (!M(r.indices) || !r.indices.length) return;
853
+ const { indices: n, value: i } = r;
854
+ let c = { indices: n, value: i };
855
+ r.key && (c.key = r.key.src),
856
+ r.idx > -1 && (c.refIndex = r.idx),
857
+ e.matches.push(c);
858
+ });
859
+ }
860
+ function Ye(s, e) {
861
+ e.score = s.score;
862
+ }
863
+ function Ge(
864
+ s,
865
+ e,
866
+ {
867
+ includeMatches: t = f.includeMatches,
868
+ includeScore: r = f.includeScore,
869
+ } = {}
870
+ ) {
871
+ const n = [];
872
+ return (
873
+ t && n.push(Ve),
874
+ r && n.push(Ye),
875
+ s.map((i) => {
876
+ const { idx: c } = i,
877
+ o = { item: e[c], refIndex: c };
878
+ return (
879
+ n.length &&
880
+ n.forEach((a) => {
881
+ a(i, o);
882
+ }),
883
+ o
884
+ );
885
+ })
886
+ );
887
+ }
888
+ class $ {
889
+ constructor(e, t = {}, r) {
890
+ (this.options = { ...f, ...t }),
891
+ this.options.useExtendedSearch,
892
+ (this._keyStore = new Ae(this.options.keys)),
893
+ this.setCollection(e, r);
894
+ }
895
+ setCollection(e, t) {
896
+ if (((this._docs = e), t && !(t instanceof K))) throw new Error(ye);
897
+ this._myIndex =
898
+ t ||
899
+ te(this.options.keys, this._docs, {
900
+ getFn: this.options.getFn,
901
+ fieldNormWeight: this.options.fieldNormWeight,
902
+ });
903
+ }
904
+ add(e) {
905
+ M(e) && (this._docs.push(e), this._myIndex.add(e));
906
+ }
907
+ remove(e = () => !1) {
908
+ const t = [];
909
+ for (let r = 0, n = this._docs.length; r < n; r += 1) {
910
+ const i = this._docs[r];
911
+ e(i, r) && (this.removeAt(r), (r -= 1), (n -= 1), t.push(i));
912
+ }
913
+ return t;
914
+ }
915
+ removeAt(e) {
916
+ this._docs.splice(e, 1), this._myIndex.removeAt(e);
917
+ }
918
+ getIndex() {
919
+ return this._myIndex;
920
+ }
921
+ search(e, { limit: t = -1 } = {}) {
922
+ const {
923
+ includeMatches: r,
924
+ includeScore: n,
925
+ shouldSort: i,
926
+ sortFn: c,
927
+ ignoreFieldNorm: o,
928
+ } = this.options;
929
+ let a = A(e)
930
+ ? A(this._docs[0])
931
+ ? this._searchStringList(e)
932
+ : this._searchObjectList(e)
933
+ : this._searchLogical(e);
934
+ return (
935
+ ze(a, { ignoreFieldNorm: o }),
936
+ i && a.sort(c),
937
+ Q(t) && t > -1 && (a = a.slice(0, t)),
938
+ Ge(a, this._docs, { includeMatches: r, includeScore: n })
939
+ );
940
+ }
941
+ _searchStringList(e) {
942
+ const t = z(e, this.options),
943
+ { records: r } = this._myIndex,
944
+ n = [];
945
+ return (
946
+ r.forEach(({ v: i, i: c, n: o }) => {
947
+ if (!M(i)) return;
948
+ const { isMatch: a, score: h, indices: l } = t.searchIn(i);
949
+ a &&
950
+ n.push({
951
+ item: i,
952
+ idx: c,
953
+ matches: [{ score: h, value: i, norm: o, indices: l }],
954
+ });
955
+ }),
956
+ n
957
+ );
958
+ }
959
+ _searchLogical(e) {
960
+ const t = ae(e, this.options),
961
+ r = (o, a, h) => {
962
+ if (!o.children) {
963
+ const { keyId: u, searcher: d } = o,
964
+ g = this._findMatches({
965
+ key: this._keyStore.get(u),
966
+ value: this._myIndex.getValueForItemAtKeyId(a, u),
967
+ searcher: d,
968
+ });
969
+ return g && g.length ? [{ idx: h, item: a, matches: g }] : [];
970
+ }
971
+ const l = [];
972
+ for (let u = 0, d = o.children.length; u < d; u += 1) {
973
+ const g = o.children[u],
974
+ p = r(g, a, h);
975
+ if (p.length) l.push(...p);
976
+ else if (o.operator === F.AND) return [];
977
+ }
978
+ return l;
979
+ },
980
+ n = this._myIndex.records,
981
+ i = {},
982
+ c = [];
983
+ return (
984
+ n.forEach(({ $: o, i: a }) => {
985
+ if (M(o)) {
986
+ let h = r(t, o, a);
987
+ h.length &&
988
+ (i[a] ||
989
+ ((i[a] = { idx: a, item: o, matches: [] }), c.push(i[a])),
990
+ h.forEach(({ matches: l }) => {
991
+ i[a].matches.push(...l);
992
+ }));
993
+ }
994
+ }),
995
+ c
996
+ );
997
+ }
998
+ _searchObjectList(e) {
999
+ const t = z(e, this.options),
1000
+ { keys: r, records: n } = this._myIndex,
1001
+ i = [];
1002
+ return (
1003
+ n.forEach(({ $: c, i: o }) => {
1004
+ if (!M(c)) return;
1005
+ let a = [];
1006
+ r.forEach((h, l) => {
1007
+ a.push(...this._findMatches({ key: h, value: c[l], searcher: t }));
1008
+ }),
1009
+ a.length && i.push({ idx: o, item: c, matches: a });
1010
+ }),
1011
+ i
1012
+ );
1013
+ }
1014
+ _findMatches({ key: e, value: t, searcher: r }) {
1015
+ if (!M(t)) return [];
1016
+ let n = [];
1017
+ if (m(t))
1018
+ t.forEach(({ v: i, i: c, n: o }) => {
1019
+ if (!M(i)) return;
1020
+ const { isMatch: a, score: h, indices: l } = r.searchIn(i);
1021
+ a &&
1022
+ n.push({ score: h, key: e, value: i, idx: c, norm: o, indices: l });
1023
+ });
1024
+ else {
1025
+ const { v: i, n: c } = t,
1026
+ { isMatch: o, score: a, indices: h } = r.searchIn(i);
1027
+ o && n.push({ score: a, key: e, value: i, norm: c, indices: h });
1028
+ }
1029
+ return n;
1030
+ }
1031
+ }
1032
+ ($.version = "6.6.2"),
1033
+ ($.createIndex = te),
1034
+ ($.parseIndex = Le),
1035
+ ($.config = f),
1036
+ ($.parseQuery = ae),
1037
+ Ke(Be);
1038
+ const Ue = `
1039
+ <style>
1040
+ :host {
1041
+ display: block;
1042
+ }
1043
+ </style>
1044
+ <div>
1045
+ <slot></slot>
1046
+ <ul id="filters"></ul>
1047
+ <input type="text" />
1048
+ <ul id="results"></ul>
1049
+ </div>
1050
+ `,
1051
+ Qe = `
1052
+ <li>
1053
+ <label>
1054
+ <input type="checkbox" />
1055
+ <span class="title">FILTERITEMTITLE</span>
1056
+ </label>
1057
+ </li>
1058
+ `,
1059
+ Xe = `
1060
+ <details open>
1061
+ <summary>TITLE</summar>
1062
+ <ul></ul>
1063
+ </details>
1064
+ `,
1065
+ Je = (s, e = "highlight") => {
1066
+ const t = (n, i, c) => {
1067
+ const o = i.split(".");
1068
+ let a;
1069
+ for (a = 0; a < o.length - 1; a++) n = n[o[a]];
1070
+ n[o[a]] = c;
1071
+ },
1072
+ r = (n, i = []) => {
1073
+ let c = "",
1074
+ o = 0;
1075
+ return (
1076
+ i.forEach((a) => {
1077
+ const h = a[1] + 1;
1078
+ (c += [
1079
+ n.substring(o, a[0]),
1080
+ `<mark class="${e}">`,
1081
+ n.substring(a[0], h),
1082
+ "</mark>",
1083
+ ].join("")),
1084
+ (o = h);
1085
+ }),
1086
+ (c += n.substring(o)),
1087
+ c
1088
+ );
1089
+ };
1090
+ return s
1091
+ .filter(({ matches: n }) => n && n.length)
1092
+ .map(({ item: n, matches: i }) => {
1093
+ const c = { ...n };
1094
+ return (
1095
+ i.forEach((o) => {
1096
+ o.key === "name" && t(c, o.key, r(o.value, o.indices));
1097
+ }),
1098
+ c
1099
+ );
1100
+ });
1101
+ },
1102
+ he = document.createElement("template");
1103
+ he.innerHTML = Ue;
1104
+ class le extends HTMLElement {
1105
+ constructor() {
1106
+ super();
1107
+ _(this, "shadowRoot");
1108
+ _(this, "apply");
1109
+ _(this, "filterProperties");
1110
+ _(this, "items");
1111
+ _(this, "fuse");
1112
+ _(this, "filters");
1113
+ _(this, "aggregateBy");
1114
+ _(this, "fuseConfig");
1115
+ this.filters = {};
1116
+ const t = this.getAttribute("aggregateResults") || !1;
1117
+ (this.shadowRoot = this.attachShadow({ mode: "open" })),
1118
+ this.shadowRoot.appendChild(he.content.cloneNode(!0)),
1119
+ (this.apply = (i) => {
1120
+ (this.items = i),
1121
+ (this.fuse = new $(this.items, {
1122
+ minMatchCharLength: 1,
1123
+ includeMatches: !0,
1124
+ keys: ["name", ...this.filterProperties],
1125
+ useExtendedSearch: !0,
1126
+ ...this.fuseConfig,
1127
+ })),
1128
+ this.filterProperties.forEach((c) => {
1129
+ const o = [
1130
+ ...new Set(this.items.reduce((h, l) => h.concat(l[c]), [])),
1131
+ ].sort(),
1132
+ a = this.shadowRoot.querySelector("ul#filters");
1133
+ o.forEach((h) => {
1134
+ const l = document.createElement("template");
1135
+ l.innerHTML = Qe;
1136
+ const u = l.content.cloneNode(!0);
1137
+ u
1138
+ .querySelector("input[type='checkbox']")
1139
+ .setAttribute("data-filter-key", c),
1140
+ u
1141
+ .querySelector("input[type='checkbox']")
1142
+ .setAttribute("data-filter-value", h),
1143
+ (u.querySelector("span.title").innerHTML = h),
1144
+ a.appendChild(u);
1145
+ }),
1146
+ t === c && (this.aggregateBy = o);
1147
+ }),
1148
+ r();
1149
+ });
1150
+ const r = () => {
1151
+ this.shadowRoot
1152
+ .querySelectorAll("input[type='checkbox']")
1153
+ .forEach((i) => {
1154
+ i.addEventListener("click", (c) => {
1155
+ const o = c.target,
1156
+ a = o.getAttribute("data-filter-key"),
1157
+ h = o.getAttribute("data-filter-value");
1158
+ o.checked
1159
+ ? (this.filters[a] || (this.filters[a] = []),
1160
+ this.filters[a].push(h))
1161
+ : (this.filters[a].splice(this.filters[a].indexOf(h), 1),
1162
+ this.filters[a].length === 0 && delete this.filters[a]),
1163
+ n(this.shadowRoot.querySelector("input[type='text']").value);
1164
+ });
1165
+ });
1166
+ },
1167
+ n = (i, c = this.filters) => {
1168
+ const o = Object.entries(c).reduce((l, [u, d]) => {
1169
+ const g = (p) => {
1170
+ const y = {};
1171
+ (y[u] = `=${p}`), l.push(y);
1172
+ };
1173
+ return Array.isArray(d) ? d.forEach((p) => g(p)) : g(d), l;
1174
+ }, []),
1175
+ a = Je(
1176
+ this.fuse.search({
1177
+ ...(i.length && Object.keys(o).length
1178
+ ? { $and: [{ name: i }, { $or: o }] }
1179
+ : { $or: [{ name: i }, { $or: o }] }),
1180
+ })
1181
+ ),
1182
+ h = this.shadowRoot.querySelector("ul#results");
1183
+ if (((h.innerHTML = ""), t)) {
1184
+ const l = document.createElement("template");
1185
+ (l.innerHTML = Xe),
1186
+ this.aggregateBy.forEach((u) => {
1187
+ if (
1188
+ !a.find((g) =>
1189
+ Array.isArray(g[t]) ? g[t].includes(u) : g[t] === u
1190
+ )
1191
+ )
1192
+ return;
1193
+ const d = l.content.cloneNode(!0);
1194
+ (d.querySelector("summary").innerHTML = u),
1195
+ d.querySelector("details").setAttribute("data-aggregate", u),
1196
+ h.appendChild(d);
1197
+ });
1198
+ }
1199
+ a.forEach((l) => {
1200
+ if (this.aggregateBy) {
1201
+ const u = l[t];
1202
+ if (Array.isArray(u))
1203
+ u.forEach((d) => {
1204
+ const g = document.createElement("li");
1205
+ (g.innerHTML = l.name),
1206
+ this.shadowRoot
1207
+ .querySelector(`details[data-aggregate=${d}]`)
1208
+ .appendChild(g);
1209
+ });
1210
+ else {
1211
+ const d = document.createElement("li");
1212
+ (d.innerHTML = l.name),
1213
+ this.shadowRoot
1214
+ .querySelector(`details[data-aggregate=${u}]`)
1215
+ .appendChild(d);
1216
+ }
1217
+ } else {
1218
+ const u = document.createElement("li");
1219
+ (u.innerHTML = l.name), h.appendChild(u);
1220
+ }
1221
+ });
1222
+ };
1223
+ this.shadowRoot
1224
+ .querySelector("input[type='text']")
1225
+ .addEventListener("input", (i) => {
1226
+ n(i.target.value);
1227
+ });
1228
+ }
1229
+ }
1230
+ customElements.define("eox-itemfilter", le),
1231
+ (E.EOxItemFilter = le),
1232
+ Object.defineProperty(E, Symbol.toStringTag, { value: "Module" });
1233
+ });