@peam-ai/next 0.1.3 → 0.1.5

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