@unifold/ui-web 0.1.58 → 0.1.59

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 (3) hide show
  1. package/dist/index.js +2046 -24
  2. package/dist/index.mjs +2046 -24
  3. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -3248,11 +3248,11 @@ var require_react_dom_client_production = __commonJS({
3248
3248
  valueField
3249
3249
  );
3250
3250
  if (!node.hasOwnProperty(valueField) && "undefined" !== typeof descriptor && "function" === typeof descriptor.get && "function" === typeof descriptor.set) {
3251
- var get = descriptor.get, set = descriptor.set;
3251
+ var get2 = descriptor.get, set = descriptor.set;
3252
3252
  Object.defineProperty(node, valueField, {
3253
3253
  configurable: true,
3254
3254
  get: function() {
3255
- return get.call(this);
3255
+ return get2.call(this);
3256
3256
  },
3257
3257
  set: function(value) {
3258
3258
  currentValue = "" + value;
@@ -15402,11 +15402,11 @@ var require_react_dom_client_development = __commonJS({
15402
15402
  valueField
15403
15403
  );
15404
15404
  if (!node.hasOwnProperty(valueField) && "undefined" !== typeof descriptor && "function" === typeof descriptor.get && "function" === typeof descriptor.set) {
15405
- var get = descriptor.get, set = descriptor.set;
15405
+ var get2 = descriptor.get, set = descriptor.set;
15406
15406
  Object.defineProperty(node, valueField, {
15407
15407
  configurable: true,
15408
15408
  get: function() {
15409
- return get.call(this);
15409
+ return get2.call(this);
15410
15410
  },
15411
15411
  set: function(value) {
15412
15412
  checkFormFieldValueStringCoercion(value);
@@ -43245,12 +43245,12 @@ var ExecutionStatus = /* @__PURE__ */ ((ExecutionStatus2) => {
43245
43245
  ExecutionStatus2["WAITING"] = "waiting";
43246
43246
  return ExecutionStatus2;
43247
43247
  })(ExecutionStatus || {});
43248
- async function queryExecutions(externalUserId, publishableKey, actionType) {
43248
+ async function queryExecutions(externalUserId, publishableKey, actionType = "deposit") {
43249
43249
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
43250
43250
  validatePublishableKey(pk);
43251
43251
  const body = {
43252
43252
  external_user_id: externalUserId,
43253
- ...actionType ? { action_type: actionType } : {}
43253
+ action_type: actionType
43254
43254
  };
43255
43255
  const response = await fetch(
43256
43256
  `${API_BASE_URL}/v1/public/direct_executions/query`,
@@ -44159,6 +44159,2002 @@ var cva = (base, config) => (props) => {
44159
44159
  }, []);
44160
44160
  return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
44161
44161
  };
44162
+ function isArray(value) {
44163
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
44164
+ }
44165
+ function baseToString(value) {
44166
+ if (typeof value == "string") {
44167
+ return value;
44168
+ }
44169
+ if (typeof value === "bigint") {
44170
+ return value.toString();
44171
+ }
44172
+ const result = value + "";
44173
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
44174
+ }
44175
+ function toString(value) {
44176
+ return value == null ? "" : baseToString(value);
44177
+ }
44178
+ function isString(value) {
44179
+ return typeof value === "string";
44180
+ }
44181
+ function isNumber2(value) {
44182
+ return typeof value === "number";
44183
+ }
44184
+ function isBoolean(value) {
44185
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
44186
+ }
44187
+ function isObject(value) {
44188
+ return typeof value === "object";
44189
+ }
44190
+ function isObjectLike(value) {
44191
+ return isObject(value) && value !== null;
44192
+ }
44193
+ function isDefined(value) {
44194
+ return value !== void 0 && value !== null;
44195
+ }
44196
+ function isBlank(value) {
44197
+ return !value.trim().length;
44198
+ }
44199
+ function getTag(value) {
44200
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
44201
+ }
44202
+ var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
44203
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
44204
+ var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
44205
+ var PATTERN_LENGTH_TOO_LARGE = (max2) => `Pattern length exceeds max of ${max2}.`;
44206
+ var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
44207
+ var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
44208
+ var FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED = `Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.`;
44209
+ var hasOwn2 = Object.prototype.hasOwnProperty;
44210
+ var KeyStore = class {
44211
+ constructor(keys) {
44212
+ this._keys = [];
44213
+ this._keyMap = {};
44214
+ let totalWeight = 0;
44215
+ keys.forEach((key) => {
44216
+ const obj = createKey(key);
44217
+ this._keys.push(obj);
44218
+ this._keyMap[obj.id] = obj;
44219
+ totalWeight += obj.weight;
44220
+ });
44221
+ this._keys.forEach((key) => {
44222
+ key.weight /= totalWeight;
44223
+ });
44224
+ }
44225
+ get(keyId) {
44226
+ return this._keyMap[keyId];
44227
+ }
44228
+ keys() {
44229
+ return this._keys;
44230
+ }
44231
+ toJSON() {
44232
+ return JSON.stringify(this._keys);
44233
+ }
44234
+ };
44235
+ function createKey(key) {
44236
+ let path = null;
44237
+ let id = null;
44238
+ let src = null;
44239
+ let weight = 1;
44240
+ let getFn = null;
44241
+ if (isString(key) || isArray(key)) {
44242
+ src = key;
44243
+ path = createKeyPath(key);
44244
+ id = createKeyId(key);
44245
+ } else {
44246
+ if (!hasOwn2.call(key, "name")) {
44247
+ throw new Error(MISSING_KEY_PROPERTY("name"));
44248
+ }
44249
+ const name = key.name;
44250
+ src = name;
44251
+ if (hasOwn2.call(key, "weight") && key.weight !== void 0) {
44252
+ weight = key.weight;
44253
+ if (weight <= 0) {
44254
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
44255
+ }
44256
+ }
44257
+ path = createKeyPath(name);
44258
+ id = createKeyId(name);
44259
+ getFn = key.getFn ?? null;
44260
+ }
44261
+ return {
44262
+ path,
44263
+ id,
44264
+ weight,
44265
+ src,
44266
+ getFn
44267
+ };
44268
+ }
44269
+ function createKeyPath(key) {
44270
+ return isArray(key) ? key : key.split(".");
44271
+ }
44272
+ function createKeyId(key) {
44273
+ return isArray(key) ? key.join(".") : key;
44274
+ }
44275
+ function get(obj, path) {
44276
+ const list = [];
44277
+ let arr = false;
44278
+ const deepGet = (obj2, path2, index2, arrayIndex) => {
44279
+ if (!isDefined(obj2)) {
44280
+ return;
44281
+ }
44282
+ if (!path2[index2]) {
44283
+ list.push(arrayIndex !== void 0 ? {
44284
+ v: obj2,
44285
+ i: arrayIndex
44286
+ } : obj2);
44287
+ } else {
44288
+ const key = path2[index2];
44289
+ const value = obj2[key];
44290
+ if (!isDefined(value)) {
44291
+ return;
44292
+ }
44293
+ if (index2 === path2.length - 1 && (isString(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
44294
+ list.push(arrayIndex !== void 0 ? {
44295
+ v: toString(value),
44296
+ i: arrayIndex
44297
+ } : toString(value));
44298
+ } else if (isArray(value)) {
44299
+ arr = true;
44300
+ for (let i = 0, len = value.length; i < len; i += 1) {
44301
+ deepGet(value[i], path2, index2 + 1, i);
44302
+ }
44303
+ } else if (path2.length) {
44304
+ deepGet(value, path2, index2 + 1, arrayIndex);
44305
+ }
44306
+ }
44307
+ };
44308
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
44309
+ return arr ? list : list[0];
44310
+ }
44311
+ var MatchOptions = {
44312
+ includeMatches: false,
44313
+ findAllMatches: false,
44314
+ minMatchCharLength: 1
44315
+ };
44316
+ var BasicOptions = {
44317
+ isCaseSensitive: false,
44318
+ ignoreDiacritics: false,
44319
+ includeScore: false,
44320
+ keys: [],
44321
+ shouldSort: true,
44322
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
44323
+ };
44324
+ var FuzzyOptions = {
44325
+ location: 0,
44326
+ threshold: 0.6,
44327
+ distance: 100
44328
+ };
44329
+ var AdvancedOptions = {
44330
+ useExtendedSearch: false,
44331
+ useTokenSearch: false,
44332
+ tokenize: void 0,
44333
+ tokenMatch: "any",
44334
+ getFn: get,
44335
+ ignoreLocation: false,
44336
+ ignoreFieldNorm: false,
44337
+ fieldNormWeight: 1
44338
+ };
44339
+ var Config = Object.freeze({
44340
+ ...BasicOptions,
44341
+ ...MatchOptions,
44342
+ ...FuzzyOptions,
44343
+ ...AdvancedOptions
44344
+ });
44345
+ function norm(weight = 1, mantissa = 3) {
44346
+ const cache = /* @__PURE__ */ new Map();
44347
+ const m = Math.pow(10, mantissa);
44348
+ return {
44349
+ get(value) {
44350
+ let numTokens = 1;
44351
+ let inSpace = false;
44352
+ for (let i = 0; i < value.length; i++) {
44353
+ if (value.charCodeAt(i) === 32) {
44354
+ if (!inSpace) {
44355
+ numTokens++;
44356
+ inSpace = true;
44357
+ }
44358
+ } else {
44359
+ inSpace = false;
44360
+ }
44361
+ }
44362
+ if (cache.has(numTokens)) {
44363
+ return cache.get(numTokens);
44364
+ }
44365
+ const n = Math.round(m / Math.pow(numTokens, 0.5 * weight)) / m;
44366
+ cache.set(numTokens, n);
44367
+ return n;
44368
+ },
44369
+ clear() {
44370
+ cache.clear();
44371
+ }
44372
+ };
44373
+ }
44374
+ var FuseIndex = class {
44375
+ constructor({
44376
+ getFn = Config.getFn,
44377
+ fieldNormWeight = Config.fieldNormWeight
44378
+ } = {}) {
44379
+ this.norm = norm(fieldNormWeight, 3);
44380
+ this.getFn = getFn;
44381
+ this.isCreated = false;
44382
+ this.docs = [];
44383
+ this.keys = [];
44384
+ this._keysMap = {};
44385
+ this.setIndexRecords();
44386
+ }
44387
+ setSources(docs = []) {
44388
+ this.docs = docs;
44389
+ }
44390
+ setIndexRecords(records = []) {
44391
+ this.records = records;
44392
+ }
44393
+ setKeys(keys = []) {
44394
+ this.keys = keys;
44395
+ this._keysMap = {};
44396
+ keys.forEach((key, idx) => {
44397
+ this._keysMap[key.id] = idx;
44398
+ });
44399
+ }
44400
+ create() {
44401
+ if (this.isCreated || !this.docs.length) {
44402
+ return;
44403
+ }
44404
+ this.isCreated = true;
44405
+ const len = this.docs.length;
44406
+ this.records = new Array(len);
44407
+ let recordCount = 0;
44408
+ if (isString(this.docs[0])) {
44409
+ for (let i = 0; i < len; i++) {
44410
+ const record = this._createStringRecord(this.docs[i], i);
44411
+ if (record) {
44412
+ this.records[recordCount++] = record;
44413
+ }
44414
+ }
44415
+ } else {
44416
+ for (let i = 0; i < len; i++) {
44417
+ this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
44418
+ }
44419
+ }
44420
+ this.records.length = recordCount;
44421
+ this.norm.clear();
44422
+ }
44423
+ // Appends a record for `doc` at `docIndex` (the doc's position in the source
44424
+ // array). Returns the appended record, or null when `doc` is a blank string
44425
+ // (those are skipped at record creation; see `_createStringRecord`). Callers
44426
+ // use the return value to gate downstream bookkeeping like the inverted
44427
+ // index, which must not be touched when no record was produced.
44428
+ add(doc, docIndex) {
44429
+ if (!Number.isInteger(docIndex) || docIndex < 0) {
44430
+ throw new Error(INVALID_DOC_INDEX);
44431
+ }
44432
+ if (isString(doc)) {
44433
+ const record2 = this._createStringRecord(doc, docIndex);
44434
+ if (record2) {
44435
+ this.records.push(record2);
44436
+ }
44437
+ return record2;
44438
+ }
44439
+ const record = this._createObjectRecord(doc, docIndex);
44440
+ this.records.push(record);
44441
+ return record;
44442
+ }
44443
+ // Removes the record for the doc at the specified source-array (docs) index.
44444
+ // Blank string docs have no record; callers may pass such an index and the
44445
+ // splice is a no-op, but subsequent records still need their .i decremented
44446
+ // to track the docs array that the caller is splicing in parallel.
44447
+ removeAt(idx) {
44448
+ if (!Number.isInteger(idx) || idx < 0) {
44449
+ throw new Error(INVALID_DOC_INDEX);
44450
+ }
44451
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44452
+ if (this.records[i].i === idx) {
44453
+ this.records.splice(i, 1);
44454
+ break;
44455
+ }
44456
+ }
44457
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44458
+ if (this.records[i].i > idx) {
44459
+ this.records[i].i -= 1;
44460
+ }
44461
+ }
44462
+ }
44463
+ // Removes records for the docs at the specified source-array indices, then
44464
+ // shifts every surviving record's .i down by the count of removed indices
44465
+ // strictly less than it (mirrors removeAndShiftInvertedIndex's shift math).
44466
+ // Invalid entries (non-integer, negative) in `indices` are dropped silently
44467
+ // — removeAll's natural use case is "caller passed a list of matched doc
44468
+ // indices"; asymmetric throw-vs-no-op would be more surprising than a clean
44469
+ // filter.
44470
+ removeAll(indices) {
44471
+ const toRemove = /* @__PURE__ */ new Set();
44472
+ for (const v of indices) {
44473
+ if (Number.isInteger(v) && v >= 0) {
44474
+ toRemove.add(v);
44475
+ }
44476
+ }
44477
+ if (toRemove.size === 0) {
44478
+ return;
44479
+ }
44480
+ this.records = this.records.filter((r2) => !toRemove.has(r2.i));
44481
+ const sorted = Array.from(toRemove).sort((a, b) => a - b);
44482
+ for (const record of this.records) {
44483
+ let lo = 0;
44484
+ let hi = sorted.length;
44485
+ while (lo < hi) {
44486
+ const mid = lo + hi >>> 1;
44487
+ if (sorted[mid] < record.i) lo = mid + 1;
44488
+ else hi = mid;
44489
+ }
44490
+ record.i -= lo;
44491
+ }
44492
+ }
44493
+ getValueForItemAtKeyId(item, keyId) {
44494
+ return item[this._keysMap[keyId]];
44495
+ }
44496
+ size() {
44497
+ return this.records.length;
44498
+ }
44499
+ _createStringRecord(doc, docIndex) {
44500
+ if (!isDefined(doc) || isBlank(doc)) {
44501
+ return null;
44502
+ }
44503
+ return {
44504
+ v: doc,
44505
+ i: docIndex,
44506
+ n: this.norm.get(doc)
44507
+ };
44508
+ }
44509
+ _createObjectRecord(doc, docIndex) {
44510
+ const record = {
44511
+ i: docIndex,
44512
+ $: {}
44513
+ };
44514
+ for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
44515
+ const key = this.keys[keyIndex];
44516
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
44517
+ if (!isDefined(value)) {
44518
+ continue;
44519
+ }
44520
+ if (isArray(value)) {
44521
+ const subRecords = [];
44522
+ for (let i = 0, len = value.length; i < len; i += 1) {
44523
+ const item = value[i];
44524
+ if (!isDefined(item)) {
44525
+ continue;
44526
+ }
44527
+ if (isString(item)) {
44528
+ if (!isBlank(item)) {
44529
+ const subRecord = {
44530
+ v: item,
44531
+ i,
44532
+ n: this.norm.get(item)
44533
+ };
44534
+ subRecords.push(subRecord);
44535
+ }
44536
+ } else if (isDefined(item.v)) {
44537
+ const text = isString(item.v) ? item.v : toString(item.v);
44538
+ if (!isBlank(text)) {
44539
+ const subRecord = {
44540
+ v: text,
44541
+ i: item.i,
44542
+ n: this.norm.get(text)
44543
+ };
44544
+ subRecords.push(subRecord);
44545
+ }
44546
+ }
44547
+ }
44548
+ record.$[keyIndex] = subRecords;
44549
+ } else if (isString(value) && !isBlank(value)) {
44550
+ const subRecord = {
44551
+ v: value,
44552
+ n: this.norm.get(value)
44553
+ };
44554
+ record.$[keyIndex] = subRecord;
44555
+ }
44556
+ }
44557
+ return record;
44558
+ }
44559
+ toJSON() {
44560
+ return {
44561
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
44562
+ keys: this.keys.map(({
44563
+ getFn,
44564
+ ...key
44565
+ }) => key),
44566
+ records: this.records
44567
+ };
44568
+ }
44569
+ };
44570
+ function createIndex(keys, docs, {
44571
+ getFn = Config.getFn,
44572
+ fieldNormWeight = Config.fieldNormWeight
44573
+ } = {}) {
44574
+ const myIndex = new FuseIndex({
44575
+ getFn,
44576
+ fieldNormWeight
44577
+ });
44578
+ myIndex.setKeys(keys.map(createKey));
44579
+ myIndex.setSources(docs);
44580
+ myIndex.create();
44581
+ return myIndex;
44582
+ }
44583
+ function parseIndex(data, {
44584
+ getFn = Config.getFn,
44585
+ fieldNormWeight = Config.fieldNormWeight
44586
+ } = {}) {
44587
+ const {
44588
+ keys,
44589
+ records
44590
+ } = data;
44591
+ const myIndex = new FuseIndex({
44592
+ getFn,
44593
+ fieldNormWeight
44594
+ });
44595
+ myIndex.setKeys(keys);
44596
+ myIndex.setIndexRecords(records);
44597
+ return myIndex;
44598
+ }
44599
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
44600
+ const indices = [];
44601
+ let start = -1;
44602
+ let end = -1;
44603
+ let i = 0;
44604
+ for (let len = matchmask.length; i < len; i += 1) {
44605
+ const match = matchmask[i];
44606
+ if (match && start === -1) {
44607
+ start = i;
44608
+ } else if (!match && start !== -1) {
44609
+ end = i - 1;
44610
+ if (end - start + 1 >= minMatchCharLength) {
44611
+ indices.push([start, end]);
44612
+ }
44613
+ start = -1;
44614
+ }
44615
+ }
44616
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
44617
+ indices.push([start, i - 1]);
44618
+ }
44619
+ return indices;
44620
+ }
44621
+ var MAX_BITS = 32;
44622
+ function search(text, pattern, patternAlphabet, {
44623
+ location = Config.location,
44624
+ distance = Config.distance,
44625
+ threshold = Config.threshold,
44626
+ findAllMatches = Config.findAllMatches,
44627
+ minMatchCharLength = Config.minMatchCharLength,
44628
+ includeMatches = Config.includeMatches,
44629
+ ignoreLocation = Config.ignoreLocation
44630
+ } = {}) {
44631
+ if (pattern.length > MAX_BITS) {
44632
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
44633
+ }
44634
+ const patternLen = pattern.length;
44635
+ const textLen = text.length;
44636
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
44637
+ let currentThreshold = threshold;
44638
+ let bestLocation = expectedLocation;
44639
+ const calcScore = (errors, currentLocation) => {
44640
+ const accuracy = errors / patternLen;
44641
+ if (ignoreLocation) return accuracy;
44642
+ const proximity = Math.abs(expectedLocation - currentLocation);
44643
+ if (!distance) return proximity ? 1 : accuracy;
44644
+ return accuracy + proximity / distance;
44645
+ };
44646
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
44647
+ const matchMask = computeMatches ? Array(textLen) : [];
44648
+ let index2;
44649
+ while ((index2 = text.indexOf(pattern, bestLocation)) > -1) {
44650
+ const score = calcScore(0, index2);
44651
+ currentThreshold = Math.min(score, currentThreshold);
44652
+ bestLocation = index2 + patternLen;
44653
+ if (computeMatches) {
44654
+ let i = 0;
44655
+ while (i < patternLen) {
44656
+ matchMask[index2 + i] = 1;
44657
+ i += 1;
44658
+ }
44659
+ }
44660
+ }
44661
+ bestLocation = -1;
44662
+ let lastBitArr = [];
44663
+ let finalScore = 1;
44664
+ let bestErrors = 0;
44665
+ let binMax = patternLen + textLen;
44666
+ const mask = 1 << patternLen - 1;
44667
+ for (let i = 0; i < patternLen; i += 1) {
44668
+ let binMin = 0;
44669
+ let binMid = binMax;
44670
+ while (binMin < binMid) {
44671
+ const score2 = calcScore(i, expectedLocation + binMid);
44672
+ if (score2 <= currentThreshold) {
44673
+ binMin = binMid;
44674
+ } else {
44675
+ binMax = binMid;
44676
+ }
44677
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
44678
+ }
44679
+ binMax = binMid;
44680
+ let start = Math.max(1, expectedLocation - binMid + 1);
44681
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
44682
+ const bitArr = Array(finish + 2);
44683
+ bitArr[finish + 1] = (1 << i) - 1;
44684
+ for (let j = finish; j >= start; j -= 1) {
44685
+ const currentLocation = j - 1;
44686
+ const charMatch = patternAlphabet[text[currentLocation]];
44687
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
44688
+ if (i) {
44689
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
44690
+ }
44691
+ if (bitArr[j] & mask) {
44692
+ finalScore = calcScore(i, currentLocation);
44693
+ if (finalScore <= currentThreshold) {
44694
+ currentThreshold = finalScore;
44695
+ bestLocation = currentLocation;
44696
+ bestErrors = i;
44697
+ if (bestLocation <= expectedLocation) {
44698
+ break;
44699
+ }
44700
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
44701
+ }
44702
+ }
44703
+ }
44704
+ const score = calcScore(i + 1, expectedLocation);
44705
+ if (score > currentThreshold) {
44706
+ break;
44707
+ }
44708
+ lastBitArr = bitArr;
44709
+ }
44710
+ if (computeMatches && bestLocation >= 0) {
44711
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
44712
+ for (let k = bestLocation; k <= matchEnd; k += 1) {
44713
+ if (patternAlphabet[text[k]]) {
44714
+ matchMask[k] = 1;
44715
+ }
44716
+ }
44717
+ }
44718
+ const result = {
44719
+ isMatch: bestLocation >= 0,
44720
+ // Count exact matches (those with a score of 0) to be "almost" exact
44721
+ score: Math.max(1e-3, finalScore)
44722
+ };
44723
+ if (computeMatches) {
44724
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
44725
+ if (!indices.length) {
44726
+ result.isMatch = false;
44727
+ } else if (includeMatches) {
44728
+ result.indices = indices;
44729
+ }
44730
+ }
44731
+ return result;
44732
+ }
44733
+ function createPatternAlphabet(pattern) {
44734
+ const mask = {};
44735
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
44736
+ const char = pattern.charAt(i);
44737
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
44738
+ }
44739
+ return mask;
44740
+ }
44741
+ function mergeIndices(indices) {
44742
+ if (indices.length <= 1) return indices;
44743
+ indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
44744
+ const merged = [indices[0]];
44745
+ for (let i = 1, len = indices.length; i < len; i += 1) {
44746
+ const last = merged[merged.length - 1];
44747
+ const curr = indices[i];
44748
+ if (curr[0] <= last[1] + 1) {
44749
+ last[1] = Math.max(last[1], curr[1]);
44750
+ } else {
44751
+ merged.push(curr);
44752
+ }
44753
+ }
44754
+ return merged;
44755
+ }
44756
+ var NON_DECOMPOSABLE_MAP = {
44757
+ "\u0142": "l",
44758
+ // ł
44759
+ "\u0141": "L",
44760
+ // Ł
44761
+ "\u0111": "d",
44762
+ // đ
44763
+ "\u0110": "D",
44764
+ // Đ
44765
+ "\xF8": "o",
44766
+ // ø
44767
+ "\xD8": "O",
44768
+ // Ø
44769
+ "\u0127": "h",
44770
+ // ħ
44771
+ "\u0126": "H",
44772
+ // Ħ
44773
+ "\u0167": "t",
44774
+ // ŧ
44775
+ "\u0166": "T",
44776
+ // Ŧ
44777
+ "\u0131": "i",
44778
+ // ı
44779
+ "\xDF": "ss"
44780
+ // ß
44781
+ };
44782
+ var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
44783
+ var stripDiacritics = typeof String.prototype.normalize === "function" ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch) => NON_DECOMPOSABLE_MAP[ch]) : (str) => str;
44784
+ var BitapSearch = class {
44785
+ constructor(pattern, {
44786
+ location = Config.location,
44787
+ threshold = Config.threshold,
44788
+ distance = Config.distance,
44789
+ includeMatches = Config.includeMatches,
44790
+ findAllMatches = Config.findAllMatches,
44791
+ minMatchCharLength = Config.minMatchCharLength,
44792
+ isCaseSensitive = Config.isCaseSensitive,
44793
+ ignoreDiacritics = Config.ignoreDiacritics,
44794
+ ignoreLocation = Config.ignoreLocation
44795
+ } = {}) {
44796
+ this.options = {
44797
+ location,
44798
+ threshold,
44799
+ distance,
44800
+ includeMatches,
44801
+ findAllMatches,
44802
+ minMatchCharLength,
44803
+ isCaseSensitive,
44804
+ ignoreDiacritics,
44805
+ ignoreLocation
44806
+ };
44807
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
44808
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
44809
+ this.pattern = pattern;
44810
+ this.chunks = [];
44811
+ if (!this.pattern.length) {
44812
+ return;
44813
+ }
44814
+ const addChunk = (pattern2, startIndex) => {
44815
+ this.chunks.push({
44816
+ pattern: pattern2,
44817
+ alphabet: createPatternAlphabet(pattern2),
44818
+ startIndex
44819
+ });
44820
+ };
44821
+ const len = this.pattern.length;
44822
+ if (len > MAX_BITS) {
44823
+ let i = 0;
44824
+ const remainder = len % MAX_BITS;
44825
+ const end = len - remainder;
44826
+ while (i < end) {
44827
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
44828
+ i += MAX_BITS;
44829
+ }
44830
+ if (remainder) {
44831
+ const startIndex = len - MAX_BITS;
44832
+ addChunk(this.pattern.substr(startIndex), startIndex);
44833
+ }
44834
+ } else {
44835
+ addChunk(this.pattern, 0);
44836
+ }
44837
+ }
44838
+ searchIn(text) {
44839
+ const {
44840
+ isCaseSensitive,
44841
+ ignoreDiacritics,
44842
+ includeMatches
44843
+ } = this.options;
44844
+ text = isCaseSensitive ? text : text.toLowerCase();
44845
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
44846
+ if (this.pattern === text) {
44847
+ const result2 = {
44848
+ isMatch: true,
44849
+ score: 0
44850
+ };
44851
+ if (includeMatches) {
44852
+ result2.indices = [[0, text.length - 1]];
44853
+ }
44854
+ return result2;
44855
+ }
44856
+ const {
44857
+ location,
44858
+ distance,
44859
+ threshold,
44860
+ findAllMatches,
44861
+ minMatchCharLength,
44862
+ ignoreLocation
44863
+ } = this.options;
44864
+ const allIndices = [];
44865
+ let totalScore = 0;
44866
+ let hasMatches = false;
44867
+ this.chunks.forEach(({
44868
+ pattern,
44869
+ alphabet,
44870
+ startIndex
44871
+ }) => {
44872
+ const {
44873
+ isMatch,
44874
+ score,
44875
+ indices
44876
+ } = search(text, pattern, alphabet, {
44877
+ location: location + startIndex,
44878
+ distance,
44879
+ threshold,
44880
+ findAllMatches,
44881
+ minMatchCharLength,
44882
+ includeMatches,
44883
+ ignoreLocation
44884
+ });
44885
+ if (isMatch) {
44886
+ hasMatches = true;
44887
+ }
44888
+ totalScore += score;
44889
+ if (isMatch && indices) {
44890
+ allIndices.push(...indices);
44891
+ }
44892
+ });
44893
+ const result = {
44894
+ isMatch: hasMatches,
44895
+ score: hasMatches ? totalScore / this.chunks.length : 1
44896
+ };
44897
+ if (hasMatches && includeMatches) {
44898
+ result.indices = mergeIndices(allIndices);
44899
+ }
44900
+ return result;
44901
+ }
44902
+ };
44903
+ var MULTI_MATCH_TYPES = /* @__PURE__ */ new Set(["fuzzy", "include"]);
44904
+ function isInverse(type) {
44905
+ return type.startsWith("inverse");
44906
+ }
44907
+ var matchers = [
44908
+ // =term — exact match
44909
+ {
44910
+ type: "exact",
44911
+ multiRegex: /^="(.*)"$/,
44912
+ singleRegex: /^=(.*)$/,
44913
+ create: (pattern) => ({
44914
+ type: "exact",
44915
+ search(text) {
44916
+ const isMatch = text === pattern;
44917
+ return {
44918
+ isMatch,
44919
+ score: isMatch ? 0 : 1,
44920
+ indices: [0, pattern.length - 1]
44921
+ };
44922
+ }
44923
+ })
44924
+ },
44925
+ // 'term — include (substring) match
44926
+ {
44927
+ type: "include",
44928
+ multiRegex: /^'"(.*)"$/,
44929
+ singleRegex: /^'(.*)$/,
44930
+ create: (pattern) => ({
44931
+ type: "include",
44932
+ search(text) {
44933
+ let location = 0;
44934
+ let index2;
44935
+ const indices = [];
44936
+ const patternLen = pattern.length;
44937
+ while ((index2 = text.indexOf(pattern, location)) > -1) {
44938
+ location = index2 + patternLen;
44939
+ indices.push([index2, location - 1]);
44940
+ }
44941
+ const isMatch = !!indices.length;
44942
+ return {
44943
+ isMatch,
44944
+ score: isMatch ? 0 : 1,
44945
+ indices
44946
+ };
44947
+ }
44948
+ })
44949
+ },
44950
+ // ^term — prefix match
44951
+ {
44952
+ type: "prefix-exact",
44953
+ multiRegex: /^\^"(.*)"$/,
44954
+ singleRegex: /^\^(.*)$/,
44955
+ create: (pattern) => ({
44956
+ type: "prefix-exact",
44957
+ search(text) {
44958
+ const isMatch = text.startsWith(pattern);
44959
+ return {
44960
+ isMatch,
44961
+ score: isMatch ? 0 : 1,
44962
+ indices: [0, pattern.length - 1]
44963
+ };
44964
+ }
44965
+ })
44966
+ },
44967
+ // !^term — inverse prefix match
44968
+ {
44969
+ type: "inverse-prefix-exact",
44970
+ multiRegex: /^!\^"(.*)"$/,
44971
+ singleRegex: /^!\^(.*)$/,
44972
+ create: (pattern) => ({
44973
+ type: "inverse-prefix-exact",
44974
+ search(text) {
44975
+ const isMatch = !text.startsWith(pattern);
44976
+ return {
44977
+ isMatch,
44978
+ score: isMatch ? 0 : 1,
44979
+ indices: [0, text.length - 1]
44980
+ };
44981
+ }
44982
+ })
44983
+ },
44984
+ // !term$ — inverse suffix match
44985
+ {
44986
+ type: "inverse-suffix-exact",
44987
+ multiRegex: /^!"(.*)"\$$/,
44988
+ singleRegex: /^!(.*)\$$/,
44989
+ create: (pattern) => ({
44990
+ type: "inverse-suffix-exact",
44991
+ search(text) {
44992
+ const isMatch = !text.endsWith(pattern);
44993
+ return {
44994
+ isMatch,
44995
+ score: isMatch ? 0 : 1,
44996
+ indices: [0, text.length - 1]
44997
+ };
44998
+ }
44999
+ })
45000
+ },
45001
+ // term$ — suffix match
45002
+ {
45003
+ type: "suffix-exact",
45004
+ multiRegex: /^"(.*)"\$$/,
45005
+ singleRegex: /^(.*)\$$/,
45006
+ create: (pattern) => ({
45007
+ type: "suffix-exact",
45008
+ search(text) {
45009
+ const isMatch = text.endsWith(pattern);
45010
+ return {
45011
+ isMatch,
45012
+ score: isMatch ? 0 : 1,
45013
+ indices: [text.length - pattern.length, text.length - 1]
45014
+ };
45015
+ }
45016
+ })
45017
+ },
45018
+ // !term — inverse exact (does not contain)
45019
+ {
45020
+ type: "inverse-exact",
45021
+ multiRegex: /^!"(.*)"$/,
45022
+ singleRegex: /^!(.*)$/,
45023
+ create: (pattern) => ({
45024
+ type: "inverse-exact",
45025
+ search(text) {
45026
+ const isMatch = text.indexOf(pattern) === -1;
45027
+ return {
45028
+ isMatch,
45029
+ score: isMatch ? 0 : 1,
45030
+ indices: [0, text.length - 1]
45031
+ };
45032
+ }
45033
+ })
45034
+ },
45035
+ // term — fuzzy match (catch-all, must be last)
45036
+ {
45037
+ type: "fuzzy",
45038
+ multiRegex: /^"(.*)"$/,
45039
+ singleRegex: /^(.*)$/,
45040
+ create: (pattern, options2 = {}) => {
45041
+ const bitap = new BitapSearch(pattern, {
45042
+ location: options2.location ?? Config.location,
45043
+ threshold: options2.threshold ?? Config.threshold,
45044
+ distance: options2.distance ?? Config.distance,
45045
+ includeMatches: options2.includeMatches ?? Config.includeMatches,
45046
+ findAllMatches: options2.findAllMatches ?? Config.findAllMatches,
45047
+ minMatchCharLength: options2.minMatchCharLength ?? Config.minMatchCharLength,
45048
+ isCaseSensitive: options2.isCaseSensitive ?? Config.isCaseSensitive,
45049
+ ignoreDiacritics: options2.ignoreDiacritics ?? Config.ignoreDiacritics,
45050
+ ignoreLocation: options2.ignoreLocation ?? Config.ignoreLocation
45051
+ });
45052
+ return {
45053
+ type: "fuzzy",
45054
+ search(text) {
45055
+ return bitap.searchIn(text);
45056
+ }
45057
+ };
45058
+ }
45059
+ }
45060
+ ];
45061
+ var matchersLen = matchers.length;
45062
+ var ESCAPED_PIPE = "\0";
45063
+ var OR_TOKEN = "|";
45064
+ function tokenize(pattern) {
45065
+ const tokens = [];
45066
+ const len = pattern.length;
45067
+ let i = 0;
45068
+ while (i < len) {
45069
+ while (i < len && pattern[i] === " ") i++;
45070
+ if (i >= len) break;
45071
+ let j = i;
45072
+ while (j < len && pattern[j] !== " " && pattern[j] !== '"') j++;
45073
+ if (j < len && pattern[j] === '"') {
45074
+ j++;
45075
+ while (j < len) {
45076
+ if (pattern[j] === '"') {
45077
+ const next = j + 1;
45078
+ if (next >= len || pattern[next] === " ") {
45079
+ j++;
45080
+ break;
45081
+ }
45082
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
45083
+ j += 2;
45084
+ break;
45085
+ }
45086
+ }
45087
+ j++;
45088
+ }
45089
+ tokens.push(pattern.substring(i, j));
45090
+ i = j;
45091
+ } else {
45092
+ while (j < len && pattern[j] !== " ") j++;
45093
+ tokens.push(pattern.substring(i, j));
45094
+ i = j;
45095
+ }
45096
+ }
45097
+ return tokens;
45098
+ }
45099
+ function getMatch(pattern, exp) {
45100
+ const matches = pattern.match(exp);
45101
+ return matches ? matches[1] : null;
45102
+ }
45103
+ function parseQuery(pattern, options2 = {}) {
45104
+ const escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
45105
+ return escaped.split(OR_TOKEN).map((item) => {
45106
+ const restored = item.replace(/\u0000/g, "|");
45107
+ const query = tokenize(restored.trim()).filter((item2) => item2 && !!item2.trim());
45108
+ const results = [];
45109
+ for (let i = 0, len = query.length; i < len; i += 1) {
45110
+ const queryItem = query[i];
45111
+ let found = false;
45112
+ let idx = -1;
45113
+ while (!found && ++idx < matchersLen) {
45114
+ const def = matchers[idx];
45115
+ const token = getMatch(queryItem, def.multiRegex);
45116
+ if (token) {
45117
+ results.push(def.create(token, options2));
45118
+ found = true;
45119
+ }
45120
+ }
45121
+ if (found) {
45122
+ continue;
45123
+ }
45124
+ idx = -1;
45125
+ while (++idx < matchersLen) {
45126
+ const def = matchers[idx];
45127
+ const token = getMatch(queryItem, def.singleRegex);
45128
+ if (token) {
45129
+ results.push(def.create(token, options2));
45130
+ break;
45131
+ }
45132
+ }
45133
+ }
45134
+ return results;
45135
+ });
45136
+ }
45137
+ var ExtendedSearch = class {
45138
+ constructor(pattern, {
45139
+ isCaseSensitive = Config.isCaseSensitive,
45140
+ ignoreDiacritics = Config.ignoreDiacritics,
45141
+ includeMatches = Config.includeMatches,
45142
+ minMatchCharLength = Config.minMatchCharLength,
45143
+ ignoreLocation = Config.ignoreLocation,
45144
+ findAllMatches = Config.findAllMatches,
45145
+ location = Config.location,
45146
+ threshold = Config.threshold,
45147
+ distance = Config.distance
45148
+ } = {}) {
45149
+ this.query = null;
45150
+ this.options = {
45151
+ isCaseSensitive,
45152
+ ignoreDiacritics,
45153
+ includeMatches,
45154
+ minMatchCharLength,
45155
+ findAllMatches,
45156
+ ignoreLocation,
45157
+ location,
45158
+ threshold,
45159
+ distance
45160
+ };
45161
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
45162
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
45163
+ this.pattern = pattern;
45164
+ this.query = parseQuery(this.pattern, this.options);
45165
+ }
45166
+ static condition(_, options2) {
45167
+ return options2.useExtendedSearch;
45168
+ }
45169
+ // Note: searchIn operates on a single text value and sets hasInverse on the
45170
+ // result when inverse patterns are involved. _searchObjectList uses this to
45171
+ // switch from "ANY key" to "ALL keys" aggregation. See #712.
45172
+ searchIn(text) {
45173
+ const query = this.query;
45174
+ if (!query) {
45175
+ return {
45176
+ isMatch: false,
45177
+ score: 1
45178
+ };
45179
+ }
45180
+ const {
45181
+ includeMatches,
45182
+ isCaseSensitive,
45183
+ ignoreDiacritics
45184
+ } = this.options;
45185
+ text = isCaseSensitive ? text : text.toLowerCase();
45186
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
45187
+ let numMatches = 0;
45188
+ const allIndices = [];
45189
+ let totalScore = 0;
45190
+ let hasInverse = false;
45191
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
45192
+ const searchers = query[i];
45193
+ allIndices.length = 0;
45194
+ numMatches = 0;
45195
+ hasInverse = false;
45196
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
45197
+ const matcher = searchers[j];
45198
+ const {
45199
+ isMatch,
45200
+ indices,
45201
+ score
45202
+ } = matcher.search(text);
45203
+ if (isMatch) {
45204
+ numMatches += 1;
45205
+ totalScore += score;
45206
+ if (isInverse(matcher.type)) {
45207
+ hasInverse = true;
45208
+ }
45209
+ if (includeMatches) {
45210
+ if (MULTI_MATCH_TYPES.has(matcher.type)) {
45211
+ allIndices.push(...indices);
45212
+ } else {
45213
+ allIndices.push(indices);
45214
+ }
45215
+ }
45216
+ } else {
45217
+ totalScore = 0;
45218
+ numMatches = 0;
45219
+ allIndices.length = 0;
45220
+ hasInverse = false;
45221
+ break;
45222
+ }
45223
+ }
45224
+ if (numMatches) {
45225
+ const result = {
45226
+ isMatch: true,
45227
+ score: totalScore / numMatches
45228
+ };
45229
+ if (hasInverse) {
45230
+ result.hasInverse = true;
45231
+ }
45232
+ if (includeMatches) {
45233
+ result.indices = mergeIndices(allIndices);
45234
+ }
45235
+ return result;
45236
+ }
45237
+ }
45238
+ return {
45239
+ isMatch: false,
45240
+ score: 1
45241
+ };
45242
+ }
45243
+ };
45244
+ var registeredSearchers = [];
45245
+ function register(...args) {
45246
+ registeredSearchers.push(...args);
45247
+ }
45248
+ function createSearcher(pattern, options2) {
45249
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
45250
+ const searcherClass = registeredSearchers[i];
45251
+ if (searcherClass.condition(pattern, options2)) {
45252
+ return new searcherClass(pattern, options2);
45253
+ }
45254
+ }
45255
+ return new BitapSearch(pattern, options2);
45256
+ }
45257
+ var LogicalOperator = {
45258
+ AND: "$and",
45259
+ OR: "$or"
45260
+ };
45261
+ var KeyType = {
45262
+ PATH: "$path",
45263
+ PATTERN: "$val"
45264
+ };
45265
+ var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
45266
+ var isPath = (query) => !!query[KeyType.PATH];
45267
+ var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
45268
+ var convertToExplicit = (query) => ({
45269
+ [LogicalOperator.AND]: Object.keys(query).map((key) => ({
45270
+ [key]: query[key]
45271
+ }))
45272
+ });
45273
+ function parse2(query, options2, {
45274
+ auto = true
45275
+ } = {}) {
45276
+ const next = (query2) => {
45277
+ if (isString(query2)) {
45278
+ const obj = {
45279
+ keyId: null,
45280
+ pattern: query2
45281
+ };
45282
+ if (auto) {
45283
+ obj.searcher = createSearcher(query2, options2);
45284
+ }
45285
+ return obj;
45286
+ }
45287
+ const keys = Object.keys(query2);
45288
+ const isQueryPath = isPath(query2);
45289
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
45290
+ return next(convertToExplicit(query2));
45291
+ }
45292
+ if (isLeaf(query2)) {
45293
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
45294
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
45295
+ if (!isString(pattern)) {
45296
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
45297
+ }
45298
+ const obj = {
45299
+ keyId: createKeyId(key),
45300
+ pattern
45301
+ };
45302
+ if (auto) {
45303
+ obj.searcher = createSearcher(pattern, options2);
45304
+ }
45305
+ return obj;
45306
+ }
45307
+ const node = {
45308
+ children: [],
45309
+ operator: keys[0]
45310
+ };
45311
+ keys.forEach((key) => {
45312
+ const value = query2[key];
45313
+ if (isArray(value)) {
45314
+ value.forEach((item) => {
45315
+ node.children.push(next(item));
45316
+ });
45317
+ }
45318
+ });
45319
+ return node;
45320
+ };
45321
+ if (!isExpression(query)) {
45322
+ query = convertToExplicit(query);
45323
+ }
45324
+ return next(query);
45325
+ }
45326
+ function computeScoreSingle(matches, {
45327
+ ignoreFieldNorm = Config.ignoreFieldNorm
45328
+ }) {
45329
+ let totalScore = 1;
45330
+ matches.forEach(({
45331
+ key,
45332
+ norm: norm2,
45333
+ score
45334
+ }) => {
45335
+ const weight = key ? key.weight : null;
45336
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
45337
+ });
45338
+ return totalScore;
45339
+ }
45340
+ function computeScore(results, {
45341
+ ignoreFieldNorm = Config.ignoreFieldNorm
45342
+ }) {
45343
+ results.forEach((result) => {
45344
+ result.score = computeScoreSingle(result.matches, {
45345
+ ignoreFieldNorm
45346
+ });
45347
+ });
45348
+ }
45349
+ var MaxHeap = class {
45350
+ constructor(limit) {
45351
+ this.limit = limit;
45352
+ this.heap = [];
45353
+ }
45354
+ get size() {
45355
+ return this.heap.length;
45356
+ }
45357
+ shouldInsert(score) {
45358
+ return this.size < this.limit || score < this.heap[0].score;
45359
+ }
45360
+ insert(item) {
45361
+ if (this.size < this.limit) {
45362
+ this.heap.push(item);
45363
+ this._bubbleUp(this.size - 1);
45364
+ } else if (item.score < this.heap[0].score) {
45365
+ this.heap[0] = item;
45366
+ this._sinkDown(0);
45367
+ }
45368
+ }
45369
+ extractSorted(sortFn) {
45370
+ return this.heap.sort(sortFn);
45371
+ }
45372
+ _bubbleUp(i) {
45373
+ const heap = this.heap;
45374
+ while (i > 0) {
45375
+ const parent = i - 1 >> 1;
45376
+ if (heap[i].score <= heap[parent].score) break;
45377
+ const tmp = heap[i];
45378
+ heap[i] = heap[parent];
45379
+ heap[parent] = tmp;
45380
+ i = parent;
45381
+ }
45382
+ }
45383
+ _sinkDown(i) {
45384
+ const heap = this.heap;
45385
+ const len = heap.length;
45386
+ let largest = i;
45387
+ do {
45388
+ i = largest;
45389
+ const left = 2 * i + 1;
45390
+ const right = 2 * i + 2;
45391
+ if (left < len && heap[left].score > heap[largest].score) {
45392
+ largest = left;
45393
+ }
45394
+ if (right < len && heap[right].score > heap[largest].score) {
45395
+ largest = right;
45396
+ }
45397
+ if (largest !== i) {
45398
+ const tmp = heap[i];
45399
+ heap[i] = heap[largest];
45400
+ heap[largest] = tmp;
45401
+ }
45402
+ } while (largest !== i);
45403
+ }
45404
+ };
45405
+ function formatMatches(result) {
45406
+ const matches = [];
45407
+ result.matches.forEach((match) => {
45408
+ if (!isDefined(match.indices) || !match.indices.length) {
45409
+ return;
45410
+ }
45411
+ const obj = {
45412
+ indices: match.indices,
45413
+ value: match.value
45414
+ };
45415
+ if (match.key) {
45416
+ obj.key = match.key.id;
45417
+ }
45418
+ if (match.idx > -1) {
45419
+ obj.refIndex = match.idx;
45420
+ }
45421
+ matches.push(obj);
45422
+ });
45423
+ return matches;
45424
+ }
45425
+ function format(results, docs, {
45426
+ includeMatches = Config.includeMatches,
45427
+ includeScore = Config.includeScore
45428
+ } = {}) {
45429
+ return results.map((result) => {
45430
+ const {
45431
+ idx
45432
+ } = result;
45433
+ const data = {
45434
+ item: docs[idx],
45435
+ refIndex: idx
45436
+ };
45437
+ if (includeMatches) data.matches = formatMatches(result);
45438
+ if (includeScore) data.score = result.score;
45439
+ return data;
45440
+ });
45441
+ }
45442
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
45443
+ var warned = /* @__PURE__ */ new WeakSet();
45444
+ function warnNonGlobal(regex) {
45445
+ if (!warned.has(regex)) {
45446
+ warned.add(regex);
45447
+ console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
45448
+ }
45449
+ }
45450
+ function resolveTokenize(tokenize2) {
45451
+ if (typeof tokenize2 === "function") {
45452
+ let validated = false;
45453
+ return (text) => {
45454
+ const result = tokenize2(text);
45455
+ if (!validated) {
45456
+ validated = true;
45457
+ if (!Array.isArray(result) || result.some((t12) => typeof t12 !== "string")) {
45458
+ throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
45459
+ }
45460
+ }
45461
+ return result;
45462
+ };
45463
+ }
45464
+ if (tokenize2 instanceof RegExp) {
45465
+ if (!tokenize2.global) warnNonGlobal(tokenize2);
45466
+ return (text) => text.match(tokenize2) || [];
45467
+ }
45468
+ return (text) => text.match(DEFAULT_TOKEN) || [];
45469
+ }
45470
+ function createAnalyzer({
45471
+ isCaseSensitive = false,
45472
+ ignoreDiacritics = false,
45473
+ tokenize: tokenize2
45474
+ } = {}) {
45475
+ const tokenizeFn = resolveTokenize(tokenize2);
45476
+ return {
45477
+ tokenize(text) {
45478
+ if (!isCaseSensitive) {
45479
+ text = text.toLowerCase();
45480
+ }
45481
+ if (ignoreDiacritics) {
45482
+ text = stripDiacritics(text);
45483
+ }
45484
+ return tokenizeFn(text);
45485
+ }
45486
+ };
45487
+ }
45488
+ var MAX_MASK_TERMS = 31;
45489
+ var TokenSearch = class {
45490
+ // `tokenMatch: 'all'` (AND) coverage. When true, searchIn reports which
45491
+ // query terms matched each text so the core loop can require record-level
45492
+ // coverage of every term. Bitmask is the ≤31-term fast path; Set is the
45493
+ // ≥32-term fallback (JS bitwise ops are 32-bit signed).
45494
+ static condition(_, options2) {
45495
+ return options2.useTokenSearch;
45496
+ }
45497
+ constructor(pattern, options2) {
45498
+ this.options = options2;
45499
+ this.analyzer = createAnalyzer({
45500
+ isCaseSensitive: options2.isCaseSensitive,
45501
+ ignoreDiacritics: options2.ignoreDiacritics,
45502
+ tokenize: options2.tokenize
45503
+ });
45504
+ const queryTerms = this.analyzer.tokenize(pattern);
45505
+ const invertedIndex = options2._invertedIndex;
45506
+ const {
45507
+ df,
45508
+ fieldCount
45509
+ } = invertedIndex;
45510
+ this.termSearchers = [];
45511
+ this.idfWeights = [];
45512
+ for (const term of queryTerms) {
45513
+ this.termSearchers.push(new BitapSearch(term, {
45514
+ location: options2.location,
45515
+ threshold: options2.threshold,
45516
+ distance: options2.distance,
45517
+ includeMatches: options2.includeMatches,
45518
+ findAllMatches: options2.findAllMatches,
45519
+ minMatchCharLength: options2.minMatchCharLength,
45520
+ isCaseSensitive: options2.isCaseSensitive,
45521
+ ignoreDiacritics: options2.ignoreDiacritics,
45522
+ ignoreLocation: true
45523
+ }));
45524
+ const docFreq = df.get(term) || 0;
45525
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
45526
+ this.idfWeights.push(idf);
45527
+ }
45528
+ this.combineAll = options2.tokenMatch === "all";
45529
+ this.numTerms = this.termSearchers.length;
45530
+ this.useMask = this.numTerms <= MAX_MASK_TERMS;
45531
+ }
45532
+ searchIn(text) {
45533
+ if (!this.termSearchers.length) {
45534
+ return {
45535
+ isMatch: false,
45536
+ score: 1
45537
+ };
45538
+ }
45539
+ const allIndices = [];
45540
+ let weightedScore = 0;
45541
+ let maxPossibleScore = 0;
45542
+ let matchedCount = 0;
45543
+ let matchedMask = 0;
45544
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
45545
+ for (let i = 0; i < this.termSearchers.length; i++) {
45546
+ const result = this.termSearchers[i].searchIn(text);
45547
+ const idf = this.idfWeights[i];
45548
+ maxPossibleScore += idf;
45549
+ if (result.isMatch) {
45550
+ matchedCount++;
45551
+ weightedScore += idf * (1 - result.score);
45552
+ if (result.indices) {
45553
+ allIndices.push(...result.indices);
45554
+ }
45555
+ if (this.combineAll) {
45556
+ if (this.useMask) {
45557
+ matchedMask |= 1 << i;
45558
+ } else {
45559
+ matchedTerms.add(i);
45560
+ }
45561
+ }
45562
+ }
45563
+ }
45564
+ if (matchedCount === 0) {
45565
+ return {
45566
+ isMatch: false,
45567
+ score: 1
45568
+ };
45569
+ }
45570
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
45571
+ const searchResult = {
45572
+ isMatch: true,
45573
+ score: Math.max(1e-3, normalized)
45574
+ };
45575
+ if (this.options.includeMatches && allIndices.length) {
45576
+ searchResult.indices = mergeIndices(allIndices);
45577
+ }
45578
+ if (this.combineAll) {
45579
+ if (this.useMask) {
45580
+ searchResult.matchedMask = matchedMask;
45581
+ } else {
45582
+ searchResult.matchedTerms = matchedTerms;
45583
+ }
45584
+ searchResult.termCount = this.numTerms;
45585
+ }
45586
+ return searchResult;
45587
+ }
45588
+ };
45589
+ function addField(index2, text, docIdx, analyzer) {
45590
+ const tokens = analyzer.tokenize(text);
45591
+ if (!tokens.length) return;
45592
+ index2.fieldCount++;
45593
+ index2.docFieldCount.set(docIdx, (index2.docFieldCount.get(docIdx) || 0) + 1);
45594
+ const distinctTerms = new Set(tokens);
45595
+ let perDocTerms = index2.docTermFieldHits.get(docIdx);
45596
+ if (!perDocTerms) {
45597
+ perDocTerms = /* @__PURE__ */ new Map();
45598
+ index2.docTermFieldHits.set(docIdx, perDocTerms);
45599
+ }
45600
+ for (const term of distinctTerms) {
45601
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
45602
+ index2.df.set(term, (index2.df.get(term) || 0) + 1);
45603
+ }
45604
+ }
45605
+ function ingestRecord(index2, record, keyCount, analyzer) {
45606
+ const {
45607
+ i: docIdx,
45608
+ v,
45609
+ $: fields
45610
+ } = record;
45611
+ if (v !== void 0) {
45612
+ addField(index2, v, docIdx, analyzer);
45613
+ return;
45614
+ }
45615
+ if (!fields) return;
45616
+ for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
45617
+ const value = fields[keyIdx];
45618
+ if (!value) continue;
45619
+ if (Array.isArray(value)) {
45620
+ for (const sub of value) addField(index2, sub.v, docIdx, analyzer);
45621
+ } else {
45622
+ addField(index2, value.v, docIdx, analyzer);
45623
+ }
45624
+ }
45625
+ }
45626
+ function buildInvertedIndex(records, keyCount, analyzer) {
45627
+ const index2 = {
45628
+ fieldCount: 0,
45629
+ df: /* @__PURE__ */ new Map(),
45630
+ docFieldCount: /* @__PURE__ */ new Map(),
45631
+ docTermFieldHits: /* @__PURE__ */ new Map()
45632
+ };
45633
+ for (const record of records) {
45634
+ ingestRecord(index2, record, keyCount, analyzer);
45635
+ }
45636
+ return index2;
45637
+ }
45638
+ function addToInvertedIndex(index2, record, keyCount, analyzer) {
45639
+ ingestRecord(index2, record, keyCount, analyzer);
45640
+ }
45641
+ function removeFromInvertedIndex(index2, docIdx) {
45642
+ const fieldCount = index2.docFieldCount.get(docIdx);
45643
+ if (fieldCount === void 0) return;
45644
+ index2.fieldCount -= fieldCount;
45645
+ index2.docFieldCount.delete(docIdx);
45646
+ const perDocTerms = index2.docTermFieldHits.get(docIdx);
45647
+ if (!perDocTerms) return;
45648
+ for (const [term, hits] of perDocTerms) {
45649
+ const next = (index2.df.get(term) || 0) - hits;
45650
+ if (next <= 0) {
45651
+ index2.df.delete(term);
45652
+ } else {
45653
+ index2.df.set(term, next);
45654
+ }
45655
+ }
45656
+ index2.docTermFieldHits.delete(docIdx);
45657
+ }
45658
+ function removeAndShiftInvertedIndex(index2, removedIndices) {
45659
+ if (removedIndices.length === 0) return;
45660
+ const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
45661
+ for (const idx of sorted) {
45662
+ removeFromInvertedIndex(index2, idx);
45663
+ }
45664
+ const shift4 = (oldIdx) => {
45665
+ let lo = 0;
45666
+ let hi = sorted.length;
45667
+ while (lo < hi) {
45668
+ const mid = lo + hi >>> 1;
45669
+ if (sorted[mid] < oldIdx) lo = mid + 1;
45670
+ else hi = mid;
45671
+ }
45672
+ return oldIdx - lo;
45673
+ };
45674
+ const firstRemoved = sorted[0];
45675
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map();
45676
+ for (const [oldKey, count3] of index2.docFieldCount) {
45677
+ shiftedDocFieldCount.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, count3);
45678
+ }
45679
+ index2.docFieldCount = shiftedDocFieldCount;
45680
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
45681
+ for (const [oldKey, terms] of index2.docTermFieldHits) {
45682
+ shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, terms);
45683
+ }
45684
+ index2.docTermFieldHits = shiftedDocTermFieldHits;
45685
+ }
45686
+ var Fuse = class {
45687
+ // Statics are assigned in entry.ts
45688
+ constructor(docs, options2, index2) {
45689
+ this.options = {
45690
+ ...Config,
45691
+ ...options2
45692
+ };
45693
+ if (this.options.useExtendedSearch && false) ;
45694
+ if (this.options.useTokenSearch && false) ;
45695
+ this._keyStore = new KeyStore(this.options.keys);
45696
+ this._docs = docs;
45697
+ this._myIndex = null;
45698
+ this._invertedIndex = null;
45699
+ this.setCollection(docs, index2);
45700
+ this._lastQuery = null;
45701
+ this._lastSearcher = null;
45702
+ }
45703
+ _getSearcher(query) {
45704
+ if (this._lastQuery === query) {
45705
+ return this._lastSearcher;
45706
+ }
45707
+ const opts = this._invertedIndex ? {
45708
+ ...this.options,
45709
+ _invertedIndex: this._invertedIndex
45710
+ } : this.options;
45711
+ const searcher = createSearcher(query, opts);
45712
+ this._lastQuery = query;
45713
+ this._lastSearcher = searcher;
45714
+ return searcher;
45715
+ }
45716
+ setCollection(docs, index2) {
45717
+ this._docs = docs;
45718
+ if (index2 && !(index2 instanceof FuseIndex)) {
45719
+ throw new Error(INCORRECT_INDEX_TYPE);
45720
+ }
45721
+ this._myIndex = index2 || createIndex(this.options.keys, this._docs, {
45722
+ getFn: this.options.getFn,
45723
+ fieldNormWeight: this.options.fieldNormWeight
45724
+ });
45725
+ if (this.options.useTokenSearch) {
45726
+ const analyzer = createAnalyzer({
45727
+ isCaseSensitive: this.options.isCaseSensitive,
45728
+ ignoreDiacritics: this.options.ignoreDiacritics,
45729
+ tokenize: this.options.tokenize
45730
+ });
45731
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
45732
+ }
45733
+ this._invalidateSearcherCache();
45734
+ }
45735
+ add(doc) {
45736
+ if (!isDefined(doc)) {
45737
+ return;
45738
+ }
45739
+ this._docs.push(doc);
45740
+ const record = this._myIndex.add(doc, this._docs.length - 1);
45741
+ if (this._invertedIndex && record) {
45742
+ const analyzer = createAnalyzer({
45743
+ isCaseSensitive: this.options.isCaseSensitive,
45744
+ ignoreDiacritics: this.options.ignoreDiacritics,
45745
+ tokenize: this.options.tokenize
45746
+ });
45747
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
45748
+ }
45749
+ this._invalidateSearcherCache();
45750
+ }
45751
+ remove(predicate = () => false) {
45752
+ const results = [];
45753
+ const indicesToRemove = [];
45754
+ for (let i = 0, len = this._docs.length; i < len; i += 1) {
45755
+ if (predicate(this._docs[i], i)) {
45756
+ results.push(this._docs[i]);
45757
+ indicesToRemove.push(i);
45758
+ }
45759
+ }
45760
+ if (indicesToRemove.length) {
45761
+ if (this._invertedIndex) {
45762
+ removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
45763
+ }
45764
+ const toRemove = new Set(indicesToRemove);
45765
+ this._docs = this._docs.filter((_, i) => !toRemove.has(i));
45766
+ this._myIndex.removeAll(indicesToRemove);
45767
+ this._invalidateSearcherCache();
45768
+ }
45769
+ return results;
45770
+ }
45771
+ removeAt(idx) {
45772
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) {
45773
+ throw new Error(INVALID_DOC_INDEX);
45774
+ }
45775
+ if (this._invertedIndex) {
45776
+ removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
45777
+ }
45778
+ const doc = this._docs.splice(idx, 1)[0];
45779
+ this._myIndex.removeAt(idx);
45780
+ this._invalidateSearcherCache();
45781
+ return doc;
45782
+ }
45783
+ _invalidateSearcherCache() {
45784
+ this._lastQuery = null;
45785
+ this._lastSearcher = null;
45786
+ }
45787
+ getIndex() {
45788
+ return this._myIndex;
45789
+ }
45790
+ search(query, options2) {
45791
+ const {
45792
+ limit = -1
45793
+ } = options2 || {};
45794
+ const {
45795
+ includeMatches,
45796
+ includeScore,
45797
+ shouldSort,
45798
+ sortFn,
45799
+ ignoreFieldNorm
45800
+ } = this.options;
45801
+ if (isString(query) && !query.trim()) {
45802
+ let docs = this._docs.map((item, idx) => ({
45803
+ item,
45804
+ refIndex: idx
45805
+ }));
45806
+ if (isNumber2(limit) && limit > -1) {
45807
+ docs = docs.slice(0, limit);
45808
+ }
45809
+ return docs;
45810
+ }
45811
+ const useHeap = isNumber2(limit) && limit > 0 && isString(query);
45812
+ let results;
45813
+ if (useHeap) {
45814
+ const heap = new MaxHeap(limit);
45815
+ if (isString(this._docs[0])) {
45816
+ this._searchStringList(query, {
45817
+ heap,
45818
+ ignoreFieldNorm
45819
+ });
45820
+ } else {
45821
+ this._searchObjectList(query, {
45822
+ heap,
45823
+ ignoreFieldNorm
45824
+ });
45825
+ }
45826
+ results = heap.extractSorted(sortFn);
45827
+ } else {
45828
+ results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
45829
+ computeScore(results, {
45830
+ ignoreFieldNorm
45831
+ });
45832
+ if (shouldSort) {
45833
+ results.sort(sortFn);
45834
+ }
45835
+ if (isNumber2(limit) && limit > -1) {
45836
+ results = results.slice(0, limit);
45837
+ }
45838
+ }
45839
+ return format(results, this._docs, {
45840
+ includeMatches,
45841
+ includeScore
45842
+ });
45843
+ }
45844
+ _searchStringList(query, {
45845
+ heap,
45846
+ ignoreFieldNorm
45847
+ } = {}) {
45848
+ const searcher = this._getSearcher(query);
45849
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
45850
+ const {
45851
+ records
45852
+ } = this._myIndex;
45853
+ const results = heap ? null : [];
45854
+ records.forEach(({
45855
+ v: text,
45856
+ i: idx,
45857
+ n: norm2
45858
+ }) => {
45859
+ if (!isDefined(text)) {
45860
+ return;
45861
+ }
45862
+ const searchResult = searcher.searchIn(text);
45863
+ if (searchResult.isMatch) {
45864
+ const match = {
45865
+ score: searchResult.score,
45866
+ value: text,
45867
+ norm: norm2,
45868
+ indices: searchResult.indices
45869
+ };
45870
+ if (requireAllTokens) {
45871
+ match.matchedMask = searchResult.matchedMask;
45872
+ match.matchedTerms = searchResult.matchedTerms;
45873
+ match.termCount = searchResult.termCount;
45874
+ }
45875
+ const matches = [match];
45876
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
45877
+ const result = {
45878
+ item: text,
45879
+ idx,
45880
+ matches
45881
+ };
45882
+ if (heap) {
45883
+ result.score = computeScoreSingle(result.matches, {
45884
+ ignoreFieldNorm
45885
+ });
45886
+ if (heap.shouldInsert(result.score)) {
45887
+ heap.insert(result);
45888
+ }
45889
+ } else {
45890
+ results.push(result);
45891
+ }
45892
+ }
45893
+ }
45894
+ });
45895
+ return results;
45896
+ }
45897
+ _searchLogical(query) {
45898
+ const expression = parse2(query, this.options);
45899
+ const evaluate2 = (node, item, idx) => {
45900
+ if (!("children" in node)) {
45901
+ const {
45902
+ keyId,
45903
+ searcher
45904
+ } = node;
45905
+ let matches;
45906
+ if (keyId === null) {
45907
+ matches = [];
45908
+ this._myIndex.keys.forEach((key, keyIndex) => {
45909
+ matches.push(...this._findMatches({
45910
+ key,
45911
+ value: item[keyIndex],
45912
+ searcher
45913
+ }));
45914
+ });
45915
+ } else {
45916
+ matches = this._findMatches({
45917
+ key: this._keyStore.get(keyId),
45918
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
45919
+ searcher
45920
+ });
45921
+ }
45922
+ if (matches && matches.length) {
45923
+ return [{
45924
+ idx,
45925
+ item,
45926
+ matches
45927
+ }];
45928
+ }
45929
+ return [];
45930
+ }
45931
+ const {
45932
+ children,
45933
+ operator
45934
+ } = node;
45935
+ const res = [];
45936
+ for (let i = 0, len = children.length; i < len; i += 1) {
45937
+ const child = children[i];
45938
+ const result = evaluate2(child, item, idx);
45939
+ if (result.length) {
45940
+ res.push(...result);
45941
+ } else if (operator === LogicalOperator.AND) {
45942
+ return [];
45943
+ }
45944
+ }
45945
+ return res;
45946
+ };
45947
+ const records = this._myIndex.records;
45948
+ const resultMap = /* @__PURE__ */ new Map();
45949
+ const results = [];
45950
+ records.forEach(({
45951
+ $: item,
45952
+ i: idx
45953
+ }) => {
45954
+ if (isDefined(item)) {
45955
+ const expResults = evaluate2(expression, item, idx);
45956
+ if (expResults.length) {
45957
+ if (!resultMap.has(idx)) {
45958
+ resultMap.set(idx, {
45959
+ idx,
45960
+ item,
45961
+ matches: []
45962
+ });
45963
+ results.push(resultMap.get(idx));
45964
+ }
45965
+ expResults.forEach(({
45966
+ matches
45967
+ }) => {
45968
+ resultMap.get(idx).matches.push(...matches);
45969
+ });
45970
+ }
45971
+ }
45972
+ });
45973
+ return results;
45974
+ }
45975
+ // When a search involves inverse patterns (e.g. !Syrup), the aggregation
45976
+ // across keys switches from "ANY key matches" to "ALL keys must match."
45977
+ // This is signaled by hasInverse on the SearchResult from ExtendedSearch.
45978
+ //
45979
+ // For mixed patterns like "^hello !Syrup", a key failure is ambiguous —
45980
+ // it could be the positive or inverse term that failed. In that case we
45981
+ // conservatively exclude the item, which is strictly better than the old
45982
+ // behavior of including it. See: https://github.com/krisk/Fuse/issues/712
45983
+ _searchObjectList(query, {
45984
+ heap,
45985
+ ignoreFieldNorm
45986
+ } = {}) {
45987
+ const searcher = this._getSearcher(query);
45988
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
45989
+ const {
45990
+ keys,
45991
+ records
45992
+ } = this._myIndex;
45993
+ const results = heap ? null : [];
45994
+ records.forEach(({
45995
+ $: item,
45996
+ i: idx
45997
+ }) => {
45998
+ if (!isDefined(item)) {
45999
+ return;
46000
+ }
46001
+ const matches = [];
46002
+ let anyKeyFailed = false;
46003
+ let hasInverse = false;
46004
+ keys.forEach((key, keyIndex) => {
46005
+ const keyMatches = this._findMatches({
46006
+ key,
46007
+ value: item[keyIndex],
46008
+ searcher
46009
+ });
46010
+ if (keyMatches.length) {
46011
+ matches.push(...keyMatches);
46012
+ if (keyMatches[0].hasInverse) {
46013
+ hasInverse = true;
46014
+ }
46015
+ } else {
46016
+ anyKeyFailed = true;
46017
+ }
46018
+ });
46019
+ if (hasInverse && anyKeyFailed) {
46020
+ return;
46021
+ }
46022
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
46023
+ const result = {
46024
+ idx,
46025
+ item,
46026
+ matches
46027
+ };
46028
+ if (heap) {
46029
+ result.score = computeScoreSingle(result.matches, {
46030
+ ignoreFieldNorm
46031
+ });
46032
+ if (heap.shouldInsert(result.score)) {
46033
+ heap.insert(result);
46034
+ }
46035
+ } else {
46036
+ results.push(result);
46037
+ }
46038
+ }
46039
+ });
46040
+ return results;
46041
+ }
46042
+ _findMatches({
46043
+ key,
46044
+ value,
46045
+ searcher
46046
+ }) {
46047
+ if (!isDefined(value)) {
46048
+ return [];
46049
+ }
46050
+ const matches = [];
46051
+ if (isArray(value)) {
46052
+ value.forEach(({
46053
+ v: text,
46054
+ i: idx,
46055
+ n: norm2
46056
+ }) => {
46057
+ if (!isDefined(text)) {
46058
+ return;
46059
+ }
46060
+ const searchResult = searcher.searchIn(text);
46061
+ if (searchResult.isMatch) {
46062
+ const match = {
46063
+ score: searchResult.score,
46064
+ key,
46065
+ value: text,
46066
+ idx,
46067
+ norm: norm2,
46068
+ indices: searchResult.indices,
46069
+ hasInverse: searchResult.hasInverse
46070
+ };
46071
+ if (searchResult.termCount !== void 0) {
46072
+ match.matchedMask = searchResult.matchedMask;
46073
+ match.matchedTerms = searchResult.matchedTerms;
46074
+ match.termCount = searchResult.termCount;
46075
+ }
46076
+ matches.push(match);
46077
+ }
46078
+ });
46079
+ } else {
46080
+ const {
46081
+ v: text,
46082
+ n: norm2
46083
+ } = value;
46084
+ const searchResult = searcher.searchIn(text);
46085
+ if (searchResult.isMatch) {
46086
+ const match = {
46087
+ score: searchResult.score,
46088
+ key,
46089
+ value: text,
46090
+ norm: norm2,
46091
+ indices: searchResult.indices,
46092
+ hasInverse: searchResult.hasInverse
46093
+ };
46094
+ if (searchResult.termCount !== void 0) {
46095
+ match.matchedMask = searchResult.matchedMask;
46096
+ match.matchedTerms = searchResult.matchedTerms;
46097
+ match.termCount = searchResult.termCount;
46098
+ }
46099
+ matches.push(match);
46100
+ }
46101
+ }
46102
+ return matches;
46103
+ }
46104
+ // Record-level AND gate for token search (`tokenMatch: 'all'`). Returns true
46105
+ // unless the matched terms across ALL of a record's field/array-element
46106
+ // matches fail to cover every query term. `termCount` is only set by
46107
+ // TokenSearch in 'all' mode, so non-token / 'any' searches always pass.
46108
+ _coversAllTokens(matches) {
46109
+ const termCount = matches.length ? matches[0].termCount : void 0;
46110
+ if (termCount === void 0) {
46111
+ return true;
46112
+ }
46113
+ if (termCount <= MAX_MASK_TERMS) {
46114
+ let coverage2 = 0;
46115
+ for (let i = 0; i < matches.length; i++) {
46116
+ coverage2 |= matches[i].matchedMask || 0;
46117
+ }
46118
+ return coverage2 === 2 ** termCount - 1;
46119
+ }
46120
+ const coverage = /* @__PURE__ */ new Set();
46121
+ for (let i = 0; i < matches.length; i++) {
46122
+ const terms = matches[i].matchedTerms;
46123
+ if (terms) {
46124
+ for (const t12 of terms) {
46125
+ coverage.add(t12);
46126
+ }
46127
+ }
46128
+ }
46129
+ return coverage.size === termCount;
46130
+ }
46131
+ };
46132
+ Fuse.version = "7.4.0";
46133
+ Fuse.createIndex = createIndex;
46134
+ Fuse.parseIndex = parseIndex;
46135
+ Fuse.config = Config;
46136
+ Fuse.match = function(pattern, text, options2) {
46137
+ if (options2 && options2.useTokenSearch) {
46138
+ throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
46139
+ }
46140
+ const searcher = createSearcher(pattern, {
46141
+ ...Config,
46142
+ ...options2
46143
+ });
46144
+ return searcher.searchIn(text);
46145
+ };
46146
+ {
46147
+ Fuse.parseQuery = parse2;
46148
+ }
46149
+ {
46150
+ register(ExtendedSearch);
46151
+ }
46152
+ {
46153
+ register(TokenSearch);
46154
+ }
46155
+ Fuse.use = function(...plugins) {
46156
+ plugins.forEach((plugin) => register(plugin));
46157
+ };
44162
46158
  var sides = ["top", "right", "bottom", "left"];
