web-doc 0.4.0 → 0.6.0

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.
@@ -0,0 +1,1680 @@
1
+ // ../../node_modules/fuse.js/dist/fuse.mjs
2
+ function isArray(value) {
3
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
4
+ }
5
+ function baseToString(value) {
6
+ if (typeof value == "string") return value;
7
+ if (typeof value === "bigint") return value.toString();
8
+ const result = value + "";
9
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
10
+ }
11
+ function toString(value) {
12
+ return value == null ? "" : baseToString(value);
13
+ }
14
+ function isString(value) {
15
+ return typeof value === "string";
16
+ }
17
+ function isNumber(value) {
18
+ return typeof value === "number";
19
+ }
20
+ function isBoolean(value) {
21
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
22
+ }
23
+ function isObject(value) {
24
+ return typeof value === "object";
25
+ }
26
+ function isObjectLike(value) {
27
+ return isObject(value) && value !== null;
28
+ }
29
+ function isDefined(value) {
30
+ return value !== void 0 && value !== null;
31
+ }
32
+ function isBlank(value) {
33
+ return !value.trim().length;
34
+ }
35
+ function getTag(value) {
36
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
37
+ }
38
+ var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
39
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
40
+ var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
41
+ var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
42
+ var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
43
+ var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
44
+ var FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED = "Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.";
45
+ var hasOwn = Object.prototype.hasOwnProperty;
46
+ var KeyStore = class {
47
+ constructor(keys) {
48
+ this._keys = [];
49
+ this._keyMap = {};
50
+ let totalWeight = 0;
51
+ keys.forEach((key) => {
52
+ const obj = createKey(key);
53
+ this._keys.push(obj);
54
+ this._keyMap[obj.id] = obj;
55
+ totalWeight += obj.weight;
56
+ });
57
+ this._keys.forEach((key) => {
58
+ key.weight /= totalWeight;
59
+ });
60
+ }
61
+ get(keyId) {
62
+ return this._keyMap[keyId];
63
+ }
64
+ keys() {
65
+ return this._keys;
66
+ }
67
+ toJSON() {
68
+ return JSON.stringify(this._keys);
69
+ }
70
+ };
71
+ function createKey(key) {
72
+ let path = null;
73
+ let id = null;
74
+ let src = null;
75
+ let weight = 1;
76
+ let getFn = null;
77
+ if (isString(key) || isArray(key)) {
78
+ src = key;
79
+ path = createKeyPath(key);
80
+ id = createKeyId(key);
81
+ } else {
82
+ if (!hasOwn.call(key, "name")) throw new Error(MISSING_KEY_PROPERTY("name"));
83
+ const name = key.name;
84
+ src = name;
85
+ if (hasOwn.call(key, "weight") && key.weight !== void 0) {
86
+ weight = key.weight;
87
+ if (weight <= 0) throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
88
+ }
89
+ path = createKeyPath(name);
90
+ id = createKeyId(name);
91
+ getFn = key.getFn ?? null;
92
+ }
93
+ return {
94
+ path,
95
+ id,
96
+ weight,
97
+ src,
98
+ getFn
99
+ };
100
+ }
101
+ function createKeyPath(key) {
102
+ return isArray(key) ? key : key.split(".");
103
+ }
104
+ function createKeyId(key) {
105
+ return isArray(key) ? key.join(".") : key;
106
+ }
107
+ function get(obj, path) {
108
+ const list = [];
109
+ let arr = false;
110
+ const deepGet = (obj2, path2, index, arrayIndex) => {
111
+ if (!isDefined(obj2)) return;
112
+ if (!path2[index]) list.push(arrayIndex !== void 0 ? {
113
+ v: obj2,
114
+ i: arrayIndex
115
+ } : obj2);
116
+ else {
117
+ const value = obj2[path2[index]];
118
+ if (!isDefined(value)) return;
119
+ if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value) || typeof value === "bigint")) list.push(arrayIndex !== void 0 ? {
120
+ v: toString(value),
121
+ i: arrayIndex
122
+ } : toString(value));
123
+ else if (isArray(value)) {
124
+ arr = true;
125
+ for (let i = 0, len = value.length; i < len; i += 1) deepGet(value[i], path2, index + 1, i);
126
+ } else if (path2.length) deepGet(value, path2, index + 1, arrayIndex);
127
+ }
128
+ };
129
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
130
+ return arr ? list : list[0];
131
+ }
132
+ var MatchOptions = {
133
+ includeMatches: false,
134
+ findAllMatches: false,
135
+ minMatchCharLength: 1
136
+ };
137
+ var BasicOptions = {
138
+ isCaseSensitive: false,
139
+ ignoreDiacritics: false,
140
+ includeScore: false,
141
+ keys: [],
142
+ shouldSort: true,
143
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
144
+ };
145
+ var FuzzyOptions = {
146
+ location: 0,
147
+ threshold: 0.6,
148
+ distance: 100
149
+ };
150
+ var AdvancedOptions = {
151
+ useExtendedSearch: false,
152
+ useTokenSearch: false,
153
+ tokenize: void 0,
154
+ tokenMatch: "any",
155
+ getFn: get,
156
+ ignoreLocation: false,
157
+ ignoreFieldNorm: false,
158
+ fieldNormWeight: 1
159
+ };
160
+ var Config = Object.freeze({
161
+ ...BasicOptions,
162
+ ...MatchOptions,
163
+ ...FuzzyOptions,
164
+ ...AdvancedOptions
165
+ });
166
+ function isWordSeparator(code) {
167
+ return code >= 9 && code <= 13 || code === 32 || code === 160;
168
+ }
169
+ function norm(weight = 1, mantissa = 3) {
170
+ const cache = /* @__PURE__ */ new Map();
171
+ const m = Math.pow(10, mantissa);
172
+ return {
173
+ get(value) {
174
+ let numTokens = 0;
175
+ let inWord = false;
176
+ for (let i = 0; i < value.length; i++) if (!isWordSeparator(value.charCodeAt(i))) {
177
+ if (!inWord) {
178
+ numTokens++;
179
+ inWord = true;
180
+ }
181
+ } else inWord = false;
182
+ if (numTokens === 0) numTokens = 1;
183
+ if (cache.has(numTokens)) return cache.get(numTokens);
184
+ const n = Math.round(m / Math.pow(numTokens, 0.5 * weight)) / m;
185
+ cache.set(numTokens, n);
186
+ return n;
187
+ },
188
+ clear() {
189
+ cache.clear();
190
+ }
191
+ };
192
+ }
193
+ var FuseIndex = class {
194
+ constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
195
+ this.norm = norm(fieldNormWeight, 3);
196
+ this.getFn = getFn;
197
+ this.isCreated = false;
198
+ this.docs = [];
199
+ this.keys = [];
200
+ this._keysMap = {};
201
+ this.setIndexRecords();
202
+ }
203
+ setSources(docs = []) {
204
+ this.docs = docs;
205
+ }
206
+ setIndexRecords(records = []) {
207
+ this.records = records;
208
+ }
209
+ setKeys(keys = []) {
210
+ this.keys = keys;
211
+ this._keysMap = {};
212
+ keys.forEach((key, idx) => {
213
+ this._keysMap[key.id] = idx;
214
+ });
215
+ }
216
+ create() {
217
+ if (this.isCreated || !this.docs.length) return;
218
+ this.isCreated = true;
219
+ const len = this.docs.length;
220
+ this.records = new Array(len);
221
+ let recordCount = 0;
222
+ if (isString(this.docs[0])) for (let i = 0; i < len; i++) {
223
+ const record = this._createStringRecord(this.docs[i], i);
224
+ if (record) this.records[recordCount++] = record;
225
+ }
226
+ else for (let i = 0; i < len; i++) this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
227
+ this.records.length = recordCount;
228
+ this.norm.clear();
229
+ }
230
+ add(doc, docIndex) {
231
+ if (!Number.isInteger(docIndex) || docIndex < 0) throw new Error(INVALID_DOC_INDEX);
232
+ if (isString(doc)) {
233
+ const record2 = this._createStringRecord(doc, docIndex);
234
+ if (record2) this.records.push(record2);
235
+ return record2;
236
+ }
237
+ const record = this._createObjectRecord(doc, docIndex);
238
+ this.records.push(record);
239
+ return record;
240
+ }
241
+ removeAt(idx) {
242
+ if (!Number.isInteger(idx) || idx < 0) throw new Error(INVALID_DOC_INDEX);
243
+ for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i === idx) {
244
+ this.records.splice(i, 1);
245
+ break;
246
+ }
247
+ for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i > idx) this.records[i].i -= 1;
248
+ }
249
+ removeAll(indices) {
250
+ const toRemove = /* @__PURE__ */ new Set();
251
+ for (const v of indices) if (Number.isInteger(v) && v >= 0) toRemove.add(v);
252
+ if (toRemove.size === 0) return;
253
+ this.records = this.records.filter((r) => !toRemove.has(r.i));
254
+ const sorted = Array.from(toRemove).sort((a, b) => a - b);
255
+ for (const record of this.records) {
256
+ let lo = 0;
257
+ let hi = sorted.length;
258
+ while (lo < hi) {
259
+ const mid = lo + hi >>> 1;
260
+ if (sorted[mid] < record.i) lo = mid + 1;
261
+ else hi = mid;
262
+ }
263
+ record.i -= lo;
264
+ }
265
+ }
266
+ getValueForItemAtKeyId(item, keyId) {
267
+ return item[this._keysMap[keyId]];
268
+ }
269
+ size() {
270
+ return this.records.length;
271
+ }
272
+ _createStringRecord(doc, docIndex) {
273
+ if (!isDefined(doc) || isBlank(doc)) return null;
274
+ return {
275
+ v: doc,
276
+ i: docIndex,
277
+ n: this.norm.get(doc)
278
+ };
279
+ }
280
+ _createObjectRecord(doc, docIndex) {
281
+ const record = {
282
+ i: docIndex,
283
+ $: {}
284
+ };
285
+ for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
286
+ const key = this.keys[keyIndex];
287
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
288
+ if (!isDefined(value)) continue;
289
+ if (isArray(value)) {
290
+ const subRecords = [];
291
+ for (let i = 0, len = value.length; i < len; i += 1) {
292
+ const item = value[i];
293
+ if (!isDefined(item)) continue;
294
+ if (isString(item)) {
295
+ if (!isBlank(item)) {
296
+ const subRecord = {
297
+ v: item,
298
+ i,
299
+ n: this.norm.get(item)
300
+ };
301
+ subRecords.push(subRecord);
302
+ }
303
+ } else if (isDefined(item.v)) {
304
+ const text = isString(item.v) ? item.v : toString(item.v);
305
+ if (!isBlank(text)) {
306
+ const subRecord = {
307
+ v: text,
308
+ i: item.i,
309
+ n: this.norm.get(text)
310
+ };
311
+ subRecords.push(subRecord);
312
+ }
313
+ }
314
+ }
315
+ record.$[keyIndex] = subRecords;
316
+ } else if (isString(value) && !isBlank(value)) {
317
+ const subRecord = {
318
+ v: value,
319
+ n: this.norm.get(value)
320
+ };
321
+ record.$[keyIndex] = subRecord;
322
+ }
323
+ }
324
+ return record;
325
+ }
326
+ toJSON() {
327
+ return {
328
+ keys: this.keys.map(({ getFn, ...key }) => key),
329
+ records: this.records
330
+ };
331
+ }
332
+ };
333
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
334
+ const myIndex = new FuseIndex({
335
+ getFn,
336
+ fieldNormWeight
337
+ });
338
+ myIndex.setKeys(keys.map(createKey));
339
+ myIndex.setSources(docs);
340
+ myIndex.create();
341
+ return myIndex;
342
+ }
343
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
344
+ const { keys, records } = data;
345
+ const myIndex = new FuseIndex({
346
+ getFn,
347
+ fieldNormWeight
348
+ });
349
+ myIndex.setKeys(keys);
350
+ myIndex.setIndexRecords(records);
351
+ return myIndex;
352
+ }
353
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
354
+ const indices = [];
355
+ let start = -1;
356
+ let end = -1;
357
+ let i = 0;
358
+ for (let len = matchmask.length; i < len; i += 1) {
359
+ const match = matchmask[i];
360
+ if (match && start === -1) start = i;
361
+ else if (!match && start !== -1) {
362
+ end = i - 1;
363
+ if (end - start + 1 >= minMatchCharLength) indices.push([start, end]);
364
+ start = -1;
365
+ }
366
+ }
367
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) indices.push([start, i - 1]);
368
+ return indices;
369
+ }
370
+ function search(text, pattern, patternAlphabet, { location = Config.location, distance = Config.distance, threshold = Config.threshold, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, includeMatches = Config.includeMatches, ignoreLocation = Config.ignoreLocation } = {}) {
371
+ if (pattern.length > 32) throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
372
+ const patternLen = pattern.length;
373
+ const textLen = text.length;
374
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
375
+ let currentThreshold = threshold;
376
+ let bestLocation = expectedLocation;
377
+ const calcScore = (errors, currentLocation) => {
378
+ const accuracy = errors / patternLen;
379
+ if (ignoreLocation) return accuracy;
380
+ const proximity = Math.abs(expectedLocation - currentLocation);
381
+ if (!distance) return proximity ? 1 : accuracy;
382
+ return accuracy + proximity / distance;
383
+ };
384
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
385
+ const matchMask = computeMatches ? Array(textLen) : [];
386
+ let index;
387
+ while ((index = text.indexOf(pattern, bestLocation)) > -1) {
388
+ const score = calcScore(0, index);
389
+ currentThreshold = Math.min(score, currentThreshold);
390
+ bestLocation = index + patternLen;
391
+ if (computeMatches) {
392
+ let i = 0;
393
+ while (i < patternLen) {
394
+ matchMask[index + i] = 1;
395
+ i += 1;
396
+ }
397
+ }
398
+ }
399
+ bestLocation = -1;
400
+ let lastBitArr = [];
401
+ let finalScore = 1;
402
+ let bestErrors = 0;
403
+ let binMax = patternLen + textLen;
404
+ const mask = 1 << patternLen - 1;
405
+ for (let i = 0; i < patternLen; i += 1) {
406
+ let binMin = 0;
407
+ let binMid = binMax;
408
+ while (binMin < binMid) {
409
+ if (calcScore(i, expectedLocation + binMid) <= currentThreshold) binMin = binMid;
410
+ else binMax = binMid;
411
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
412
+ }
413
+ binMax = binMid;
414
+ let start = Math.max(1, expectedLocation - binMid + 1);
415
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
416
+ const bitArr = Array(finish + 2);
417
+ bitArr[finish + 1] = (1 << i) - 1;
418
+ for (let j = finish; j >= start; j -= 1) {
419
+ const currentLocation = j - 1;
420
+ const charMatch = patternAlphabet[text[currentLocation]];
421
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
422
+ if (i) bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
423
+ if (bitArr[j] & mask) {
424
+ finalScore = calcScore(i, currentLocation);
425
+ if (finalScore <= currentThreshold) {
426
+ currentThreshold = finalScore;
427
+ bestLocation = currentLocation;
428
+ bestErrors = i;
429
+ if (bestLocation <= expectedLocation) break;
430
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
431
+ }
432
+ }
433
+ }
434
+ if (calcScore(i + 1, expectedLocation) > currentThreshold) break;
435
+ lastBitArr = bitArr;
436
+ }
437
+ if (computeMatches && bestLocation >= 0) {
438
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
439
+ for (let k = bestLocation; k <= matchEnd; k += 1) if (patternAlphabet[text[k]]) matchMask[k] = 1;
440
+ }
441
+ const result = {
442
+ isMatch: bestLocation >= 0,
443
+ score: Math.max(1e-3, finalScore)
444
+ };
445
+ if (computeMatches) {
446
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
447
+ if (!indices.length) result.isMatch = false;
448
+ else if (includeMatches) result.indices = indices;
449
+ }
450
+ return result;
451
+ }
452
+ function createPatternAlphabet(pattern) {
453
+ const mask = {};
454
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
455
+ const char = pattern.charAt(i);
456
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
457
+ }
458
+ return mask;
459
+ }
460
+ function mergeIndices(indices) {
461
+ if (indices.length <= 1) return indices;
462
+ indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
463
+ const merged = [indices[0]];
464
+ for (let i = 1, len = indices.length; i < len; i += 1) {
465
+ const last = merged[merged.length - 1];
466
+ const curr = indices[i];
467
+ if (curr[0] <= last[1] + 1) last[1] = Math.max(last[1], curr[1]);
468
+ else merged.push(curr);
469
+ }
470
+ return merged;
471
+ }
472
+ var NON_DECOMPOSABLE_MAP = {
473
+ "\u0142": "l",
474
+ "\u0141": "L",
475
+ "\u0111": "d",
476
+ "\u0110": "D",
477
+ "\xF8": "o",
478
+ "\xD8": "O",
479
+ "\u0127": "h",
480
+ "\u0126": "H",
481
+ "\u0167": "t",
482
+ "\u0166": "T",
483
+ "\u0131": "i",
484
+ "\xDF": "ss"
485
+ };
486
+ var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
487
+ var stripDiacritics = typeof String.prototype.normalize === "function" ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch) => NON_DECOMPOSABLE_MAP[ch]) : (str) => str;
488
+ var BitapSearch = class {
489
+ constructor(pattern, { location = Config.location, threshold = Config.threshold, distance = Config.distance, includeMatches = Config.includeMatches, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, ignoreLocation = Config.ignoreLocation } = {}) {
490
+ this.options = {
491
+ location,
492
+ threshold,
493
+ distance,
494
+ includeMatches,
495
+ findAllMatches,
496
+ minMatchCharLength,
497
+ isCaseSensitive,
498
+ ignoreDiacritics,
499
+ ignoreLocation
500
+ };
501
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
502
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
503
+ this.pattern = pattern;
504
+ this.chunks = [];
505
+ if (!this.pattern.length) return;
506
+ const addChunk = (pattern2, startIndex) => {
507
+ this.chunks.push({
508
+ pattern: pattern2,
509
+ alphabet: createPatternAlphabet(pattern2),
510
+ startIndex
511
+ });
512
+ };
513
+ const len = this.pattern.length;
514
+ if (len > 32) {
515
+ let i = 0;
516
+ const remainder = len % 32;
517
+ const end = len - remainder;
518
+ while (i < end) {
519
+ addChunk(this.pattern.substr(i, 32), i);
520
+ i += 32;
521
+ }
522
+ if (remainder) {
523
+ const startIndex = len - 32;
524
+ addChunk(this.pattern.substr(startIndex), startIndex);
525
+ }
526
+ } else addChunk(this.pattern, 0);
527
+ }
528
+ searchIn(text) {
529
+ const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
530
+ text = isCaseSensitive ? text : text.toLowerCase();
531
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
532
+ if (this.pattern === text) {
533
+ if (text.length < this.options.minMatchCharLength) return {
534
+ isMatch: false,
535
+ score: 1
536
+ };
537
+ const result2 = {
538
+ isMatch: true,
539
+ score: 0
540
+ };
541
+ if (includeMatches) result2.indices = [[0, text.length - 1]];
542
+ return result2;
543
+ }
544
+ const { location, distance, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
545
+ const allIndices = [];
546
+ let totalScore = 0;
547
+ let hasMatches = false;
548
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
549
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
550
+ location: location + startIndex,
551
+ distance,
552
+ threshold,
553
+ findAllMatches,
554
+ minMatchCharLength,
555
+ includeMatches,
556
+ ignoreLocation
557
+ });
558
+ if (isMatch) hasMatches = true;
559
+ totalScore += score;
560
+ if (isMatch && indices) allIndices.push(...indices);
561
+ });
562
+ const result = {
563
+ isMatch: hasMatches,
564
+ score: hasMatches ? totalScore / this.chunks.length : 1
565
+ };
566
+ if (hasMatches && includeMatches) result.indices = mergeIndices(allIndices);
567
+ return result;
568
+ }
569
+ };
570
+ var MULTI_MATCH_TYPES = /* @__PURE__ */ new Set(["fuzzy", "include"]);
571
+ function isInverse(type) {
572
+ return type.startsWith("inverse");
573
+ }
574
+ var matchers = [
575
+ {
576
+ type: "exact",
577
+ multiRegex: /^="(.*)"$/,
578
+ singleRegex: /^=(.*)$/,
579
+ create: (pattern) => ({
580
+ type: "exact",
581
+ search(text) {
582
+ const isMatch = text === pattern;
583
+ return {
584
+ isMatch,
585
+ score: isMatch ? 0 : 1,
586
+ indices: [0, pattern.length - 1]
587
+ };
588
+ }
589
+ })
590
+ },
591
+ {
592
+ type: "include",
593
+ multiRegex: /^'"(.*)"$/,
594
+ singleRegex: /^'(.*)$/,
595
+ create: (pattern) => ({
596
+ type: "include",
597
+ search(text) {
598
+ let location = 0;
599
+ let index;
600
+ const indices = [];
601
+ const patternLen = pattern.length;
602
+ while ((index = text.indexOf(pattern, location)) > -1) {
603
+ location = index + patternLen;
604
+ indices.push([index, location - 1]);
605
+ }
606
+ const isMatch = !!indices.length;
607
+ return {
608
+ isMatch,
609
+ score: isMatch ? 0 : 1,
610
+ indices
611
+ };
612
+ }
613
+ })
614
+ },
615
+ {
616
+ type: "prefix-exact",
617
+ multiRegex: /^\^"(.*)"$/,
618
+ singleRegex: /^\^(.*)$/,
619
+ create: (pattern) => ({
620
+ type: "prefix-exact",
621
+ search(text) {
622
+ const isMatch = text.startsWith(pattern);
623
+ return {
624
+ isMatch,
625
+ score: isMatch ? 0 : 1,
626
+ indices: [0, pattern.length - 1]
627
+ };
628
+ }
629
+ })
630
+ },
631
+ {
632
+ type: "inverse-prefix-exact",
633
+ multiRegex: /^!\^"(.*)"$/,
634
+ singleRegex: /^!\^(.*)$/,
635
+ create: (pattern) => ({
636
+ type: "inverse-prefix-exact",
637
+ search(text) {
638
+ const isMatch = !text.startsWith(pattern);
639
+ return {
640
+ isMatch,
641
+ score: isMatch ? 0 : 1,
642
+ indices: [0, text.length - 1]
643
+ };
644
+ }
645
+ })
646
+ },
647
+ {
648
+ type: "inverse-suffix-exact",
649
+ multiRegex: /^!"(.*)"\$$/,
650
+ singleRegex: /^!(.*)\$$/,
651
+ create: (pattern) => ({
652
+ type: "inverse-suffix-exact",
653
+ search(text) {
654
+ const isMatch = !text.endsWith(pattern);
655
+ return {
656
+ isMatch,
657
+ score: isMatch ? 0 : 1,
658
+ indices: [0, text.length - 1]
659
+ };
660
+ }
661
+ })
662
+ },
663
+ {
664
+ type: "suffix-exact",
665
+ multiRegex: /^"(.*)"\$$/,
666
+ singleRegex: /^(.*)\$$/,
667
+ create: (pattern) => ({
668
+ type: "suffix-exact",
669
+ search(text) {
670
+ const isMatch = text.endsWith(pattern);
671
+ return {
672
+ isMatch,
673
+ score: isMatch ? 0 : 1,
674
+ indices: [text.length - pattern.length, text.length - 1]
675
+ };
676
+ }
677
+ })
678
+ },
679
+ {
680
+ type: "inverse-exact",
681
+ multiRegex: /^!"(.*)"$/,
682
+ singleRegex: /^!(.*)$/,
683
+ create: (pattern) => ({
684
+ type: "inverse-exact",
685
+ search(text) {
686
+ const isMatch = text.indexOf(pattern) === -1;
687
+ return {
688
+ isMatch,
689
+ score: isMatch ? 0 : 1,
690
+ indices: [0, text.length - 1]
691
+ };
692
+ }
693
+ })
694
+ },
695
+ {
696
+ type: "fuzzy",
697
+ multiRegex: /^"(.*)"$/,
698
+ singleRegex: /^(.*)$/,
699
+ create: (pattern, options = {}) => {
700
+ const bitap = new BitapSearch(pattern, {
701
+ location: options.location ?? Config.location,
702
+ threshold: options.threshold ?? Config.threshold,
703
+ distance: options.distance ?? Config.distance,
704
+ includeMatches: options.includeMatches ?? Config.includeMatches,
705
+ findAllMatches: options.findAllMatches ?? Config.findAllMatches,
706
+ minMatchCharLength: options.minMatchCharLength ?? Config.minMatchCharLength,
707
+ isCaseSensitive: options.isCaseSensitive ?? Config.isCaseSensitive,
708
+ ignoreDiacritics: options.ignoreDiacritics ?? Config.ignoreDiacritics,
709
+ ignoreLocation: options.ignoreLocation ?? Config.ignoreLocation
710
+ });
711
+ return {
712
+ type: "fuzzy",
713
+ search(text) {
714
+ return bitap.searchIn(text);
715
+ }
716
+ };
717
+ }
718
+ }
719
+ ];
720
+ var matchersLen = matchers.length;
721
+ var ESCAPED_PIPE = "\0";
722
+ var OR_TOKEN = "|";
723
+ function tokenize(pattern) {
724
+ const tokens = [];
725
+ const len = pattern.length;
726
+ let i = 0;
727
+ while (i < len) {
728
+ while (i < len && pattern[i] === " ") i++;
729
+ if (i >= len) break;
730
+ let j = i;
731
+ while (j < len && pattern[j] !== " " && pattern[j] !== '"') j++;
732
+ if (j < len && pattern[j] === '"') {
733
+ j++;
734
+ while (j < len) {
735
+ if (pattern[j] === '"') {
736
+ const next = j + 1;
737
+ if (next >= len || pattern[next] === " ") {
738
+ j++;
739
+ break;
740
+ }
741
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
742
+ j += 2;
743
+ break;
744
+ }
745
+ }
746
+ j++;
747
+ }
748
+ tokens.push(pattern.substring(i, j));
749
+ i = j;
750
+ } else {
751
+ while (j < len && pattern[j] !== " ") j++;
752
+ tokens.push(pattern.substring(i, j));
753
+ i = j;
754
+ }
755
+ }
756
+ return tokens;
757
+ }
758
+ function getMatch(pattern, exp) {
759
+ const matches = pattern.match(exp);
760
+ return matches ? matches[1] : null;
761
+ }
762
+ function parseQuery(pattern, options = {}) {
763
+ return pattern.replace(/\\\|/g, ESCAPED_PIPE).split(OR_TOKEN).map((item) => {
764
+ const query = tokenize(item.replace(/\u0000/g, "|").trim()).filter((item2) => item2 && !!item2.trim());
765
+ const results = [];
766
+ for (let i = 0, len = query.length; i < len; i += 1) {
767
+ const queryItem = query[i];
768
+ let found = false;
769
+ let idx = -1;
770
+ while (!found && ++idx < matchersLen) {
771
+ const def = matchers[idx];
772
+ const token = getMatch(queryItem, def.multiRegex);
773
+ if (token) {
774
+ results.push(def.create(token, options));
775
+ found = true;
776
+ }
777
+ }
778
+ if (found) continue;
779
+ idx = -1;
780
+ while (++idx < matchersLen) {
781
+ const def = matchers[idx];
782
+ const token = getMatch(queryItem, def.singleRegex);
783
+ if (token) {
784
+ results.push(def.create(token, options));
785
+ break;
786
+ }
787
+ }
788
+ }
789
+ return results;
790
+ });
791
+ }
792
+ var ExtendedSearch = class {
793
+ constructor(pattern, { isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, includeMatches = Config.includeMatches, minMatchCharLength = Config.minMatchCharLength, ignoreLocation = Config.ignoreLocation, findAllMatches = Config.findAllMatches, location = Config.location, threshold = Config.threshold, distance = Config.distance } = {}) {
794
+ this.query = null;
795
+ this.options = {
796
+ isCaseSensitive,
797
+ ignoreDiacritics,
798
+ includeMatches,
799
+ minMatchCharLength,
800
+ findAllMatches,
801
+ ignoreLocation,
802
+ location,
803
+ threshold,
804
+ distance
805
+ };
806
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
807
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
808
+ this.pattern = pattern;
809
+ this.query = parseQuery(this.pattern, this.options);
810
+ }
811
+ static condition(_, options) {
812
+ return options.useExtendedSearch;
813
+ }
814
+ searchIn(text) {
815
+ const query = this.query;
816
+ if (!query) return {
817
+ isMatch: false,
818
+ score: 1
819
+ };
820
+ const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
821
+ text = isCaseSensitive ? text : text.toLowerCase();
822
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
823
+ let numMatches = 0;
824
+ const allIndices = [];
825
+ let totalScore = 0;
826
+ let hasInverse = false;
827
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
828
+ const searchers = query[i];
829
+ allIndices.length = 0;
830
+ numMatches = 0;
831
+ hasInverse = false;
832
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
833
+ const matcher = searchers[j];
834
+ const { isMatch, indices, score } = matcher.search(text);
835
+ if (isMatch) {
836
+ numMatches += 1;
837
+ totalScore += score;
838
+ if (isInverse(matcher.type)) hasInverse = true;
839
+ if (includeMatches) if (MULTI_MATCH_TYPES.has(matcher.type)) allIndices.push(...indices);
840
+ else allIndices.push(indices);
841
+ } else {
842
+ totalScore = 0;
843
+ numMatches = 0;
844
+ allIndices.length = 0;
845
+ hasInverse = false;
846
+ break;
847
+ }
848
+ }
849
+ if (numMatches) {
850
+ const result = {
851
+ isMatch: true,
852
+ score: totalScore / numMatches
853
+ };
854
+ if (hasInverse) result.hasInverse = true;
855
+ if (includeMatches) result.indices = mergeIndices(allIndices);
856
+ return result;
857
+ }
858
+ }
859
+ return {
860
+ isMatch: false,
861
+ score: 1
862
+ };
863
+ }
864
+ };
865
+ var registeredSearchers = [];
866
+ function register(...args) {
867
+ registeredSearchers.push(...args);
868
+ }
869
+ function createSearcher(pattern, options) {
870
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
871
+ const searcherClass = registeredSearchers[i];
872
+ if (searcherClass.condition(pattern, options)) return new searcherClass(pattern, options);
873
+ }
874
+ return new BitapSearch(pattern, options);
875
+ }
876
+ var LogicalOperator = {
877
+ AND: "$and",
878
+ OR: "$or"
879
+ };
880
+ var KeyType = {
881
+ PATH: "$path",
882
+ PATTERN: "$val"
883
+ };
884
+ var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
885
+ var isPath = (query) => !!query[KeyType.PATH];
886
+ var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
887
+ var convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
888
+ function parse(query, options, { auto = true } = {}) {
889
+ const next = (query2) => {
890
+ if (isString(query2)) {
891
+ const obj = {
892
+ keyId: null,
893
+ pattern: query2
894
+ };
895
+ if (auto) obj.searcher = createSearcher(query2, options);
896
+ return obj;
897
+ }
898
+ const keys = Object.keys(query2);
899
+ const isQueryPath = isPath(query2);
900
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) return next(convertToExplicit(query2));
901
+ if (isLeaf(query2)) {
902
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
903
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
904
+ if (!isString(pattern)) throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
905
+ const obj = {
906
+ keyId: createKeyId(key),
907
+ pattern
908
+ };
909
+ if (auto) obj.searcher = createSearcher(pattern, options);
910
+ return obj;
911
+ }
912
+ const node = {
913
+ children: [],
914
+ operator: keys[0]
915
+ };
916
+ keys.forEach((key) => {
917
+ const value = query2[key];
918
+ if (isArray(value)) value.forEach((item) => {
919
+ node.children.push(next(item));
920
+ });
921
+ });
922
+ return node;
923
+ };
924
+ if (!isExpression(query)) query = convertToExplicit(query);
925
+ return next(query);
926
+ }
927
+ function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
928
+ let totalScore = 1;
929
+ matches.forEach(({ key, norm: norm2, score }) => {
930
+ const weight = key ? key.weight : null;
931
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
932
+ });
933
+ return totalScore;
934
+ }
935
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
936
+ results.forEach((result) => {
937
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
938
+ });
939
+ }
940
+ var MaxHeap = class {
941
+ constructor(limit, comparator) {
942
+ this.limit = limit;
943
+ this.heap = [];
944
+ this.comparator = comparator;
945
+ }
946
+ get size() {
947
+ return this.heap.length;
948
+ }
949
+ insert(item) {
950
+ if (this.size < this.limit) {
951
+ this.heap.push(item);
952
+ this._bubbleUp(this.size - 1);
953
+ } else if (this.comparator(item, this.heap[0]) < 0) {
954
+ this.heap[0] = item;
955
+ this._sinkDown(0);
956
+ }
957
+ }
958
+ extractSorted() {
959
+ return this.heap.sort(this.comparator);
960
+ }
961
+ _bubbleUp(i) {
962
+ const heap = this.heap;
963
+ while (i > 0) {
964
+ const parent = i - 1 >> 1;
965
+ if (this.comparator(heap[i], heap[parent]) <= 0) break;
966
+ const tmp = heap[i];
967
+ heap[i] = heap[parent];
968
+ heap[parent] = tmp;
969
+ i = parent;
970
+ }
971
+ }
972
+ _sinkDown(i) {
973
+ const heap = this.heap;
974
+ const len = heap.length;
975
+ let largest = i;
976
+ do {
977
+ i = largest;
978
+ const left = 2 * i + 1;
979
+ const right = 2 * i + 2;
980
+ if (left < len && this.comparator(heap[left], heap[largest]) > 0) largest = left;
981
+ if (right < len && this.comparator(heap[right], heap[largest]) > 0) largest = right;
982
+ if (largest !== i) {
983
+ const tmp = heap[i];
984
+ heap[i] = heap[largest];
985
+ heap[largest] = tmp;
986
+ }
987
+ } while (largest !== i);
988
+ }
989
+ };
990
+ function formatMatches(result) {
991
+ const matches = [];
992
+ result.matches.forEach((match) => {
993
+ if (!isDefined(match.indices) || !match.indices.length) return;
994
+ const obj = {
995
+ indices: match.indices,
996
+ value: match.value
997
+ };
998
+ if (match.key) obj.key = match.key.id;
999
+ if (match.idx > -1) obj.refIndex = match.idx;
1000
+ matches.push(obj);
1001
+ });
1002
+ return matches;
1003
+ }
1004
+ function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
1005
+ return results.map((result) => {
1006
+ const { idx } = result;
1007
+ const data = {
1008
+ item: docs[idx],
1009
+ refIndex: idx
1010
+ };
1011
+ if (includeMatches) data.matches = formatMatches(result);
1012
+ if (includeScore) data.score = result.score;
1013
+ return data;
1014
+ });
1015
+ }
1016
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
1017
+ var warned = /* @__PURE__ */ new WeakSet();
1018
+ function warnNonGlobal(regex) {
1019
+ if (!warned.has(regex)) {
1020
+ warned.add(regex);
1021
+ console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
1022
+ }
1023
+ }
1024
+ function resolveTokenize(tokenize2) {
1025
+ if (typeof tokenize2 === "function") {
1026
+ let validated = false;
1027
+ return (text) => {
1028
+ const result = tokenize2(text);
1029
+ if (!validated) {
1030
+ validated = true;
1031
+ if (!Array.isArray(result) || result.some((t) => typeof t !== "string")) throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
1032
+ }
1033
+ return result;
1034
+ };
1035
+ }
1036
+ if (tokenize2 instanceof RegExp) {
1037
+ if (!tokenize2.global) warnNonGlobal(tokenize2);
1038
+ return (text) => text.match(tokenize2) || [];
1039
+ }
1040
+ return (text) => text.match(DEFAULT_TOKEN) || [];
1041
+ }
1042
+ function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize: tokenize2 } = {}) {
1043
+ const tokenizeFn = resolveTokenize(tokenize2);
1044
+ return { tokenize(text) {
1045
+ if (!isCaseSensitive) text = text.toLowerCase();
1046
+ if (ignoreDiacritics) text = stripDiacritics(text);
1047
+ return tokenizeFn(text);
1048
+ } };
1049
+ }
1050
+ var TokenSearch = class {
1051
+ static condition(_, options) {
1052
+ return options.useTokenSearch;
1053
+ }
1054
+ constructor(pattern, options) {
1055
+ this.options = options;
1056
+ this.analyzer = createAnalyzer({
1057
+ isCaseSensitive: options.isCaseSensitive,
1058
+ ignoreDiacritics: options.ignoreDiacritics,
1059
+ tokenize: options.tokenize
1060
+ });
1061
+ const queryTerms = this.analyzer.tokenize(pattern);
1062
+ const { df, fieldCount } = options._invertedIndex;
1063
+ this.termSearchers = [];
1064
+ this.idfWeights = [];
1065
+ for (const term of queryTerms) {
1066
+ this.termSearchers.push(new BitapSearch(term, {
1067
+ location: options.location,
1068
+ threshold: options.threshold,
1069
+ distance: options.distance,
1070
+ includeMatches: options.includeMatches,
1071
+ findAllMatches: options.findAllMatches,
1072
+ minMatchCharLength: options.minMatchCharLength,
1073
+ isCaseSensitive: options.isCaseSensitive,
1074
+ ignoreDiacritics: options.ignoreDiacritics,
1075
+ ignoreLocation: true
1076
+ }));
1077
+ const docFreq = df.get(term) || 0;
1078
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
1079
+ this.idfWeights.push(idf);
1080
+ }
1081
+ this.combineAll = options.tokenMatch === "all";
1082
+ this.numTerms = this.termSearchers.length;
1083
+ this.useMask = this.numTerms <= 31;
1084
+ }
1085
+ searchIn(text) {
1086
+ if (!this.termSearchers.length) return {
1087
+ isMatch: false,
1088
+ score: 1
1089
+ };
1090
+ const allIndices = [];
1091
+ let weightedScore = 0;
1092
+ let maxPossibleScore = 0;
1093
+ let matchedCount = 0;
1094
+ let matchedMask = 0;
1095
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
1096
+ for (let i = 0; i < this.termSearchers.length; i++) {
1097
+ const result = this.termSearchers[i].searchIn(text);
1098
+ const idf = this.idfWeights[i];
1099
+ maxPossibleScore += idf;
1100
+ if (result.isMatch) {
1101
+ matchedCount++;
1102
+ weightedScore += idf * (1 - result.score);
1103
+ if (result.indices) allIndices.push(...result.indices);
1104
+ if (this.combineAll) if (this.useMask) matchedMask |= 1 << i;
1105
+ else matchedTerms.add(i);
1106
+ }
1107
+ }
1108
+ if (matchedCount === 0) return {
1109
+ isMatch: false,
1110
+ score: 1
1111
+ };
1112
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
1113
+ const searchResult = {
1114
+ isMatch: true,
1115
+ score: Math.max(1e-3, normalized)
1116
+ };
1117
+ if (this.options.includeMatches && allIndices.length) searchResult.indices = mergeIndices(allIndices);
1118
+ if (this.combineAll) {
1119
+ if (this.useMask) searchResult.matchedMask = matchedMask;
1120
+ else searchResult.matchedTerms = matchedTerms;
1121
+ searchResult.termCount = this.numTerms;
1122
+ }
1123
+ return searchResult;
1124
+ }
1125
+ };
1126
+ function addField(index, text, docIdx, analyzer) {
1127
+ const tokens = analyzer.tokenize(text);
1128
+ if (!tokens.length) return;
1129
+ index.fieldCount++;
1130
+ index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
1131
+ const distinctTerms = new Set(tokens);
1132
+ let perDocTerms = index.docTermFieldHits.get(docIdx);
1133
+ if (!perDocTerms) {
1134
+ perDocTerms = /* @__PURE__ */ new Map();
1135
+ index.docTermFieldHits.set(docIdx, perDocTerms);
1136
+ }
1137
+ for (const term of distinctTerms) {
1138
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
1139
+ index.df.set(term, (index.df.get(term) || 0) + 1);
1140
+ }
1141
+ }
1142
+ function ingestRecord(index, record, keyCount, analyzer) {
1143
+ const { i: docIdx, v, $: fields } = record;
1144
+ if (v !== void 0) {
1145
+ addField(index, v, docIdx, analyzer);
1146
+ return;
1147
+ }
1148
+ if (!fields) return;
1149
+ for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
1150
+ const value = fields[keyIdx];
1151
+ if (!value) continue;
1152
+ if (Array.isArray(value)) for (const sub of value) addField(index, sub.v, docIdx, analyzer);
1153
+ else addField(index, value.v, docIdx, analyzer);
1154
+ }
1155
+ }
1156
+ function buildInvertedIndex(records, keyCount, analyzer) {
1157
+ const index = {
1158
+ fieldCount: 0,
1159
+ df: /* @__PURE__ */ new Map(),
1160
+ docFieldCount: /* @__PURE__ */ new Map(),
1161
+ docTermFieldHits: /* @__PURE__ */ new Map()
1162
+ };
1163
+ for (const record of records) ingestRecord(index, record, keyCount, analyzer);
1164
+ return index;
1165
+ }
1166
+ function addToInvertedIndex(index, record, keyCount, analyzer) {
1167
+ ingestRecord(index, record, keyCount, analyzer);
1168
+ }
1169
+ function removeFromInvertedIndex(index, docIdx) {
1170
+ const fieldCount = index.docFieldCount.get(docIdx);
1171
+ if (fieldCount === void 0) return;
1172
+ index.fieldCount -= fieldCount;
1173
+ index.docFieldCount.delete(docIdx);
1174
+ const perDocTerms = index.docTermFieldHits.get(docIdx);
1175
+ if (!perDocTerms) return;
1176
+ for (const [term, hits] of perDocTerms) {
1177
+ const next = (index.df.get(term) || 0) - hits;
1178
+ if (next <= 0) index.df.delete(term);
1179
+ else index.df.set(term, next);
1180
+ }
1181
+ index.docTermFieldHits.delete(docIdx);
1182
+ }
1183
+ function removeAndShiftInvertedIndex(index, removedIndices) {
1184
+ if (removedIndices.length === 0) return;
1185
+ const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
1186
+ for (const idx of sorted) removeFromInvertedIndex(index, idx);
1187
+ const shift = (oldIdx) => {
1188
+ let lo = 0;
1189
+ let hi = sorted.length;
1190
+ while (lo < hi) {
1191
+ const mid = lo + hi >>> 1;
1192
+ if (sorted[mid] < oldIdx) lo = mid + 1;
1193
+ else hi = mid;
1194
+ }
1195
+ return oldIdx - lo;
1196
+ };
1197
+ const firstRemoved = sorted[0];
1198
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map();
1199
+ for (const [oldKey, count] of index.docFieldCount) shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
1200
+ index.docFieldCount = shiftedDocFieldCount;
1201
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
1202
+ for (const [oldKey, terms] of index.docTermFieldHits) shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
1203
+ index.docTermFieldHits = shiftedDocTermFieldHits;
1204
+ }
1205
+ var Fuse = class {
1206
+ constructor(docs, options, index) {
1207
+ this.options = {
1208
+ ...Config,
1209
+ ...options
1210
+ };
1211
+ if (this.options.useExtendedSearch && false) ;
1212
+ if (this.options.useTokenSearch && false) ;
1213
+ this._keyStore = new KeyStore(this.options.keys);
1214
+ this._docs = docs;
1215
+ this._myIndex = null;
1216
+ this._invertedIndex = null;
1217
+ this.setCollection(docs, index);
1218
+ this._lastQuery = null;
1219
+ this._lastSearcher = null;
1220
+ }
1221
+ _getSearcher(query) {
1222
+ if (this._lastQuery === query) return this._lastSearcher;
1223
+ const searcher = createSearcher(query, this._invertedIndex ? {
1224
+ ...this.options,
1225
+ _invertedIndex: this._invertedIndex
1226
+ } : this.options);
1227
+ this._lastQuery = query;
1228
+ this._lastSearcher = searcher;
1229
+ return searcher;
1230
+ }
1231
+ setCollection(docs, index) {
1232
+ this._docs = docs;
1233
+ if (index && !(index instanceof FuseIndex)) throw new Error(INCORRECT_INDEX_TYPE);
1234
+ this._myIndex = index || createIndex(this.options.keys, this._docs, {
1235
+ getFn: this.options.getFn,
1236
+ fieldNormWeight: this.options.fieldNormWeight
1237
+ });
1238
+ if (this.options.useTokenSearch) {
1239
+ const analyzer = createAnalyzer({
1240
+ isCaseSensitive: this.options.isCaseSensitive,
1241
+ ignoreDiacritics: this.options.ignoreDiacritics,
1242
+ tokenize: this.options.tokenize
1243
+ });
1244
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
1245
+ }
1246
+ this._invalidateSearcherCache();
1247
+ }
1248
+ add(doc) {
1249
+ if (!isDefined(doc)) return;
1250
+ this._docs.push(doc);
1251
+ const record = this._myIndex.add(doc, this._docs.length - 1);
1252
+ if (this._invertedIndex && record) {
1253
+ const analyzer = createAnalyzer({
1254
+ isCaseSensitive: this.options.isCaseSensitive,
1255
+ ignoreDiacritics: this.options.ignoreDiacritics,
1256
+ tokenize: this.options.tokenize
1257
+ });
1258
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
1259
+ }
1260
+ this._invalidateSearcherCache();
1261
+ }
1262
+ remove(predicate = () => false) {
1263
+ const results = [];
1264
+ const indicesToRemove = [];
1265
+ for (let i = 0, len = this._docs.length; i < len; i += 1) if (predicate(this._docs[i], i)) {
1266
+ results.push(this._docs[i]);
1267
+ indicesToRemove.push(i);
1268
+ }
1269
+ if (indicesToRemove.length) {
1270
+ if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
1271
+ const toRemove = new Set(indicesToRemove);
1272
+ this._docs = this._docs.filter((_, i) => !toRemove.has(i));
1273
+ this._myIndex.removeAll(indicesToRemove);
1274
+ this._invalidateSearcherCache();
1275
+ }
1276
+ return results;
1277
+ }
1278
+ removeAt(idx) {
1279
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) throw new Error(INVALID_DOC_INDEX);
1280
+ if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
1281
+ const doc = this._docs.splice(idx, 1)[0];
1282
+ this._myIndex.removeAt(idx);
1283
+ this._invalidateSearcherCache();
1284
+ return doc;
1285
+ }
1286
+ _invalidateSearcherCache() {
1287
+ this._lastQuery = null;
1288
+ this._lastSearcher = null;
1289
+ }
1290
+ getIndex() {
1291
+ return this._myIndex;
1292
+ }
1293
+ _normalizedKeys() {
1294
+ return this._myIndex.keys.map((key) => this._keyStore.get(key.id) || key);
1295
+ }
1296
+ search(query, options) {
1297
+ const { limit = -1 } = options || {};
1298
+ const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
1299
+ if (isString(query) && !query.trim()) {
1300
+ let docs = this._docs.map((item, idx) => ({
1301
+ item,
1302
+ refIndex: idx
1303
+ }));
1304
+ if (isNumber(limit) && limit > -1) docs = docs.slice(0, limit);
1305
+ return docs;
1306
+ }
1307
+ const useHeap = shouldSort && isNumber(limit) && limit > 0 && isString(query);
1308
+ const comparator = sortFn;
1309
+ const stable = (a, b) => comparator(a, b) || a.idx - b.idx;
1310
+ let results;
1311
+ if (useHeap) {
1312
+ const heap = new MaxHeap(limit, stable);
1313
+ if (isString(this._docs[0])) this._searchStringList(query, {
1314
+ heap,
1315
+ ignoreFieldNorm
1316
+ });
1317
+ else this._searchObjectList(query, {
1318
+ heap,
1319
+ ignoreFieldNorm
1320
+ });
1321
+ results = heap.extractSorted();
1322
+ } else {
1323
+ results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
1324
+ computeScore(results, { ignoreFieldNorm });
1325
+ if (shouldSort) results.sort(isString(query) ? stable : comparator);
1326
+ if (isNumber(limit) && limit > -1) results = results.slice(0, limit);
1327
+ }
1328
+ return format(results, this._docs, {
1329
+ includeMatches,
1330
+ includeScore
1331
+ });
1332
+ }
1333
+ _searchStringList(query, { heap, ignoreFieldNorm } = {}) {
1334
+ const searcher = this._getSearcher(query);
1335
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
1336
+ const { records } = this._myIndex;
1337
+ const results = heap ? null : [];
1338
+ records.forEach(({ v: text, i: idx, n: norm2 }) => {
1339
+ if (!isDefined(text)) return;
1340
+ const searchResult = searcher.searchIn(text);
1341
+ if (searchResult.isMatch) {
1342
+ const match = {
1343
+ score: searchResult.score,
1344
+ value: text,
1345
+ norm: norm2,
1346
+ indices: searchResult.indices
1347
+ };
1348
+ if (requireAllTokens) {
1349
+ match.matchedMask = searchResult.matchedMask;
1350
+ match.matchedTerms = searchResult.matchedTerms;
1351
+ match.termCount = searchResult.termCount;
1352
+ }
1353
+ const matches = [match];
1354
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
1355
+ const result = {
1356
+ item: text,
1357
+ idx,
1358
+ matches
1359
+ };
1360
+ if (heap) {
1361
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
1362
+ heap.insert(result);
1363
+ } else results.push(result);
1364
+ }
1365
+ }
1366
+ });
1367
+ return results;
1368
+ }
1369
+ _searchLogical(query) {
1370
+ const expression = parse(query, this.options);
1371
+ const keys = this._normalizedKeys();
1372
+ const evaluate = (node, item, idx) => {
1373
+ if (!("children" in node)) {
1374
+ const { keyId, searcher } = node;
1375
+ let matches;
1376
+ if (keyId === null) {
1377
+ matches = [];
1378
+ keys.forEach((key, keyIndex) => {
1379
+ matches.push(...this._findMatches({
1380
+ key,
1381
+ value: item[keyIndex],
1382
+ searcher
1383
+ }));
1384
+ });
1385
+ } else matches = this._findMatches({
1386
+ key: this._keyStore.get(keyId),
1387
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
1388
+ searcher
1389
+ });
1390
+ if (matches && matches.length) return [{
1391
+ idx,
1392
+ item,
1393
+ matches
1394
+ }];
1395
+ return [];
1396
+ }
1397
+ const { children, operator } = node;
1398
+ const res = [];
1399
+ for (let i = 0, len = children.length; i < len; i += 1) {
1400
+ const child = children[i];
1401
+ const result = evaluate(child, item, idx);
1402
+ if (result.length) res.push(...result);
1403
+ else if (operator === LogicalOperator.AND) return [];
1404
+ }
1405
+ return res;
1406
+ };
1407
+ const records = this._myIndex.records;
1408
+ const resultMap = /* @__PURE__ */ new Map();
1409
+ const results = [];
1410
+ records.forEach(({ $: item, i: idx }) => {
1411
+ if (isDefined(item)) {
1412
+ const expResults = evaluate(expression, item, idx);
1413
+ if (expResults.length) {
1414
+ if (!resultMap.has(idx)) {
1415
+ resultMap.set(idx, {
1416
+ idx,
1417
+ item,
1418
+ matches: []
1419
+ });
1420
+ results.push(resultMap.get(idx));
1421
+ }
1422
+ expResults.forEach(({ matches }) => {
1423
+ resultMap.get(idx).matches.push(...matches);
1424
+ });
1425
+ }
1426
+ }
1427
+ });
1428
+ return results;
1429
+ }
1430
+ _searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
1431
+ const searcher = this._getSearcher(query);
1432
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
1433
+ const { records } = this._myIndex;
1434
+ const keys = this._normalizedKeys();
1435
+ const results = heap ? null : [];
1436
+ records.forEach(({ $: item, i: idx }) => {
1437
+ if (!isDefined(item)) return;
1438
+ const matches = [];
1439
+ let anyKeyFailed = false;
1440
+ let hasInverse = false;
1441
+ keys.forEach((key, keyIndex) => {
1442
+ const keyMatches = this._findMatches({
1443
+ key,
1444
+ value: item[keyIndex],
1445
+ searcher
1446
+ });
1447
+ if (keyMatches.length) {
1448
+ matches.push(...keyMatches);
1449
+ if (keyMatches[0].hasInverse) hasInverse = true;
1450
+ } else anyKeyFailed = true;
1451
+ });
1452
+ if (hasInverse && anyKeyFailed) return;
1453
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
1454
+ const result = {
1455
+ idx,
1456
+ item,
1457
+ matches
1458
+ };
1459
+ if (heap) {
1460
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
1461
+ heap.insert(result);
1462
+ } else results.push(result);
1463
+ }
1464
+ });
1465
+ return results;
1466
+ }
1467
+ _findMatches({ key, value, searcher }) {
1468
+ if (!isDefined(value)) return [];
1469
+ const matches = [];
1470
+ if (isArray(value)) value.forEach(({ v: text, i: idx, n: norm2 }) => {
1471
+ if (!isDefined(text)) return;
1472
+ const searchResult = searcher.searchIn(text);
1473
+ if (searchResult.isMatch) {
1474
+ const match = {
1475
+ score: searchResult.score,
1476
+ key,
1477
+ value: text,
1478
+ idx,
1479
+ norm: norm2,
1480
+ indices: searchResult.indices,
1481
+ hasInverse: searchResult.hasInverse
1482
+ };
1483
+ if (searchResult.termCount !== void 0) {
1484
+ match.matchedMask = searchResult.matchedMask;
1485
+ match.matchedTerms = searchResult.matchedTerms;
1486
+ match.termCount = searchResult.termCount;
1487
+ }
1488
+ matches.push(match);
1489
+ }
1490
+ });
1491
+ else {
1492
+ const { v: text, n: norm2 } = value;
1493
+ const searchResult = searcher.searchIn(text);
1494
+ if (searchResult.isMatch) {
1495
+ const match = {
1496
+ score: searchResult.score,
1497
+ key,
1498
+ value: text,
1499
+ norm: norm2,
1500
+ indices: searchResult.indices,
1501
+ hasInverse: searchResult.hasInverse
1502
+ };
1503
+ if (searchResult.termCount !== void 0) {
1504
+ match.matchedMask = searchResult.matchedMask;
1505
+ match.matchedTerms = searchResult.matchedTerms;
1506
+ match.termCount = searchResult.termCount;
1507
+ }
1508
+ matches.push(match);
1509
+ }
1510
+ }
1511
+ return matches;
1512
+ }
1513
+ _coversAllTokens(matches) {
1514
+ const termCount = matches.length ? matches[0].termCount : void 0;
1515
+ if (termCount === void 0) return true;
1516
+ if (termCount <= 31) {
1517
+ let coverage2 = 0;
1518
+ for (let i = 0; i < matches.length; i++) coverage2 |= matches[i].matchedMask || 0;
1519
+ return coverage2 === 2 ** termCount - 1;
1520
+ }
1521
+ const coverage = /* @__PURE__ */ new Set();
1522
+ for (let i = 0; i < matches.length; i++) {
1523
+ const terms = matches[i].matchedTerms;
1524
+ if (terms) for (const t of terms) coverage.add(t);
1525
+ }
1526
+ return coverage.size === termCount;
1527
+ }
1528
+ };
1529
+ Fuse.version = "7.5.0";
1530
+ Fuse.createIndex = createIndex;
1531
+ Fuse.parseIndex = parseIndex;
1532
+ Fuse.config = Config;
1533
+ Fuse.match = function(pattern, text, options) {
1534
+ if (options && options.useTokenSearch) throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
1535
+ return createSearcher(pattern, {
1536
+ ...Config,
1537
+ ...options
1538
+ }).searchIn(text);
1539
+ };
1540
+ Fuse.parseQuery = parse;
1541
+ register(ExtendedSearch);
1542
+ register(TokenSearch);
1543
+ Fuse.use = function(...plugins) {
1544
+ plugins.forEach((plugin) => register(plugin));
1545
+ };
1546
+ var entry_default = Fuse;
1547
+
1548
+ // src/fuzzy-search.ts
1549
+ var DEFAULT_FUZZY_SEARCH_OPTIONS = Object.freeze({
1550
+ threshold: 0.3,
1551
+ maxScore: 0.4,
1552
+ // Bitap cost grows with the query; 600 characters still identifies a
1553
+ // passage while keeping a page under ~100 ms on a laptop.
1554
+ maxQueryLength: 600,
1555
+ maxPageTextLength: 2e4,
1556
+ pagesPerBatch: 2,
1557
+ pageWindow: 12,
1558
+ worker: true
1559
+ });
1560
+ function fuseOptions(threshold, caseSensitive) {
1561
+ return {
1562
+ keys: ["text"],
1563
+ isCaseSensitive: caseSensitive,
1564
+ ignoreDiacritics: false,
1565
+ includeMatches: true,
1566
+ includeScore: true,
1567
+ // A citation can sit anywhere on the page; Fuse's location bias would
1568
+ // otherwise penalize matches far from the start of the text.
1569
+ ignoreLocation: true,
1570
+ // Long page text must not dilute the score of a match inside it.
1571
+ ignoreFieldNorm: true,
1572
+ threshold,
1573
+ minMatchCharLength: 3,
1574
+ shouldSort: false
1575
+ };
1576
+ }
1577
+ var FuzzyPageIndex = class {
1578
+ #pages;
1579
+ #index;
1580
+ #options;
1581
+ #fuse;
1582
+ constructor(pages, options, caseSensitive = false) {
1583
+ this.#pages = pages.map((page) => ({
1584
+ pageIndex: page.pageIndex,
1585
+ text: page.text.slice(0, options.maxPageTextLength)
1586
+ }));
1587
+ this.#options = fuseOptions(options.threshold, caseSensitive);
1588
+ this.#index = entry_default.createIndex(["text"], this.#pages);
1589
+ this.#fuse = new entry_default(this.#pages, this.#options, this.#index);
1590
+ }
1591
+ get pageCount() {
1592
+ return this.#pages.length;
1593
+ }
1594
+ /**
1595
+ * One match per page whose text holds the query within the edit budget:
1596
+ * the span from the first to the last matched character, so the highlight
1597
+ * covers the passage as one block. `pageIndices` restricts the scan; the
1598
+ * result is in page order either way.
1599
+ */
1600
+ search(query, maxScore, pageIndices) {
1601
+ if (!query.trim()) return [];
1602
+ const fuse = pageIndices ? this.#subset(pageIndices) : this.#fuse;
1603
+ const matches = [];
1604
+ for (const result of fuse.search(query)) {
1605
+ if ((result.score ?? 1) > maxScore) continue;
1606
+ const indices = result.matches?.[0]?.indices ?? [];
1607
+ if (indices.length === 0) continue;
1608
+ let start = Number.POSITIVE_INFINITY;
1609
+ let end = 0;
1610
+ for (const [first, last] of indices) {
1611
+ start = Math.min(start, first);
1612
+ end = Math.max(end, last + 1);
1613
+ }
1614
+ const text = result.item.text.slice(start, end);
1615
+ matches.push({ pageIndex: result.item.pageIndex, start, end, text });
1616
+ }
1617
+ return matches.sort((a, b) => a.pageIndex - b.pageIndex);
1618
+ }
1619
+ #subset(pageIndices) {
1620
+ const wanted = new Set(pageIndices);
1621
+ const { keys, records } = this.#index.toJSON();
1622
+ const kept = records.filter(
1623
+ (record) => wanted.has(this.#pages[record.i]?.pageIndex ?? -1)
1624
+ );
1625
+ return new entry_default(
1626
+ this.#pages,
1627
+ this.#options,
1628
+ entry_default.parseIndex({ keys, records: kept })
1629
+ );
1630
+ }
1631
+ };
1632
+
1633
+ // src/fuzzy-worker-protocol.ts
1634
+ function handleFuzzyWorkerRequest(state2, request) {
1635
+ try {
1636
+ if (request.kind === "index") {
1637
+ state2.index = new FuzzyPageIndex(
1638
+ request.pages,
1639
+ {
1640
+ threshold: request.threshold,
1641
+ maxPageTextLength: request.maxPageTextLength
1642
+ },
1643
+ request.caseSensitive
1644
+ );
1645
+ return {
1646
+ kind: "indexed",
1647
+ id: request.id,
1648
+ pageCount: state2.index.pageCount
1649
+ };
1650
+ }
1651
+ if (!state2.index)
1652
+ return {
1653
+ kind: "failure",
1654
+ id: request.id,
1655
+ message: "No document is indexed"
1656
+ };
1657
+ return {
1658
+ kind: "matches",
1659
+ id: request.id,
1660
+ matches: state2.index.search(
1661
+ request.query,
1662
+ request.maxScore,
1663
+ request.pageIndices
1664
+ )
1665
+ };
1666
+ } catch (error) {
1667
+ return {
1668
+ kind: "failure",
1669
+ id: request.id,
1670
+ message: error instanceof Error ? error.message : String(error)
1671
+ };
1672
+ }
1673
+ }
1674
+
1675
+ // src/fuzzy-search-worker.ts
1676
+ var workerScope = self;
1677
+ var state = {};
1678
+ workerScope.onmessage = (event) => {
1679
+ workerScope.postMessage(handleFuzzyWorkerRequest(state, event.data));
1680
+ };