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