@peam-ai/next 0.1.3 → 0.1.5

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/route.mjs CHANGED
@@ -1,7 +1,2566 @@
1
1
  import { createHandler } from 'peam/server';
2
+ import * as fsSync from 'fs';
3
+ import * as fs from 'fs/promises';
4
+ import * as path from 'path';
5
+
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
13
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
14
+ }) : x)(function(x) {
15
+ if (typeof require !== "undefined") return require.apply(this, arguments);
16
+ throw Error('Dynamic require of "' + x + '" is not supported');
17
+ });
18
+ var __commonJS = (cb2, mod) => function __require2() {
19
+ return mod || (0, cb2[__getOwnPropNames(cb2)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
35
+ mod
36
+ ));
37
+
38
+ // ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
39
+ var require_picocolors = __commonJS({
40
+ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports$1, module2) {
41
+ var p = process || {};
42
+ var argv = p.argv || [];
43
+ var env = p.env || {};
44
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
45
+ var formatter = (open, close, replace = open) => (input) => {
46
+ let string = "" + input, index = string.indexOf(close, open.length);
47
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
48
+ };
49
+ var replaceClose = (string, close, replace, index) => {
50
+ let result = "", cursor = 0;
51
+ do {
52
+ result += string.substring(cursor, index) + replace;
53
+ cursor = index + close.length;
54
+ index = string.indexOf(close, cursor);
55
+ } while (~index);
56
+ return result + string.substring(cursor);
57
+ };
58
+ var createColors = (enabled = isColorSupported) => {
59
+ let f = enabled ? formatter : () => String;
60
+ return {
61
+ isColorSupported: enabled,
62
+ reset: f("\x1B[0m", "\x1B[0m"),
63
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
64
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
65
+ italic: f("\x1B[3m", "\x1B[23m"),
66
+ underline: f("\x1B[4m", "\x1B[24m"),
67
+ inverse: f("\x1B[7m", "\x1B[27m"),
68
+ hidden: f("\x1B[8m", "\x1B[28m"),
69
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
70
+ black: f("\x1B[30m", "\x1B[39m"),
71
+ red: f("\x1B[31m", "\x1B[39m"),
72
+ green: f("\x1B[32m", "\x1B[39m"),
73
+ yellow: f("\x1B[33m", "\x1B[39m"),
74
+ blue: f("\x1B[34m", "\x1B[39m"),
75
+ magenta: f("\x1B[35m", "\x1B[39m"),
76
+ cyan: f("\x1B[36m", "\x1B[39m"),
77
+ white: f("\x1B[37m", "\x1B[39m"),
78
+ gray: f("\x1B[90m", "\x1B[39m"),
79
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
80
+ bgRed: f("\x1B[41m", "\x1B[49m"),
81
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
82
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
83
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
84
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
85
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
86
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
87
+ blackBright: f("\x1B[90m", "\x1B[39m"),
88
+ redBright: f("\x1B[91m", "\x1B[39m"),
89
+ greenBright: f("\x1B[92m", "\x1B[39m"),
90
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
91
+ blueBright: f("\x1B[94m", "\x1B[39m"),
92
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
93
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
94
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
95
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
96
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
97
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
98
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
99
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
100
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
101
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
102
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
103
+ };
104
+ };
105
+ module2.exports = createColors();
106
+ module2.exports.createColors = createColors;
107
+ }
108
+ });
109
+
110
+ // ../logger/dist/index.mjs
111
+ var import_picocolors = __toESM(require_picocolors());
112
+ var PEAM_LOGGING_KEY = "PEAM_LOGGING";
113
+ function readBrowserLoggingSetting() {
114
+ var _a;
115
+ try {
116
+ const g = globalThis;
117
+ if (!g.localStorage) return void 0;
118
+ return (_a = g.localStorage.getItem(PEAM_LOGGING_KEY)) != null ? _a : void 0;
119
+ } catch (e) {
120
+ return void 0;
121
+ }
122
+ }
123
+ function readServerLoggingSetting() {
124
+ try {
125
+ return typeof process !== "undefined" && typeof process.env !== "undefined" && PEAM_LOGGING_KEY in process.env ? process.env[PEAM_LOGGING_KEY] : void 0;
126
+ } catch (e) {
127
+ return void 0;
128
+ }
129
+ }
130
+ function isLoggingEnabled() {
131
+ const serverSetting = readServerLoggingSetting();
132
+ if (serverSetting !== void 0) return Boolean(serverSetting);
133
+ const browserSetting = readBrowserLoggingSetting();
134
+ if (browserSetting !== void 0) return Boolean(browserSetting);
135
+ return false;
136
+ }
137
+ function createLogger(namespace) {
138
+ return {
139
+ error: (message, ...args) => print(message, args, { namespace, color: "red" }),
140
+ warn: (message, ...args) => print(message, args, { namespace, color: "yellow" }),
141
+ debug: (message, ...args) => print(message, args, { namespace, color: "yellow" })
142
+ };
143
+ }
144
+ function print(message, args, { namespace, color = "white" }) {
145
+ var _a;
146
+ if (!isLoggingEnabled()) return;
147
+ const colorize = (_a = import_picocolors.default[color]) != null ? _a : import_picocolors.default.white;
148
+ const header = `${colorize("[Peam]")} `;
149
+ const ns = namespace ? `${import_picocolors.default.dim(namespace)} ` : "";
150
+ console.log(header + ns + colorize(String(message)), ...args);
151
+ }
152
+ var loggers = {
153
+ search: createLogger("peam:search")
154
+ };
155
+
156
+ // ../../node_modules/.pnpm/flexsearch@0.8.212/node_modules/flexsearch/dist/flexsearch.bundle.module.min.mjs
157
+ var import_meta = {};
158
+ var w;
159
+ function H(a, c, b) {
160
+ const e = typeof b, d = typeof a;
161
+ if (e !== "undefined") {
162
+ if (d !== "undefined") {
163
+ if (b) {
164
+ if (d === "function" && e === d) return function(k) {
165
+ return a(b(k));
166
+ };
167
+ c = a.constructor;
168
+ if (c === b.constructor) {
169
+ if (c === Array) return b.concat(a);
170
+ if (c === Map) {
171
+ var f = new Map(b);
172
+ for (var g of a) f.set(g[0], g[1]);
173
+ return f;
174
+ }
175
+ if (c === Set) {
176
+ g = new Set(b);
177
+ for (f of a.values()) g.add(f);
178
+ return g;
179
+ }
180
+ }
181
+ }
182
+ return a;
183
+ }
184
+ return b;
185
+ }
186
+ return d === "undefined" ? c : a;
187
+ }
188
+ function aa(a, c) {
189
+ return typeof a === "undefined" ? c : a;
190
+ }
191
+ function I() {
192
+ return /* @__PURE__ */ Object.create(null);
193
+ }
194
+ function M(a) {
195
+ return typeof a === "string";
196
+ }
197
+ function ba(a) {
198
+ return typeof a === "object";
199
+ }
200
+ function ca(a, c) {
201
+ if (M(c)) a = a[c];
202
+ else for (let b = 0; a && b < c.length; b++) a = a[c[b]];
203
+ return a;
204
+ }
205
+ var ea = /[^\p{L}\p{N}]+/u;
206
+ var fa = /(\d{3})/g;
207
+ var ha = /(\D)(\d{3})/g;
208
+ var ia = /(\d{3})(\D)/g;
209
+ var ja = /[\u0300-\u036f]/g;
210
+ function ka(a = {}) {
211
+ if (!this || this.constructor !== ka) return new ka(...arguments);
212
+ if (arguments.length) for (a = 0; a < arguments.length; a++) this.assign(arguments[a]);
213
+ else this.assign(a);
214
+ }
215
+ w = ka.prototype;
216
+ w.assign = function(a) {
217
+ this.normalize = H(a.normalize, true, this.normalize);
218
+ let c = a.include, b = c || a.exclude || a.split, e;
219
+ if (b || b === "") {
220
+ if (typeof b === "object" && b.constructor !== RegExp) {
221
+ let d = "";
222
+ e = !c;
223
+ c || (d += "\\p{Z}");
224
+ b.letter && (d += "\\p{L}");
225
+ b.number && (d += "\\p{N}", e = !!c);
226
+ b.symbol && (d += "\\p{S}");
227
+ b.punctuation && (d += "\\p{P}");
228
+ b.control && (d += "\\p{C}");
229
+ if (b = b.char) d += typeof b === "object" ? b.join("") : b;
230
+ try {
231
+ this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u");
232
+ } catch (f) {
233
+ this.split = /\s+/;
234
+ }
235
+ } else this.split = b, e = b === false || "a1a".split(b).length < 2;
236
+ this.numeric = H(a.numeric, e);
237
+ } else {
238
+ try {
239
+ this.split = H(this.split, ea);
240
+ } catch (d) {
241
+ this.split = /\s+/;
242
+ }
243
+ this.numeric = H(a.numeric, H(this.numeric, true));
244
+ }
245
+ this.prepare = H(a.prepare, null, this.prepare);
246
+ this.finalize = H(a.finalize, null, this.finalize);
247
+ b = a.filter;
248
+ this.filter = typeof b === "function" ? b : H(b && new Set(b), null, this.filter);
249
+ this.dedupe = H(a.dedupe, true, this.dedupe);
250
+ this.matcher = H((b = a.matcher) && new Map(b), null, this.matcher);
251
+ this.mapper = H((b = a.mapper) && new Map(b), null, this.mapper);
252
+ this.stemmer = H(
253
+ (b = a.stemmer) && new Map(b),
254
+ null,
255
+ this.stemmer
256
+ );
257
+ this.replacer = H(a.replacer, null, this.replacer);
258
+ this.minlength = H(a.minlength, 1, this.minlength);
259
+ this.maxlength = H(a.maxlength, 1024, this.maxlength);
260
+ this.rtl = H(a.rtl, false, this.rtl);
261
+ if (this.cache = b = H(a.cache, true, this.cache)) this.F = null, this.L = typeof b === "number" ? b : 2e5, this.B = /* @__PURE__ */ new Map(), this.D = /* @__PURE__ */ new Map(), this.I = this.H = 128;
262
+ this.h = "";
263
+ this.J = null;
264
+ this.A = "";
265
+ this.K = null;
266
+ if (this.matcher) for (const d of this.matcher.keys()) this.h += (this.h ? "|" : "") + d;
267
+ if (this.stemmer) for (const d of this.stemmer.keys()) this.A += (this.A ? "|" : "") + d;
268
+ return this;
269
+ };
270
+ w.addStemmer = function(a, c) {
271
+ this.stemmer || (this.stemmer = /* @__PURE__ */ new Map());
272
+ this.stemmer.set(a, c);
273
+ this.A += (this.A ? "|" : "") + a;
274
+ this.K = null;
275
+ this.cache && Q(this);
276
+ return this;
277
+ };
278
+ w.addFilter = function(a) {
279
+ typeof a === "function" ? this.filter = a : (this.filter || (this.filter = /* @__PURE__ */ new Set()), this.filter.add(a));
280
+ this.cache && Q(this);
281
+ return this;
282
+ };
283
+ w.addMapper = function(a, c) {
284
+ if (typeof a === "object") return this.addReplacer(a, c);
285
+ if (a.length > 1) return this.addMatcher(a, c);
286
+ this.mapper || (this.mapper = /* @__PURE__ */ new Map());
287
+ this.mapper.set(a, c);
288
+ this.cache && Q(this);
289
+ return this;
290
+ };
291
+ w.addMatcher = function(a, c) {
292
+ if (typeof a === "object") return this.addReplacer(a, c);
293
+ if (a.length < 2 && (this.dedupe || this.mapper)) return this.addMapper(a, c);
294
+ this.matcher || (this.matcher = /* @__PURE__ */ new Map());
295
+ this.matcher.set(a, c);
296
+ this.h += (this.h ? "|" : "") + a;
297
+ this.J = null;
298
+ this.cache && Q(this);
299
+ return this;
300
+ };
301
+ w.addReplacer = function(a, c) {
302
+ if (typeof a === "string") return this.addMatcher(a, c);
303
+ this.replacer || (this.replacer = []);
304
+ this.replacer.push(a, c);
305
+ this.cache && Q(this);
306
+ return this;
307
+ };
308
+ w.encode = function(a, c) {
309
+ if (this.cache && a.length <= this.H) if (this.F) {
310
+ if (this.B.has(a)) return this.B.get(a);
311
+ } else this.F = setTimeout(Q, 50, this);
312
+ this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase());
313
+ this.prepare && (a = this.prepare(a));
314
+ this.numeric && a.length > 3 && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 "));
315
+ const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer);
316
+ let e = [], d = I(), f, g, k = this.split || this.split === "" ? a.split(this.split) : [a];
317
+ for (let l = 0, m, p; l < k.length; l++) if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) {
318
+ if (c) {
319
+ if (d[m]) continue;
320
+ d[m] = 1;
321
+ } else {
322
+ if (f === m) continue;
323
+ f = m;
324
+ }
325
+ if (b) e.push(m);
326
+ else if (!this.filter || (typeof this.filter === "function" ? this.filter(m) : !this.filter.has(m))) {
327
+ if (this.cache && m.length <= this.I) if (this.F) {
328
+ var h = this.D.get(m);
329
+ if (h || h === "") {
330
+ h && e.push(h);
331
+ continue;
332
+ }
333
+ } else this.F = setTimeout(Q, 50, this);
334
+ if (this.stemmer) {
335
+ this.K || (this.K = new RegExp("(?!^)(" + this.A + ")$"));
336
+ let u;
337
+ for (; u !== m && m.length > 2; ) u = m, m = m.replace(this.K, (r) => this.stemmer.get(r));
338
+ }
339
+ if (m && (this.mapper || this.dedupe && m.length > 1)) {
340
+ h = "";
341
+ for (let u = 0, r = "", t, n; u < m.length; u++) t = m.charAt(u), t === r && this.dedupe || ((n = this.mapper && this.mapper.get(t)) || n === "" ? n === r && this.dedupe || !(r = n) || (h += n) : h += r = t);
342
+ m = h;
343
+ }
344
+ this.matcher && m.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.J, (u) => this.matcher.get(u)));
345
+ if (m && this.replacer) for (h = 0; m && h < this.replacer.length; h += 2) m = m.replace(
346
+ this.replacer[h],
347
+ this.replacer[h + 1]
348
+ );
349
+ this.cache && p.length <= this.I && (this.D.set(p, m), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0));
350
+ if (m) {
351
+ if (m !== p) if (c) {
352
+ if (d[m]) continue;
353
+ d[m] = 1;
354
+ } else {
355
+ if (g === m) continue;
356
+ g = m;
357
+ }
358
+ e.push(m);
359
+ }
360
+ }
361
+ }
362
+ this.finalize && (e = this.finalize(e) || e);
363
+ this.cache && a.length <= this.H && (this.B.set(a, e), this.B.size > this.L && (this.B.clear(), this.H = this.H / 1.1 | 0));
364
+ return e;
365
+ };
366
+ function Q(a) {
367
+ a.F = null;
368
+ a.B.clear();
369
+ a.D.clear();
370
+ }
371
+ function la(a, c, b) {
372
+ b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : b = a);
373
+ b && (a = b.query || a, c = b.limit || c);
374
+ let e = "" + (c || 0);
375
+ b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (b.resolve !== false) + (b.resolution || this.resolution) + (b.boost || 0));
376
+ a = ("" + a).toLowerCase();
377
+ this.cache || (this.cache = new ma());
378
+ let d = this.cache.get(a + e);
379
+ if (!d) {
380
+ const f = b && b.cache;
381
+ f && (b.cache = false);
382
+ d = this.search(a, c, b);
383
+ f && (b.cache = f);
384
+ this.cache.set(a + e, d);
385
+ }
386
+ return d;
387
+ }
388
+ function ma(a) {
389
+ this.limit = a && a !== true ? a : 1e3;
390
+ this.cache = /* @__PURE__ */ new Map();
391
+ this.h = "";
392
+ }
393
+ ma.prototype.set = function(a, c) {
394
+ this.cache.set(this.h = a, c);
395
+ this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value);
396
+ };
397
+ ma.prototype.get = function(a) {
398
+ const c = this.cache.get(a);
399
+ c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c));
400
+ return c;
401
+ };
402
+ ma.prototype.remove = function(a) {
403
+ for (const c of this.cache) {
404
+ const b = c[0];
405
+ c[1].includes(a) && this.cache.delete(b);
406
+ }
407
+ };
408
+ ma.prototype.clear = function() {
409
+ this.cache.clear();
410
+ this.h = "";
411
+ };
412
+ var na = { normalize: false, numeric: false, dedupe: false };
413
+ var oa = {};
414
+ var ra = /* @__PURE__ */ new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]);
415
+ var sa = /* @__PURE__ */ new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]);
416
+ var ta = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"];
417
+ var ua = { a: "", e: "", i: "", o: "", u: "", y: "", b: 1, f: 1, p: 1, v: 1, c: 2, g: 2, j: 2, k: 2, q: 2, s: 2, x: 2, z: 2, "\xDF": 2, d: 3, t: 3, l: 4, m: 5, n: 5, r: 6 };
418
+ var va = { Exact: na, Default: oa, Normalize: oa, LatinBalance: { mapper: ra }, LatinAdvanced: { mapper: ra, matcher: sa, replacer: ta }, LatinExtra: { mapper: ra, replacer: ta.concat([/(?!^)[aeo]/g, ""]), matcher: sa }, LatinSoundex: { dedupe: false, include: { letter: true }, finalize: function(a) {
419
+ for (let b = 0; b < a.length; b++) {
420
+ var c = a[b];
421
+ let e = c.charAt(0), d = ua[e];
422
+ for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = ua[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) ;
423
+ a[b] = e;
424
+ }
425
+ } }, CJK: { split: "" }, LatinExact: na, LatinDefault: oa, LatinSimple: oa };
426
+ function wa(a, c, b, e) {
427
+ let d = [];
428
+ for (let f = 0, g; f < a.index.length; f++) if (g = a.index[f], c >= g.length) c -= g.length;
429
+ else {
430
+ c = g[e ? "splice" : "slice"](c, b);
431
+ const k = c.length;
432
+ if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) break;
433
+ c = 0;
434
+ }
435
+ return d;
436
+ }
437
+ function xa(a) {
438
+ if (!this || this.constructor !== xa) return new xa(a);
439
+ this.index = a ? [a] : [];
440
+ this.length = a ? a.length : 0;
441
+ const c = this;
442
+ return new Proxy([], { get(b, e) {
443
+ if (e === "length") return c.length;
444
+ if (e === "push") return function(d) {
445
+ c.index[c.index.length - 1].push(d);
446
+ c.length++;
447
+ };
448
+ if (e === "pop") return function() {
449
+ if (c.length) return c.length--, c.index[c.index.length - 1].pop();
450
+ };
451
+ if (e === "indexOf") return function(d) {
452
+ let f = 0;
453
+ for (let g = 0, k, h; g < c.index.length; g++) {
454
+ k = c.index[g];
455
+ h = k.indexOf(d);
456
+ if (h >= 0) return f + h;
457
+ f += k.length;
458
+ }
459
+ return -1;
460
+ };
461
+ if (e === "includes") return function(d) {
462
+ for (let f = 0; f < c.index.length; f++) if (c.index[f].includes(d)) return true;
463
+ return false;
464
+ };
465
+ if (e === "slice") return function(d, f) {
466
+ return wa(c, d || 0, f || c.length, false);
467
+ };
468
+ if (e === "splice") return function(d, f) {
469
+ return wa(c, d || 0, f || c.length, true);
470
+ };
471
+ if (e === "constructor") return Array;
472
+ if (typeof e !== "symbol") return (b = c.index[e / 2 ** 31 | 0]) && b[e];
473
+ }, set(b, e, d) {
474
+ b = e / 2 ** 31 | 0;
475
+ (c.index[b] || (c.index[b] = []))[e] = d;
476
+ c.length++;
477
+ return true;
478
+ } });
479
+ }
480
+ xa.prototype.clear = function() {
481
+ this.index.length = 0;
482
+ };
483
+ xa.prototype.push = function() {
484
+ };
485
+ function R(a = 8) {
486
+ if (!this || this.constructor !== R) return new R(a);
487
+ this.index = I();
488
+ this.h = [];
489
+ this.size = 0;
490
+ a > 32 ? (this.B = Aa, this.A = BigInt(a)) : (this.B = Ba, this.A = a);
491
+ }
492
+ R.prototype.get = function(a) {
493
+ const c = this.index[this.B(a)];
494
+ return c && c.get(a);
495
+ };
496
+ R.prototype.set = function(a, c) {
497
+ var b = this.B(a);
498
+ let e = this.index[b];
499
+ e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = /* @__PURE__ */ new Map([[a, c]]), this.h.push(e), this.size++);
500
+ };
501
+ function S(a = 8) {
502
+ if (!this || this.constructor !== S) return new S(a);
503
+ this.index = I();
504
+ this.h = [];
505
+ this.size = 0;
506
+ a > 32 ? (this.B = Aa, this.A = BigInt(a)) : (this.B = Ba, this.A = a);
507
+ }
508
+ S.prototype.add = function(a) {
509
+ var c = this.B(a);
510
+ let b = this.index[c];
511
+ b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = /* @__PURE__ */ new Set([a]), this.h.push(b), this.size++);
512
+ };
513
+ w = R.prototype;
514
+ w.has = S.prototype.has = function(a) {
515
+ const c = this.index[this.B(a)];
516
+ return c && c.has(a);
517
+ };
518
+ w.delete = S.prototype.delete = function(a) {
519
+ const c = this.index[this.B(a)];
520
+ c && c.delete(a) && this.size--;
521
+ };
522
+ w.clear = S.prototype.clear = function() {
523
+ this.index = I();
524
+ this.h = [];
525
+ this.size = 0;
526
+ };
527
+ w.values = S.prototype.values = function* () {
528
+ for (let a = 0; a < this.h.length; a++) for (let c of this.h[a].values()) yield c;
529
+ };
530
+ w.keys = S.prototype.keys = function* () {
531
+ for (let a = 0; a < this.h.length; a++) for (let c of this.h[a].keys()) yield c;
532
+ };
533
+ w.entries = S.prototype.entries = function* () {
534
+ for (let a = 0; a < this.h.length; a++) for (let c of this.h[a].entries()) yield c;
535
+ };
536
+ function Ba(a) {
537
+ let c = 2 ** this.A - 1;
538
+ if (typeof a == "number") return a & c;
539
+ let b = 0, e = this.A + 1;
540
+ for (let d = 0; d < a.length; d++) b = (b * e ^ a.charCodeAt(d)) & c;
541
+ return this.A === 32 ? b + 2 ** 31 : b;
542
+ }
543
+ function Aa(a) {
544
+ let c = BigInt(2) ** this.A - BigInt(1);
545
+ var b = typeof a;
546
+ if (b === "bigint") return a & c;
547
+ if (b === "number") return BigInt(a) & c;
548
+ b = BigInt(0);
549
+ let e = this.A + BigInt(1);
550
+ for (let d = 0; d < a.length; d++) b = (b * e ^ BigInt(a.charCodeAt(d))) & c;
551
+ return b;
552
+ }
553
+ var Ca;
554
+ var Da;
555
+ async function Ea(a) {
556
+ a = a.data;
557
+ var c = a.task;
558
+ const b = a.id;
559
+ let e = a.args;
560
+ switch (c) {
561
+ case "init":
562
+ Da = a.options || {};
563
+ (c = a.factory) ? (Function("return " + c)()(self), Ca = new self.FlexSearch.Index(Da), delete self.FlexSearch) : Ca = new T(Da);
564
+ postMessage({ id: b });
565
+ break;
566
+ default:
567
+ let d;
568
+ c === "export" && (e[1] ? (e[0] = Da.export, e[2] = 0, e[3] = 1) : e = null);
569
+ c === "import" ? e[0] && (a = await Da.import.call(Ca, e[0]), Ca.import(e[0], a)) : ((d = e && Ca[c].apply(Ca, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result));
570
+ postMessage(c === "search" ? { id: b, msg: d } : { id: b });
571
+ }
572
+ }
573
+ function Fa(a) {
574
+ Ga.call(a, "add");
575
+ Ga.call(a, "append");
576
+ Ga.call(a, "search");
577
+ Ga.call(a, "update");
578
+ Ga.call(a, "remove");
579
+ Ga.call(a, "searchCache");
580
+ }
581
+ var Ha;
582
+ var Ia;
583
+ var Ja;
584
+ function Ka() {
585
+ Ha = Ja = 0;
586
+ }
587
+ function Ga(a) {
588
+ this[a + "Async"] = function() {
589
+ const c = arguments;
590
+ var b = c[c.length - 1];
591
+ let e;
592
+ typeof b === "function" && (e = b, delete c[c.length - 1]);
593
+ Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now());
594
+ if (Ja) {
595
+ const f = this;
596
+ return new Promise((g) => {
597
+ setTimeout(function() {
598
+ g(f[a + "Async"].apply(f, c));
599
+ }, 0);
600
+ });
601
+ }
602
+ const d = this[a].apply(this, c);
603
+ b = d.then ? d : new Promise((f) => f(d));
604
+ e && b.then(e);
605
+ return b;
606
+ };
607
+ }
608
+ var V = 0;
609
+ function La(a = {}, c) {
610
+ function b(k) {
611
+ function h(l) {
612
+ l = l.data || l;
613
+ const m = l.id, p = m && f.h[m];
614
+ p && (p(l.msg), delete f.h[m]);
615
+ }
616
+ this.worker = k;
617
+ this.h = I();
618
+ if (this.worker) {
619
+ d ? this.worker.on("message", h) : this.worker.onmessage = h;
620
+ if (a.config) return new Promise(function(l) {
621
+ V > 1e9 && (V = 0);
622
+ f.h[++V] = function() {
623
+ l(f);
624
+ };
625
+ f.worker.postMessage({ id: V, task: "init", factory: e, options: a });
626
+ });
627
+ this.priority = a.priority || 4;
628
+ this.encoder = c || null;
629
+ this.worker.postMessage({ task: "init", factory: e, options: a });
630
+ return this;
631
+ }
632
+ }
633
+ if (!this || this.constructor !== La) return new La(a);
634
+ let e = typeof self !== "undefined" ? self._factory : typeof window !== "undefined" ? window._factory : null;
635
+ e && (e = e.toString());
636
+ const d = typeof window === "undefined", f = this, g = Ma(e, d, a.worker);
637
+ return g.then ? g.then(function(k) {
638
+ return b.call(f, k);
639
+ }) : b.call(this, g);
640
+ }
641
+ W("add");
642
+ W("append");
643
+ W("search");
644
+ W("update");
645
+ W("remove");
646
+ W("clear");
647
+ W("export");
648
+ W("import");
649
+ La.prototype.searchCache = la;
650
+ Fa(La.prototype);
651
+ function W(a) {
652
+ La.prototype[a] = function() {
653
+ const c = this, b = [].slice.call(arguments);
654
+ var e = b[b.length - 1];
655
+ let d;
656
+ typeof e === "function" && (d = e, b.pop());
657
+ e = new Promise(function(f) {
658
+ a === "export" && typeof b[0] === "function" && (b[0] = null);
659
+ V > 1e9 && (V = 0);
660
+ c.h[++V] = f;
661
+ c.worker.postMessage({ task: a, id: V, args: b });
662
+ });
663
+ return d ? (e.then(d), this) : e;
664
+ };
665
+ }
666
+ function Ma(a, c, b) {
667
+ return c ? typeof module !== "undefined" ? new (__require("worker_threads"))["Worker"](__dirname + "/worker/node.js") : import('worker_threads').then(function(worker) {
668
+ return new worker["Worker"](import_meta.dirname + "/node/node.mjs");
669
+ }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], { type: "text/javascript" }))) : new window.Worker(typeof b === "string" ? b : import_meta.url.replace("/worker.js", "/worker/worker.js").replace(
670
+ "flexsearch.bundle.module.min.js",
671
+ "module/worker/worker.js"
672
+ ).replace("flexsearch.bundle.module.min.mjs", "module/worker/worker.js"), { type: "module" });
673
+ }
674
+ Na.prototype.add = function(a, c, b) {
675
+ ba(a) && (c = a, a = ca(c, this.key));
676
+ if (c && (a || a === 0)) {
677
+ if (!b && this.reg.has(a)) return this.update(a, c);
678
+ for (let k = 0, h; k < this.field.length; k++) {
679
+ h = this.B[k];
680
+ var e = this.index.get(this.field[k]);
681
+ if (typeof h === "function") {
682
+ var d = h(c);
683
+ d && e.add(a, d, b, true);
684
+ } else if (d = h.G, !d || d(c)) h.constructor === String ? h = ["" + h] : M(h) && (h = [h]), Qa(c, h, this.D, 0, e, a, h[0], b);
685
+ }
686
+ if (this.tag) for (e = 0; e < this.A.length; e++) {
687
+ var f = this.A[e];
688
+ d = this.tag.get(this.F[e]);
689
+ let k = I();
690
+ if (typeof f === "function") {
691
+ if (f = f(c), !f) continue;
692
+ } else {
693
+ var g = f.G;
694
+ if (g && !g(c)) continue;
695
+ f.constructor === String && (f = "" + f);
696
+ f = ca(c, f);
697
+ }
698
+ if (d && f) {
699
+ M(f) && (f = [f]);
700
+ for (let h = 0, l, m; h < f.length; h++) if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) {
701
+ if (m.length === 2 ** 31 - 1) {
702
+ g = new xa(m);
703
+ if (this.fastupdate) for (let p of this.reg.values()) p.includes(m) && (p[p.indexOf(m)] = g);
704
+ d.set(l, m = g);
705
+ }
706
+ m.push(a);
707
+ this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m]));
708
+ }
709
+ }
710
+ }
711
+ if (this.store && (!b || !this.store.has(a))) {
712
+ let k;
713
+ if (this.h) {
714
+ k = I();
715
+ for (let h = 0, l; h < this.h.length; h++) {
716
+ l = this.h[h];
717
+ if ((b = l.G) && !b(c)) continue;
718
+ let m;
719
+ if (typeof l === "function") {
720
+ m = l(c);
721
+ if (!m) continue;
722
+ l = [l.O];
723
+ } else if (M(l) || l.constructor === String) {
724
+ k[l] = c[l];
725
+ continue;
726
+ }
727
+ Ra(c, k, l, 0, l[0], m);
728
+ }
729
+ }
730
+ this.store.set(a, k || c);
731
+ }
732
+ this.worker && (this.fastupdate || this.reg.add(a));
733
+ }
734
+ return this;
735
+ };
736
+ function Ra(a, c, b, e, d, f) {
737
+ a = a[d];
738
+ if (e === b.length - 1) c[d] = f || a;
739
+ else if (a) if (a.constructor === Array) for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) Ra(a, c, b, e, d);
740
+ else c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d);
741
+ }
742
+ function Qa(a, c, b, e, d, f, g, k) {
743
+ if (a = a[g]) if (e === c.length - 1) {
744
+ if (a.constructor === Array) {
745
+ if (b[e]) {
746
+ for (c = 0; c < a.length; c++) d.add(f, a[c], true, true);
747
+ return;
748
+ }
749
+ a = a.join(" ");
750
+ }
751
+ d.add(f, a, k, true);
752
+ } else if (a.constructor === Array) for (g = 0; g < a.length; g++) Qa(a, c, b, e, d, f, g, k);
753
+ else g = c[++e], Qa(a, c, b, e, d, f, g, k);
754
+ }
755
+ function Sa(a, c, b, e) {
756
+ if (!a.length) return a;
757
+ if (a.length === 1) return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a;
758
+ let d = [];
759
+ for (let f = 0, g, k; f < a.length; f++) if ((g = a[f]) && (k = g.length)) {
760
+ if (b) {
761
+ if (b >= k) {
762
+ b -= k;
763
+ continue;
764
+ }
765
+ g = g.slice(b, b + c);
766
+ k = g.length;
767
+ b = 0;
768
+ }
769
+ k > c && (g = g.slice(0, c), k = c);
770
+ if (!d.length && k >= c) return e ? Ta.call(this, g) : g;
771
+ d.push(g);
772
+ c -= k;
773
+ if (!c) break;
774
+ }
775
+ d = d.length > 1 ? [].concat.apply([], d) : d[0];
776
+ return e ? Ta.call(this, d) : d;
777
+ }
778
+ function Ua(a, c, b, e) {
779
+ var d = e[0];
780
+ if (d[0] && d[0].query) return a[c].apply(a, d);
781
+ if (!(c !== "and" && c !== "not" || a.result.length || a.await || d.suggest)) return e.length > 1 && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a;
782
+ let f = [], g = 0, k = 0, h, l, m, p, u;
783
+ for (c = 0; c < e.length; c++) if (d = e[c]) {
784
+ var r = void 0;
785
+ if (d.constructor === X) r = d.await || d.result;
786
+ else if (d.then || d.constructor === Array) r = d;
787
+ else {
788
+ g = d.limit || 0;
789
+ k = d.offset || 0;
790
+ m = d.suggest;
791
+ l = d.resolve;
792
+ h = ((p = d.highlight || a.highlight) || d.enrich) && l;
793
+ r = d.queue;
794
+ let t = d.async || r, n = d.index, q = d.query;
795
+ n ? a.index || (a.index = n) : n = a.index;
796
+ if (q || d.tag) {
797
+ const x = d.field || d.pluck;
798
+ x && (!q || a.query && !p || (a.query = q, a.field = x, a.highlight = p), n = n.index.get(x));
799
+ if (r && (u || a.await)) {
800
+ u = 1;
801
+ let v;
802
+ const A = a.C.length, D = new Promise(function(F) {
803
+ v = F;
804
+ });
805
+ (function(F, E) {
806
+ D.h = function() {
807
+ E.index = null;
808
+ E.resolve = false;
809
+ let B = t ? F.searchAsync(E) : F.search(E);
810
+ if (B.then) return B.then(function(z) {
811
+ a.C[A] = z = z.result || z;
812
+ v(z);
813
+ return z;
814
+ });
815
+ B = B.result || B;
816
+ v(B);
817
+ return B;
818
+ };
819
+ })(n, Object.assign({}, d));
820
+ a.C.push(D);
821
+ f[c] = D;
822
+ continue;
823
+ } else d.resolve = false, d.index = null, r = t ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n;
824
+ } else if (d.and) r = Va(d, "and", n);
825
+ else if (d.or) r = Va(d, "or", n);
826
+ else if (d.not) r = Va(d, "not", n);
827
+ else if (d.xor) r = Va(d, "xor", n);
828
+ else continue;
829
+ }
830
+ r.await ? (u = 1, r = r.await) : r.then ? (u = 1, r = r.then(function(t) {
831
+ return t.result || t;
832
+ })) : r = r.result || r;
833
+ f[c] = r;
834
+ }
835
+ u && !a.await && (a.await = new Promise(function(t) {
836
+ a.return = t;
837
+ }));
838
+ if (u) {
839
+ const t = Promise.all(f).then(function(n) {
840
+ for (let q = 0; q < a.C.length; q++) if (a.C[q] === t) {
841
+ a.C[q] = function() {
842
+ return b.call(a, n, g, k, h, l, m, p);
843
+ };
844
+ break;
845
+ }
846
+ Wa(a);
847
+ });
848
+ a.C.push(t);
849
+ } else if (a.await) a.C.push(function() {
850
+ return b.call(a, f, g, k, h, l, m, p);
851
+ });
852
+ else return b.call(a, f, g, k, h, l, m, p);
853
+ return l ? a.await || a.result : a;
854
+ }
855
+ function Va(a, c, b) {
856
+ a = a[c];
857
+ const e = a[0] || a;
858
+ e.index || (e.index = b);
859
+ b = new X(e);
860
+ a.length > 1 && (b = b[c].apply(b, a.slice(1)));
861
+ return b;
862
+ }
863
+ X.prototype.or = function() {
864
+ return Ua(this, "or", Xa, arguments);
865
+ };
866
+ function Xa(a, c, b, e, d, f, g) {
867
+ a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Ya(a, c, b, false, this.h), b = 0));
868
+ d && (this.await = null);
869
+ return d ? this.resolve(c, b, e, g) : this;
870
+ }
871
+ X.prototype.and = function() {
872
+ return Ua(this, "and", Za, arguments);
873
+ };
874
+ function Za(a, c, b, e, d, f, g) {
875
+ if (!f && !this.result.length) return d ? this.result : this;
876
+ let k;
877
+ if (a.length) if (this.result.length && a.unshift(this.result), a.length < 2) this.result = a[0];
878
+ else {
879
+ let h = 0;
880
+ for (let l = 0, m, p; l < a.length; l++) if ((m = a[l]) && (p = m.length)) h < p && (h = p);
881
+ else if (!f) {
882
+ h = 0;
883
+ break;
884
+ }
885
+ h ? (this.result = $a(a, h, c, b, f, this.h, d), k = true) : this.result = [];
886
+ }
887
+ else f || (this.result = a);
888
+ d && (this.await = null);
889
+ return d ? this.resolve(c, b, e, g, k) : this;
890
+ }
891
+ X.prototype.xor = function() {
892
+ return Ua(this, "xor", ab, arguments);
893
+ };
894
+ function ab(a, c, b, e, d, f, g) {
895
+ if (a.length) if (this.result.length && a.unshift(this.result), a.length < 2) this.result = a[0];
896
+ else {
897
+ a: {
898
+ f = b;
899
+ var k = this.h;
900
+ const h = [], l = I();
901
+ let m = 0;
902
+ for (let p = 0, u; p < a.length; p++) if (u = a[p]) {
903
+ m < u.length && (m = u.length);
904
+ for (let r = 0, t; r < u.length; r++) if (t = u[r]) for (let n = 0, q; n < t.length; n++) q = t[n], l[q] = l[q] ? 2 : 1;
905
+ }
906
+ for (let p = 0, u, r = 0; p < m; p++) for (let t = 0, n; t < a.length; t++) if (n = a[t]) {
907
+ if (u = n[p]) {
908
+ for (let q = 0, x; q < u.length; q++) if (x = u[q], l[x] === 1) if (f) f--;
909
+ else if (d) {
910
+ if (h.push(x), h.length === c) {
911
+ a = h;
912
+ break a;
913
+ }
914
+ } else {
915
+ const v = p + (t ? k : 0);
916
+ h[v] || (h[v] = []);
917
+ h[v].push(x);
918
+ if (++r === c) {
919
+ a = h;
920
+ break a;
921
+ }
922
+ }
923
+ }
924
+ }
925
+ a = h;
926
+ }
927
+ this.result = a;
928
+ k = true;
929
+ }
930
+ else f || (this.result = a);
931
+ d && (this.await = null);
932
+ return d ? this.resolve(c, b, e, g, k) : this;
933
+ }
934
+ X.prototype.not = function() {
935
+ return Ua(this, "not", bb, arguments);
936
+ };
937
+ function bb(a, c, b, e, d, f, g) {
938
+ if (!f && !this.result.length) return d ? this.result : this;
939
+ if (a.length && this.result.length) {
940
+ a: {
941
+ f = b;
942
+ var k = [];
943
+ a = new Set(a.flat().flat());
944
+ for (let h = 0, l, m = 0; h < this.result.length; h++) if (l = this.result[h]) {
945
+ for (let p = 0, u; p < l.length; p++) if (u = l[p], !a.has(u)) {
946
+ if (f) f--;
947
+ else if (d) {
948
+ if (k.push(u), k.length === c) {
949
+ a = k;
950
+ break a;
951
+ }
952
+ } else if (k[h] || (k[h] = []), k[h].push(u), ++m === c) {
953
+ a = k;
954
+ break a;
955
+ }
956
+ }
957
+ }
958
+ a = k;
959
+ }
960
+ this.result = a;
961
+ k = true;
962
+ }
963
+ d && (this.await = null);
964
+ return d ? this.resolve(c, b, e, g, k) : this;
965
+ }
966
+ function cb(a, c, b, e, d) {
967
+ let f, g, k;
968
+ typeof d === "string" ? (f = d, d = "") : f = d.template;
969
+ g = f.indexOf("$1");
970
+ k = f.substring(g + 2);
971
+ g = f.substring(0, g);
972
+ let h = d && d.boundary, l = !d || d.clip !== false, m = d && d.merge && k && g && new RegExp(k + " " + g, "g");
973
+ d = d && d.ellipsis;
974
+ var p = 0;
975
+ if (typeof d === "object") {
976
+ var u = d.template;
977
+ p = u.length - 2;
978
+ d = d.pattern;
979
+ }
980
+ typeof d !== "string" && (d = d === false ? "" : "...");
981
+ p && (d = u.replace("$1", d));
982
+ u = d.length - p;
983
+ let r, t;
984
+ typeof h === "object" && (r = h.before, r === 0 && (r = -1), t = h.after, t === 0 && (t = -1), h = h.total || 9e5);
985
+ p = /* @__PURE__ */ new Map();
986
+ for (let Oa = 0, da, db, pa; Oa < c.length; Oa++) {
987
+ let qa;
988
+ if (e) qa = c, pa = e;
989
+ else {
990
+ var n = c[Oa];
991
+ pa = n.field;
992
+ if (!pa) continue;
993
+ qa = n.result;
994
+ }
995
+ db = b.get(pa);
996
+ da = db.encoder;
997
+ n = p.get(da);
998
+ typeof n !== "string" && (n = da.encode(a), p.set(da, n));
999
+ for (let ya = 0; ya < qa.length; ya++) {
1000
+ var q = qa[ya].doc;
1001
+ if (!q) continue;
1002
+ q = ca(q, pa);
1003
+ if (!q) continue;
1004
+ var x = q.trim().split(/\s+/);
1005
+ if (!x.length) continue;
1006
+ q = "";
1007
+ var v = [];
1008
+ let za = [];
1009
+ var A = -1, D = -1, F = 0;
1010
+ for (var E = 0; E < x.length; E++) {
1011
+ var B = x[E], z = da.encode(B);
1012
+ z = z.length > 1 ? z.join(" ") : z[0];
1013
+ let y;
1014
+ if (z && B) {
1015
+ var C = B.length, J = (da.split ? B.replace(da.split, "") : B).length - z.length, G = "", N = 0;
1016
+ for (var O = 0; O < n.length; O++) {
1017
+ var P = n[O];
1018
+ if (P) {
1019
+ var L = P.length;
1020
+ L += J < 0 ? 0 : J;
1021
+ N && L <= N || (P = z.indexOf(P), P > -1 && (G = (P ? B.substring(0, P) : "") + g + B.substring(P, P + L) + k + (P + L < C ? B.substring(P + L) : ""), N = L, y = true));
1022
+ }
1023
+ }
1024
+ G && (h && (A < 0 && (A = q.length + (q ? 1 : 0)), D = q.length + (q ? 1 : 0) + G.length, F += C, za.push(v.length), v.push({ match: G })), q += (q ? " " : "") + G);
1025
+ }
1026
+ if (!y) B = x[E], q += (q ? " " : "") + B, h && v.push({ text: B });
1027
+ else if (h && F >= h) break;
1028
+ }
1029
+ F = za.length * (f.length - 2);
1030
+ if (r || t || h && q.length - F > h) if (F = h + F - u * 2, E = D - A, r > 0 && (E += r), t > 0 && (E += t), E <= F) x = r ? A - (r > 0 ? r : 0) : A - ((F - E) / 2 | 0), v = t ? D + (t > 0 ? t : 0) : x + F, l || (x > 0 && q.charAt(x) !== " " && q.charAt(x - 1) !== " " && (x = q.indexOf(" ", x), x < 0 && (x = 0)), v < q.length && q.charAt(v - 1) !== " " && q.charAt(v) !== " " && (v = q.lastIndexOf(" ", v), v < D ? v = D : ++v)), q = (x ? d : "") + q.substring(x, v) + (v < q.length ? d : "");
1031
+ else {
1032
+ D = [];
1033
+ A = {};
1034
+ F = {};
1035
+ E = {};
1036
+ B = {};
1037
+ z = {};
1038
+ G = J = C = 0;
1039
+ for (O = N = 1; ; ) {
1040
+ var U = void 0;
1041
+ for (let y = 0, K; y < za.length; y++) {
1042
+ K = za[y];
1043
+ if (G) if (J !== G) {
1044
+ if (E[y + 1]) continue;
1045
+ K += G;
1046
+ if (A[K]) {
1047
+ C -= u;
1048
+ F[y + 1] = 1;
1049
+ E[y + 1] = 1;
1050
+ continue;
1051
+ }
1052
+ if (K >= v.length - 1) {
1053
+ if (K >= v.length) {
1054
+ E[y + 1] = 1;
1055
+ K >= x.length && (F[y + 1] = 1);
1056
+ continue;
1057
+ }
1058
+ C -= u;
1059
+ }
1060
+ q = v[K].text;
1061
+ if (L = t && z[y]) if (L > 0) {
1062
+ if (q.length > L) if (E[y + 1] = 1, l) q = q.substring(0, L);
1063
+ else continue;
1064
+ (L -= q.length) || (L = -1);
1065
+ z[y] = L;
1066
+ } else {
1067
+ E[y + 1] = 1;
1068
+ continue;
1069
+ }
1070
+ if (C + q.length + 1 <= h) q = " " + q, D[y] += q;
1071
+ else if (l) U = h - C - 1, U > 0 && (q = " " + q.substring(0, U), D[y] += q), E[y + 1] = 1;
1072
+ else {
1073
+ E[y + 1] = 1;
1074
+ continue;
1075
+ }
1076
+ } else {
1077
+ if (E[y]) continue;
1078
+ K -= J;
1079
+ if (A[K]) {
1080
+ C -= u;
1081
+ E[y] = 1;
1082
+ F[y] = 1;
1083
+ continue;
1084
+ }
1085
+ if (K <= 0) {
1086
+ if (K < 0) {
1087
+ E[y] = 1;
1088
+ F[y] = 1;
1089
+ continue;
1090
+ }
1091
+ C -= u;
1092
+ }
1093
+ q = v[K].text;
1094
+ if (L = r && B[y]) if (L > 0) {
1095
+ if (q.length > L) if (E[y] = 1, l) q = q.substring(q.length - L);
1096
+ else continue;
1097
+ (L -= q.length) || (L = -1);
1098
+ B[y] = L;
1099
+ } else {
1100
+ E[y] = 1;
1101
+ continue;
1102
+ }
1103
+ if (C + q.length + 1 <= h) q += " ", D[y] = q + D[y];
1104
+ else if (l) U = q.length + 1 - (h - C), U >= 0 && U < q.length && (q = q.substring(U) + " ", D[y] = q + D[y]), E[y] = 1;
1105
+ else {
1106
+ E[y] = 1;
1107
+ continue;
1108
+ }
1109
+ }
1110
+ else {
1111
+ q = v[K].match;
1112
+ r && (B[y] = r);
1113
+ t && (z[y] = t);
1114
+ y && C++;
1115
+ let Pa;
1116
+ K ? !y && u && (C += u) : (F[y] = 1, E[y] = 1);
1117
+ K >= x.length - 1 ? Pa = 1 : K < v.length - 1 && v[K + 1].match ? Pa = 1 : u && (C += u);
1118
+ C -= f.length - 2;
1119
+ if (!y || C + q.length <= h) D[y] = q;
1120
+ else {
1121
+ U = N = O = F[y] = 0;
1122
+ break;
1123
+ }
1124
+ Pa && (F[y + 1] = 1, E[y + 1] = 1);
1125
+ }
1126
+ C += q.length;
1127
+ U = A[K] = 1;
1128
+ }
1129
+ if (U) J === G ? G++ : J++;
1130
+ else {
1131
+ J === G ? N = 0 : O = 0;
1132
+ if (!N && !O) break;
1133
+ N ? (J++, G = J) : G++;
1134
+ }
1135
+ }
1136
+ q = "";
1137
+ for (let y = 0, K; y < D.length; y++) K = (F[y] ? y ? " " : "" : (y && !d ? " " : "") + d) + D[y], q += K;
1138
+ d && !F[D.length] && (q += d);
1139
+ }
1140
+ m && (q = q.replace(m, " "));
1141
+ qa[ya].highlight = q;
1142
+ }
1143
+ if (e) break;
1144
+ }
1145
+ return c;
1146
+ }
1147
+ function X(a, c) {
1148
+ if (!this || this.constructor !== X) return new X(a, c);
1149
+ let b = 0, e, d, f, g, k, h;
1150
+ if (a && a.index) {
1151
+ const l = a;
1152
+ c = l.index;
1153
+ b = l.boost || 0;
1154
+ if (d = l.query) {
1155
+ f = l.field || l.pluck;
1156
+ g = l.highlight;
1157
+ const m = l.resolve;
1158
+ a = l.async || l.queue;
1159
+ l.resolve = false;
1160
+ l.index = null;
1161
+ a = a ? c.searchAsync(l) : c.search(l);
1162
+ l.resolve = m;
1163
+ l.index = c;
1164
+ a = a.result || a;
1165
+ } else a = [];
1166
+ }
1167
+ if (a && a.then) {
1168
+ const l = this;
1169
+ a = a.then(function(m) {
1170
+ l.C[0] = l.result = m.result || m;
1171
+ Wa(l);
1172
+ });
1173
+ e = [a];
1174
+ a = [];
1175
+ k = new Promise(function(m) {
1176
+ h = m;
1177
+ });
1178
+ }
1179
+ this.index = c || null;
1180
+ this.result = a || [];
1181
+ this.h = b;
1182
+ this.C = e || [];
1183
+ this.await = k || null;
1184
+ this.return = h || null;
1185
+ this.highlight = g || null;
1186
+ this.query = d || "";
1187
+ this.field = f || "";
1188
+ }
1189
+ w = X.prototype;
1190
+ w.limit = function(a) {
1191
+ if (this.await) {
1192
+ const c = this;
1193
+ this.C.push(function() {
1194
+ return c.limit(a).result;
1195
+ });
1196
+ } else if (this.result.length) {
1197
+ const c = [];
1198
+ for (let b = 0, e; b < this.result.length; b++) if (e = this.result[b]) if (e.length <= a) {
1199
+ if (c[b] = e, a -= e.length, !a) break;
1200
+ } else {
1201
+ c[b] = e.slice(0, a);
1202
+ break;
1203
+ }
1204
+ this.result = c;
1205
+ }
1206
+ return this;
1207
+ };
1208
+ w.offset = function(a) {
1209
+ if (this.await) {
1210
+ const c = this;
1211
+ this.C.push(function() {
1212
+ return c.offset(a).result;
1213
+ });
1214
+ } else if (this.result.length) {
1215
+ const c = [];
1216
+ for (let b = 0, e; b < this.result.length; b++) if (e = this.result[b]) e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0);
1217
+ this.result = c;
1218
+ }
1219
+ return this;
1220
+ };
1221
+ w.boost = function(a) {
1222
+ if (this.await) {
1223
+ const c = this;
1224
+ this.C.push(function() {
1225
+ return c.boost(a).result;
1226
+ });
1227
+ } else this.h += a;
1228
+ return this;
1229
+ };
1230
+ function Wa(a, c) {
1231
+ let b = a.result;
1232
+ var e = a.await;
1233
+ a.await = null;
1234
+ for (let d = 0, f; d < a.C.length; d++) if (f = a.C[d]) {
1235
+ if (typeof f === "function") b = f(), a.C[d] = b = b.result || b, d--;
1236
+ else if (f.h) b = f.h(), a.C[d] = b = b.result || b, d--;
1237
+ else if (f.then) return a.await = e;
1238
+ }
1239
+ e = a.return;
1240
+ a.C = [];
1241
+ a.return = null;
1242
+ c || e(b);
1243
+ return b;
1244
+ }
1245
+ w.resolve = function(a, c, b, e, d) {
1246
+ let f = this.await ? Wa(this, true) : this.result;
1247
+ if (f.then) {
1248
+ const g = this;
1249
+ return f.then(function() {
1250
+ return g.resolve(a, c, b, e, d);
1251
+ });
1252
+ }
1253
+ f.length && (typeof a === "object" ? (e = a.highlight || this.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : (e = e || this.highlight, b = !!e || b), f = d ? b ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, c, b));
1254
+ return this.finalize(f, e);
1255
+ };
1256
+ w.finalize = function(a, c) {
1257
+ if (a.then) {
1258
+ const e = this;
1259
+ return a.then(function(d) {
1260
+ return e.finalize(d, c);
1261
+ });
1262
+ }
1263
+ c && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, c));
1264
+ const b = this.return;
1265
+ this.highlight = this.index = this.result = this.C = this.await = this.return = null;
1266
+ this.query = this.field = "";
1267
+ b && b(a);
1268
+ return a;
1269
+ };
1270
+ function $a(a, c, b, e, d, f, g) {
1271
+ const k = a.length;
1272
+ let h = [], l, m;
1273
+ l = I();
1274
+ for (let p = 0, u, r, t, n; p < c; p++) for (let q = 0; q < k; q++) if (t = a[q], p < t.length && (u = t[p])) for (let x = 0; x < u.length; x++) {
1275
+ r = u[x];
1276
+ (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1);
1277
+ n = h[m] || (h[m] = []);
1278
+ if (!g) {
1279
+ let v = p + (q || !d ? 0 : f || 0);
1280
+ n = n[v] || (n[v] = []);
1281
+ }
1282
+ n.push(r);
1283
+ if (g && b && m === k - 1 && n.length - e === b) return e ? n.slice(e) : n;
1284
+ }
1285
+ if (a = h.length) if (d) h = h.length > 1 ? Ya(h, b, e, g, f) : (h = h[0]) && b && h.length > b || e ? h.slice(e, b + e) : h;
1286
+ else {
1287
+ if (a < k) return [];
1288
+ h = h[a - 1];
1289
+ if (b || e) if (g) {
1290
+ if (h.length > b || e) h = h.slice(e, b + e);
1291
+ } else {
1292
+ d = [];
1293
+ for (let p = 0, u; p < h.length; p++) if (u = h[p]) if (e && u.length > e) e -= u.length;
1294
+ else {
1295
+ if (b && u.length > b || e) u = u.slice(e, b + e), b -= u.length, e && (e -= u.length);
1296
+ d.push(u);
1297
+ if (!b) break;
1298
+ }
1299
+ h = d;
1300
+ }
1301
+ }
1302
+ return h;
1303
+ }
1304
+ function Ya(a, c, b, e, d) {
1305
+ const f = [], g = I();
1306
+ let k;
1307
+ var h = a.length;
1308
+ let l;
1309
+ if (e) for (d = h - 1; d >= 0; d--) {
1310
+ if (l = (e = a[d]) && e.length) {
1311
+ for (h = 0; h < l; h++) if (k = e[h], !g[k]) {
1312
+ if (g[k] = 1, b) b--;
1313
+ else if (f.push(k), f.length === c) return f;
1314
+ }
1315
+ }
1316
+ }
1317
+ else for (let m = h - 1, p, u = 0; m >= 0; m--) {
1318
+ p = a[m];
1319
+ for (let r = 0; r < p.length; r++) if (l = (e = p[r]) && e.length) {
1320
+ for (let t = 0; t < l; t++) if (k = e[t], !g[k]) if (g[k] = 1, b) b--;
1321
+ else {
1322
+ let n = (r + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0;
1323
+ (f[n] || (f[n] = [])).push(k);
1324
+ if (++u === c) return f;
1325
+ }
1326
+ }
1327
+ }
1328
+ return f;
1329
+ }
1330
+ function eb(a, c, b, e, d) {
1331
+ const f = I(), g = [];
1332
+ for (let k = 0, h; k < c.length; k++) {
1333
+ h = c[k];
1334
+ for (let l = 0; l < h.length; l++) f[h[l]] = 1;
1335
+ }
1336
+ if (d) for (let k = 0, h; k < a.length; k++) {
1337
+ if (h = a[k], f[h]) {
1338
+ if (e) e--;
1339
+ else if (g.push(h), f[h] = 0, b && --b === 0) break;
1340
+ }
1341
+ }
1342
+ else for (let k = 0, h, l; k < a.result.length; k++) for (h = a.result[k], c = 0; c < h.length; c++) l = h[c], f[l] && ((g[k] || (g[k] = [])).push(l), f[l] = 0);
1343
+ return g;
1344
+ }
1345
+ Na.prototype.search = function(a, c, b, e) {
1346
+ b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0));
1347
+ let d = [];
1348
+ var f = [];
1349
+ let g;
1350
+ let k, h, l, m, p;
1351
+ let u = 0, r = true, t;
1352
+ if (b) {
1353
+ b.constructor === Array && (b = { index: b });
1354
+ a = b.query || a;
1355
+ g = b.pluck;
1356
+ k = b.merge;
1357
+ l = b.boost;
1358
+ p = g || b.field || (p = b.index) && (p.index ? null : p);
1359
+ var n = this.tag && b.tag;
1360
+ h = b.suggest;
1361
+ r = b.resolve !== false;
1362
+ m = b.cache;
1363
+ t = r && this.store && b.highlight;
1364
+ var q = !!t || r && this.store && b.enrich;
1365
+ c = b.limit || c;
1366
+ var x = b.offset || 0;
1367
+ c || (c = r ? 100 : 0);
1368
+ if (n && (!this.db || !e)) {
1369
+ n.constructor !== Array && (n = [n]);
1370
+ var v = [];
1371
+ for (let B = 0, z; B < n.length; B++) if (z = n[B], z.field && z.tag) {
1372
+ var A = z.tag;
1373
+ if (A.constructor === Array) for (var D = 0; D < A.length; D++) v.push(z.field, A[D]);
1374
+ else v.push(z.field, A);
1375
+ } else {
1376
+ A = Object.keys(z);
1377
+ for (let C = 0, J, G; C < A.length; C++) if (J = A[C], G = z[J], G.constructor === Array) for (D = 0; D < G.length; D++) v.push(J, G[D]);
1378
+ else v.push(J, G);
1379
+ }
1380
+ n = v;
1381
+ if (!a) {
1382
+ f = [];
1383
+ if (v.length) for (n = 0; n < v.length; n += 2) {
1384
+ if (this.db) {
1385
+ e = this.index.get(v[n]);
1386
+ if (!e) continue;
1387
+ f.push(e = e.db.tag(v[n + 1], c, x, q));
1388
+ } else e = fb.call(this, v[n], v[n + 1], c, x, q);
1389
+ d.push(r ? { field: v[n], tag: v[n + 1], result: e } : [e]);
1390
+ }
1391
+ if (f.length) {
1392
+ const B = this;
1393
+ return Promise.all(f).then(function(z) {
1394
+ for (let C = 0; C < z.length; C++) r ? d[C].result = z[C] : d[C] = z[C];
1395
+ return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, h, l) : d[0], B);
1396
+ });
1397
+ }
1398
+ return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, h, l) : d[0], this);
1399
+ }
1400
+ }
1401
+ r || g || !(p = p || this.field) || (M(p) ? g = p : (p.constructor === Array && p.length === 1 && (p = p[0]), g = p.field || p.index));
1402
+ p && p.constructor !== Array && (p = [p]);
1403
+ }
1404
+ p || (p = this.field);
1405
+ let F;
1406
+ v = (this.worker || this.db) && !e && [];
1407
+ for (let B = 0, z, C, J; B < p.length; B++) {
1408
+ C = p[B];
1409
+ if (this.db && this.tag && !this.B[B]) continue;
1410
+ let G;
1411
+ M(C) || (G = C, C = G.field, a = G.query || a, c = aa(G.limit, c), x = aa(G.offset, x), h = aa(G.suggest, h), t = r && this.store && aa(G.highlight, t), q = !!t || r && this.store && aa(G.enrich, q), m = aa(G.cache, m));
1412
+ if (e) z = e[B];
1413
+ else {
1414
+ A = G || b || {};
1415
+ D = A.enrich;
1416
+ var E = this.index.get(C);
1417
+ n && (this.db && (A.tag = n, A.field = p, F = E.db.support_tag_search), !F && D && (A.enrich = false), F || (A.limit = 0, A.offset = 0));
1418
+ z = m ? E.searchCache(a, n && !F ? 0 : c, A) : E.search(a, n && !F ? 0 : c, A);
1419
+ n && !F && (A.limit = c, A.offset = x);
1420
+ D && (A.enrich = D);
1421
+ if (v) {
1422
+ v[B] = z;
1423
+ continue;
1424
+ }
1425
+ }
1426
+ J = (z = z.result || z) && z.length;
1427
+ if (n && J) {
1428
+ A = [];
1429
+ D = 0;
1430
+ if (this.db && e) {
1431
+ if (!F) for (E = p.length; E < e.length; E++) {
1432
+ let N = e[E];
1433
+ if (N && N.length) D++, A.push(N);
1434
+ else if (!h) return r ? d : new X(d, this);
1435
+ }
1436
+ } else for (let N = 0, O, P; N < n.length; N += 2) {
1437
+ O = this.tag.get(n[N]);
1438
+ if (!O) if (h) continue;
1439
+ else return r ? d : new X(d, this);
1440
+ if (P = (O = O && O.get(n[N + 1])) && O.length) D++, A.push(O);
1441
+ else if (!h) return r ? d : new X(d, this);
1442
+ }
1443
+ if (D) {
1444
+ z = eb(z, A, c, x, r);
1445
+ J = z.length;
1446
+ if (!J && !h) return r ? z : new X(z, this);
1447
+ D--;
1448
+ }
1449
+ }
1450
+ if (J) f[u] = C, d.push(z), u++;
1451
+ else if (p.length === 1) return r ? d : new X(
1452
+ d,
1453
+ this
1454
+ );
1455
+ }
1456
+ if (v) {
1457
+ if (this.db && n && n.length && !F) for (q = 0; q < n.length; q += 2) {
1458
+ f = this.index.get(n[q]);
1459
+ if (!f) if (h) continue;
1460
+ else return r ? d : new X(d, this);
1461
+ v.push(f.db.tag(n[q + 1], c, x, false));
1462
+ }
1463
+ const B = this;
1464
+ return Promise.all(v).then(function(z) {
1465
+ b && (b.resolve = r);
1466
+ z.length && (z = B.search(a, c, b, z));
1467
+ return z;
1468
+ });
1469
+ }
1470
+ if (!u) return r ? d : new X(d, this);
1471
+ if (g && (!q || !this.store)) return d = d[0], r ? d : new X(d, this);
1472
+ v = [];
1473
+ for (x = 0; x < f.length; x++) {
1474
+ n = d[x];
1475
+ q && n.length && typeof n[0].doc === "undefined" && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n));
1476
+ if (g) return r ? t ? cb(a, n, this.index, g, t) : n : new X(n, this);
1477
+ d[x] = { field: f[x], result: n };
1478
+ }
1479
+ if (q && this.db && v.length) {
1480
+ const B = this;
1481
+ return Promise.all(v).then(function(z) {
1482
+ for (let C = 0; C < z.length; C++) d[C].result = z[C];
1483
+ t && (d = cb(a, d, B.index, g, t));
1484
+ return k ? gb(d) : d;
1485
+ });
1486
+ }
1487
+ t && (d = cb(a, d, this.index, g, t));
1488
+ return k ? gb(d) : d;
1489
+ };
1490
+ function gb(a) {
1491
+ const c = [], b = I(), e = I();
1492
+ for (let d = 0, f, g, k, h, l, m, p; d < a.length; d++) {
1493
+ f = a[d];
1494
+ g = f.field;
1495
+ k = f.result;
1496
+ for (let u = 0; u < k.length; u++) if (l = k[u], typeof l !== "object" ? l = { id: h = l } : h = l.id, (m = b[h]) ? m.push(g) : (l.field = b[h] = [g], c.push(l)), p = l.highlight) m = e[h], m || (e[h] = m = {}, l.highlight = m), m[g] = p;
1497
+ }
1498
+ return c;
1499
+ }
1500
+ function fb(a, c, b, e, d) {
1501
+ a = this.tag.get(a);
1502
+ if (!a) return [];
1503
+ a = a.get(c);
1504
+ if (!a) return [];
1505
+ c = a.length - e;
1506
+ if (c > 0) {
1507
+ if (b && c > b || e) a = a.slice(e, e + b);
1508
+ d && (a = Ta.call(this, a));
1509
+ }
1510
+ return a;
1511
+ }
1512
+ function Ta(a) {
1513
+ if (!this || !this.store) return a;
1514
+ if (this.db) return this.index.get(this.field[0]).db.enrich(a);
1515
+ const c = Array(a.length);
1516
+ for (let b = 0, e; b < a.length; b++) e = a[b], c[b] = { id: e, doc: this.store.get(e) };
1517
+ return c;
1518
+ }
1519
+ function Na(a) {
1520
+ if (!this || this.constructor !== Na) return new Na(a);
1521
+ const c = a.document || a.doc || a;
1522
+ let b, e;
1523
+ this.B = [];
1524
+ this.field = [];
1525
+ this.D = [];
1526
+ this.key = (b = c.key || c.id) && hb(b, this.D) || "id";
1527
+ (e = a.keystore || 0) && (this.keystore = e);
1528
+ this.fastupdate = !!a.fastupdate;
1529
+ this.reg = !this.fastupdate || a.worker || a.db ? e ? new S(e) : /* @__PURE__ */ new Set() : e ? new R(e) : /* @__PURE__ */ new Map();
1530
+ this.h = (b = c.store || null) && b && b !== true && [];
1531
+ this.store = b ? e ? new R(e) : /* @__PURE__ */ new Map() : null;
1532
+ this.cache = (b = a.cache || null) && new ma(b);
1533
+ a.cache = false;
1534
+ this.worker = a.worker || false;
1535
+ this.priority = a.priority || 4;
1536
+ this.index = ib.call(this, a, c);
1537
+ this.tag = null;
1538
+ if (b = c.tag) {
1539
+ if (typeof b === "string" && (b = [b]), b.length) {
1540
+ this.tag = /* @__PURE__ */ new Map();
1541
+ this.A = [];
1542
+ this.F = [];
1543
+ for (let d = 0, f, g; d < b.length; d++) {
1544
+ f = b[d];
1545
+ g = f.field || f;
1546
+ if (!g) throw Error("The tag field from the document descriptor is undefined.");
1547
+ f.custom ? this.A[d] = f.custom : (this.A[d] = hb(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter));
1548
+ this.F[d] = g;
1549
+ this.tag.set(g, /* @__PURE__ */ new Map());
1550
+ }
1551
+ }
1552
+ }
1553
+ if (this.worker) {
1554
+ this.fastupdate = false;
1555
+ a = [];
1556
+ for (const d of this.index.values()) d.then && a.push(d);
1557
+ if (a.length) {
1558
+ const d = this;
1559
+ return Promise.all(a).then(function(f) {
1560
+ let g = 0;
1561
+ for (const k of d.index.entries()) {
1562
+ const h = k[0];
1563
+ let l = k[1];
1564
+ l.then && (l = f[g], d.index.set(h, l), g++);
1565
+ }
1566
+ return d;
1567
+ });
1568
+ }
1569
+ } else a.db && (this.fastupdate = false, this.mount(a.db));
1570
+ }
1571
+ w = Na.prototype;
1572
+ w.mount = function(a) {
1573
+ let c = this.field;
1574
+ if (this.tag) for (let f = 0, g; f < this.F.length; f++) {
1575
+ g = this.F[f];
1576
+ var b = void 0;
1577
+ this.index.set(g, b = new T({}, this.reg));
1578
+ c === this.field && (c = c.slice(0));
1579
+ c.push(g);
1580
+ b.tag = this.tag.get(g);
1581
+ }
1582
+ b = [];
1583
+ const e = { db: a.db, type: a.type, fastupdate: a.fastupdate };
1584
+ for (let f = 0, g, k; f < c.length; f++) {
1585
+ e.field = k = c[f];
1586
+ g = this.index.get(k);
1587
+ const h = new a.constructor(a.id, e);
1588
+ h.id = a.id;
1589
+ b[f] = h.mount(g);
1590
+ g.document = true;
1591
+ f ? g.bypass = true : g.store = this.store;
1592
+ }
1593
+ const d = this;
1594
+ return this.db = Promise.all(b).then(function() {
1595
+ d.db = true;
1596
+ });
1597
+ };
1598
+ w.commit = async function() {
1599
+ const a = [];
1600
+ for (const c of this.index.values()) a.push(c.commit());
1601
+ await Promise.all(a);
1602
+ this.reg.clear();
1603
+ };
1604
+ w.destroy = function() {
1605
+ const a = [];
1606
+ for (const c of this.index.values()) a.push(c.destroy());
1607
+ return Promise.all(a);
1608
+ };
1609
+ function ib(a, c) {
1610
+ const b = /* @__PURE__ */ new Map();
1611
+ let e = c.index || c.field || c;
1612
+ M(e) && (e = [e]);
1613
+ for (let f = 0, g, k; f < e.length; f++) {
1614
+ g = e[f];
1615
+ M(g) || (k = g, g = g.field);
1616
+ k = ba(k) ? Object.assign({}, a, k) : a;
1617
+ if (this.worker) {
1618
+ var d = void 0;
1619
+ d = (d = k.encoder) && d.encode ? d : new ka(typeof d === "string" ? va[d] : d || {});
1620
+ d = new La(k, d);
1621
+ b.set(g, d);
1622
+ }
1623
+ this.worker || b.set(g, new T(k, this.reg));
1624
+ k.custom ? this.B[f] = k.custom : (this.B[f] = hb(g, this.D), k.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = k.filter));
1625
+ this.field[f] = g;
1626
+ }
1627
+ if (this.h) {
1628
+ a = c.store;
1629
+ M(a) && (a = [a]);
1630
+ for (let f = 0, g, k; f < a.length; f++) g = a[f], k = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = k) : (this.h[f] = hb(k, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter));
1631
+ }
1632
+ return b;
1633
+ }
1634
+ function hb(a, c) {
1635
+ const b = a.split(":");
1636
+ let e = 0;
1637
+ for (let d = 0; d < b.length; d++) a = b[d], a[a.length - 1] === "]" && (a = a.substring(0, a.length - 2)) && (c[e] = true), a && (b[e++] = a);
1638
+ e < b.length && (b.length = e);
1639
+ return e > 1 ? b : b[0];
1640
+ }
1641
+ w.append = function(a, c) {
1642
+ return this.add(a, c, true);
1643
+ };
1644
+ w.update = function(a, c) {
1645
+ return this.remove(a).add(a, c);
1646
+ };
1647
+ w.remove = function(a) {
1648
+ ba(a) && (a = ca(a, this.key));
1649
+ for (var c of this.index.values()) c.remove(a, true);
1650
+ if (this.reg.has(a)) {
1651
+ if (this.tag && !this.fastupdate) for (let b of this.tag.values()) for (let e of b) {
1652
+ c = e[0];
1653
+ const d = e[1], f = d.indexOf(a);
1654
+ f > -1 && (d.length > 1 ? d.splice(f, 1) : b.delete(c));
1655
+ }
1656
+ this.store && this.store.delete(a);
1657
+ this.reg.delete(a);
1658
+ }
1659
+ this.cache && this.cache.remove(a);
1660
+ return this;
1661
+ };
1662
+ w.clear = function() {
1663
+ const a = [];
1664
+ for (const c of this.index.values()) {
1665
+ const b = c.clear();
1666
+ b.then && a.push(b);
1667
+ }
1668
+ if (this.tag) for (const c of this.tag.values()) c.clear();
1669
+ this.store && this.store.clear();
1670
+ this.cache && this.cache.clear();
1671
+ return a.length ? Promise.all(a) : this;
1672
+ };
1673
+ w.contain = function(a) {
1674
+ return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a);
1675
+ };
1676
+ w.cleanup = function() {
1677
+ for (const a of this.index.values()) a.cleanup();
1678
+ return this;
1679
+ };
1680
+ w.get = function(a) {
1681
+ return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) {
1682
+ return c[0] && c[0].doc || null;
1683
+ }) : this.store.get(a) || null;
1684
+ };
1685
+ w.set = function(a, c) {
1686
+ typeof a === "object" && (c = a, a = ca(c, this.key));
1687
+ this.store.set(a, c);
1688
+ return this;
1689
+ };
1690
+ w.searchCache = la;
1691
+ w.export = jb;
1692
+ w.import = kb;
1693
+ Fa(Na.prototype);
1694
+ function lb(a, c = 0) {
1695
+ let b = [], e = [];
1696
+ c && (c = 25e4 / c * 5e3 | 0);
1697
+ for (const d of a.entries()) e.push(d), e.length === c && (b.push(e), e = []);
1698
+ e.length && b.push(e);
1699
+ return b;
1700
+ }
1701
+ function mb(a, c) {
1702
+ c || (c = /* @__PURE__ */ new Map());
1703
+ for (let b = 0, e; b < a.length; b++) e = a[b], c.set(e[0], e[1]);
1704
+ return c;
1705
+ }
1706
+ function nb(a, c = 0) {
1707
+ let b = [], e = [];
1708
+ c && (c = 25e4 / c * 1e3 | 0);
1709
+ for (const d of a.entries()) e.push([d[0], lb(d[1])[0] || []]), e.length === c && (b.push(e), e = []);
1710
+ e.length && b.push(e);
1711
+ return b;
1712
+ }
1713
+ function ob(a, c) {
1714
+ c || (c = /* @__PURE__ */ new Map());
1715
+ for (let b = 0, e, d; b < a.length; b++) e = a[b], d = c.get(e[0]), c.set(e[0], mb(e[1], d));
1716
+ return c;
1717
+ }
1718
+ function pb(a) {
1719
+ let c = [], b = [];
1720
+ for (const e of a.keys()) b.push(e), b.length === 25e4 && (c.push(b), b = []);
1721
+ b.length && c.push(b);
1722
+ return c;
1723
+ }
1724
+ function qb(a, c) {
1725
+ c || (c = /* @__PURE__ */ new Set());
1726
+ for (let b = 0; b < a.length; b++) c.add(a[b]);
1727
+ return c;
1728
+ }
1729
+ function rb(a, c, b, e, d, f, g = 0) {
1730
+ const k = e && e.constructor === Array;
1731
+ var h = k ? e.shift() : e;
1732
+ if (!h) return this.export(a, c, d, f + 1);
1733
+ if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) {
1734
+ const l = this;
1735
+ return h.then(function() {
1736
+ return rb.call(l, a, c, b, k ? e : null, d, f, g + 1);
1737
+ });
1738
+ }
1739
+ return rb.call(this, a, c, b, k ? e : null, d, f, g + 1);
1740
+ }
1741
+ function jb(a, c, b = 0, e = 0) {
1742
+ if (b < this.field.length) {
1743
+ const g = this.field[b];
1744
+ if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) {
1745
+ const k = this;
1746
+ return c.then(function() {
1747
+ return k.export(a, g, b + 1);
1748
+ });
1749
+ }
1750
+ return this.export(a, g, b + 1);
1751
+ }
1752
+ let d, f;
1753
+ switch (e) {
1754
+ case 0:
1755
+ d = "reg";
1756
+ f = pb(this.reg);
1757
+ c = null;
1758
+ break;
1759
+ case 1:
1760
+ d = "tag";
1761
+ f = this.tag && nb(this.tag, this.reg.size);
1762
+ c = null;
1763
+ break;
1764
+ case 2:
1765
+ d = "doc";
1766
+ f = this.store && lb(this.store);
1767
+ c = null;
1768
+ break;
1769
+ default:
1770
+ return;
1771
+ }
1772
+ return rb.call(this, a, c, d, f || null, b, e);
1773
+ }
1774
+ function kb(a, c) {
1775
+ var b = a.split(".");
1776
+ b[b.length - 1] === "json" && b.pop();
1777
+ const e = b.length > 2 ? b[0] : "";
1778
+ b = b.length > 2 ? b[2] : b[1];
1779
+ if (this.worker && e) return this.index.get(e).import(a);
1780
+ if (c) {
1781
+ typeof c === "string" && (c = JSON.parse(c));
1782
+ if (e) return this.index.get(e).import(b, c);
1783
+ switch (b) {
1784
+ case "reg":
1785
+ this.fastupdate = false;
1786
+ this.reg = qb(c, this.reg);
1787
+ for (let d = 0, f; d < this.field.length; d++) f = this.index.get(this.field[d]), f.fastupdate = false, f.reg = this.reg;
1788
+ if (this.worker) {
1789
+ c = [];
1790
+ for (const d of this.index.values()) c.push(d.import(a));
1791
+ return Promise.all(c);
1792
+ }
1793
+ break;
1794
+ case "tag":
1795
+ this.tag = ob(c, this.tag);
1796
+ break;
1797
+ case "doc":
1798
+ this.store = mb(c, this.store);
1799
+ }
1800
+ }
1801
+ }
1802
+ function sb(a, c) {
1803
+ let b = "";
1804
+ for (const e of a.entries()) {
1805
+ a = e[0];
1806
+ const d = e[1];
1807
+ let f = "";
1808
+ for (let g = 0, k; g < d.length; g++) {
1809
+ k = d[g] || [""];
1810
+ let h = "";
1811
+ for (let l = 0; l < k.length; l++) h += (h ? "," : "") + (c === "string" ? '"' + k[l] + '"' : k[l]);
1812
+ h = "[" + h + "]";
1813
+ f += (f ? "," : "") + h;
1814
+ }
1815
+ f = '["' + a + '",[' + f + "]]";
1816
+ b += (b ? "," : "") + f;
1817
+ }
1818
+ return b;
1819
+ }
1820
+ T.prototype.remove = function(a, c) {
1821
+ const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a));
1822
+ if (b) {
1823
+ if (this.fastupdate) for (let e = 0, d, f; e < b.length; e++) {
1824
+ if ((d = b[e]) && (f = d.length)) if (d[f - 1] === a) d.pop();
1825
+ else {
1826
+ const g = d.indexOf(a);
1827
+ g >= 0 && d.splice(g, 1);
1828
+ }
1829
+ }
1830
+ else tb(this.map, a), this.depth && tb(this.ctx, a);
1831
+ c || this.reg.delete(a);
1832
+ }
1833
+ this.db && (this.commit_task.push({ del: a }), this.M && ub(this));
1834
+ this.cache && this.cache.remove(a);
1835
+ return this;
1836
+ };
1837
+ function tb(a, c) {
1838
+ let b = 0;
1839
+ var e = typeof c === "undefined";
1840
+ if (a.constructor === Array) for (let d = 0, f, g, k; d < a.length; d++) {
1841
+ if ((f = a[d]) && f.length) {
1842
+ if (e) return 1;
1843
+ g = f.indexOf(c);
1844
+ if (g >= 0) {
1845
+ if (f.length > 1) return f.splice(g, 1), 1;
1846
+ delete a[d];
1847
+ if (b) return 1;
1848
+ k = 1;
1849
+ } else {
1850
+ if (k) return 1;
1851
+ b++;
1852
+ }
1853
+ }
1854
+ }
1855
+ else for (let d of a.entries()) e = d[0], tb(d[1], c) ? b++ : a.delete(e);
1856
+ return b;
1857
+ }
1858
+ var vb = { memory: { resolution: 1 }, performance: { resolution: 3, fastupdate: true, context: { depth: 1, resolution: 1 } }, match: { tokenize: "forward" }, score: { resolution: 9, context: { depth: 2, resolution: 3 } } };
1859
+ T.prototype.add = function(a, c, b, e) {
1860
+ if (c && (a || a === 0)) {
1861
+ if (!e && !b && this.reg.has(a)) return this.update(a, c);
1862
+ e = this.depth;
1863
+ c = this.encoder.encode(c, !e);
1864
+ const l = c.length;
1865
+ if (l) {
1866
+ const m = I(), p = I(), u = this.resolution;
1867
+ for (let r = 0; r < l; r++) {
1868
+ let t = c[this.rtl ? l - 1 - r : r];
1869
+ var d = t.length;
1870
+ if (d && (e || !p[t])) {
1871
+ var f = this.score ? this.score(c, t, r, null, 0) : wb(u, l, r), g = "";
1872
+ switch (this.tokenize) {
1873
+ case "tolerant":
1874
+ Y(this, p, t, f, a, b);
1875
+ if (d > 2) {
1876
+ for (let n = 1, q, x, v, A; n < d - 1; n++) q = t.charAt(n), x = t.charAt(n + 1), v = t.substring(0, n) + x, A = t.substring(n + 2), g = v + q + A, Y(this, p, g, f, a, b), g = v + A, Y(this, p, g, f, a, b);
1877
+ Y(this, p, t.substring(0, t.length - 1), f, a, b);
1878
+ }
1879
+ break;
1880
+ case "full":
1881
+ if (d > 2) {
1882
+ for (let n = 0, q; n < d; n++) for (f = d; f > n; f--) {
1883
+ g = t.substring(n, f);
1884
+ q = this.rtl ? d - 1 - n : n;
1885
+ var k = this.score ? this.score(c, t, r, g, q) : wb(u, l, r, d, q);
1886
+ Y(this, p, g, k, a, b);
1887
+ }
1888
+ break;
1889
+ }
1890
+ case "bidirectional":
1891
+ case "reverse":
1892
+ if (d > 1) {
1893
+ for (k = d - 1; k > 0; k--) {
1894
+ g = t[this.rtl ? d - 1 - k : k] + g;
1895
+ var h = this.score ? this.score(c, t, r, g, k) : wb(u, l, r, d, k);
1896
+ Y(this, p, g, h, a, b);
1897
+ }
1898
+ g = "";
1899
+ }
1900
+ case "forward":
1901
+ if (d > 1) {
1902
+ for (k = 0; k < d; k++) g += t[this.rtl ? d - 1 - k : k], Y(
1903
+ this,
1904
+ p,
1905
+ g,
1906
+ f,
1907
+ a,
1908
+ b
1909
+ );
1910
+ break;
1911
+ }
1912
+ default:
1913
+ if (Y(this, p, t, f, a, b), e && l > 1 && r < l - 1) for (d = this.N, g = t, f = Math.min(e + 1, this.rtl ? r + 1 : l - r), k = 1; k < f; k++) {
1914
+ t = c[this.rtl ? l - 1 - r - k : r + k];
1915
+ h = this.bidirectional && t > g;
1916
+ const n = this.score ? this.score(c, g, r, t, k - 1) : wb(d + (l / 2 > d ? 0 : 1), l, r, f - 1, k - 1);
1917
+ Y(this, m, h ? g : t, n, a, b, h ? t : g);
1918
+ }
1919
+ }
1920
+ }
1921
+ }
1922
+ this.fastupdate || this.reg.add(a);
1923
+ }
1924
+ }
1925
+ this.db && (this.commit_task.push(b ? { ins: a } : { del: a }), this.M && ub(this));
1926
+ return this;
1927
+ };
1928
+ function Y(a, c, b, e, d, f, g) {
1929
+ let k, h;
1930
+ if (!(k = c[b]) || g && !k[g]) {
1931
+ g ? (c = k || (c[b] = I()), c[g] = 1, h = a.ctx, (k = h.get(g)) ? h = k : h.set(g, h = a.keystore ? new R(a.keystore) : /* @__PURE__ */ new Map())) : (h = a.map, c[b] = 1);
1932
+ (k = h.get(b)) ? h = k : h.set(b, h = k = []);
1933
+ if (f) {
1934
+ for (let l = 0, m; l < k.length; l++) if ((m = k[l]) && m.includes(d)) {
1935
+ if (l <= e) return;
1936
+ m.splice(m.indexOf(d), 1);
1937
+ a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(m), 1);
1938
+ break;
1939
+ }
1940
+ }
1941
+ h = h[e] || (h[e] = []);
1942
+ h.push(d);
1943
+ if (h.length === 2 ** 31 - 1) {
1944
+ c = new xa(h);
1945
+ if (a.fastupdate) for (let l of a.reg.values()) l.includes(h) && (l[l.indexOf(h)] = c);
1946
+ k[e] = h = c;
1947
+ }
1948
+ a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h]));
1949
+ }
1950
+ }
1951
+ function wb(a, c, b, e, d) {
1952
+ return b && a > 1 ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0;
1953
+ }
1954
+ T.prototype.search = function(a, c, b) {
1955
+ b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : (b = a, a = ""));
1956
+ if (b && b.cache) return b.cache = false, a = this.searchCache(a, c, b), b.cache = true, a;
1957
+ let e = [], d, f, g, k = 0, h, l, m, p, u;
1958
+ b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, u = (h = b.resolve) && b.enrich, m = b.boost, p = b.resolution, l = this.db && b.tag);
1959
+ typeof h === "undefined" && (h = this.resolve);
1960
+ f = this.depth && f !== false;
1961
+ let r = this.encoder.encode(a, !f);
1962
+ d = r.length;
1963
+ c = c || (h ? 100 : 0);
1964
+ if (d === 1) return xb.call(
1965
+ this,
1966
+ r[0],
1967
+ "",
1968
+ c,
1969
+ k,
1970
+ h,
1971
+ u,
1972
+ l
1973
+ );
1974
+ if (d === 2 && f && !g) return xb.call(this, r[1], r[0], c, k, h, u, l);
1975
+ let t = I(), n = 0, q;
1976
+ f && (q = r[0], n = 1);
1977
+ p || p === 0 || (p = q ? this.N : this.resolution);
1978
+ if (this.db) {
1979
+ if (this.db.search && (b = this.db.search(this, r, c, k, g, h, u, l), b !== false)) return b;
1980
+ const x = this;
1981
+ return (async function() {
1982
+ for (let v, A; n < d; n++) {
1983
+ if ((A = r[n]) && !t[A]) {
1984
+ t[A] = 1;
1985
+ v = await yb(x, A, q, 0, 0, false, false);
1986
+ if (v = zb(v, e, g, p)) {
1987
+ e = v;
1988
+ break;
1989
+ }
1990
+ q && (g && v && e.length || (q = A));
1991
+ }
1992
+ g && q && n === d - 1 && !e.length && (p = x.resolution, q = "", n = -1, t = I());
1993
+ }
1994
+ return Ab(e, p, c, k, g, m, h);
1995
+ })();
1996
+ }
1997
+ for (let x, v; n < d; n++) {
1998
+ if ((v = r[n]) && !t[v]) {
1999
+ t[v] = 1;
2000
+ x = yb(this, v, q, 0, 0, false, false);
2001
+ if (x = zb(x, e, g, p)) {
2002
+ e = x;
2003
+ break;
2004
+ }
2005
+ q && (g && x && e.length || (q = v));
2006
+ }
2007
+ g && q && n === d - 1 && !e.length && (p = this.resolution, q = "", n = -1, t = I());
2008
+ }
2009
+ return Ab(e, p, c, k, g, m, h);
2010
+ };
2011
+ function Ab(a, c, b, e, d, f, g) {
2012
+ let k = a.length, h = a;
2013
+ if (k > 1) h = $a(a, c, b, e, d, f, g);
2014
+ else if (k === 1) return g ? Sa.call(null, a[0], b, e) : new X(a[0], this);
2015
+ return g ? h : new X(h, this);
2016
+ }
2017
+ function xb(a, c, b, e, d, f, g) {
2018
+ a = yb(this, a, c, b, e, d, f, g);
2019
+ return this.db ? a.then(function(k) {
2020
+ return d ? k || [] : new X(k, this);
2021
+ }) : a && a.length ? d ? Sa.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this);
2022
+ }
2023
+ function zb(a, c, b, e) {
2024
+ let d = [];
2025
+ if (a && a.length) {
2026
+ if (a.length <= e) {
2027
+ c.push(a);
2028
+ return;
2029
+ }
2030
+ for (let f = 0, g; f < e; f++) if (g = a[f]) d[f] = g;
2031
+ if (d.length) {
2032
+ c.push(d);
2033
+ return;
2034
+ }
2035
+ }
2036
+ if (!b) return d;
2037
+ }
2038
+ function yb(a, c, b, e, d, f, g, k) {
2039
+ let h;
2040
+ b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h);
2041
+ if (a.db) return a.db.get(c, b, e, d, f, g, k);
2042
+ a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c);
2043
+ return a;
2044
+ }
2045
+ function T(a, c) {
2046
+ if (!this || this.constructor !== T) return new T(a);
2047
+ if (a) {
2048
+ var b = M(a) ? a : a.preset;
2049
+ b && (a = Object.assign({}, vb[b], a));
2050
+ } else a = {};
2051
+ b = a.context;
2052
+ const e = b === true ? { depth: 1 } : b || {}, d = M(a.encoder) ? va[a.encoder] : a.encode || a.encoder || {};
2053
+ this.encoder = d.encode ? d : typeof d === "object" ? new ka(d) : { encode: d };
2054
+ this.resolution = a.resolution || 9;
2055
+ this.tokenize = b = (b = a.tokenize) && b !== "default" && b !== "exact" && b || "strict";
2056
+ this.depth = b === "strict" && e.depth || 0;
2057
+ this.bidirectional = e.bidirectional !== false;
2058
+ this.fastupdate = !!a.fastupdate;
2059
+ this.score = a.score || null;
2060
+ (b = a.keystore || 0) && (this.keystore = b);
2061
+ this.map = b ? new R(b) : /* @__PURE__ */ new Map();
2062
+ this.ctx = b ? new R(b) : /* @__PURE__ */ new Map();
2063
+ this.reg = c || (this.fastupdate ? b ? new R(b) : /* @__PURE__ */ new Map() : b ? new S(b) : /* @__PURE__ */ new Set());
2064
+ this.N = e.resolution || 3;
2065
+ this.rtl = d.rtl || a.rtl || false;
2066
+ this.cache = (b = a.cache || null) && new ma(b);
2067
+ this.resolve = a.resolve !== false;
2068
+ if (b = a.db) this.db = this.mount(b);
2069
+ this.M = a.commit !== false;
2070
+ this.commit_task = [];
2071
+ this.commit_timer = null;
2072
+ this.priority = a.priority || 4;
2073
+ }
2074
+ w = T.prototype;
2075
+ w.mount = function(a) {
2076
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
2077
+ return a.mount(this);
2078
+ };
2079
+ w.commit = function() {
2080
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
2081
+ return this.db.commit(this);
2082
+ };
2083
+ w.destroy = function() {
2084
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
2085
+ return this.db.destroy();
2086
+ };
2087
+ function ub(a) {
2088
+ a.commit_timer || (a.commit_timer = setTimeout(function() {
2089
+ a.commit_timer = null;
2090
+ a.db.commit(a);
2091
+ }, 1));
2092
+ }
2093
+ w.clear = function() {
2094
+ this.map.clear();
2095
+ this.ctx.clear();
2096
+ this.reg.clear();
2097
+ this.cache && this.cache.clear();
2098
+ return this.db ? (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [], this.db.clear()) : this;
2099
+ };
2100
+ w.append = function(a, c) {
2101
+ return this.add(a, c, true);
2102
+ };
2103
+ w.contain = function(a) {
2104
+ return this.db ? this.db.has(a) : this.reg.has(a);
2105
+ };
2106
+ w.update = function(a, c) {
2107
+ const b = this, e = this.remove(a);
2108
+ return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c);
2109
+ };
2110
+ w.cleanup = function() {
2111
+ if (!this.fastupdate) return this;
2112
+ tb(this.map);
2113
+ this.depth && tb(this.ctx);
2114
+ return this;
2115
+ };
2116
+ w.searchCache = la;
2117
+ w.export = function(a, c, b = 0, e = 0) {
2118
+ let d, f;
2119
+ switch (e) {
2120
+ case 0:
2121
+ d = "reg";
2122
+ f = pb(this.reg);
2123
+ break;
2124
+ case 1:
2125
+ d = "cfg";
2126
+ f = null;
2127
+ break;
2128
+ case 2:
2129
+ d = "map";
2130
+ f = lb(this.map, this.reg.size);
2131
+ break;
2132
+ case 3:
2133
+ d = "ctx";
2134
+ f = nb(this.ctx, this.reg.size);
2135
+ break;
2136
+ default:
2137
+ return;
2138
+ }
2139
+ return rb.call(this, a, c, d, f, b, e);
2140
+ };
2141
+ w.import = function(a, c) {
2142
+ if (c) switch (typeof c === "string" && (c = JSON.parse(c)), a = a.split("."), a[a.length - 1] === "json" && a.pop(), a.length === 3 && a.shift(), a = a.length > 1 ? a[1] : a[0], a) {
2143
+ case "reg":
2144
+ this.fastupdate = false;
2145
+ this.reg = qb(c, this.reg);
2146
+ break;
2147
+ case "map":
2148
+ this.map = mb(c, this.map);
2149
+ break;
2150
+ case "ctx":
2151
+ this.ctx = ob(c, this.ctx);
2152
+ }
2153
+ };
2154
+ w.serialize = function(a = true) {
2155
+ let c = "", b = "", e = "";
2156
+ if (this.reg.size) {
2157
+ let f;
2158
+ for (var d of this.reg.keys()) f || (f = typeof d), c += (c ? "," : "") + (f === "string" ? '"' + d + '"' : d);
2159
+ c = "index.reg=new Set([" + c + "]);";
2160
+ b = sb(this.map, f);
2161
+ b = "index.map=new Map([" + b + "]);";
2162
+ for (const g of this.ctx.entries()) {
2163
+ d = g[0];
2164
+ let k = sb(g[1], f);
2165
+ k = "new Map([" + k + "])";
2166
+ k = '["' + d + '",' + k + "]";
2167
+ e += (e ? "," : "") + k;
2168
+ }
2169
+ e = "index.ctx=new Map([" + e + "]);";
2170
+ }
2171
+ return a ? "function inject(index){" + c + b + e + "}" : c + b + e;
2172
+ };
2173
+ Fa(T.prototype);
2174
+ var Bb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB);
2175
+ var Cb = ["map", "ctx", "tag", "reg", "cfg"];
2176
+ var Db = I();
2177
+ function Eb(a, c = {}) {
2178
+ if (!this || this.constructor !== Eb) return new Eb(a, c);
2179
+ typeof a === "object" && (c = a, a = a.name);
2180
+ a || console.info("Default storage space was used, because a name was not passed.");
2181
+ this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : "");
2182
+ this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : "";
2183
+ this.type = c.type;
2184
+ this.fastupdate = this.support_tag_search = false;
2185
+ this.db = null;
2186
+ this.h = {};
2187
+ }
2188
+ w = Eb.prototype;
2189
+ w.mount = function(a) {
2190
+ if (a.index) return a.mount(this);
2191
+ a.db = this;
2192
+ return this.open();
2193
+ };
2194
+ w.open = function() {
2195
+ if (this.db) return this.db;
2196
+ let a = this;
2197
+ navigator.storage && navigator.storage.persist && navigator.storage.persist();
2198
+ Db[a.id] || (Db[a.id] = []);
2199
+ Db[a.id].push(a.field);
2200
+ const c = Bb.open(a.id, 1);
2201
+ c.onupgradeneeded = function() {
2202
+ const b = a.db = this.result;
2203
+ for (let e = 0, d; e < Cb.length; e++) {
2204
+ d = Cb[e];
2205
+ for (let f = 0, g; f < Db[a.id].length; f++) g = Db[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : ""));
2206
+ }
2207
+ };
2208
+ return a.db = Z(c, function(b) {
2209
+ a.db = b;
2210
+ a.db.onversionchange = function() {
2211
+ a.close();
2212
+ };
2213
+ });
2214
+ };
2215
+ w.close = function() {
2216
+ this.db && this.db.close();
2217
+ this.db = null;
2218
+ };
2219
+ w.destroy = function() {
2220
+ const a = Bb.deleteDatabase(this.id);
2221
+ return Z(a);
2222
+ };
2223
+ w.clear = function() {
2224
+ const a = [];
2225
+ for (let b = 0, e; b < Cb.length; b++) {
2226
+ e = Cb[b];
2227
+ for (let d = 0, f; d < Db[this.id].length; d++) f = Db[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : ""));
2228
+ }
2229
+ const c = this.db.transaction(a, "readwrite");
2230
+ for (let b = 0; b < a.length; b++) c.objectStore(a[b]).clear();
2231
+ return Z(c);
2232
+ };
2233
+ w.get = function(a, c, b = 0, e = 0, d = true, f = false) {
2234
+ a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a);
2235
+ const g = this;
2236
+ return Z(a).then(function(k) {
2237
+ let h = [];
2238
+ if (!k || !k.length) return h;
2239
+ if (d) {
2240
+ if (!b && !e && k.length === 1) return k[0];
2241
+ for (let l = 0, m; l < k.length; l++) if ((m = k[l]) && m.length) {
2242
+ if (e >= m.length) {
2243
+ e -= m.length;
2244
+ continue;
2245
+ }
2246
+ const p = b ? e + Math.min(m.length - e, b) : m.length;
2247
+ for (let u = e; u < p; u++) h.push(m[u]);
2248
+ e = 0;
2249
+ if (h.length === b) break;
2250
+ }
2251
+ return f ? g.enrich(h) : h;
2252
+ }
2253
+ return k;
2254
+ });
2255
+ };
2256
+ w.tag = function(a, c = 0, b = 0, e = false) {
2257
+ a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a);
2258
+ const d = this;
2259
+ return Z(a).then(function(f) {
2260
+ if (!f || !f.length || b >= f.length) return [];
2261
+ if (!c && !b) return f;
2262
+ f = f.slice(b, b + c);
2263
+ return e ? d.enrich(f) : f;
2264
+ });
2265
+ };
2266
+ w.enrich = function(a) {
2267
+ typeof a !== "object" && (a = [a]);
2268
+ const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = [];
2269
+ for (let e = 0; e < a.length; e++) b[e] = Z(c.get(a[e]));
2270
+ return Promise.all(b).then(function(e) {
2271
+ for (let d = 0; d < e.length; d++) e[d] = { id: a[d], doc: e[d] ? JSON.parse(e[d]) : null };
2272
+ return e;
2273
+ });
2274
+ };
2275
+ w.has = function(a) {
2276
+ a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a);
2277
+ return Z(a).then(function(c) {
2278
+ return !!c;
2279
+ });
2280
+ };
2281
+ w.search = null;
2282
+ w.info = function() {
2283
+ };
2284
+ w.transaction = function(a, c, b) {
2285
+ a += a !== "reg" ? this.field ? ":" + this.field : "" : "";
2286
+ let e = this.h[a + ":" + c];
2287
+ if (e) return b.call(this, e);
2288
+ let d = this.db.transaction(a, c);
2289
+ this.h[a + ":" + c] = e = d.objectStore(a);
2290
+ const f = b.call(this, e);
2291
+ this.h[a + ":" + c] = null;
2292
+ return Z(d).finally(function() {
2293
+ return f;
2294
+ });
2295
+ };
2296
+ w.commit = async function(a) {
2297
+ let c = a.commit_task, b = [];
2298
+ a.commit_task = [];
2299
+ for (let e = 0, d; e < c.length; e++) d = c[e], d.del && b.push(d.del);
2300
+ b.length && await this.remove(b);
2301
+ a.reg.size && (await this.transaction("map", "readwrite", function(e) {
2302
+ for (const d of a.map) {
2303
+ const f = d[0], g = d[1];
2304
+ g.length && (e.get(f).onsuccess = function() {
2305
+ let k = this.result;
2306
+ var h;
2307
+ if (k && k.length) {
2308
+ const l = Math.max(k.length, g.length);
2309
+ for (let m = 0, p, u; m < l; m++) if ((u = g[m]) && u.length) {
2310
+ if ((p = k[m]) && p.length) for (h = 0; h < u.length; h++) p.push(u[h]);
2311
+ else k[m] = u;
2312
+ h = 1;
2313
+ }
2314
+ } else k = g, h = 1;
2315
+ h && e.put(k, f);
2316
+ });
2317
+ }
2318
+ }), await this.transaction("ctx", "readwrite", function(e) {
2319
+ for (const d of a.ctx) {
2320
+ const f = d[0], g = d[1];
2321
+ for (const k of g) {
2322
+ const h = k[0], l = k[1];
2323
+ l.length && (e.get(f + ":" + h).onsuccess = function() {
2324
+ let m = this.result;
2325
+ var p;
2326
+ if (m && m.length) {
2327
+ const u = Math.max(m.length, l.length);
2328
+ for (let r = 0, t, n; r < u; r++) if ((n = l[r]) && n.length) {
2329
+ if ((t = m[r]) && t.length) for (p = 0; p < n.length; p++) t.push(n[p]);
2330
+ else m[r] = n;
2331
+ p = 1;
2332
+ }
2333
+ } else m = l, p = 1;
2334
+ p && e.put(m, f + ":" + h);
2335
+ });
2336
+ }
2337
+ }
2338
+ }), a.store ? await this.transaction(
2339
+ "reg",
2340
+ "readwrite",
2341
+ function(e) {
2342
+ for (const d of a.store) {
2343
+ const f = d[0], g = d[1];
2344
+ e.put(typeof g === "object" ? JSON.stringify(g) : 1, f);
2345
+ }
2346
+ }
2347
+ ) : a.bypass || await this.transaction("reg", "readwrite", function(e) {
2348
+ for (const d of a.reg.keys()) e.put(1, d);
2349
+ }), a.tag && await this.transaction("tag", "readwrite", function(e) {
2350
+ for (const d of a.tag) {
2351
+ const f = d[0], g = d[1];
2352
+ g.length && (e.get(f).onsuccess = function() {
2353
+ let k = this.result;
2354
+ k = k && k.length ? k.concat(g) : g;
2355
+ e.put(k, f);
2356
+ });
2357
+ }
2358
+ }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear());
2359
+ };
2360
+ function Fb(a, c, b) {
2361
+ const e = a.value;
2362
+ let d, f = 0;
2363
+ for (let g = 0, k; g < e.length; g++) {
2364
+ if (k = b ? e : e[g]) {
2365
+ for (let h = 0, l, m; h < c.length; h++) if (m = c[h], l = k.indexOf(m), l >= 0) if (d = 1, k.length > 1) k.splice(l, 1);
2366
+ else {
2367
+ e[g] = [];
2368
+ break;
2369
+ }
2370
+ f += k.length;
2371
+ }
2372
+ if (b) break;
2373
+ }
2374
+ f ? d && a.update(e) : a.delete();
2375
+ a.continue();
2376
+ }
2377
+ w.remove = function(a) {
2378
+ typeof a !== "object" && (a = [a]);
2379
+ return Promise.all([this.transaction("map", "readwrite", function(c) {
2380
+ c.openCursor().onsuccess = function() {
2381
+ const b = this.result;
2382
+ b && Fb(b, a);
2383
+ };
2384
+ }), this.transaction("ctx", "readwrite", function(c) {
2385
+ c.openCursor().onsuccess = function() {
2386
+ const b = this.result;
2387
+ b && Fb(b, a);
2388
+ };
2389
+ }), this.transaction("tag", "readwrite", function(c) {
2390
+ c.openCursor().onsuccess = function() {
2391
+ const b = this.result;
2392
+ b && Fb(b, a, true);
2393
+ };
2394
+ }), this.transaction("reg", "readwrite", function(c) {
2395
+ for (let b = 0; b < a.length; b++) c.delete(a[b]);
2396
+ })]);
2397
+ };
2398
+ function Z(a, c) {
2399
+ return new Promise((b, e) => {
2400
+ a.onsuccess = a.oncomplete = function() {
2401
+ c && c(this.result);
2402
+ c = null;
2403
+ b(this.result);
2404
+ };
2405
+ a.onerror = a.onblocked = e;
2406
+ a = null;
2407
+ });
2408
+ }
2409
+ var __defProp2 = Object.defineProperty;
2410
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2411
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
2412
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2413
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2414
+ var __spreadValues = (a, b) => {
2415
+ for (var prop in b || (b = {}))
2416
+ if (__hasOwnProp2.call(b, prop))
2417
+ __defNormalProp(a, prop, b[prop]);
2418
+ if (__getOwnPropSymbols)
2419
+ for (var prop of __getOwnPropSymbols(b)) {
2420
+ if (__propIsEnum.call(b, prop))
2421
+ __defNormalProp(a, prop, b[prop]);
2422
+ }
2423
+ return a;
2424
+ };
2425
+ var __async = (__this, __arguments, generator) => {
2426
+ return new Promise((resolve, reject) => {
2427
+ var fulfilled = (value) => {
2428
+ try {
2429
+ step(generator.next(value));
2430
+ } catch (e) {
2431
+ reject(e);
2432
+ }
2433
+ };
2434
+ var rejected = (value) => {
2435
+ try {
2436
+ step(generator.throw(value));
2437
+ } catch (e) {
2438
+ reject(e);
2439
+ }
2440
+ };
2441
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2442
+ step((generator = generator.apply(__this, __arguments)).next());
2443
+ });
2444
+ };
2445
+ var log3 = loggers.search;
2446
+ var FileBasedSearchIndexExporter = class {
2447
+ constructor(options) {
2448
+ this.cachedData = null;
2449
+ var _a;
2450
+ this.baseDir = (_a = options.baseDir) != null ? _a : process.cwd();
2451
+ this.indexPath = options.indexPath;
2452
+ }
2453
+ getFullPath() {
2454
+ return path.join(this.baseDir, this.indexPath);
2455
+ }
2456
+ loadData() {
2457
+ return __async(this, null, function* () {
2458
+ if (this.cachedData) {
2459
+ return this.cachedData;
2460
+ }
2461
+ const fullPath = this.getFullPath();
2462
+ try {
2463
+ const fileContent = yield fs.readFile(fullPath, "utf-8");
2464
+ const data = JSON.parse(fileContent);
2465
+ if (!data || !data.keys || !Array.isArray(data.keys) || !data.data) {
2466
+ log3.warn("Invalid search index structure in file:", fullPath);
2467
+ return null;
2468
+ }
2469
+ if (data.keys.length === 0) {
2470
+ log3.debug("Search index is empty:", fullPath);
2471
+ return null;
2472
+ }
2473
+ this.cachedData = data;
2474
+ log3.debug("Search index loaded from file:", fullPath, "with", data.keys.length, "keys");
2475
+ return data;
2476
+ } catch (error) {
2477
+ log3.error("Failed to load search index from file:", fullPath, error);
2478
+ return null;
2479
+ }
2480
+ });
2481
+ }
2482
+ import() {
2483
+ return __async(this, null, function* () {
2484
+ const data = yield this.loadData();
2485
+ return data;
2486
+ });
2487
+ }
2488
+ export(_0) {
2489
+ return __async(this, arguments, function* (data, options = { override: true }) {
2490
+ const fullPath = this.getFullPath();
2491
+ try {
2492
+ if (!(options == null ? void 0 : options.override)) {
2493
+ try {
2494
+ yield fs.access(fullPath);
2495
+ log3.debug("Search index file already exists and override is false, skipping export:", fullPath);
2496
+ return;
2497
+ } catch (e) {
2498
+ }
2499
+ }
2500
+ const dir = path.dirname(fullPath);
2501
+ yield fs.mkdir(dir, { recursive: true });
2502
+ yield fs.writeFile(fullPath, JSON.stringify(data, null, 2), "utf-8");
2503
+ log3.debug("Search index saved to file:", fullPath, "with", data.keys.length, "keys");
2504
+ } catch (error) {
2505
+ log3.error("Failed to save search index to file:", fullPath, error);
2506
+ throw error;
2507
+ }
2508
+ });
2509
+ }
2510
+ exportSync(data, options = { override: true }) {
2511
+ const fullPath = this.getFullPath();
2512
+ try {
2513
+ if (!(options == null ? void 0 : options.override)) {
2514
+ try {
2515
+ fsSync.accessSync(fullPath);
2516
+ log3.debug("Search index file already exists and override is false, skipping export:", fullPath);
2517
+ return;
2518
+ } catch (e) {
2519
+ }
2520
+ }
2521
+ const dir = path.dirname(fullPath);
2522
+ fsSync.mkdirSync(dir, { recursive: true });
2523
+ fsSync.writeFileSync(fullPath, JSON.stringify(data, null, 2), "utf-8");
2524
+ log3.debug("Search index saved to file:", fullPath, "with", data.keys.length, "keys");
2525
+ } catch (error) {
2526
+ log3.error("Failed to save search index to file:", fullPath, error);
2527
+ throw error;
2528
+ }
2529
+ }
2530
+ };
2531
+ function createExporterFromConfig(exporterConfig) {
2532
+ if (exporterConfig.type === "fileBased") {
2533
+ return new FileBasedSearchIndexExporter(__spreadValues({}, exporterConfig.config));
2534
+ }
2535
+ throw new Error(`Unknown exporter type: ${exporterConfig.type}`);
2536
+ }
2537
+
2538
+ // src/config.ts
2539
+ var getConfig = () => {
2540
+ if (!process.env.PEAM_SEARCH_EXPORTER_TYPE || !process.env.PEAM_SEARCH_EXPORTER_CONFIG) {
2541
+ throw new Error(
2542
+ "Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
2543
+ );
2544
+ }
2545
+ const searchExporterConfig = {
2546
+ type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
2547
+ config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
2548
+ };
2549
+ const resolvedConfig = {
2550
+ searchExporter: searchExporterConfig,
2551
+ searchIndexExporter: createExporterFromConfig(searchExporterConfig),
2552
+ respectRobotsTxt: process.env.PEAM_RESPECT_ROBOTS_TXT === "true",
2553
+ robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
2554
+ exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
2555
+ };
2556
+ return resolvedConfig;
2557
+ };
2
2558
 
3
2559
  // src/route.ts
4
- var POST = createHandler();
2560
+ var config = getConfig();
2561
+ var POST = createHandler({
2562
+ searchIndexExporter: config.searchIndexExporter
2563
+ });
5
2564
 
6
2565
  export { POST };
7
2566
  //# sourceMappingURL=route.mjs.map