@peam-ai/next 0.1.2 → 0.1.4

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