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