44163
46159
  var min = Math.min;
44164
46160
  var max = Math.max;
@@ -47057,10 +49053,10 @@ var SelectTrigger = React35.forwardRef(
47057
49053
  const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
47058
49054
  const getItems = useCollection(__scopeSelect);
47059
49055
  const pointerTypeRef = React35.useRef("touch");
47060
- const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
49056
+ const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search2) => {
47061
49057
  const enabledItems = getItems().filter((item) => !item.disabled);
47062
49058
  const currentItem = enabledItems.find((item) => item.value === context.value);
47063
- const nextItem = findNextItem(enabledItems, search, currentItem);
49059
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47064
49060
  if (nextItem !== void 0) {
47065
49061
  context.onValueChange(nextItem.value);
47066
49062
  }
@@ -47287,10 +49283,10 @@ var SelectContentImpl = React35.forwardRef(
47287
49283
  window.removeEventListener("resize", close);
47288
49284
  };
47289
49285
  }, [onOpenChange]);
47290
- const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
49286
+ const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search2) => {
47291
49287
  const enabledItems = getItems().filter((item) => !item.disabled);
47292
49288
  const currentItem = enabledItems.find((item) => item.ref.current === document.activeElement);
47293
- const nextItem = findNextItem(enabledItems, search, currentItem);
49289
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47294
49290
  if (nextItem) {
47295
49291
  setTimeout(() => nextItem.ref.current.focus());
47296
49292
  }
@@ -48019,13 +50015,13 @@ function useTypeaheadSearch(onSearchChange) {
48019
50015
  const timerRef = React35.useRef(0);
48020
50016
  const handleTypeaheadSearch = React35.useCallback(
48021
50017
  (key) => {
48022
- const search = searchRef.current + key;
48023
- handleSearchChange(search);
50018
+ const search2 = searchRef.current + key;
50019
+ handleSearchChange(search2);
48024
50020
  (function updateSearch(value) {
48025
50021
  searchRef.current = value;
48026
50022
  window.clearTimeout(timerRef.current);
48027
50023
  if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
48028
- })(search);
50024
+ })(search2);
48029
50025
  },
48030
50026
  [handleSearchChange]
48031
50027
  );
