@arbetsformedlingen/yrkesvaljaren 2.0.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.
Files changed (146) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +369 -0
  3. package/dist/cjs/af-validation-message-BzY5H0xU.js +16 -0
  4. package/dist/cjs/core-selector.cjs.entry.js +476 -0
  5. package/dist/cjs/digi-service-job-selector.cjs.entry.js +1619 -0
  6. package/dist/cjs/fuse-BTLNKxuL.js +1631 -0
  7. package/dist/cjs/geo-valjaren.cjs.entry.js +14910 -0
  8. package/dist/cjs/index-BOuTGlEp.js +1817 -0
  9. package/dist/cjs/index.cjs.js +14 -0
  10. package/dist/cjs/job-selector-demo.cjs.entry.js +692 -0
  11. package/dist/cjs/loader.cjs.js +12 -0
  12. package/dist/cjs/neobrutal-search.cjs.entry.js +171 -0
  13. package/dist/cjs/search.engine-D0cMelRi.js +489 -0
  14. package/dist/cjs/taxonomy-registry-DVmuDUpM.js +435 -0
  15. package/dist/cjs/types-CtHBl6Ra.js +14 -0
  16. package/dist/cjs/yrkesvaljaren.cjs.js +24 -0
  17. package/dist/collection/collection-manifest.json +15 -0
  18. package/dist/collection/components/core-selector/core-selector.css +803 -0
  19. package/dist/collection/components/core-selector/core-selector.js +761 -0
  20. package/dist/collection/components/core-selector/types.js +1 -0
  21. package/dist/collection/components/design-compat/af-icon.js +13 -0
  22. package/dist/collection/components/design-compat/af-label.js +2 -0
  23. package/dist/collection/components/design-compat/af-tag.js +6 -0
  24. package/dist/collection/components/design-compat/af-validation-message.js +11 -0
  25. package/dist/collection/components/design-compat/index.js +4 -0
  26. package/dist/collection/components/geovaljaren/geovaljaren.css +21 -0
  27. package/dist/collection/components/geovaljaren/geovaljaren.js +304 -0
  28. package/dist/collection/components/geovaljaren/logic/adapter.utils.js +20 -0
  29. package/dist/collection/components/geovaljaren/logic/data.utils.js +12 -0
  30. package/dist/collection/components/geovaljaren/logic/history-service.js +25 -0
  31. package/dist/collection/components/geovaljaren/logic/search.engine.js +28 -0
  32. package/dist/collection/components/job-selector/constants.js +26 -0
  33. package/dist/collection/components/job-selector/history-service.js +41 -0
  34. package/dist/collection/components/job-selector/job-selector-controller.js +835 -0
  35. package/dist/collection/components/job-selector/job-selector.css +318 -0
  36. package/dist/collection/components/job-selector/job-selector.js +1378 -0
  37. package/dist/collection/components/job-selector/keyboard-handlers.js +84 -0
  38. package/dist/collection/components/job-selector/logic/adapter.utils.js +75 -0
  39. package/dist/collection/components/job-selector/logic/label-formatter.js +118 -0
  40. package/dist/collection/components/job-selector/logic/search.engine.js +50 -0
  41. package/dist/collection/components/job-selector/search-logic.js +35 -0
  42. package/dist/collection/components/job-selector/search.utils.js +224 -0
  43. package/dist/collection/components/job-selector/suggestions-list.js +31 -0
  44. package/dist/collection/components/job-selector/taxonomy-registry.js +60 -0
  45. package/dist/collection/components/job-selector/test-data.mock.js +33 -0
  46. package/dist/collection/components/job-selector/types.js +10 -0
  47. package/dist/collection/components/job-selector/validation-message.js +24 -0
  48. package/dist/collection/demo-data.js +20 -0
  49. package/dist/collection/index.js +7 -0
  50. package/dist/collection/verkstad/verkstad.js +407 -0
  51. package/dist/components/core-selector.d.ts +11 -0
  52. package/dist/components/core-selector.js +1 -0
  53. package/dist/components/core-selector2.js +1 -0
  54. package/dist/components/digi-service-job-selector.d.ts +11 -0
  55. package/dist/components/digi-service-job-selector.js +1 -0
  56. package/dist/components/fuse.js +1 -0
  57. package/dist/components/geo-valjaren.d.ts +11 -0
  58. package/dist/components/geo-valjaren.js +1 -0
  59. package/dist/components/index.d.ts +35 -0
  60. package/dist/components/index.js +1 -0
  61. package/dist/components/job-selector-demo.d.ts +11 -0
  62. package/dist/components/job-selector-demo.js +1 -0
  63. package/dist/components/job-selector.js +1 -0
  64. package/dist/components/neobrutal-search.d.ts +11 -0
  65. package/dist/components/neobrutal-search.js +1 -0
  66. package/dist/components/search.engine.js +1 -0
  67. package/dist/components/types.js +1 -0
  68. package/dist/esm/af-validation-message-F8NIH2rC.js +14 -0
  69. package/dist/esm/core-selector.entry.js +474 -0
  70. package/dist/esm/digi-service-job-selector.entry.js +1617 -0
  71. package/dist/esm/fuse-BPnhMTul.js +1629 -0
  72. package/dist/esm/geo-valjaren.entry.js +14908 -0
  73. package/dist/esm/index-CGXZllj2.js +1806 -0
  74. package/dist/esm/index.js +10 -0
  75. package/dist/esm/job-selector-demo.entry.js +690 -0
  76. package/dist/esm/loader.js +10 -0
  77. package/dist/esm/neobrutal-search.entry.js +169 -0
  78. package/dist/esm/search.engine-nZ7AcXba.js +479 -0
  79. package/dist/esm/taxonomy-registry-Dw0VR9Aw.js +430 -0
  80. package/dist/esm/types-DHUftoZJ.js +12 -0
  81. package/dist/esm/yrkesvaljaren.js +20 -0
  82. package/dist/index.cjs.js +1 -0
  83. package/dist/index.js +1 -0
  84. package/dist/types/components/core-selector/core-selector.d.ts +46 -0
  85. package/dist/types/components/core-selector/types.d.ts +1 -0
  86. package/dist/types/components/design-compat/af-icon.d.ts +7 -0
  87. package/dist/types/components/design-compat/af-label.d.ts +8 -0
  88. package/dist/types/components/design-compat/af-tag.d.ts +8 -0
  89. package/dist/types/components/design-compat/af-validation-message.d.ts +9 -0
  90. package/dist/types/components/design-compat/index.d.ts +5 -0
  91. package/dist/types/components/geovaljaren/geovaljaren.d.ts +24 -0
  92. package/dist/types/components/geovaljaren/logic/adapter.utils.d.ts +7 -0
  93. package/dist/types/components/geovaljaren/logic/data.utils.d.ts +7 -0
  94. package/dist/types/components/geovaljaren/logic/history-service.d.ts +6 -0
  95. package/dist/types/components/geovaljaren/logic/search.engine.d.ts +7 -0
  96. package/dist/types/components/job-selector/ambient.d.ts +4 -0
  97. package/dist/types/components/job-selector/constants.d.ts +13 -0
  98. package/dist/types/components/job-selector/history-service.d.ts +6 -0
  99. package/dist/types/components/job-selector/job-selector-controller.d.ts +82 -0
  100. package/dist/types/components/job-selector/job-selector.d.ts +140 -0
  101. package/dist/types/components/job-selector/keyboard-handlers.d.ts +13 -0
  102. package/dist/types/components/job-selector/logic/adapter.utils.d.ts +12 -0
  103. package/dist/types/components/job-selector/logic/label-formatter.d.ts +4 -0
  104. package/dist/types/components/job-selector/logic/search.engine.d.ts +21 -0
  105. package/dist/types/components/job-selector/search-logic.d.ts +17 -0
  106. package/dist/types/components/job-selector/search.utils.d.ts +10 -0
  107. package/dist/types/components/job-selector/suggestions-list.d.ts +13 -0
  108. package/dist/types/components/job-selector/taxonomy-registry.d.ts +20 -0
  109. package/dist/types/components/job-selector/test-data.mock.d.ts +7 -0
  110. package/dist/types/components/job-selector/types.d.ts +107 -0
  111. package/dist/types/components/job-selector/validation-message.d.ts +8 -0
  112. package/dist/types/components/job-selector-demo/job-selector-demo.d.ts +55 -0
  113. package/dist/types/components/neobrutal-search/neobrutal-search.d.ts +18 -0
  114. package/dist/types/components.d.ts +425 -0
  115. package/dist/types/demo-data.d.ts +16 -0
  116. package/dist/types/index.d.ts +5 -0
  117. package/dist/types/stencil-public-runtime.d.ts +1873 -0
  118. package/dist/types/verkstad/verkstad.d.ts +1 -0
  119. package/dist/yrkesvaljaren/fuse-B0eHOxow.js.map +1 -0
  120. package/dist/yrkesvaljaren/index-Cy4BCo5s.js.map +1 -0
  121. package/dist/yrkesvaljaren/index-DfJXTQqL.js.map +1 -0
  122. package/dist/yrkesvaljaren/index.esm.js +1 -0
  123. package/dist/yrkesvaljaren/index.esm.js.map +1 -0
  124. package/dist/yrkesvaljaren/p-16636162.entry.js +1 -0
  125. package/dist/yrkesvaljaren/p-273cf6df.entry.js +1 -0
  126. package/dist/yrkesvaljaren/p-9e48afa4.entry.js +1 -0
  127. package/dist/yrkesvaljaren/p-BPnhMTul.js +1 -0
  128. package/dist/yrkesvaljaren/p-CGXZllj2.js +3 -0
  129. package/dist/yrkesvaljaren/p-DHUftoZJ.js +1 -0
  130. package/dist/yrkesvaljaren/p-DYFAzvqX.js +1 -0
  131. package/dist/yrkesvaljaren/p-Dw0VR9Aw.js +1 -0
  132. package/dist/yrkesvaljaren/p-aef7b5ae.entry.js +1 -0
  133. package/dist/yrkesvaljaren/p-b0f16abd.entry.js +1 -0
  134. package/dist/yrkesvaljaren/p-uBrs3sSs.js +1 -0
  135. package/dist/yrkesvaljaren/search.engine-DPT6roRm.js.map +1 -0
  136. package/dist/yrkesvaljaren/taxonomy-registry-s5khf6s4.js.map +1 -0
  137. package/dist/yrkesvaljaren/types-DHUftoZJ.js.map +1 -0
  138. package/dist/yrkesvaljaren/yrkesvaljaren.css +1 -0
  139. package/dist/yrkesvaljaren/yrkesvaljaren.esm.js +1 -0
  140. package/dist/yrkesvaljaren/yrkesvaljaren.esm.js.map +1 -0
  141. package/loader/cdn.js +1 -0
  142. package/loader/index.cjs.js +1 -0
  143. package/loader/index.d.ts +24 -0
  144. package/loader/index.es2017.js +1 -0
  145. package/loader/index.js +2 -0
  146. package/package.json +126 -0
