typerighter 0.7.0 → 0.9.0
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.
Potentially problematic release.
This version of typerighter might be problematic. Click here for more details.
- package/dist/app-C-qfoH4a.js +373 -0
- package/dist/brand-CG1fQshq.js +5 -0
- package/dist/{cli-CDd4TNg1.js → cli-mg9QpUrf.js} +159 -132
- package/dist/cli.js +1 -1
- package/dist/client/app/index.d.ts +12 -3
- package/dist/client/app/index.d.ts.map +1 -1
- package/dist/client/app/router.d.ts +6 -2
- package/dist/client/app/router.d.ts.map +1 -1
- package/dist/client/theme-default.js +541 -417
- package/dist/client.js +1 -1
- package/dist/es-CG8rP6j5.js +22524 -0
- package/dist/index.js +2 -2
- package/dist/{init-Bfnl0t1B.js → init-BSgCv7vy.js} +664 -654
- package/dist/node/build/index.d.ts.map +1 -1
- package/dist/node/build/prerender.d.ts +2 -0
- package/dist/node/build/prerender.d.ts.map +1 -1
- package/dist/node/plugin/vite/index.d.ts.map +1 -1
- package/dist/shared/utils/field.d.ts +2 -0
- package/dist/shared/utils/field.d.ts.map +1 -0
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/index.d.ts.map +1 -1
- package/dist/shared/utils/url.d.ts +5 -0
- package/dist/shared/utils/url.d.ts.map +1 -1
- package/dist/shared-BIdsxcZ2.js +265 -0
- package/dist/shared.js +2 -0
- package/dist/typerighter.css +1 -1
- package/dist/vite-8CV23ALg.js +10704 -0
- package/dist/vite.js +1 -1
- package/package.json +7 -3
- package/dist/app-Bf0aLzaG.js +0 -370
- package/dist/brand-BfamszbH.js +0 -12
- package/dist/client/app/composables/useUrl.d.ts +0 -6
- package/dist/client/app/composables/useUrl.d.ts.map +0 -1
- package/dist/constants-DJbUAb1-.js +0 -32189
- package/dist/es-ClqUVRJn.js +0 -705
- package/dist/shared-CpPZZ8IH.js +0 -196
- package/dist/vite-DnP-_NzR.js +0 -326
package/dist/es-ClqUVRJn.js
DELETED
|
@@ -1,705 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/minisearch@7.2.0/node_modules/minisearch/dist/es/index.js
|
|
2
|
-
var e = "KEYS", t = "VALUES", n = class {
|
|
3
|
-
constructor(e, t) {
|
|
4
|
-
let n = e._tree, r = Array.from(n.keys());
|
|
5
|
-
this.set = e, this._type = t, this._path = r.length > 0 ? [{
|
|
6
|
-
node: n,
|
|
7
|
-
keys: r
|
|
8
|
-
}] : [];
|
|
9
|
-
}
|
|
10
|
-
next() {
|
|
11
|
-
let e = this.dive();
|
|
12
|
-
return this.backtrack(), e;
|
|
13
|
-
}
|
|
14
|
-
dive() {
|
|
15
|
-
if (this._path.length === 0) return {
|
|
16
|
-
done: !0,
|
|
17
|
-
value: void 0
|
|
18
|
-
};
|
|
19
|
-
let { node: e, keys: t } = r(this._path);
|
|
20
|
-
if (r(t) === "") return {
|
|
21
|
-
done: !1,
|
|
22
|
-
value: this.result()
|
|
23
|
-
};
|
|
24
|
-
let n = e.get(r(t));
|
|
25
|
-
return this._path.push({
|
|
26
|
-
node: n,
|
|
27
|
-
keys: Array.from(n.keys())
|
|
28
|
-
}), this.dive();
|
|
29
|
-
}
|
|
30
|
-
backtrack() {
|
|
31
|
-
if (this._path.length === 0) return;
|
|
32
|
-
let e = r(this._path).keys;
|
|
33
|
-
e.pop(), !(e.length > 0) && (this._path.pop(), this.backtrack());
|
|
34
|
-
}
|
|
35
|
-
key() {
|
|
36
|
-
return this.set._prefix + this._path.map(({ keys: e }) => r(e)).filter((e) => e !== "").join("");
|
|
37
|
-
}
|
|
38
|
-
value() {
|
|
39
|
-
return r(this._path).node.get("");
|
|
40
|
-
}
|
|
41
|
-
result() {
|
|
42
|
-
switch (this._type) {
|
|
43
|
-
case t: return this.value();
|
|
44
|
-
case e: return this.key();
|
|
45
|
-
default: return [this.key(), this.value()];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
[Symbol.iterator]() {
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
}, r = (e) => e[e.length - 1], i = (e, t, n) => {
|
|
52
|
-
let r = /* @__PURE__ */ new Map();
|
|
53
|
-
if (t === void 0) return r;
|
|
54
|
-
let i = t.length + 1, o = i + n, s = new Uint8Array(o * i).fill(n + 1);
|
|
55
|
-
for (let e = 0; e < i; ++e) s[e] = e;
|
|
56
|
-
for (let e = 1; e < o; ++e) s[e * i] = e;
|
|
57
|
-
return a(e, t, n, r, s, 1, i, ""), r;
|
|
58
|
-
}, a = (e, t, n, r, i, o, s, c) => {
|
|
59
|
-
let l = o * s;
|
|
60
|
-
key: for (let u of e.keys()) if (u === "") {
|
|
61
|
-
let t = i[l - 1];
|
|
62
|
-
t <= n && r.set(c, [e.get(u), t]);
|
|
63
|
-
} else {
|
|
64
|
-
let l = o;
|
|
65
|
-
for (let e = 0; e < u.length; ++e, ++l) {
|
|
66
|
-
let r = u[e], a = s * l, o = a - s, c = i[a], d = Math.max(0, l - n - 1), f = Math.min(s - 1, l + n);
|
|
67
|
-
for (let e = d; e < f; ++e) {
|
|
68
|
-
let n = r !== t[e], s = i[o + e] + +n, l = i[o + e + 1] + 1, u = i[a + e] + 1, d = i[a + e + 1] = Math.min(s, l, u);
|
|
69
|
-
d < c && (c = d);
|
|
70
|
-
}
|
|
71
|
-
if (c > n) continue key;
|
|
72
|
-
}
|
|
73
|
-
a(e.get(u), t, n, r, i, l, s, c + u);
|
|
74
|
-
}
|
|
75
|
-
}, o = class r {
|
|
76
|
-
constructor(e = /* @__PURE__ */ new Map(), t = "") {
|
|
77
|
-
this._size = void 0, this._tree = e, this._prefix = t;
|
|
78
|
-
}
|
|
79
|
-
atPrefix(e) {
|
|
80
|
-
if (!e.startsWith(this._prefix)) throw Error("Mismatched prefix");
|
|
81
|
-
let [t, n] = s(this._tree, e.slice(this._prefix.length));
|
|
82
|
-
if (t === void 0) {
|
|
83
|
-
let [t, i] = p(n);
|
|
84
|
-
for (let n of t.keys()) if (n !== "" && n.startsWith(i)) {
|
|
85
|
-
let a = /* @__PURE__ */ new Map();
|
|
86
|
-
return a.set(n.slice(i.length), t.get(n)), new r(a, e);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return new r(t, e);
|
|
90
|
-
}
|
|
91
|
-
clear() {
|
|
92
|
-
this._size = void 0, this._tree.clear();
|
|
93
|
-
}
|
|
94
|
-
delete(e) {
|
|
95
|
-
return this._size = void 0, u(this._tree, e);
|
|
96
|
-
}
|
|
97
|
-
entries() {
|
|
98
|
-
return new n(this, "ENTRIES");
|
|
99
|
-
}
|
|
100
|
-
forEach(e) {
|
|
101
|
-
for (let [t, n] of this) e(t, n, this);
|
|
102
|
-
}
|
|
103
|
-
fuzzyGet(e, t) {
|
|
104
|
-
return i(this._tree, e, t);
|
|
105
|
-
}
|
|
106
|
-
get(e) {
|
|
107
|
-
let t = c(this._tree, e);
|
|
108
|
-
return t === void 0 ? void 0 : t.get("");
|
|
109
|
-
}
|
|
110
|
-
has(e) {
|
|
111
|
-
let t = c(this._tree, e);
|
|
112
|
-
return t !== void 0 && t.has("");
|
|
113
|
-
}
|
|
114
|
-
keys() {
|
|
115
|
-
return new n(this, e);
|
|
116
|
-
}
|
|
117
|
-
set(e, t) {
|
|
118
|
-
if (typeof e != "string") throw Error("key must be a string");
|
|
119
|
-
return this._size = void 0, l(this._tree, e).set("", t), this;
|
|
120
|
-
}
|
|
121
|
-
get size() {
|
|
122
|
-
if (this._size) return this._size;
|
|
123
|
-
this._size = 0;
|
|
124
|
-
let e = this.entries();
|
|
125
|
-
for (; !e.next().done;) this._size += 1;
|
|
126
|
-
return this._size;
|
|
127
|
-
}
|
|
128
|
-
update(e, t) {
|
|
129
|
-
if (typeof e != "string") throw Error("key must be a string");
|
|
130
|
-
this._size = void 0;
|
|
131
|
-
let n = l(this._tree, e);
|
|
132
|
-
return n.set("", t(n.get(""))), this;
|
|
133
|
-
}
|
|
134
|
-
fetch(e, t) {
|
|
135
|
-
if (typeof e != "string") throw Error("key must be a string");
|
|
136
|
-
this._size = void 0;
|
|
137
|
-
let n = l(this._tree, e), r = n.get("");
|
|
138
|
-
return r === void 0 && n.set("", r = t()), r;
|
|
139
|
-
}
|
|
140
|
-
values() {
|
|
141
|
-
return new n(this, t);
|
|
142
|
-
}
|
|
143
|
-
[Symbol.iterator]() {
|
|
144
|
-
return this.entries();
|
|
145
|
-
}
|
|
146
|
-
static from(e) {
|
|
147
|
-
let t = new r();
|
|
148
|
-
for (let [n, r] of e) t.set(n, r);
|
|
149
|
-
return t;
|
|
150
|
-
}
|
|
151
|
-
static fromObject(e) {
|
|
152
|
-
return r.from(Object.entries(e));
|
|
153
|
-
}
|
|
154
|
-
}, s = (e, t, n = []) => {
|
|
155
|
-
if (t.length === 0 || e == null) return [e, n];
|
|
156
|
-
for (let r of e.keys()) if (r !== "" && t.startsWith(r)) return n.push([e, r]), s(e.get(r), t.slice(r.length), n);
|
|
157
|
-
return n.push([e, t]), s(void 0, "", n);
|
|
158
|
-
}, c = (e, t) => {
|
|
159
|
-
if (t.length === 0 || e == null) return e;
|
|
160
|
-
for (let n of e.keys()) if (n !== "" && t.startsWith(n)) return c(e.get(n), t.slice(n.length));
|
|
161
|
-
}, l = (e, t) => {
|
|
162
|
-
let n = t.length;
|
|
163
|
-
outer: for (let r = 0; e && r < n;) {
|
|
164
|
-
for (let i of e.keys()) if (i !== "" && t[r] === i[0]) {
|
|
165
|
-
let a = Math.min(n - r, i.length), o = 1;
|
|
166
|
-
for (; o < a && t[r + o] === i[o];) ++o;
|
|
167
|
-
let s = e.get(i);
|
|
168
|
-
if (o === i.length) e = s;
|
|
169
|
-
else {
|
|
170
|
-
let n = /* @__PURE__ */ new Map();
|
|
171
|
-
n.set(i.slice(o), s), e.set(t.slice(r, r + o), n), e.delete(i), e = n;
|
|
172
|
-
}
|
|
173
|
-
r += o;
|
|
174
|
-
continue outer;
|
|
175
|
-
}
|
|
176
|
-
let i = /* @__PURE__ */ new Map();
|
|
177
|
-
return e.set(t.slice(r), i), i;
|
|
178
|
-
}
|
|
179
|
-
return e;
|
|
180
|
-
}, u = (e, t) => {
|
|
181
|
-
let [n, r] = s(e, t);
|
|
182
|
-
if (n !== void 0) {
|
|
183
|
-
if (n.delete(""), n.size === 0) d(r);
|
|
184
|
-
else if (n.size === 1) {
|
|
185
|
-
let [e, t] = n.entries().next().value;
|
|
186
|
-
f(r, e, t);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}, d = (e) => {
|
|
190
|
-
if (e.length === 0) return;
|
|
191
|
-
let [t, n] = p(e);
|
|
192
|
-
if (t.delete(n), t.size === 0) d(e.slice(0, -1));
|
|
193
|
-
else if (t.size === 1) {
|
|
194
|
-
let [n, r] = t.entries().next().value;
|
|
195
|
-
n !== "" && f(e.slice(0, -1), n, r);
|
|
196
|
-
}
|
|
197
|
-
}, f = (e, t, n) => {
|
|
198
|
-
if (e.length === 0) return;
|
|
199
|
-
let [r, i] = p(e);
|
|
200
|
-
r.set(i + t, n), r.delete(i);
|
|
201
|
-
}, p = (e) => e[e.length - 1], m = "or", h = "and", g = "and_not", _ = class e {
|
|
202
|
-
constructor(e) {
|
|
203
|
-
if (e?.fields == null) throw Error("MiniSearch: option \"fields\" must be provided");
|
|
204
|
-
let t = e.autoVacuum == null || e.autoVacuum === !0 ? O : e.autoVacuum;
|
|
205
|
-
this._options = {
|
|
206
|
-
...C,
|
|
207
|
-
...e,
|
|
208
|
-
autoVacuum: t,
|
|
209
|
-
searchOptions: {
|
|
210
|
-
...w,
|
|
211
|
-
...e.searchOptions || {}
|
|
212
|
-
},
|
|
213
|
-
autoSuggestOptions: {
|
|
214
|
-
...T,
|
|
215
|
-
...e.autoSuggestOptions || {}
|
|
216
|
-
}
|
|
217
|
-
}, this._index = new o(), this._documentCount = 0, this._documentIds = /* @__PURE__ */ new Map(), this._idToShortId = /* @__PURE__ */ new Map(), this._fieldIds = {}, this._fieldLength = /* @__PURE__ */ new Map(), this._avgFieldLength = [], this._nextId = 0, this._storedFields = /* @__PURE__ */ new Map(), this._dirtCount = 0, this._currentVacuum = null, this._enqueuedVacuum = null, this._enqueuedVacuumConditions = D, this.addFields(this._options.fields);
|
|
218
|
-
}
|
|
219
|
-
add(e) {
|
|
220
|
-
let { extractField: t, stringifyField: n, tokenize: r, processTerm: i, fields: a, idField: o } = this._options, s = t(e, o);
|
|
221
|
-
if (s == null) throw Error(`MiniSearch: document does not have ID field "${o}"`);
|
|
222
|
-
if (this._idToShortId.has(s)) throw Error(`MiniSearch: duplicate ID ${s}`);
|
|
223
|
-
let c = this.addDocumentId(s);
|
|
224
|
-
this.saveStoredFields(c, e);
|
|
225
|
-
for (let o of a) {
|
|
226
|
-
let a = t(e, o);
|
|
227
|
-
if (a == null) continue;
|
|
228
|
-
let s = r(n(a, o), o), l = this._fieldIds[o], u = new Set(s).size;
|
|
229
|
-
this.addFieldLength(c, l, this._documentCount - 1, u);
|
|
230
|
-
for (let e of s) {
|
|
231
|
-
let t = i(e, o);
|
|
232
|
-
if (Array.isArray(t)) for (let e of t) this.addTerm(l, c, e);
|
|
233
|
-
else t && this.addTerm(l, c, t);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
addAll(e) {
|
|
238
|
-
for (let t of e) this.add(t);
|
|
239
|
-
}
|
|
240
|
-
addAllAsync(e, t = {}) {
|
|
241
|
-
let { chunkSize: n = 10 } = t, r = {
|
|
242
|
-
chunk: [],
|
|
243
|
-
promise: Promise.resolve()
|
|
244
|
-
}, { chunk: i, promise: a } = e.reduce(({ chunk: e, promise: t }, r, i) => (e.push(r), (i + 1) % n === 0 ? {
|
|
245
|
-
chunk: [],
|
|
246
|
-
promise: t.then(() => new Promise((e) => setTimeout(e, 0))).then(() => this.addAll(e))
|
|
247
|
-
} : {
|
|
248
|
-
chunk: e,
|
|
249
|
-
promise: t
|
|
250
|
-
}), r);
|
|
251
|
-
return a.then(() => this.addAll(i));
|
|
252
|
-
}
|
|
253
|
-
remove(e) {
|
|
254
|
-
let { tokenize: t, processTerm: n, extractField: r, stringifyField: i, fields: a, idField: o } = this._options, s = r(e, o);
|
|
255
|
-
if (s == null) throw Error(`MiniSearch: document does not have ID field "${o}"`);
|
|
256
|
-
let c = this._idToShortId.get(s);
|
|
257
|
-
if (c == null) throw Error(`MiniSearch: cannot remove document with ID ${s}: it is not in the index`);
|
|
258
|
-
for (let o of a) {
|
|
259
|
-
let a = r(e, o);
|
|
260
|
-
if (a == null) continue;
|
|
261
|
-
let s = t(i(a, o), o), l = this._fieldIds[o], u = new Set(s).size;
|
|
262
|
-
this.removeFieldLength(c, l, this._documentCount, u);
|
|
263
|
-
for (let e of s) {
|
|
264
|
-
let t = n(e, o);
|
|
265
|
-
if (Array.isArray(t)) for (let e of t) this.removeTerm(l, c, e);
|
|
266
|
-
else t && this.removeTerm(l, c, t);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
this._storedFields.delete(c), this._documentIds.delete(c), this._idToShortId.delete(s), this._fieldLength.delete(c), --this._documentCount;
|
|
270
|
-
}
|
|
271
|
-
removeAll(e) {
|
|
272
|
-
if (e) for (let t of e) this.remove(t);
|
|
273
|
-
else if (arguments.length > 0) throw Error("Expected documents to be present. Omit the argument to remove all documents.");
|
|
274
|
-
else this._index = new o(), this._documentCount = 0, this._documentIds = /* @__PURE__ */ new Map(), this._idToShortId = /* @__PURE__ */ new Map(), this._fieldLength = /* @__PURE__ */ new Map(), this._avgFieldLength = [], this._storedFields = /* @__PURE__ */ new Map(), this._nextId = 0;
|
|
275
|
-
}
|
|
276
|
-
discard(e) {
|
|
277
|
-
let t = this._idToShortId.get(e);
|
|
278
|
-
if (t == null) throw Error(`MiniSearch: cannot discard document with ID ${e}: it is not in the index`);
|
|
279
|
-
this._idToShortId.delete(e), this._documentIds.delete(t), this._storedFields.delete(t), (this._fieldLength.get(t) || []).forEach((e, n) => {
|
|
280
|
-
this.removeFieldLength(t, n, this._documentCount, e);
|
|
281
|
-
}), this._fieldLength.delete(t), --this._documentCount, this._dirtCount += 1, this.maybeAutoVacuum();
|
|
282
|
-
}
|
|
283
|
-
maybeAutoVacuum() {
|
|
284
|
-
if (this._options.autoVacuum === !1) return;
|
|
285
|
-
let { minDirtFactor: e, minDirtCount: t, batchSize: n, batchWait: r } = this._options.autoVacuum;
|
|
286
|
-
this.conditionalVacuum({
|
|
287
|
-
batchSize: n,
|
|
288
|
-
batchWait: r
|
|
289
|
-
}, {
|
|
290
|
-
minDirtCount: t,
|
|
291
|
-
minDirtFactor: e
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
discardAll(e) {
|
|
295
|
-
let t = this._options.autoVacuum;
|
|
296
|
-
try {
|
|
297
|
-
this._options.autoVacuum = !1;
|
|
298
|
-
for (let t of e) this.discard(t);
|
|
299
|
-
} finally {
|
|
300
|
-
this._options.autoVacuum = t;
|
|
301
|
-
}
|
|
302
|
-
this.maybeAutoVacuum();
|
|
303
|
-
}
|
|
304
|
-
replace(e) {
|
|
305
|
-
let { idField: t, extractField: n } = this._options, r = n(e, t);
|
|
306
|
-
this.discard(r), this.add(e);
|
|
307
|
-
}
|
|
308
|
-
vacuum(e = {}) {
|
|
309
|
-
return this.conditionalVacuum(e);
|
|
310
|
-
}
|
|
311
|
-
conditionalVacuum(e, t) {
|
|
312
|
-
return this._currentVacuum ? (this._enqueuedVacuumConditions = this._enqueuedVacuumConditions && t, this._enqueuedVacuum ??= this._currentVacuum.then(() => {
|
|
313
|
-
let t = this._enqueuedVacuumConditions;
|
|
314
|
-
return this._enqueuedVacuumConditions = D, this.performVacuuming(e, t);
|
|
315
|
-
}), this._enqueuedVacuum) : this.vacuumConditionsMet(t) === !1 ? Promise.resolve() : (this._currentVacuum = this.performVacuuming(e), this._currentVacuum);
|
|
316
|
-
}
|
|
317
|
-
async performVacuuming(e, t) {
|
|
318
|
-
let n = this._dirtCount;
|
|
319
|
-
if (this.vacuumConditionsMet(t)) {
|
|
320
|
-
let t = e.batchSize || E.batchSize, r = e.batchWait || E.batchWait, i = 1;
|
|
321
|
-
for (let [e, n] of this._index) {
|
|
322
|
-
for (let [e, t] of n) for (let [r] of t) this._documentIds.has(r) || (t.size <= 1 ? n.delete(e) : t.delete(r));
|
|
323
|
-
this._index.get(e).size === 0 && this._index.delete(e), i % t === 0 && await new Promise((e) => setTimeout(e, r)), i += 1;
|
|
324
|
-
}
|
|
325
|
-
this._dirtCount -= n;
|
|
326
|
-
}
|
|
327
|
-
await null, this._currentVacuum = this._enqueuedVacuum, this._enqueuedVacuum = null;
|
|
328
|
-
}
|
|
329
|
-
vacuumConditionsMet(e) {
|
|
330
|
-
if (e == null) return !0;
|
|
331
|
-
let { minDirtCount: t, minDirtFactor: n } = e;
|
|
332
|
-
return t ||= O.minDirtCount, n ||= O.minDirtFactor, this.dirtCount >= t && this.dirtFactor >= n;
|
|
333
|
-
}
|
|
334
|
-
get isVacuuming() {
|
|
335
|
-
return this._currentVacuum != null;
|
|
336
|
-
}
|
|
337
|
-
get dirtCount() {
|
|
338
|
-
return this._dirtCount;
|
|
339
|
-
}
|
|
340
|
-
get dirtFactor() {
|
|
341
|
-
return this._dirtCount / (1 + this._documentCount + this._dirtCount);
|
|
342
|
-
}
|
|
343
|
-
has(e) {
|
|
344
|
-
return this._idToShortId.has(e);
|
|
345
|
-
}
|
|
346
|
-
getStoredFields(e) {
|
|
347
|
-
let t = this._idToShortId.get(e);
|
|
348
|
-
if (t != null) return this._storedFields.get(t);
|
|
349
|
-
}
|
|
350
|
-
search(t, n = {}) {
|
|
351
|
-
let { searchOptions: r } = this._options, i = {
|
|
352
|
-
...r,
|
|
353
|
-
...n
|
|
354
|
-
}, a = this.executeQuery(t, n), o = [];
|
|
355
|
-
for (let [e, { score: t, terms: n, match: r }] of a) {
|
|
356
|
-
let a = n.length || 1, s = {
|
|
357
|
-
id: this._documentIds.get(e),
|
|
358
|
-
score: t * a,
|
|
359
|
-
terms: Object.keys(r),
|
|
360
|
-
queryTerms: n,
|
|
361
|
-
match: r
|
|
362
|
-
};
|
|
363
|
-
Object.assign(s, this._storedFields.get(e)), (i.filter == null || i.filter(s)) && o.push(s);
|
|
364
|
-
}
|
|
365
|
-
return t === e.wildcard && i.boostDocument == null || o.sort(j), o;
|
|
366
|
-
}
|
|
367
|
-
autoSuggest(e, t = {}) {
|
|
368
|
-
t = {
|
|
369
|
-
...this._options.autoSuggestOptions,
|
|
370
|
-
...t
|
|
371
|
-
};
|
|
372
|
-
let n = /* @__PURE__ */ new Map();
|
|
373
|
-
for (let { score: r, terms: i } of this.search(e, t)) {
|
|
374
|
-
let e = i.join(" "), t = n.get(e);
|
|
375
|
-
t == null ? n.set(e, {
|
|
376
|
-
score: r,
|
|
377
|
-
terms: i,
|
|
378
|
-
count: 1
|
|
379
|
-
}) : (t.score += r, t.count += 1);
|
|
380
|
-
}
|
|
381
|
-
let r = [];
|
|
382
|
-
for (let [e, { score: t, terms: i, count: a }] of n) r.push({
|
|
383
|
-
suggestion: e,
|
|
384
|
-
terms: i,
|
|
385
|
-
score: t / a
|
|
386
|
-
});
|
|
387
|
-
return r.sort(j), r;
|
|
388
|
-
}
|
|
389
|
-
get documentCount() {
|
|
390
|
-
return this._documentCount;
|
|
391
|
-
}
|
|
392
|
-
get termCount() {
|
|
393
|
-
return this._index.size;
|
|
394
|
-
}
|
|
395
|
-
static loadJSON(e, t) {
|
|
396
|
-
if (t == null) throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");
|
|
397
|
-
return this.loadJS(JSON.parse(e), t);
|
|
398
|
-
}
|
|
399
|
-
static async loadJSONAsync(e, t) {
|
|
400
|
-
if (t == null) throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");
|
|
401
|
-
return this.loadJSAsync(JSON.parse(e), t);
|
|
402
|
-
}
|
|
403
|
-
static getDefault(e) {
|
|
404
|
-
if (C.hasOwnProperty(e)) return v(C, e);
|
|
405
|
-
throw Error(`MiniSearch: unknown option "${e}"`);
|
|
406
|
-
}
|
|
407
|
-
static loadJS(e, t) {
|
|
408
|
-
let { index: n, documentIds: r, fieldLength: i, storedFields: a, serializationVersion: o } = e, s = this.instantiateMiniSearch(e, t);
|
|
409
|
-
s._documentIds = N(r), s._fieldLength = N(i), s._storedFields = N(a);
|
|
410
|
-
for (let [e, t] of s._documentIds) s._idToShortId.set(t, e);
|
|
411
|
-
for (let [e, t] of n) {
|
|
412
|
-
let n = /* @__PURE__ */ new Map();
|
|
413
|
-
for (let e of Object.keys(t)) {
|
|
414
|
-
let r = t[e];
|
|
415
|
-
o === 1 && (r = r.ds), n.set(parseInt(e, 10), N(r));
|
|
416
|
-
}
|
|
417
|
-
s._index.set(e, n);
|
|
418
|
-
}
|
|
419
|
-
return s;
|
|
420
|
-
}
|
|
421
|
-
static async loadJSAsync(e, t) {
|
|
422
|
-
let { index: n, documentIds: r, fieldLength: i, storedFields: a, serializationVersion: o } = e, s = this.instantiateMiniSearch(e, t);
|
|
423
|
-
s._documentIds = await P(r), s._fieldLength = await P(i), s._storedFields = await P(a);
|
|
424
|
-
for (let [e, t] of s._documentIds) s._idToShortId.set(t, e);
|
|
425
|
-
let c = 0;
|
|
426
|
-
for (let [e, t] of n) {
|
|
427
|
-
let n = /* @__PURE__ */ new Map();
|
|
428
|
-
for (let e of Object.keys(t)) {
|
|
429
|
-
let r = t[e];
|
|
430
|
-
o === 1 && (r = r.ds), n.set(parseInt(e, 10), await P(r));
|
|
431
|
-
}
|
|
432
|
-
++c % 1e3 == 0 && await F(0), s._index.set(e, n);
|
|
433
|
-
}
|
|
434
|
-
return s;
|
|
435
|
-
}
|
|
436
|
-
static instantiateMiniSearch(t, n) {
|
|
437
|
-
let { documentCount: r, nextId: i, fieldIds: a, averageFieldLength: s, dirtCount: c, serializationVersion: l } = t;
|
|
438
|
-
if (l !== 1 && l !== 2) throw Error("MiniSearch: cannot deserialize an index created with an incompatible version");
|
|
439
|
-
let u = new e(n);
|
|
440
|
-
return u._documentCount = r, u._nextId = i, u._idToShortId = /* @__PURE__ */ new Map(), u._fieldIds = a, u._avgFieldLength = s, u._dirtCount = c || 0, u._index = new o(), u;
|
|
441
|
-
}
|
|
442
|
-
executeQuery(t, n = {}) {
|
|
443
|
-
if (t === e.wildcard) return this.executeWildcardQuery(n);
|
|
444
|
-
if (typeof t != "string") {
|
|
445
|
-
let e = {
|
|
446
|
-
...n,
|
|
447
|
-
...t,
|
|
448
|
-
queries: void 0
|
|
449
|
-
}, r = t.queries.map((t) => this.executeQuery(t, e));
|
|
450
|
-
return this.combineResults(r, e.combineWith);
|
|
451
|
-
}
|
|
452
|
-
let { tokenize: r, processTerm: i, searchOptions: a } = this._options, o = {
|
|
453
|
-
tokenize: r,
|
|
454
|
-
processTerm: i,
|
|
455
|
-
...a,
|
|
456
|
-
...n
|
|
457
|
-
}, { tokenize: s, processTerm: c } = o, l = s(t).flatMap((e) => c(e)).filter((e) => !!e).map(S(o)).map((e) => this.executeQuerySpec(e, o));
|
|
458
|
-
return this.combineResults(l, o.combineWith);
|
|
459
|
-
}
|
|
460
|
-
executeQuerySpec(e, t) {
|
|
461
|
-
let n = {
|
|
462
|
-
...this._options.searchOptions,
|
|
463
|
-
...t
|
|
464
|
-
}, r = (n.fields || this._options.fields).reduce((e, t) => ({
|
|
465
|
-
...e,
|
|
466
|
-
[t]: v(n.boost, t) || 1
|
|
467
|
-
}), {}), { boostDocument: i, weights: a, maxFuzzy: o, bm25: s } = n, { fuzzy: c, prefix: l } = {
|
|
468
|
-
...w.weights,
|
|
469
|
-
...a
|
|
470
|
-
}, u = this._index.get(e.term), d = this.termResults(e.term, e.term, 1, e.termBoost, u, r, i, s), f, p;
|
|
471
|
-
if (e.prefix && (f = this._index.atPrefix(e.term)), e.fuzzy) {
|
|
472
|
-
let t = e.fuzzy === !0 ? .2 : e.fuzzy, n = t < 1 ? Math.min(o, Math.round(e.term.length * t)) : t;
|
|
473
|
-
n && (p = this._index.fuzzyGet(e.term, n));
|
|
474
|
-
}
|
|
475
|
-
if (f) for (let [t, n] of f) {
|
|
476
|
-
let a = t.length - e.term.length;
|
|
477
|
-
if (!a) continue;
|
|
478
|
-
p?.delete(t);
|
|
479
|
-
let o = l * t.length / (t.length + .3 * a);
|
|
480
|
-
this.termResults(e.term, t, o, e.termBoost, n, r, i, s, d);
|
|
481
|
-
}
|
|
482
|
-
if (p) for (let t of p.keys()) {
|
|
483
|
-
let [n, a] = p.get(t);
|
|
484
|
-
if (!a) continue;
|
|
485
|
-
let o = c * t.length / (t.length + a);
|
|
486
|
-
this.termResults(e.term, t, o, e.termBoost, n, r, i, s, d);
|
|
487
|
-
}
|
|
488
|
-
return d;
|
|
489
|
-
}
|
|
490
|
-
executeWildcardQuery(e) {
|
|
491
|
-
let t = /* @__PURE__ */ new Map(), n = {
|
|
492
|
-
...this._options.searchOptions,
|
|
493
|
-
...e
|
|
494
|
-
};
|
|
495
|
-
for (let [e, r] of this._documentIds) {
|
|
496
|
-
let i = n.boostDocument ? n.boostDocument(r, "", this._storedFields.get(e)) : 1;
|
|
497
|
-
t.set(e, {
|
|
498
|
-
score: i,
|
|
499
|
-
terms: [],
|
|
500
|
-
match: {}
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
return t;
|
|
504
|
-
}
|
|
505
|
-
combineResults(e, t = m) {
|
|
506
|
-
if (e.length === 0) return /* @__PURE__ */ new Map();
|
|
507
|
-
let n = y[t.toLowerCase()];
|
|
508
|
-
if (!n) throw Error(`Invalid combination operator: ${t}`);
|
|
509
|
-
return e.reduce(n) || /* @__PURE__ */ new Map();
|
|
510
|
-
}
|
|
511
|
-
toJSON() {
|
|
512
|
-
let e = [];
|
|
513
|
-
for (let [t, n] of this._index) {
|
|
514
|
-
let r = {};
|
|
515
|
-
for (let [e, t] of n) r[e] = Object.fromEntries(t);
|
|
516
|
-
e.push([t, r]);
|
|
517
|
-
}
|
|
518
|
-
return {
|
|
519
|
-
documentCount: this._documentCount,
|
|
520
|
-
nextId: this._nextId,
|
|
521
|
-
documentIds: Object.fromEntries(this._documentIds),
|
|
522
|
-
fieldIds: this._fieldIds,
|
|
523
|
-
fieldLength: Object.fromEntries(this._fieldLength),
|
|
524
|
-
averageFieldLength: this._avgFieldLength,
|
|
525
|
-
storedFields: Object.fromEntries(this._storedFields),
|
|
526
|
-
dirtCount: this._dirtCount,
|
|
527
|
-
index: e,
|
|
528
|
-
serializationVersion: 2
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
termResults(e, t, n, r, i, a, o, s, c = /* @__PURE__ */ new Map()) {
|
|
532
|
-
if (i == null) return c;
|
|
533
|
-
for (let l of Object.keys(a)) {
|
|
534
|
-
let u = a[l], d = this._fieldIds[l], f = i.get(d);
|
|
535
|
-
if (f == null) continue;
|
|
536
|
-
let p = f.size, m = this._avgFieldLength[d];
|
|
537
|
-
for (let i of f.keys()) {
|
|
538
|
-
if (!this._documentIds.has(i)) {
|
|
539
|
-
this.removeTerm(d, i, t), --p;
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
let a = o ? o(this._documentIds.get(i), t, this._storedFields.get(i)) : 1;
|
|
543
|
-
if (!a) continue;
|
|
544
|
-
let h = f.get(i), g = this._fieldLength.get(i)[d], _ = x(h, p, this._documentCount, g, m, s), y = n * r * u * a * _, b = c.get(i);
|
|
545
|
-
if (b) {
|
|
546
|
-
b.score += y, k(b.terms, e);
|
|
547
|
-
let n = v(b.match, t);
|
|
548
|
-
n ? n.push(l) : b.match[t] = [l];
|
|
549
|
-
} else c.set(i, {
|
|
550
|
-
score: y,
|
|
551
|
-
terms: [e],
|
|
552
|
-
match: { [t]: [l] }
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return c;
|
|
557
|
-
}
|
|
558
|
-
addTerm(e, t, n) {
|
|
559
|
-
let r = this._index.fetch(n, M), i = r.get(e);
|
|
560
|
-
if (i == null) i = /* @__PURE__ */ new Map(), i.set(t, 1), r.set(e, i);
|
|
561
|
-
else {
|
|
562
|
-
let e = i.get(t);
|
|
563
|
-
i.set(t, (e || 0) + 1);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
removeTerm(e, t, n) {
|
|
567
|
-
if (!this._index.has(n)) {
|
|
568
|
-
this.warnDocumentChanged(t, e, n);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
let r = this._index.fetch(n, M), i = r.get(e);
|
|
572
|
-
i == null || i.get(t) == null ? this.warnDocumentChanged(t, e, n) : i.get(t) <= 1 ? i.size <= 1 ? r.delete(e) : i.delete(t) : i.set(t, i.get(t) - 1), this._index.get(n).size === 0 && this._index.delete(n);
|
|
573
|
-
}
|
|
574
|
-
warnDocumentChanged(e, t, n) {
|
|
575
|
-
for (let r of Object.keys(this._fieldIds)) if (this._fieldIds[r] === t) {
|
|
576
|
-
this._options.logger("warn", `MiniSearch: document with ID ${this._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${r}". Removing a document after it has changed can corrupt the index!`, "version_conflict");
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
addDocumentId(e) {
|
|
581
|
-
let t = this._nextId;
|
|
582
|
-
return this._idToShortId.set(e, t), this._documentIds.set(t, e), this._documentCount += 1, this._nextId += 1, t;
|
|
583
|
-
}
|
|
584
|
-
addFields(e) {
|
|
585
|
-
for (let t = 0; t < e.length; t++) this._fieldIds[e[t]] = t;
|
|
586
|
-
}
|
|
587
|
-
addFieldLength(e, t, n, r) {
|
|
588
|
-
let i = this._fieldLength.get(e);
|
|
589
|
-
i ?? this._fieldLength.set(e, i = []), i[t] = r;
|
|
590
|
-
let a = (this._avgFieldLength[t] || 0) * n + r;
|
|
591
|
-
this._avgFieldLength[t] = a / (n + 1);
|
|
592
|
-
}
|
|
593
|
-
removeFieldLength(e, t, n, r) {
|
|
594
|
-
if (n === 1) {
|
|
595
|
-
this._avgFieldLength[t] = 0;
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
let i = this._avgFieldLength[t] * n - r;
|
|
599
|
-
this._avgFieldLength[t] = i / (n - 1);
|
|
600
|
-
}
|
|
601
|
-
saveStoredFields(e, t) {
|
|
602
|
-
let { storeFields: n, extractField: r } = this._options;
|
|
603
|
-
if (n == null || n.length === 0) return;
|
|
604
|
-
let i = this._storedFields.get(e);
|
|
605
|
-
i ?? this._storedFields.set(e, i = {});
|
|
606
|
-
for (let e of n) {
|
|
607
|
-
let n = r(t, e);
|
|
608
|
-
n !== void 0 && (i[e] = n);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
_.wildcard = Symbol("*");
|
|
613
|
-
var v = (e, t) => Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0, y = {
|
|
614
|
-
[m]: (e, t) => {
|
|
615
|
-
for (let n of t.keys()) {
|
|
616
|
-
let r = e.get(n);
|
|
617
|
-
if (r == null) e.set(n, t.get(n));
|
|
618
|
-
else {
|
|
619
|
-
let { score: e, terms: i, match: a } = t.get(n);
|
|
620
|
-
r.score += e, r.match = Object.assign(r.match, a), A(r.terms, i);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
return e;
|
|
624
|
-
},
|
|
625
|
-
[h]: (e, t) => {
|
|
626
|
-
let n = /* @__PURE__ */ new Map();
|
|
627
|
-
for (let r of t.keys()) {
|
|
628
|
-
let i = e.get(r);
|
|
629
|
-
if (i == null) continue;
|
|
630
|
-
let { score: a, terms: o, match: s } = t.get(r);
|
|
631
|
-
A(i.terms, o), n.set(r, {
|
|
632
|
-
score: i.score + a,
|
|
633
|
-
terms: i.terms,
|
|
634
|
-
match: Object.assign(i.match, s)
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
return n;
|
|
638
|
-
},
|
|
639
|
-
[g]: (e, t) => {
|
|
640
|
-
for (let n of t.keys()) e.delete(n);
|
|
641
|
-
return e;
|
|
642
|
-
}
|
|
643
|
-
}, b = {
|
|
644
|
-
k: 1.2,
|
|
645
|
-
b: .7,
|
|
646
|
-
d: .5
|
|
647
|
-
}, x = (e, t, n, r, i, a) => {
|
|
648
|
-
let { k: o, b: s, d: c } = a;
|
|
649
|
-
return Math.log(1 + (n - t + .5) / (t + .5)) * (c + e * (o + 1) / (e + o * (1 - s + s * r / i)));
|
|
650
|
-
}, S = (e) => (t, n, r) => ({
|
|
651
|
-
term: t,
|
|
652
|
-
fuzzy: typeof e.fuzzy == "function" ? e.fuzzy(t, n, r) : e.fuzzy || !1,
|
|
653
|
-
prefix: typeof e.prefix == "function" ? e.prefix(t, n, r) : e.prefix === !0,
|
|
654
|
-
termBoost: typeof e.boostTerm == "function" ? e.boostTerm(t, n, r) : 1
|
|
655
|
-
}), C = {
|
|
656
|
-
idField: "id",
|
|
657
|
-
extractField: (e, t) => e[t],
|
|
658
|
-
stringifyField: (e, t) => e.toString(),
|
|
659
|
-
tokenize: (e) => e.split(I),
|
|
660
|
-
processTerm: (e) => e.toLowerCase(),
|
|
661
|
-
fields: void 0,
|
|
662
|
-
searchOptions: void 0,
|
|
663
|
-
storeFields: [],
|
|
664
|
-
logger: (e, t) => {
|
|
665
|
-
typeof (console == null ? void 0 : console[e]) == "function" && console[e](t);
|
|
666
|
-
},
|
|
667
|
-
autoVacuum: !0
|
|
668
|
-
}, w = {
|
|
669
|
-
combineWith: m,
|
|
670
|
-
prefix: !1,
|
|
671
|
-
fuzzy: !1,
|
|
672
|
-
maxFuzzy: 6,
|
|
673
|
-
boost: {},
|
|
674
|
-
weights: {
|
|
675
|
-
fuzzy: .45,
|
|
676
|
-
prefix: .375
|
|
677
|
-
},
|
|
678
|
-
bm25: b
|
|
679
|
-
}, T = {
|
|
680
|
-
combineWith: h,
|
|
681
|
-
prefix: (e, t, n) => t === n.length - 1
|
|
682
|
-
}, E = {
|
|
683
|
-
batchSize: 1e3,
|
|
684
|
-
batchWait: 10
|
|
685
|
-
}, D = {
|
|
686
|
-
minDirtFactor: .1,
|
|
687
|
-
minDirtCount: 20
|
|
688
|
-
}, O = {
|
|
689
|
-
...E,
|
|
690
|
-
...D
|
|
691
|
-
}, k = (e, t) => {
|
|
692
|
-
e.includes(t) || e.push(t);
|
|
693
|
-
}, A = (e, t) => {
|
|
694
|
-
for (let n of t) e.includes(n) || e.push(n);
|
|
695
|
-
}, j = ({ score: e }, { score: t }) => t - e, M = () => /* @__PURE__ */ new Map(), N = (e) => {
|
|
696
|
-
let t = /* @__PURE__ */ new Map();
|
|
697
|
-
for (let n of Object.keys(e)) t.set(parseInt(n, 10), e[n]);
|
|
698
|
-
return t;
|
|
699
|
-
}, P = async (e) => {
|
|
700
|
-
let t = /* @__PURE__ */ new Map(), n = 0;
|
|
701
|
-
for (let r of Object.keys(e)) t.set(parseInt(r, 10), e[r]), ++n % 1e3 == 0 && await F(0);
|
|
702
|
-
return t;
|
|
703
|
-
}, F = (e) => new Promise((t) => setTimeout(t, e)), I = /[\n\r\p{Z}\p{P}]+/u;
|
|
704
|
-
//#endregion
|
|
705
|
-
export { _ as t };
|