@@ -48038,9 +50034,9 @@ function useTypeaheadSearch(onSearchChange) {
48038
50034
  }, []);
48039
50035
  return [searchRef, handleTypeaheadSearch, resetTypeahead];
48040
50036
  }
48041
- function findNextItem(items, search, currentItem) {
48042
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
48043
- const normalizedSearch = isRepeated ? search[0] : search;
50037
+ function findNextItem(items, search2, currentItem) {
50038
+ const isRepeated = search2.length > 1 && Array.from(search2).every((char) => char === search2[0]);
50039
+ const normalizedSearch = isRepeated ? search2[0] : search2;
48044
50040
  const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
48045
50041
  let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
48046
50042
  const excludeCurrentItem = normalizedSearch.length === 1;
@@ -58067,13 +60063,25 @@ function TokenSelectorSheet({
58067
60063
  });
58068
60064
  setRecentTokens(updated);
58069
60065
  };
60066
+ const fuse = (0, import_react21.useMemo)(
60067
+ () => new Fuse(allOptions, {
60068
+ keys: [
60069
+ { name: "token.symbol", weight: 2 },
60070
+ { name: "token.name", weight: 1 },
60071
+ { name: "chain.chain_name", weight: 0.5 }
60072
+ ],
60073
+ threshold: 0.2,
60074
+ ignoreLocation: true,
60075
+ minMatchCharLength: 2
60076
+ }),
60077
+ [allOptions]
60078
+ );
58070
60079
  const filteredOptions = (0, import_react21.useMemo)(() => {
58071
60080
  if (!searchQuery.trim()) return allOptions;
58072
- const query = searchQuery.toLowerCase();
58073
- return allOptions.filter(
58074
- ({ token, chain }) => token.symbol.toLowerCase().includes(query) || token.name.toLowerCase().includes(query) || chain.chain_name.toLowerCase().includes(query)
58075
- );
58076
- }, [allOptions, searchQuery]);
60081
+ const query = searchQuery.trim();
60082
+ const results = fuse.search(query);
60083
+ return results.map((r2) => r2.item);
60084
+ }, [fuse, allOptions, searchQuery]);
58077
60085
  const isCommonToken = (symbol, chainType, chainId) => {
58078
60086
  return COMMON_TOKENS.some(
58079
60087
  (ct) => ct.symbol === symbol && ct.chainType === chainType && ct.chainId === chainId
@@ -61716,6 +63724,7 @@ function DepositModal({
61716
63724
  enableConnectWallet = false,
61717
63725
  browserWalletAmountQuickSelect = "percentage",
61718
63726
  enablePayWithExchange,
63727
+ enableFiatOnramp,
61719
63728
  enableConnectExchange = false,
61720
63729
  enableCashApp = false,
61721
63730
  hideDepositFlowInfo = false,
@@ -61737,8 +63746,9 @@ function DepositModal({
61737
63746
  const s = initialScreen ?? "main";
61738
63747
  if (s === "tracker" && hideDepositTracker) return "main";
61739
63748
  if (s === "cashapp" && !enableCashApp) return "main";
63749
+ if (s === "card" && enableFiatOnramp === false) return "main";
61740
63750
  return s;
61741
- }, [initialScreen, hideDepositTracker, enableCashApp]);
63751
+ }, [initialScreen, hideDepositTracker, enableCashApp, enableFiatOnramp]);
61742
63752
  const [containerEl, setContainerEl] = (0, import_react3.useState)(null);
61743
63753
  const containerCallbackRef = (0, import_react3.useCallback)((el) => {
61744
63754
  setContainerEl(el);
@@ -61854,6 +63864,13 @@ function DepositModal({
61854
63864
  enabled: open
61855
63865
  });
61856
63866
  const showPayWithExchange = enablePayWithExchange ?? projectConfig?.pay_with_exchange?.enabled ?? true;
63867
+ const showFiatOnramp = enableFiatOnramp ?? projectConfig?.fiat_onramp?.enabled ?? true;
63868
+ (0, import_react3.useEffect)(() => {
63869
+ if (view === "card" && !showFiatOnramp) {
63870
+ setView("main");
63871
+ setCardView("amount");
63872
+ }
63873
+ }, [view, showFiatOnramp]);
61857
63874
  const { exchanges, isLoading: exchangesLoading } = useExchanges({
61858
63875
  publishableKey,
61859
63876
  enabled: open && showPayWithExchange
@@ -62163,7 +64180,7 @@ function DepositModal({
62163
64180
  featuredWallets: projectConfig?.connect_wallet?.wallets
62164
64181
  }
62165
64182
  ),
62166
- /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
64183
+ showFiatOnramp && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
62167
64184
  DepositWithCardButton,
62168
64185
  {
62169
64186
  onClick: () => setView("card"),
@@ -65162,6 +67179,7 @@ function UnifoldProvider2({
65162
67179
  transferInputVariant: config?.transferInputVariant,
65163
67180
  enableConnectWallet: config?.enableConnectWallet,
65164
67181
  enablePayWithExchange: config?.enablePayWithExchange,
67182
+ enableFiatOnramp: config?.enableFiatOnramp,
65165
67183
  enableConnectExchange: config?.enableConnectExchange,
65166
67184
  enableCashApp: config?.enableCashApp,
65167
67185
  onDepositSuccess: handleDepositSuccess,
@@ -65281,7 +67299,11 @@ function createUnifold(publishableKey, config) {
65281
67299
  return resolvedHandle.beginWithdraw(withdrawConfig);
65282
67300
  },
65283
67301
  closeWithdraw: () => resolvedHandle?.closeWithdraw(),
65284
- destroy: cleanup
67302
+ destroy: () => {
67303
+ resolvedHandle?.closeDeposit();
67304
+ resolvedHandle?.closeWithdraw();
67305
+ cleanup();
67306
+ }
65285
67307
  };
65286
67308
  const refCallback = (handle) => {
65287
67309
  if (handle) {