@@ -0,0 +1,1629 @@
1
+ /**
2
+ * Fuse.js v7.5.0 - Lightweight fuzzy-search (http://fusejs.io)
3
+ *
4
+ * Copyright (c) 2026 Kiro Risk (http://kiro.me)
5
+ * All Rights Reserved. Apache Software License 2.0
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ */
9
+ //#region src/helpers/typeGuards.ts
10
+ function isArray(value) {
11
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
12
+ }
13
+ function baseToString(value) {
14
+ if (typeof value == "string") return value;
15
+ if (typeof value === "bigint") return value.toString();
16
+ const result = value + "";
17
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
18
+ }
19
+ function toString(value) {
20
+ return value == null ? "" : baseToString(value);
21
+ }
22
+ function isString(value) {
23
+ return typeof value === "string";
24
+ }
25
+ function isNumber(value) {
26
+ return typeof value === "number";
27
+ }
28
+ function isBoolean(value) {
29
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
30
+ }
31
+ function isObject(value) {
32
+ return typeof value === "object";
33
+ }
34
+ function isObjectLike(value) {
35
+ return isObject(value) && value !== null;
36
+ }
37
+ function isDefined(value) {
38
+ return value !== void 0 && value !== null;
39
+ }
40
+ function isBlank(value) {
41
+ return !value.trim().length;
42
+ }
43
+ function getTag(value) {
44
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/core/errorMessages.ts
49
+ const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
50
+ const INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
51
+ const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
52
+ const PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
53
+ const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
54
+ const INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
55
+ const 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.";
56
+
57
+ //#endregion
58
+ //#region src/tools/KeyStore.ts
59
+ const hasOwn = Object.prototype.hasOwnProperty;
60
+ var KeyStore = class {
61
+ constructor(keys) {
62
+ this._keys = [];
63
+ this._keyMap = {};
64
+ let totalWeight = 0;
65
+ keys.forEach((key) => {
66
+ const obj = createKey(key);
67
+ this._keys.push(obj);
68
+ this._keyMap[obj.id] = obj;
69
+ totalWeight += obj.weight;
70
+ });
71
+ this._keys.forEach((key) => {
72
+ key.weight /= totalWeight;
73
+ });
74
+ }
75
+ get(keyId) {
76
+ return this._keyMap[keyId];
77
+ }
78
+ keys() {
79
+ return this._keys;
80
+ }
81
+ toJSON() {
82
+ return JSON.stringify(this._keys);
83
+ }
84
+ };
85
+ function createKey(key) {
86
+ let path = null;
87
+ let id = null;
88
+ let src = null;
89
+ let weight = 1;
90
+ let getFn = null;
91
+ if (isString(key) || isArray(key)) {
92
+ src = key;
93
+ path = createKeyPath(key);
94
+ id = createKeyId(key);
95
+ } else {
96
+ if (!hasOwn.call(key, "name")) throw new Error(MISSING_KEY_PROPERTY("name"));
97
+ const name = key.name;
98
+ src = name;
99
+ if (hasOwn.call(key, "weight") && key.weight !== void 0) {
100
+ weight = key.weight;
101
+ if (weight <= 0) throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
102
+ }
103
+ path = createKeyPath(name);
104
+ id = createKeyId(name);
105
+ getFn = key.getFn ?? null;
106
+ }
107
+ return {
108
+ path,
109
+ id,
110
+ weight,
111
+ src,
112
+ getFn
113
+ };
114
+ }
115
+ function createKeyPath(key) {
116
+ return isArray(key) ? key : key.split(".");
117
+ }
118
+ function createKeyId(key) {
119
+ return isArray(key) ? key.join(".") : key;
120
+ }
121
+
122
+ //#endregion
123
+ //#region src/helpers/get.ts
124
+ function get(obj, path) {
125
+ const list = [];
126
+ let arr = false;
127
+ const deepGet = (obj, path, index, arrayIndex) => {
128
+ if (!isDefined(obj)) return;
129
+ if (!path[index]) list.push(arrayIndex !== void 0 ? {
130
+ v: obj,
131
+ i: arrayIndex
132
+ } : obj);
133
+ else {
134
+ const value = obj[path[index]];
135
+ if (!isDefined(value)) return;
136
+ if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value) || typeof value === "bigint")) list.push(arrayIndex !== void 0 ? {
137
+ v: toString(value),
138
+ i: arrayIndex
139
+ } : toString(value));
140
+ else if (isArray(value)) {
141
+ arr = true;
142
+ for (let i = 0, len = value.length; i < len; i += 1) deepGet(value[i], path, index + 1, i);
143
+ } else if (path.length) deepGet(value, path, index + 1, arrayIndex);
144
+ }
145
+ };
146
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
147
+ return arr ? list : list[0];
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/core/config.ts
152
+ const MatchOptions = {
153
+ includeMatches: false,
154
+ findAllMatches: false,
155
+ minMatchCharLength: 1
156
+ };
157
+ const BasicOptions = {
158
+ isCaseSensitive: false,
159
+ ignoreDiacritics: false,
160
+ includeScore: false,
161
+ keys: [],
162
+ shouldSort: true,
163
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
164
+ };
165
+ const FuzzyOptions = {
166
+ location: 0,
167
+ threshold: .6,
168
+ distance: 100
169
+ };
170
+ const AdvancedOptions = {
171
+ useExtendedSearch: false,
172
+ useTokenSearch: false,
173
+ tokenize: void 0,
174
+ tokenMatch: "any",
175
+ getFn: get,
176
+ ignoreLocation: false,
177
+ ignoreFieldNorm: false,
178
+ fieldNormWeight: 1
179
+ };
180
+ const Config = Object.freeze({
181
+ ...BasicOptions,
182
+ ...MatchOptions,
183
+ ...FuzzyOptions,
184
+ ...AdvancedOptions
185
+ });
186
+
187
+ //#endregion
188
+ //#region src/tools/fieldNorm.ts
189
+ function isWordSeparator(code) {
190
+ return code >= 9 && code <= 13 || code === 32 || code === 160;
191
+ }
192
+ function norm(weight = 1, mantissa = 3) {
193
+ const cache = /* @__PURE__ */ new Map();
194
+ const m = Math.pow(10, mantissa);
195
+ return {
196
+ get(value) {
197
+ let numTokens = 0;
198
+ let inWord = false;
199
+ for (let i = 0; i < value.length; i++) if (!isWordSeparator(value.charCodeAt(i))) {
200
+ if (!inWord) {
201
+ numTokens++;
202
+ inWord = true;
203
+ }
204
+ } else inWord = false;
205
+ if (numTokens === 0) numTokens = 1;
206
+ if (cache.has(numTokens)) return cache.get(numTokens);
207
+ const n = Math.round(m / Math.pow(numTokens, .5 * weight)) / m;
208
+ cache.set(numTokens, n);
209
+ return n;
210
+ },
211
+ clear() {
212
+ cache.clear();
213
+ }
214
+ };
215
+ }
216
+
217
+ //#endregion
218
+ //#region src/tools/FuseIndex.ts
219
+ var FuseIndex = class {
220
+ constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
221
+ this.norm = norm(fieldNormWeight, 3);
222
+ this.getFn = getFn;
223
+ this.isCreated = false;
224
+ this.docs = [];
225
+ this.keys = [];
226
+ this._keysMap = {};
227
+ this.setIndexRecords();
228
+ }
229
+ setSources(docs = []) {
230
+ this.docs = docs;
231
+ }
232
+ setIndexRecords(records = []) {
233
+ this.records = records;
234
+ }
235
+ setKeys(keys = []) {
236
+ this.keys = keys;
237
+ this._keysMap = {};
238
+ keys.forEach((key, idx) => {
239
+ this._keysMap[key.id] = idx;
240
+ });
241
+ }
242
+ create() {
243
+ if (this.isCreated || !this.docs.length) return;
244
+ this.isCreated = true;
245
+ const len = this.docs.length;
246
+ this.records = new Array(len);
247
+ let recordCount = 0;
248
+ if (isString(this.docs[0])) for (let i = 0; i < len; i++) {
249
+ const record = this._createStringRecord(this.docs[i], i);
250
+ if (record) this.records[recordCount++] = record;
251
+ }
252
+ else for (let i = 0; i < len; i++) this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
253
+ this.records.length = recordCount;
254
+ this.norm.clear();
255
+ }
256
+ add(doc, docIndex) {
257
+ if (!Number.isInteger(docIndex) || docIndex < 0) throw new Error(INVALID_DOC_INDEX);
258
+ if (isString(doc)) {
259
+ const record = this._createStringRecord(doc, docIndex);
260
+ if (record) this.records.push(record);
261
+ return record;
262
+ }
263
+ const record = this._createObjectRecord(doc, docIndex);
264
+ this.records.push(record);
265
+ return record;
266
+ }
267
+ removeAt(idx) {
268
+ if (!Number.isInteger(idx) || idx < 0) throw new Error(INVALID_DOC_INDEX);
269
+ for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i === idx) {
270
+ this.records.splice(i, 1);
271
+ break;
272
+ }
273
+ for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i > idx) this.records[i].i -= 1;
274
+ }
275
+ removeAll(indices) {
276
+ const toRemove = /* @__PURE__ */ new Set();
277
+ for (const v of indices) if (Number.isInteger(v) && v >= 0) toRemove.add(v);
278
+ if (toRemove.size === 0) return;
279
+ this.records = this.records.filter((r) => !toRemove.has(r.i));
280
+ const sorted = Array.from(toRemove).sort((a, b) => a - b);
281
+ for (const record of this.records) {
282
+ let lo = 0;
283
+ let hi = sorted.length;
284
+ while (lo < hi) {
285
+ const mid = lo + hi >>> 1;
286
+ if (sorted[mid] < record.i) lo = mid + 1;
287
+ else hi = mid;
288
+ }
289
+ record.i -= lo;
290
+ }
291
+ }
292
+ getValueForItemAtKeyId(item, keyId) {
293
+ return item[this._keysMap[keyId]];
294
+ }
295
+ size() {
296
+ return this.records.length;
297
+ }
298
+ _createStringRecord(doc, docIndex) {
299
+ if (!isDefined(doc) || isBlank(doc)) return null;
300
+ return {
301
+ v: doc,
302
+ i: docIndex,
303
+ n: this.norm.get(doc)
304
+ };
305
+ }
306
+ _createObjectRecord(doc, docIndex) {
307
+ const record = {
308
+ i: docIndex,
309
+ $: {}
310
+ };
311
+ for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
312
+ const key = this.keys[keyIndex];
313
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
314
+ if (!isDefined(value)) continue;
315
+ if (isArray(value)) {
316
+ const subRecords = [];
317
+ for (let i = 0, len = value.length; i < len; i += 1) {
318
+ const item = value[i];
319
+ if (!isDefined(item)) continue;
320
+ if (isString(item)) {
321
+ if (!isBlank(item)) {
322
+ const subRecord = {
323
+ v: item,
324
+ i,
325
+ n: this.norm.get(item)
326
+ };
327
+ subRecords.push(subRecord);
328
+ }
329
+ } else if (isDefined(item.v)) {
330
+ const text = isString(item.v) ? item.v : toString(item.v);
331
+ if (!isBlank(text)) {
332
+ const subRecord = {
333
+ v: text,
334
+ i: item.i,
335
+ n: this.norm.get(text)
336
+ };
337
+ subRecords.push(subRecord);
338
+ }
339
+ }
340
+ }
341
+ record.$[keyIndex] = subRecords;
342
+ } else if (isString(value) && !isBlank(value)) {
343
+ const subRecord = {
344
+ v: value,
345
+ n: this.norm.get(value)
346
+ };
347
+ record.$[keyIndex] = subRecord;
348
+ }
349
+ }
350
+ return record;
351
+ }
352
+ toJSON() {
353
+ return {
354
+ keys: this.keys.map(({ getFn, ...key }) => key),
355
+ records: this.records
356
+ };
357
+ }
358
+ };
359
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
360
+ const myIndex = new FuseIndex({
361
+ getFn,
362
+ fieldNormWeight
363
+ });
364
+ myIndex.setKeys(keys.map(createKey));
365
+ myIndex.setSources(docs);
366
+ myIndex.create();
367
+ return myIndex;
368
+ }
369
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
370
+ const { keys, records } = data;
371
+ const myIndex = new FuseIndex({
372
+ getFn,
373
+ fieldNormWeight
374
+ });
375
+ myIndex.setKeys(keys);
376
+ myIndex.setIndexRecords(records);
377
+ return myIndex;
378
+ }
379
+
380
+ //#endregion
381
+ //#region src/search/bitap/convertMaskToIndices.ts
382
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
383
+ const indices = [];
384
+ let start = -1;
385
+ let end = -1;
386
+ let i = 0;
387
+ for (let len = matchmask.length; i < len; i += 1) {
388
+ const match = matchmask[i];
389
+ if (match && start === -1) start = i;
390
+ else if (!match && start !== -1) {
391
+ end = i - 1;
392
+ if (end - start + 1 >= minMatchCharLength) indices.push([start, end]);
393
+ start = -1;
394
+ }
395
+ }
396
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) indices.push([start, i - 1]);
397
+ return indices;
398
+ }
399
+
400
+ //#endregion
401
+ //#region src/search/bitap/search.ts
402
+ 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 } = {}) {
403
+ if (pattern.length > 32) throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
404
+ const patternLen = pattern.length;
405
+ const textLen = text.length;
406
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
407
+ let currentThreshold = threshold;
408
+ let bestLocation = expectedLocation;
409
+ const calcScore = (errors, currentLocation) => {
410
+ const accuracy = errors / patternLen;
411
+ if (ignoreLocation) return accuracy;
412
+ const proximity = Math.abs(expectedLocation - currentLocation);
413
+ if (!distance) return proximity ? 1 : accuracy;
414
+ return accuracy + proximity / distance;
415
+ };
416
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
417
+ const matchMask = computeMatches ? Array(textLen) : [];
418
+ let index;
419
+ while ((index = text.indexOf(pattern, bestLocation)) > -1) {
420
+ const score = calcScore(0, index);
421
+ currentThreshold = Math.min(score, currentThreshold);
422
+ bestLocation = index + patternLen;
423
+ if (computeMatches) {
424
+ let i = 0;
425
+ while (i < patternLen) {
426
+ matchMask[index + i] = 1;
427
+ i += 1;
428
+ }
429
+ }
430
+ }
431
+ bestLocation = -1;
432
+ let lastBitArr = [];
433
+ let finalScore = 1;
434
+ let bestErrors = 0;
435
+ let binMax = patternLen + textLen;
436
+ const mask = 1 << patternLen - 1;
437
+ for (let i = 0; i < patternLen; i += 1) {
438
+ let binMin = 0;
439
+ let binMid = binMax;
440
+ while (binMin < binMid) {
441
+ if (calcScore(i, expectedLocation + binMid) <= currentThreshold) binMin = binMid;
442
+ else binMax = binMid;
443
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
444
+ }
445
+ binMax = binMid;
446
+ let start = Math.max(1, expectedLocation - binMid + 1);
447
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
448
+ const bitArr = Array(finish + 2);
449
+ bitArr[finish + 1] = (1 << i) - 1;
450
+ for (let j = finish; j >= start; j -= 1) {
451
+ const currentLocation = j - 1;
452
+ const charMatch = patternAlphabet[text[currentLocation]];
453
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
454
+ if (i) bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
455
+ if (bitArr[j] & mask) {
456
+ finalScore = calcScore(i, currentLocation);
457
+ if (finalScore <= currentThreshold) {
458
+ currentThreshold = finalScore;
459
+ bestLocation = currentLocation;
460
+ bestErrors = i;
461
+ if (bestLocation <= expectedLocation) break;
462
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
463
+ }
464
+ }
465
+ }
466
+ if (calcScore(i + 1, expectedLocation) > currentThreshold) break;
467
+ lastBitArr = bitArr;
468
+ }
469
+ if (computeMatches && bestLocation >= 0) {
470
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
471
+ for (let k = bestLocation; k <= matchEnd; k += 1) if (patternAlphabet[text[k]]) matchMask[k] = 1;
472
+ }
473
+ const result = {
474
+ isMatch: bestLocation >= 0,
475
+ score: Math.max(.001, finalScore)
476
+ };
477
+ if (computeMatches) {
478
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
479
+ if (!indices.length) result.isMatch = false;
480
+ else if (includeMatches) result.indices = indices;
481
+ }
482
+ return result;
483
+ }
484
+
485
+ //#endregion
486
+ //#region src/search/bitap/createPatternAlphabet.ts
487
+ function createPatternAlphabet(pattern) {
488
+ const mask = {};
489
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
490
+ const char = pattern.charAt(i);
491
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
492
+ }
493
+ return mask;
494
+ }
495
+
496
+ //#endregion
497
+ //#region src/helpers/mergeIndices.ts
498
+ function mergeIndices(indices) {
499
+ if (indices.length <= 1) return indices;
500
+ indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
501
+ const merged = [indices[0]];
502
+ for (let i = 1, len = indices.length; i < len; i += 1) {
503
+ const last = merged[merged.length - 1];
504
+ const curr = indices[i];
505
+ if (curr[0] <= last[1] + 1) last[1] = Math.max(last[1], curr[1]);
506
+ else merged.push(curr);
507
+ }
508
+ return merged;
509
+ }
510
+
511
+ //#endregion
512
+ //#region src/helpers/diacritics.ts
513
+ const NON_DECOMPOSABLE_MAP = {
514
+ "ł": "l",
515
+ "Ł": "L",
516
+ "đ": "d",
517
+ "Đ": "D",
518
+ "ø": "o",
519
+ "Ø": "O",
520
+ "ħ": "h",
521
+ "Ħ": "H",
522
+ "ŧ": "t",
523
+ "Ŧ": "T",
524
+ "ı": "i",
525
+ "ß": "ss"
526
+ };
527
+ const NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
528
+ const 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;
529
+
530
+ //#endregion
531
+ //#region src/search/bitap/index.ts
532
+ var BitapSearch = class {
533
+ 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 } = {}) {
534
+ this.options = {
535
+ location,
536
+ threshold,
537
+ distance,
538
+ includeMatches,
539
+ findAllMatches,
540
+ minMatchCharLength,
541
+ isCaseSensitive,
542
+ ignoreDiacritics,
543
+ ignoreLocation
544
+ };
545
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
546
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
547
+ this.pattern = pattern;
548
+ this.chunks = [];
549
+ if (!this.pattern.length) return;
550
+ const addChunk = (pattern, startIndex) => {
551
+ this.chunks.push({
552
+ pattern,
553
+ alphabet: createPatternAlphabet(pattern),
554
+ startIndex
555
+ });
556
+ };
557
+ const len = this.pattern.length;
558
+ if (len > 32) {
559
+ let i = 0;
560
+ const remainder = len % 32;
561
+ const end = len - remainder;
562
+ while (i < end) {
563
+ addChunk(this.pattern.substr(i, 32), i);
564
+ i += 32;
565
+ }
566
+ if (remainder) {
567
+ const startIndex = len - 32;
568
+ addChunk(this.pattern.substr(startIndex), startIndex);
569
+ }
570
+ } else addChunk(this.pattern, 0);
571
+ }
572
+ searchIn(text) {
573
+ const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
574
+ text = isCaseSensitive ? text : text.toLowerCase();
575
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
576
+ if (this.pattern === text) {
577
+ if (text.length < this.options.minMatchCharLength) return {
578
+ isMatch: false,
579
+ score: 1
580
+ };
581
+ const result = {
582
+ isMatch: true,
583
+ score: 0
584
+ };
585
+ if (includeMatches) result.indices = [[0, text.length - 1]];
586
+ return result;
587
+ }
588
+ const { location, distance, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
589
+ const allIndices = [];
590
+ let totalScore = 0;
591
+ let hasMatches = false;
592
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
593
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
594
+ location: location + startIndex,
595
+ distance,
596
+ threshold,
597
+ findAllMatches,
598
+ minMatchCharLength,
599
+ includeMatches,
600
+ ignoreLocation
601
+ });
602
+ if (isMatch) hasMatches = true;
603
+ totalScore += score;
604
+ if (isMatch && indices) allIndices.push(...indices);
605
+ });
606
+ const result = {
607
+ isMatch: hasMatches,
608
+ score: hasMatches ? totalScore / this.chunks.length : 1
609
+ };
610
+ if (hasMatches && includeMatches) result.indices = mergeIndices(allIndices);
611
+ return result;
612
+ }
613
+ };
614
+
615
+ //#endregion
616
+ //#region src/search/extended/matchers.ts
617
+ const MULTI_MATCH_TYPES = new Set(["fuzzy", "include"]);
618
+ function isInverse(type) {
619
+ return type.startsWith("inverse");
620
+ }
621
+ const matchers = [
622
+ {
623
+ type: "exact",
624
+ multiRegex: /^="(.*)"$/,
625
+ singleRegex: /^=(.*)$/,
626
+ create: (pattern) => ({
627
+ type: "exact",
628
+ search(text) {
629
+ const isMatch = text === pattern;
630
+ return {
631
+ isMatch,
632
+ score: isMatch ? 0 : 1,
633
+ indices: [0, pattern.length - 1]
634
+ };
635
+ }
636
+ })
637
+ },
638
+ {
639
+ type: "include",
640
+ multiRegex: /^'"(.*)"$/,
641
+ singleRegex: /^'(.*)$/,
642
+ create: (pattern) => ({
643
+ type: "include",
644
+ search(text) {
645
+ let location = 0;
646
+ let index;
647
+ const indices = [];
648
+ const patternLen = pattern.length;
649
+ while ((index = text.indexOf(pattern, location)) > -1) {
650
+ location = index + patternLen;
651
+ indices.push([index, location - 1]);
652
+ }
653
+ const isMatch = !!indices.length;
654
+ return {
655
+ isMatch,
656
+ score: isMatch ? 0 : 1,
657
+ indices
658
+ };
659
+ }
660
+ })
661
+ },
662
+ {
663
+ type: "prefix-exact",
664
+ multiRegex: /^\^"(.*)"$/,
665
+ singleRegex: /^\^(.*)$/,
666
+ create: (pattern) => ({
667
+ type: "prefix-exact",
668
+ search(text) {
669
+ const isMatch = text.startsWith(pattern);
670
+ return {
671
+ isMatch,
672
+ score: isMatch ? 0 : 1,
673
+ indices: [0, pattern.length - 1]
674
+ };
675
+ }
676
+ })
677
+ },
678
+ {
679
+ type: "inverse-prefix-exact",
680
+ multiRegex: /^!\^"(.*)"$/,
681
+ singleRegex: /^!\^(.*)$/,
682
+ create: (pattern) => ({
683
+ type: "inverse-prefix-exact",
684
+ search(text) {
685
+ const isMatch = !text.startsWith(pattern);
686
+ return {
687
+ isMatch,
688
+ score: isMatch ? 0 : 1,
689
+ indices: [0, text.length - 1]
690
+ };
691
+ }
692
+ })
693
+ },
694
+ {
695
+ type: "inverse-suffix-exact",
696
+ multiRegex: /^!"(.*)"\$$/,
697
+ singleRegex: /^!(.*)\$$/,
698
+ create: (pattern) => ({
699
+ type: "inverse-suffix-exact",
700
+ search(text) {
701
+ const isMatch = !text.endsWith(pattern);
702
+ return {
703
+ isMatch,
704
+ score: isMatch ? 0 : 1,
705
+ indices: [0, text.length - 1]
706
+ };
707
+ }
708
+ })
709
+ },
710
+ {
711
+ type: "suffix-exact",
712
+ multiRegex: /^"(.*)"\$$/,
713
+ singleRegex: /^(.*)\$$/,
714
+ create: (pattern) => ({
715
+ type: "suffix-exact",
716
+ search(text) {
717
+ const isMatch = text.endsWith(pattern);
718
+ return {
719
+ isMatch,
720
+ score: isMatch ? 0 : 1,
721
+ indices: [text.length - pattern.length, text.length - 1]
722
+ };
723
+ }
724
+ })
725
+ },
726
+ {
727
+ type: "inverse-exact",
728
+ multiRegex: /^!"(.*)"$/,
729
+ singleRegex: /^!(.*)$/,
730
+ create: (pattern) => ({
731
+ type: "inverse-exact",
732
+ search(text) {
733
+ const isMatch = text.indexOf(pattern) === -1;
734
+ return {
735
+ isMatch,
736
+ score: isMatch ? 0 : 1,
737
+ indices: [0, text.length - 1]
738
+ };
739
+ }
740
+ })
741
+ },
742
+ {
743
+ type: "fuzzy",
744
+ multiRegex: /^"(.*)"$/,
745
+ singleRegex: /^(.*)$/,
746
+ create: (pattern, options = {}) => {
747
+ const bitap = new BitapSearch(pattern, {
748
+ location: options.location ?? Config.location,
749
+ threshold: options.threshold ?? Config.threshold,
750
+ distance: options.distance ?? Config.distance,
751
+ includeMatches: options.includeMatches ?? Config.includeMatches,
752
+ findAllMatches: options.findAllMatches ?? Config.findAllMatches,
753
+ minMatchCharLength: options.minMatchCharLength ?? Config.minMatchCharLength,
754
+ isCaseSensitive: options.isCaseSensitive ?? Config.isCaseSensitive,
755
+ ignoreDiacritics: options.ignoreDiacritics ?? Config.ignoreDiacritics,
756
+ ignoreLocation: options.ignoreLocation ?? Config.ignoreLocation
757
+ });
758
+ return {
759
+ type: "fuzzy",
760
+ search(text) {
761
+ return bitap.searchIn(text);
762
+ }
763
+ };
764
+ }
765
+ }
766
+ ];
767
+
768
+ //#endregion
769
+ //#region src/search/extended/parseQuery.ts
770
+ const matchersLen = matchers.length;
771
+ const ESCAPED_PIPE = "\0";
772
+ const OR_TOKEN = "|";
773
+ function tokenize(pattern) {
774
+ const tokens = [];
775
+ const len = pattern.length;
776
+ let i = 0;
777
+ while (i < len) {
778
+ while (i < len && pattern[i] === " ") i++;
779
+ if (i >= len) break;
780
+ let j = i;
781
+ while (j < len && pattern[j] !== " " && pattern[j] !== "\"") j++;
782
+ if (j < len && pattern[j] === "\"") {
783
+ j++;
784
+ while (j < len) {
785
+ if (pattern[j] === "\"") {
786
+ const next = j + 1;
787
+ if (next >= len || pattern[next] === " ") {
788
+ j++;
789
+ break;
790
+ }
791
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
792
+ j += 2;
793
+ break;
794
+ }
795
+ }
796
+ j++;
797
+ }
798
+ tokens.push(pattern.substring(i, j));
799
+ i = j;
800
+ } else {
801
+ while (j < len && pattern[j] !== " ") j++;
802
+ tokens.push(pattern.substring(i, j));
803
+ i = j;
804
+ }
805
+ }
806
+ return tokens;
807
+ }
808
+ function getMatch(pattern, exp) {
809
+ const matches = pattern.match(exp);
810
+ return matches ? matches[1] : null;
811
+ }
812
+ function parseQuery(pattern, options = {}) {
813
+ return pattern.replace(/\\\|/g, ESCAPED_PIPE).split(OR_TOKEN).map((item) => {
814
+ const query = tokenize(item.replace(/\u0000/g, "|").trim()).filter((item) => item && !!item.trim());
815
+ const results = [];
816
+ for (let i = 0, len = query.length; i < len; i += 1) {
817
+ const queryItem = query[i];
818
+ let found = false;
819
+ let idx = -1;
820
+ while (!found && ++idx < matchersLen) {
821
+ const def = matchers[idx];
822
+ const token = getMatch(queryItem, def.multiRegex);
823
+ if (token) {
824
+ results.push(def.create(token, options));
825
+ found = true;
826
+ }
827
+ }
828
+ if (found) continue;
829
+ idx = -1;
830
+ while (++idx < matchersLen) {
831
+ const def = matchers[idx];
832
+ const token = getMatch(queryItem, def.singleRegex);
833
+ if (token) {
834
+ results.push(def.create(token, options));
835
+ break;
836
+ }
837
+ }
838
+ }
839
+ return results;
840
+ });
841
+ }
842
+
843
+ //#endregion
844
+ //#region src/search/extended/index.ts
845
+ var ExtendedSearch = class {
846
+ 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 } = {}) {
847
+ this.query = null;
848
+ this.options = {
849
+ isCaseSensitive,
850
+ ignoreDiacritics,
851
+ includeMatches,
852
+ minMatchCharLength,
853
+ findAllMatches,
854
+ ignoreLocation,
855
+ location,
856
+ threshold,
857
+ distance
858
+ };
859
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
860
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
861
+ this.pattern = pattern;
862
+ this.query = parseQuery(this.pattern, this.options);
863
+ }
864
+ static condition(_, options) {
865
+ return options.useExtendedSearch;
866
+ }
867
+ searchIn(text) {
868
+ const query = this.query;
869
+ if (!query) return {
870
+ isMatch: false,
871
+ score: 1
872
+ };
873
+ const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
874
+ text = isCaseSensitive ? text : text.toLowerCase();
875
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
876
+ let numMatches = 0;
877
+ const allIndices = [];
878
+ let totalScore = 0;
879
+ let hasInverse = false;
880
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
881
+ const searchers = query[i];
882
+ allIndices.length = 0;
883
+ numMatches = 0;
884
+ hasInverse = false;
885
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
886
+ const matcher = searchers[j];
887
+ const { isMatch, indices, score } = matcher.search(text);
888
+ if (isMatch) {
889
+ numMatches += 1;
890
+ totalScore += score;
891
+ if (isInverse(matcher.type)) hasInverse = true;
892
+ if (includeMatches) if (MULTI_MATCH_TYPES.has(matcher.type)) allIndices.push(...indices);
893
+ else allIndices.push(indices);
894
+ } else {
895
+ totalScore = 0;
896
+ numMatches = 0;
897
+ allIndices.length = 0;
898
+ hasInverse = false;
899
+ break;
900
+ }
901
+ }
902
+ if (numMatches) {
903
+ const result = {
904
+ isMatch: true,
905
+ score: totalScore / numMatches
906
+ };
907
+ if (hasInverse) result.hasInverse = true;
908
+ if (includeMatches) result.indices = mergeIndices(allIndices);
909
+ return result;
910
+ }
911
+ }
912
+ return {
913
+ isMatch: false,
914
+ score: 1
915
+ };
916
+ }
917
+ };
918
+
919
+ //#endregion
920
+ //#region src/core/register.ts
921
+ const registeredSearchers = [];
922
+ function register(...args) {
923
+ registeredSearchers.push(...args);
924
+ }
925
+ function createSearcher(pattern, options) {
926
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
927
+ const searcherClass = registeredSearchers[i];
928
+ if (searcherClass.condition(pattern, options)) return new searcherClass(pattern, options);
929
+ }
930
+ return new BitapSearch(pattern, options);
931
+ }
932
+
933
+ //#endregion
934
+ //#region src/core/queryParser.ts
935
+ const LogicalOperator = {
936
+ AND: "$and",
937
+ OR: "$or"
938
+ };
939
+ const KeyType = {
940
+ PATH: "$path",
941
+ PATTERN: "$val"
942
+ };
943
+ const isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
944
+ const isPath = (query) => !!query[KeyType.PATH];
945
+ const isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
946
+ const convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
947
+ function parse(query, options, { auto = true } = {}) {
948
+ const next = (query) => {
949
+ if (isString(query)) {
950
+ const obj = {
951
+ keyId: null,
952
+ pattern: query
953
+ };
954
+ if (auto) obj.searcher = createSearcher(query, options);
955
+ return obj;
956
+ }
957
+ const keys = Object.keys(query);
958
+ const isQueryPath = isPath(query);
959
+ if (!isQueryPath && keys.length > 1 && !isExpression(query)) return next(convertToExplicit(query));
960
+ if (isLeaf(query)) {
961
+ const key = isQueryPath ? query[KeyType.PATH] : keys[0];
962
+ const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
963
+ if (!isString(pattern)) throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
964
+ const obj = {
965
+ keyId: createKeyId(key),
966
+ pattern
967
+ };
968
+ if (auto) obj.searcher = createSearcher(pattern, options);
969
+ return obj;
970
+ }
971
+ const node = {
972
+ children: [],
973
+ operator: keys[0]
974
+ };
975
+ keys.forEach((key) => {
976
+ const value = query[key];
977
+ if (isArray(value)) value.forEach((item) => {
978
+ node.children.push(next(item));
979
+ });
980
+ });
981
+ return node;
982
+ };
983
+ if (!isExpression(query)) query = convertToExplicit(query);
984
+ return next(query);
985
+ }
986
+
987
+ //#endregion
988
+ //#region src/core/computeScore.ts
989
+ function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
990
+ let totalScore = 1;
991
+ matches.forEach(({ key, norm, score }) => {
992
+ const weight = key ? key.weight : null;
993
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
994
+ });
995
+ return totalScore;
996
+ }
997
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
998
+ results.forEach((result) => {
999
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
1000
+ });
1001
+ }
1002
+
1003
+ //#endregion
1004
+ //#region src/tools/MaxHeap.ts
1005
+ var MaxHeap = class {
1006
+ constructor(limit, comparator) {
1007
+ this.limit = limit;
1008
+ this.heap = [];
1009
+ this.comparator = comparator;
1010
+ }
1011
+ get size() {
1012
+ return this.heap.length;
1013
+ }
1014
+ insert(item) {
1015
+ if (this.size < this.limit) {
1016
+ this.heap.push(item);
1017
+ this._bubbleUp(this.size - 1);
1018
+ } else if (this.comparator(item, this.heap[0]) < 0) {
1019
+ this.heap[0] = item;
1020
+ this._sinkDown(0);
1021
+ }
1022
+ }
1023
+ extractSorted() {
1024
+ return this.heap.sort(this.comparator);
1025
+ }
1026
+ _bubbleUp(i) {
1027
+ const heap = this.heap;
1028
+ while (i > 0) {
1029
+ const parent = i - 1 >> 1;
1030
+ if (this.comparator(heap[i], heap[parent]) <= 0) break;
1031
+ const tmp = heap[i];
1032
+ heap[i] = heap[parent];
1033
+ heap[parent] = tmp;
1034
+ i = parent;
1035
+ }
1036
+ }
1037
+ _sinkDown(i) {
1038
+ const heap = this.heap;
1039
+ const len = heap.length;
1040
+ let largest = i;
1041
+ do {
1042
+ i = largest;
1043
+ const left = 2 * i + 1;
1044
+ const right = 2 * i + 2;
1045
+ if (left < len && this.comparator(heap[left], heap[largest]) > 0) largest = left;
1046
+ if (right < len && this.comparator(heap[right], heap[largest]) > 0) largest = right;
1047
+ if (largest !== i) {
1048
+ const tmp = heap[i];
1049
+ heap[i] = heap[largest];
1050
+ heap[largest] = tmp;
1051
+ }
1052
+ } while (largest !== i);
1053
+ }
1054
+ };
1055
+
1056
+ //#endregion
1057
+ //#region src/core/formatMatches.ts
1058
+ function formatMatches(result) {
1059
+ const matches = [];
1060
+ result.matches.forEach((match) => {
1061
+ if (!isDefined(match.indices) || !match.indices.length) return;
1062
+ const obj = {
1063
+ indices: match.indices,
1064
+ value: match.value
1065
+ };
1066
+ if (match.key) obj.key = match.key.id;
1067
+ if (match.idx > -1) obj.refIndex = match.idx;
1068
+ matches.push(obj);
1069
+ });
1070
+ return matches;
1071
+ }
1072
+
1073
+ //#endregion
1074
+ //#region src/core/format.ts
1075
+ function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
1076
+ return results.map((result) => {
1077
+ const { idx } = result;
1078
+ const data = {
1079
+ item: docs[idx],
1080
+ refIndex: idx
1081
+ };
1082
+ if (includeMatches) data.matches = formatMatches(result);
1083
+ if (includeScore) data.score = result.score;
1084
+ return data;
1085
+ });
1086
+ }
1087
+
1088
+ //#endregion
1089
+ //#region src/search/token/analyzer.ts
1090
+ const DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
1091
+ const warned = /* @__PURE__ */ new WeakSet();
1092
+ function warnNonGlobal(regex) {
1093
+ if (!warned.has(regex)) {
1094
+ warned.add(regex);
1095
+ console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
1096
+ }
1097
+ }
1098
+ function resolveTokenize(tokenize) {
1099
+ if (typeof tokenize === "function") {
1100
+ let validated = false;
1101
+ return (text) => {
1102
+ const result = tokenize(text);
1103
+ if (!validated) {
1104
+ validated = true;
1105
+ 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}.`);
1106
+ }
1107
+ return result;
1108
+ };
1109
+ }
1110
+ if (tokenize instanceof RegExp) {
1111
+ if (!tokenize.global) warnNonGlobal(tokenize);
1112
+ return (text) => text.match(tokenize) || [];
1113
+ }
1114
+ return (text) => text.match(DEFAULT_TOKEN) || [];
1115
+ }
1116
+ function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize } = {}) {
1117
+ const tokenizeFn = resolveTokenize(tokenize);
1118
+ return { tokenize(text) {
1119
+ if (!isCaseSensitive) text = text.toLowerCase();
1120
+ if (ignoreDiacritics) text = stripDiacritics(text);
1121
+ return tokenizeFn(text);
1122
+ } };
1123
+ }
1124
+ var TokenSearch = class {
1125
+ static condition(_, options) {
1126
+ return options.useTokenSearch;
1127
+ }
1128
+ constructor(pattern, options) {
1129
+ this.options = options;
1130
+ this.analyzer = createAnalyzer({
1131
+ isCaseSensitive: options.isCaseSensitive,
1132
+ ignoreDiacritics: options.ignoreDiacritics,
1133
+ tokenize: options.tokenize
1134
+ });
1135
+ const queryTerms = this.analyzer.tokenize(pattern);
1136
+ const { df, fieldCount } = options._invertedIndex;
1137
+ this.termSearchers = [];
1138
+ this.idfWeights = [];
1139
+ for (const term of queryTerms) {
1140
+ this.termSearchers.push(new BitapSearch(term, {
1141
+ location: options.location,
1142
+ threshold: options.threshold,
1143
+ distance: options.distance,
1144
+ includeMatches: options.includeMatches,
1145
+ findAllMatches: options.findAllMatches,
1146
+ minMatchCharLength: options.minMatchCharLength,
1147
+ isCaseSensitive: options.isCaseSensitive,
1148
+ ignoreDiacritics: options.ignoreDiacritics,
1149
+ ignoreLocation: true
1150
+ }));
1151
+ const docFreq = df.get(term) || 0;
1152
+ const idf = Math.log(1 + (fieldCount - docFreq + .5) / (docFreq + .5));
1153
+ this.idfWeights.push(idf);
1154
+ }
1155
+ this.combineAll = options.tokenMatch === "all";
1156
+ this.numTerms = this.termSearchers.length;
1157
+ this.useMask = this.numTerms <= 31;
1158
+ }
1159
+ searchIn(text) {
1160
+ if (!this.termSearchers.length) return {
1161
+ isMatch: false,
1162
+ score: 1
1163
+ };
1164
+ const allIndices = [];
1165
+ let weightedScore = 0;
1166
+ let maxPossibleScore = 0;
1167
+ let matchedCount = 0;
1168
+ let matchedMask = 0;
1169
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
1170
+ for (let i = 0; i < this.termSearchers.length; i++) {
1171
+ const result = this.termSearchers[i].searchIn(text);
1172
+ const idf = this.idfWeights[i];
1173
+ maxPossibleScore += idf;
1174
+ if (result.isMatch) {
1175
+ matchedCount++;
1176
+ weightedScore += idf * (1 - result.score);
1177
+ if (result.indices) allIndices.push(...result.indices);
1178
+ if (this.combineAll) if (this.useMask) matchedMask |= 1 << i;
1179
+ else matchedTerms.add(i);
1180
+ }
1181
+ }
1182
+ if (matchedCount === 0) return {
1183
+ isMatch: false,
1184
+ score: 1
1185
+ };
1186
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
1187
+ const searchResult = {
1188
+ isMatch: true,
1189
+ score: Math.max(.001, normalized)
1190
+ };
1191
+ if (this.options.includeMatches && allIndices.length) searchResult.indices = mergeIndices(allIndices);
1192
+ if (this.combineAll) {
1193
+ if (this.useMask) searchResult.matchedMask = matchedMask;
1194
+ else searchResult.matchedTerms = matchedTerms;
1195
+ searchResult.termCount = this.numTerms;
1196
+ }
1197
+ return searchResult;
1198
+ }
1199
+ };
1200
+
1201
+ //#endregion
1202
+ //#region src/search/token/InvertedIndex.ts
1203
+ function addField(index, text, docIdx, analyzer) {
1204
+ const tokens = analyzer.tokenize(text);
1205
+ if (!tokens.length) return;
1206
+ index.fieldCount++;
1207
+ index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
1208
+ const distinctTerms = new Set(tokens);
1209
+ let perDocTerms = index.docTermFieldHits.get(docIdx);
1210
+ if (!perDocTerms) {
1211
+ perDocTerms = /* @__PURE__ */ new Map();
1212
+ index.docTermFieldHits.set(docIdx, perDocTerms);
1213
+ }
1214
+ for (const term of distinctTerms) {
1215
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
1216
+ index.df.set(term, (index.df.get(term) || 0) + 1);
1217
+ }
1218
+ }
1219
+ function ingestRecord(index, record, keyCount, analyzer) {
1220
+ const { i: docIdx, v, $: fields } = record;
1221
+ if (v !== void 0) {
1222
+ addField(index, v, docIdx, analyzer);
1223
+ return;
1224
+ }
1225
+ if (!fields) return;
1226
+ for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
1227
+ const value = fields[keyIdx];
1228
+ if (!value) continue;
1229
+ if (Array.isArray(value)) for (const sub of value) addField(index, sub.v, docIdx, analyzer);
1230
+ else addField(index, value.v, docIdx, analyzer);
1231
+ }
1232
+ }
1233
+ function buildInvertedIndex(records, keyCount, analyzer) {
1234
+ const index = {
1235
+ fieldCount: 0,
1236
+ df: /* @__PURE__ */ new Map(),
1237
+ docFieldCount: /* @__PURE__ */ new Map(),
1238
+ docTermFieldHits: /* @__PURE__ */ new Map()
1239
+ };
1240
+ for (const record of records) ingestRecord(index, record, keyCount, analyzer);
1241
+ return index;
1242
+ }
1243
+ function addToInvertedIndex(index, record, keyCount, analyzer) {
1244
+ ingestRecord(index, record, keyCount, analyzer);
1245
+ }
1246
+ function removeFromInvertedIndex(index, docIdx) {
1247
+ const fieldCount = index.docFieldCount.get(docIdx);
1248
+ if (fieldCount === void 0) return;
1249
+ index.fieldCount -= fieldCount;
1250
+ index.docFieldCount.delete(docIdx);
1251
+ const perDocTerms = index.docTermFieldHits.get(docIdx);
1252
+ if (!perDocTerms) return;
1253
+ for (const [term, hits] of perDocTerms) {
1254
+ const next = (index.df.get(term) || 0) - hits;
1255
+ if (next <= 0) index.df.delete(term);
1256
+ else index.df.set(term, next);
1257
+ }
1258
+ index.docTermFieldHits.delete(docIdx);
1259
+ }
1260
+ function removeAndShiftInvertedIndex(index, removedIndices) {
1261
+ if (removedIndices.length === 0) return;
1262
+ const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
1263
+ for (const idx of sorted) removeFromInvertedIndex(index, idx);
1264
+ const shift = (oldIdx) => {
1265
+ let lo = 0;
1266
+ let hi = sorted.length;
1267
+ while (lo < hi) {
1268
+ const mid = lo + hi >>> 1;
1269
+ if (sorted[mid] < oldIdx) lo = mid + 1;
1270
+ else hi = mid;
1271
+ }
1272
+ return oldIdx - lo;
1273
+ };
1274
+ const firstRemoved = sorted[0];
1275
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map();
1276
+ for (const [oldKey, count] of index.docFieldCount) shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
1277
+ index.docFieldCount = shiftedDocFieldCount;
1278
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
1279
+ for (const [oldKey, terms] of index.docTermFieldHits) shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
1280
+ index.docTermFieldHits = shiftedDocTermFieldHits;
1281
+ }
1282
+
1283
+ //#endregion
1284
+ //#region src/core/index.ts
1285
+ var Fuse = class {
1286
+ constructor(docs, options, index) {
1287
+ this.options = {
1288
+ ...Config,
1289
+ ...options
1290
+ };
1291
+ this._keyStore = new KeyStore(this.options.keys);
1292
+ this._docs = docs;
1293
+ this._myIndex = null;
1294
+ this._invertedIndex = null;
1295
+ this.setCollection(docs, index);
1296
+ this._lastQuery = null;
1297
+ this._lastSearcher = null;
1298
+ }
1299
+ _getSearcher(query) {
1300
+ if (this._lastQuery === query) return this._lastSearcher;
1301
+ const searcher = createSearcher(query, this._invertedIndex ? {
1302
+ ...this.options,
1303
+ _invertedIndex: this._invertedIndex
1304
+ } : this.options);
1305
+ this._lastQuery = query;
1306
+ this._lastSearcher = searcher;
1307
+ return searcher;
1308
+ }
1309
+ setCollection(docs, index) {
1310
+ this._docs = docs;
1311
+ if (index && !(index instanceof FuseIndex)) throw new Error(INCORRECT_INDEX_TYPE);
1312
+ this._myIndex = index || createIndex(this.options.keys, this._docs, {
1313
+ getFn: this.options.getFn,
1314
+ fieldNormWeight: this.options.fieldNormWeight
1315
+ });
1316
+ if (this.options.useTokenSearch) {
1317
+ const analyzer = createAnalyzer({
1318
+ isCaseSensitive: this.options.isCaseSensitive,
1319
+ ignoreDiacritics: this.options.ignoreDiacritics,
1320
+ tokenize: this.options.tokenize
1321
+ });
1322
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
1323
+ }
1324
+ this._invalidateSearcherCache();
1325
+ }
1326
+ add(doc) {
1327
+ if (!isDefined(doc)) return;
1328
+ this._docs.push(doc);
1329
+ const record = this._myIndex.add(doc, this._docs.length - 1);
1330
+ if (this._invertedIndex && record) {
1331
+ const analyzer = createAnalyzer({
1332
+ isCaseSensitive: this.options.isCaseSensitive,
1333
+ ignoreDiacritics: this.options.ignoreDiacritics,
1334
+ tokenize: this.options.tokenize
1335
+ });
1336
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
1337
+ }
1338
+ this._invalidateSearcherCache();
1339
+ }
1340
+ remove(predicate = () => false) {
1341
+ const results = [];
1342
+ const indicesToRemove = [];
1343
+ for (let i = 0, len = this._docs.length; i < len; i += 1) if (predicate(this._docs[i], i)) {
1344
+ results.push(this._docs[i]);
1345
+ indicesToRemove.push(i);
1346
+ }
1347
+ if (indicesToRemove.length) {
1348
+ if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
1349
+ const toRemove = new Set(indicesToRemove);
1350
+ this._docs = this._docs.filter((_, i) => !toRemove.has(i));
1351
+ this._myIndex.removeAll(indicesToRemove);
1352
+ this._invalidateSearcherCache();
1353
+ }
1354
+ return results;
1355
+ }
1356
+ removeAt(idx) {
1357
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) throw new Error(INVALID_DOC_INDEX);
1358
+ if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
1359
+ const doc = this._docs.splice(idx, 1)[0];
1360
+ this._myIndex.removeAt(idx);
1361
+ this._invalidateSearcherCache();
1362
+ return doc;
1363
+ }
1364
+ _invalidateSearcherCache() {
1365
+ this._lastQuery = null;
1366
+ this._lastSearcher = null;
1367
+ }
1368
+ getIndex() {
1369
+ return this._myIndex;
1370
+ }
1371
+ _normalizedKeys() {
1372
+ return this._myIndex.keys.map((key) => this._keyStore.get(key.id) || key);
1373
+ }
1374
+ search(query, options) {
1375
+ const { limit = -1 } = options || {};
1376
+ const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
1377
+ if (isString(query) && !query.trim()) {
1378
+ let docs = this._docs.map((item, idx) => ({
1379
+ item,
1380
+ refIndex: idx
1381
+ }));
1382
+ if (isNumber(limit) && limit > -1) docs = docs.slice(0, limit);
1383
+ return docs;
1384
+ }
1385
+ const useHeap = shouldSort && isNumber(limit) && limit > 0 && isString(query);
1386
+ const comparator = sortFn;
1387
+ const stable = (a, b) => comparator(a, b) || a.idx - b.idx;
1388
+ let results;
1389
+ if (useHeap) {
1390
+ const heap = new MaxHeap(limit, stable);
1391
+ if (isString(this._docs[0])) this._searchStringList(query, {
1392
+ heap,
1393
+ ignoreFieldNorm
1394
+ });
1395
+ else this._searchObjectList(query, {
1396
+ heap,
1397
+ ignoreFieldNorm
1398
+ });
1399
+ results = heap.extractSorted();
1400
+ } else {
1401
+ results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
1402
+ computeScore(results, { ignoreFieldNorm });
1403
+ if (shouldSort) results.sort(isString(query) ? stable : comparator);
1404
+ if (isNumber(limit) && limit > -1) results = results.slice(0, limit);
1405
+ }
1406
+ return format(results, this._docs, {
1407
+ includeMatches,
1408
+ includeScore
1409
+ });
1410
+ }
1411
+ _searchStringList(query, { heap, ignoreFieldNorm } = {}) {
1412
+ const searcher = this._getSearcher(query);
1413
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
1414
+ const { records } = this._myIndex;
1415
+ const results = heap ? null : [];
1416
+ records.forEach(({ v: text, i: idx, n: norm }) => {
1417
+ if (!isDefined(text)) return;
1418
+ const searchResult = searcher.searchIn(text);
1419
+ if (searchResult.isMatch) {
1420
+ const match = {
1421
+ score: searchResult.score,
1422
+ value: text,
1423
+ norm,
1424
+ indices: searchResult.indices
1425
+ };
1426
+ if (requireAllTokens) {
1427
+ match.matchedMask = searchResult.matchedMask;
1428
+ match.matchedTerms = searchResult.matchedTerms;
1429
+ match.termCount = searchResult.termCount;
1430
+ }
1431
+ const matches = [match];
1432
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
1433
+ const result = {
1434
+ item: text,
1435
+ idx,
1436
+ matches
1437
+ };
1438
+ if (heap) {
1439
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
1440
+ heap.insert(result);
1441
+ } else results.push(result);
1442
+ }
1443
+ }
1444
+ });
1445
+ return results;
1446
+ }
1447
+ _searchLogical(query) {
1448
+ const expression = parse(query, this.options);
1449
+ const keys = this._normalizedKeys();
1450
+ const evaluate = (node, item, idx) => {
1451
+ if (!("children" in node)) {
1452
+ const { keyId, searcher } = node;
1453
+ let matches;
1454
+ if (keyId === null) {
1455
+ matches = [];
1456
+ keys.forEach((key, keyIndex) => {
1457
+ matches.push(...this._findMatches({
1458
+ key,
1459
+ value: item[keyIndex],
1460
+ searcher
1461
+ }));
1462
+ });
1463
+ } else matches = this._findMatches({
1464
+ key: this._keyStore.get(keyId),
1465
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
1466
+ searcher
1467
+ });
1468
+ if (matches && matches.length) return [{
1469
+ idx,
1470
+ item,
1471
+ matches
1472
+ }];
1473
+ return [];
1474
+ }
1475
+ const { children, operator } = node;
1476
+ const res = [];
1477
+ for (let i = 0, len = children.length; i < len; i += 1) {
1478
+ const child = children[i];
1479
+ const result = evaluate(child, item, idx);
1480
+ if (result.length) res.push(...result);
1481
+ else if (operator === LogicalOperator.AND) return [];
1482
+ }
1483
+ return res;
1484
+ };
1485
+ const records = this._myIndex.records;
1486
+ const resultMap = /* @__PURE__ */ new Map();
1487
+ const results = [];
1488
+ records.forEach(({ $: item, i: idx }) => {
1489
+ if (isDefined(item)) {
1490
+ const expResults = evaluate(expression, item, idx);
1491
+ if (expResults.length) {
1492
+ if (!resultMap.has(idx)) {
1493
+ resultMap.set(idx, {
1494
+ idx,
1495
+ item,
1496
+ matches: []
1497
+ });
1498
+ results.push(resultMap.get(idx));
1499
+ }
1500
+ expResults.forEach(({ matches }) => {
1501
+ resultMap.get(idx).matches.push(...matches);
1502
+ });
1503
+ }
1504
+ }
1505
+ });
1506
+ return results;
1507
+ }
1508
+ _searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
1509
+ const searcher = this._getSearcher(query);
1510
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
1511
+ const { records } = this._myIndex;
1512
+ const keys = this._normalizedKeys();
1513
+ const results = heap ? null : [];
1514
+ records.forEach(({ $: item, i: idx }) => {
1515
+ if (!isDefined(item)) return;
1516
+ const matches = [];
1517
+ let anyKeyFailed = false;
1518
+ let hasInverse = false;
1519
+ keys.forEach((key, keyIndex) => {
1520
+ const keyMatches = this._findMatches({
1521
+ key,
1522
+ value: item[keyIndex],
1523
+ searcher
1524
+ });
1525
+ if (keyMatches.length) {
1526
+ matches.push(...keyMatches);
1527
+ if (keyMatches[0].hasInverse) hasInverse = true;
1528
+ } else anyKeyFailed = true;
1529
+ });
1530
+ if (hasInverse && anyKeyFailed) return;
1531
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
1532
+ const result = {
1533
+ idx,
1534
+ item,
1535
+ matches
1536
+ };
1537
+ if (heap) {
1538
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
1539
+ heap.insert(result);
1540
+ } else results.push(result);
1541
+ }
1542
+ });
1543
+ return results;
1544
+ }
1545
+ _findMatches({ key, value, searcher }) {
1546
+ if (!isDefined(value)) return [];
1547
+ const matches = [];
1548
+ if (isArray(value)) value.forEach(({ v: text, i: idx, n: norm }) => {
1549
+ if (!isDefined(text)) return;
1550
+ const searchResult = searcher.searchIn(text);
1551
+ if (searchResult.isMatch) {
1552
+ const match = {
1553
+ score: searchResult.score,
1554
+ key,
1555
+ value: text,
1556
+ idx,
1557
+ norm,
1558
+ indices: searchResult.indices,
1559
+ hasInverse: searchResult.hasInverse
1560
+ };
1561
+ if (searchResult.termCount !== void 0) {
1562
+ match.matchedMask = searchResult.matchedMask;
1563
+ match.matchedTerms = searchResult.matchedTerms;
1564
+ match.termCount = searchResult.termCount;
1565
+ }
1566
+ matches.push(match);
1567
+ }
1568
+ });
1569
+ else {
1570
+ const { v: text, n: norm } = value;
1571
+ const searchResult = searcher.searchIn(text);
1572
+ if (searchResult.isMatch) {
1573
+ const match = {
1574
+ score: searchResult.score,
1575
+ key,
1576
+ value: text,
1577
+ norm,
1578
+ indices: searchResult.indices,
1579
+ hasInverse: searchResult.hasInverse
1580
+ };
1581
+ if (searchResult.termCount !== void 0) {
1582
+ match.matchedMask = searchResult.matchedMask;
1583
+ match.matchedTerms = searchResult.matchedTerms;
1584
+ match.termCount = searchResult.termCount;
1585
+ }
1586
+ matches.push(match);
1587
+ }
1588
+ }
1589
+ return matches;
1590
+ }
1591
+ _coversAllTokens(matches) {
1592
+ const termCount = matches.length ? matches[0].termCount : void 0;
1593
+ if (termCount === void 0) return true;
1594
+ if (termCount <= 31) {
1595
+ let coverage = 0;
1596
+ for (let i = 0; i < matches.length; i++) coverage |= matches[i].matchedMask || 0;
1597
+ return coverage === 2 ** termCount - 1;
1598
+ }
1599
+ const coverage = /* @__PURE__ */ new Set();
1600
+ for (let i = 0; i < matches.length; i++) {
1601
+ const terms = matches[i].matchedTerms;
1602
+ if (terms) for (const t of terms) coverage.add(t);
1603
+ }
1604
+ return coverage.size === termCount;
1605
+ }
1606
+ };
1607
+
1608
+ //#endregion
1609
+ //#region src/entry.ts
1610
+ Fuse.version = "7.5.0";
1611
+ Fuse.createIndex = createIndex;
1612
+ Fuse.parseIndex = parseIndex;
1613
+ Fuse.config = Config;
1614
+ Fuse.match = function(pattern, text, options) {
1615
+ if (options && options.useTokenSearch) throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
1616
+ return createSearcher(pattern, {
1617
+ ...Config,
1618
+ ...options
1619
+ }).searchIn(text);
1620
+ };
1621
+ Fuse.parseQuery = parse;
1622
+ register(ExtendedSearch);
1623
+ register(TokenSearch);
1624
+ Fuse.use = function(...plugins) {
1625
+ plugins.forEach((plugin) => register(plugin));
1626
+ };
1627
+ var entry_default = Fuse;
1628
+
1629
+ export { entry_default as e };