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