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