@unifold/ui-web 0.1.58 → 0.1.60

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 +2288 -138
  2. package/dist/index.mjs +2288 -138
  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,2052 @@ 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 requestProviders(listener) {
44163
+ if (typeof window === "undefined")
44164
+ return;
44165
+ const handler = (event) => listener(event.detail);
44166
+ window.addEventListener("eip6963:announceProvider", handler);
44167
+ window.dispatchEvent(new CustomEvent("eip6963:requestProvider"));
44168
+ return () => window.removeEventListener("eip6963:announceProvider", handler);
44169
+ }
44170
+ function createStore() {
44171
+ const listeners = /* @__PURE__ */ new Set();
44172
+ let providerDetails = [];
44173
+ const request = () => requestProviders((providerDetail) => {
44174
+ if (providerDetails.some(({ info }) => info.uuid === providerDetail.info.uuid))
44175
+ return;
44176
+ providerDetails = [...providerDetails, providerDetail];
44177
+ listeners.forEach((listener) => listener(providerDetails, { added: [providerDetail] }));
44178
+ });
44179
+ let unwatch = request();
44180
+ return {
44181
+ _listeners() {
44182
+ return listeners;
44183
+ },
44184
+ clear() {
44185
+ listeners.forEach((listener) => listener([], { removed: [...providerDetails] }));
44186
+ providerDetails = [];
44187
+ },
44188
+ destroy() {
44189
+ this.clear();
44190
+ listeners.clear();
44191
+ unwatch?.();
44192
+ },
44193
+ findProvider({ rdns }) {
44194
+ return providerDetails.find((providerDetail) => providerDetail.info.rdns === rdns);
44195
+ },
44196
+ getProviders() {
44197
+ return providerDetails;
44198
+ },
44199
+ reset() {
44200
+ this.clear();
44201
+ unwatch?.();
44202
+ unwatch = request();
44203
+ },
44204
+ subscribe(listener, { emitImmediately } = {}) {
44205
+ listeners.add(listener);
44206
+ if (emitImmediately)
44207
+ listener(providerDetails, { added: providerDetails });
44208
+ return () => listeners.delete(listener);
44209
+ }
44210
+ };
44211
+ }
44212
+ function isArray(value) {
44213
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
44214
+ }
44215
+ function baseToString(value) {
44216
+ if (typeof value == "string") {
44217
+ return value;
44218
+ }
44219
+ if (typeof value === "bigint") {
44220
+ return value.toString();
44221
+ }
44222
+ const result = value + "";
44223
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
44224
+ }
44225
+ function toString(value) {
44226
+ return value == null ? "" : baseToString(value);
44227
+ }
44228
+ function isString(value) {
44229
+ return typeof value === "string";
44230
+ }
44231
+ function isNumber2(value) {
44232
+ return typeof value === "number";
44233
+ }
44234
+ function isBoolean(value) {
44235
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
44236
+ }
44237
+ function isObject(value) {
44238
+ return typeof value === "object";
44239
+ }
44240
+ function isObjectLike(value) {
44241
+ return isObject(value) && value !== null;
44242
+ }
44243
+ function isDefined(value) {
44244
+ return value !== void 0 && value !== null;
44245
+ }
44246
+ function isBlank(value) {
44247
+ return !value.trim().length;
44248
+ }
44249
+ function getTag(value) {
44250
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
44251
+ }
44252
+ var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
44253
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
44254
+ var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
44255
+ var PATTERN_LENGTH_TOO_LARGE = (max2) => `Pattern length exceeds max of ${max2}.`;
44256
+ var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
44257
+ var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
44258
+ 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.`;
44259
+ var hasOwn2 = Object.prototype.hasOwnProperty;
44260
+ var KeyStore = class {
44261
+ constructor(keys) {
44262
+ this._keys = [];
44263
+ this._keyMap = {};
44264
+ let totalWeight = 0;
44265
+ keys.forEach((key) => {
44266
+ const obj = createKey(key);
44267
+ this._keys.push(obj);
44268
+ this._keyMap[obj.id] = obj;
44269
+ totalWeight += obj.weight;
44270
+ });
44271
+ this._keys.forEach((key) => {
44272
+ key.weight /= totalWeight;
44273
+ });
44274
+ }
44275
+ get(keyId) {
44276
+ return this._keyMap[keyId];
44277
+ }
44278
+ keys() {
44279
+ return this._keys;
44280
+ }
44281
+ toJSON() {
44282
+ return JSON.stringify(this._keys);
44283
+ }
44284
+ };
44285
+ function createKey(key) {
44286
+ let path = null;
44287
+ let id = null;
44288
+ let src = null;
44289
+ let weight = 1;
44290
+ let getFn = null;
44291
+ if (isString(key) || isArray(key)) {
44292
+ src = key;
44293
+ path = createKeyPath(key);
44294
+ id = createKeyId(key);
44295
+ } else {
44296
+ if (!hasOwn2.call(key, "name")) {
44297
+ throw new Error(MISSING_KEY_PROPERTY("name"));
44298
+ }
44299
+ const name = key.name;
44300
+ src = name;
44301
+ if (hasOwn2.call(key, "weight") && key.weight !== void 0) {
44302
+ weight = key.weight;
44303
+ if (weight <= 0) {
44304
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
44305
+ }
44306
+ }
44307
+ path = createKeyPath(name);
44308
+ id = createKeyId(name);
44309
+ getFn = key.getFn ?? null;
44310
+ }
44311
+ return {
44312
+ path,
44313
+ id,
44314
+ weight,
44315
+ src,
44316
+ getFn
44317
+ };
44318
+ }
44319
+ function createKeyPath(key) {
44320
+ return isArray(key) ? key : key.split(".");
44321
+ }
44322
+ function createKeyId(key) {
44323
+ return isArray(key) ? key.join(".") : key;
44324
+ }
44325
+ function get(obj, path) {
44326
+ const list = [];
44327
+ let arr = false;
44328
+ const deepGet = (obj2, path2, index2, arrayIndex) => {
44329
+ if (!isDefined(obj2)) {
44330
+ return;
44331
+ }
44332
+ if (!path2[index2]) {
44333
+ list.push(arrayIndex !== void 0 ? {
44334
+ v: obj2,
44335
+ i: arrayIndex
44336
+ } : obj2);
44337
+ } else {
44338
+ const key = path2[index2];
44339
+ const value = obj2[key];
44340
+ if (!isDefined(value)) {
44341
+ return;
44342
+ }
44343
+ if (index2 === path2.length - 1 && (isString(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
44344
+ list.push(arrayIndex !== void 0 ? {
44345
+ v: toString(value),
44346
+ i: arrayIndex
44347
+ } : toString(value));
44348
+ } else if (isArray(value)) {
44349
+ arr = true;
44350
+ for (let i = 0, len = value.length; i < len; i += 1) {
44351
+ deepGet(value[i], path2, index2 + 1, i);
44352
+ }
44353
+ } else if (path2.length) {
44354
+ deepGet(value, path2, index2 + 1, arrayIndex);
44355
+ }
44356
+ }
44357
+ };
44358
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
44359
+ return arr ? list : list[0];
44360
+ }
44361
+ var MatchOptions = {
44362
+ includeMatches: false,
44363
+ findAllMatches: false,
44364
+ minMatchCharLength: 1
44365
+ };
44366
+ var BasicOptions = {
44367
+ isCaseSensitive: false,
44368
+ ignoreDiacritics: false,
44369
+ includeScore: false,
44370
+ keys: [],
44371
+ shouldSort: true,
44372
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
44373
+ };
44374
+ var FuzzyOptions = {
44375
+ location: 0,
44376
+ threshold: 0.6,
44377
+ distance: 100
44378
+ };
44379
+ var AdvancedOptions = {
44380
+ useExtendedSearch: false,
44381
+ useTokenSearch: false,
44382
+ tokenize: void 0,
44383
+ tokenMatch: "any",
44384
+ getFn: get,
44385
+ ignoreLocation: false,
44386
+ ignoreFieldNorm: false,
44387
+ fieldNormWeight: 1
44388
+ };
44389
+ var Config = Object.freeze({
44390
+ ...BasicOptions,
44391
+ ...MatchOptions,
44392
+ ...FuzzyOptions,
44393
+ ...AdvancedOptions
44394
+ });
44395
+ function norm(weight = 1, mantissa = 3) {
44396
+ const cache = /* @__PURE__ */ new Map();
44397
+ const m = Math.pow(10, mantissa);
44398
+ return {
44399
+ get(value) {
44400
+ let numTokens = 1;
44401
+ let inSpace = false;
44402
+ for (let i = 0; i < value.length; i++) {
44403
+ if (value.charCodeAt(i) === 32) {
44404
+ if (!inSpace) {
44405
+ numTokens++;
44406
+ inSpace = true;
44407
+ }
44408
+ } else {
44409
+ inSpace = false;
44410
+ }
44411
+ }
44412
+ if (cache.has(numTokens)) {
44413
+ return cache.get(numTokens);
44414
+ }
44415
+ const n = Math.round(m / Math.pow(numTokens, 0.5 * weight)) / m;
44416
+ cache.set(numTokens, n);
44417
+ return n;
44418
+ },
44419
+ clear() {
44420
+ cache.clear();
44421
+ }
44422
+ };
44423
+ }
44424
+ var FuseIndex = class {
44425
+ constructor({
44426
+ getFn = Config.getFn,
44427
+ fieldNormWeight = Config.fieldNormWeight
44428
+ } = {}) {
44429
+ this.norm = norm(fieldNormWeight, 3);
44430
+ this.getFn = getFn;
44431
+ this.isCreated = false;
44432
+ this.docs = [];
44433
+ this.keys = [];
44434
+ this._keysMap = {};
44435
+ this.setIndexRecords();
44436
+ }
44437
+ setSources(docs = []) {
44438
+ this.docs = docs;
44439
+ }
44440
+ setIndexRecords(records = []) {
44441
+ this.records = records;
44442
+ }
44443
+ setKeys(keys = []) {
44444
+ this.keys = keys;
44445
+ this._keysMap = {};
44446
+ keys.forEach((key, idx) => {
44447
+ this._keysMap[key.id] = idx;
44448
+ });
44449
+ }
44450
+ create() {
44451
+ if (this.isCreated || !this.docs.length) {
44452
+ return;
44453
+ }
44454
+ this.isCreated = true;
44455
+ const len = this.docs.length;
44456
+ this.records = new Array(len);
44457
+ let recordCount = 0;
44458
+ if (isString(this.docs[0])) {
44459
+ for (let i = 0; i < len; i++) {
44460
+ const record = this._createStringRecord(this.docs[i], i);
44461
+ if (record) {
44462
+ this.records[recordCount++] = record;
44463
+ }
44464
+ }
44465
+ } else {
44466
+ for (let i = 0; i < len; i++) {
44467
+ this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
44468
+ }
44469
+ }
44470
+ this.records.length = recordCount;
44471
+ this.norm.clear();
44472
+ }
44473
+ // Appends a record for `doc` at `docIndex` (the doc's position in the source
44474
+ // array). Returns the appended record, or null when `doc` is a blank string
44475
+ // (those are skipped at record creation; see `_createStringRecord`). Callers
44476
+ // use the return value to gate downstream bookkeeping like the inverted
44477
+ // index, which must not be touched when no record was produced.
44478
+ add(doc, docIndex) {
44479
+ if (!Number.isInteger(docIndex) || docIndex < 0) {
44480
+ throw new Error(INVALID_DOC_INDEX);
44481
+ }
44482
+ if (isString(doc)) {
44483
+ const record2 = this._createStringRecord(doc, docIndex);
44484
+ if (record2) {
44485
+ this.records.push(record2);
44486
+ }
44487
+ return record2;
44488
+ }
44489
+ const record = this._createObjectRecord(doc, docIndex);
44490
+ this.records.push(record);
44491
+ return record;
44492
+ }
44493
+ // Removes the record for the doc at the specified source-array (docs) index.
44494
+ // Blank string docs have no record; callers may pass such an index and the
44495
+ // splice is a no-op, but subsequent records still need their .i decremented
44496
+ // to track the docs array that the caller is splicing in parallel.
44497
+ removeAt(idx) {
44498
+ if (!Number.isInteger(idx) || idx < 0) {
44499
+ throw new Error(INVALID_DOC_INDEX);
44500
+ }
44501
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44502
+ if (this.records[i].i === idx) {
44503
+ this.records.splice(i, 1);
44504
+ break;
44505
+ }
44506
+ }
44507
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44508
+ if (this.records[i].i > idx) {
44509
+ this.records[i].i -= 1;
44510
+ }
44511
+ }
44512
+ }
44513
+ // Removes records for the docs at the specified source-array indices, then
44514
+ // shifts every surviving record's .i down by the count of removed indices
44515
+ // strictly less than it (mirrors removeAndShiftInvertedIndex's shift math).
44516
+ // Invalid entries (non-integer, negative) in `indices` are dropped silently
44517
+ // — removeAll's natural use case is "caller passed a list of matched doc
44518
+ // indices"; asymmetric throw-vs-no-op would be more surprising than a clean
44519
+ // filter.
44520
+ removeAll(indices) {
44521
+ const toRemove = /* @__PURE__ */ new Set();
44522
+ for (const v of indices) {
44523
+ if (Number.isInteger(v) && v >= 0) {
44524
+ toRemove.add(v);
44525
+ }
44526
+ }
44527
+ if (toRemove.size === 0) {
44528
+ return;
44529
+ }
44530
+ this.records = this.records.filter((r2) => !toRemove.has(r2.i));
44531
+ const sorted = Array.from(toRemove).sort((a, b) => a - b);
44532
+ for (const record of this.records) {
44533
+ let lo = 0;
44534
+ let hi = sorted.length;
44535
+ while (lo < hi) {
44536
+ const mid = lo + hi >>> 1;
44537
+ if (sorted[mid] < record.i) lo = mid + 1;
44538
+ else hi = mid;
44539
+ }
44540
+ record.i -= lo;
44541
+ }
44542
+ }
44543
+ getValueForItemAtKeyId(item, keyId) {
44544
+ return item[this._keysMap[keyId]];
44545
+ }
44546
+ size() {
44547
+ return this.records.length;
44548
+ }
44549
+ _createStringRecord(doc, docIndex) {
44550
+ if (!isDefined(doc) || isBlank(doc)) {
44551
+ return null;
44552
+ }
44553
+ return {
44554
+ v: doc,
44555
+ i: docIndex,
44556
+ n: this.norm.get(doc)
44557
+ };
44558
+ }
44559
+ _createObjectRecord(doc, docIndex) {
44560
+ const record = {
44561
+ i: docIndex,
44562
+ $: {}
44563
+ };
44564
+ for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
44565
+ const key = this.keys[keyIndex];
44566
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
44567
+ if (!isDefined(value)) {
44568
+ continue;
44569
+ }
44570
+ if (isArray(value)) {
44571
+ const subRecords = [];
44572
+ for (let i = 0, len = value.length; i < len; i += 1) {
44573
+ const item = value[i];
44574
+ if (!isDefined(item)) {
44575
+ continue;
44576
+ }
44577
+ if (isString(item)) {
44578
+ if (!isBlank(item)) {
44579
+ const subRecord = {
44580
+ v: item,
44581
+ i,
44582
+ n: this.norm.get(item)
44583
+ };
44584
+ subRecords.push(subRecord);
44585
+ }
44586
+ } else if (isDefined(item.v)) {
44587
+ const text = isString(item.v) ? item.v : toString(item.v);
44588
+ if (!isBlank(text)) {
44589
+ const subRecord = {
44590
+ v: text,
44591
+ i: item.i,
44592
+ n: this.norm.get(text)
44593
+ };
44594
+ subRecords.push(subRecord);
44595
+ }
44596
+ }
44597
+ }
44598
+ record.$[keyIndex] = subRecords;
44599
+ } else if (isString(value) && !isBlank(value)) {
44600
+ const subRecord = {
44601
+ v: value,
44602
+ n: this.norm.get(value)
44603
+ };
44604
+ record.$[keyIndex] = subRecord;
44605
+ }
44606
+ }
44607
+ return record;
44608
+ }
44609
+ toJSON() {
44610
+ return {
44611
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
44612
+ keys: this.keys.map(({
44613
+ getFn,
44614
+ ...key
44615
+ }) => key),
44616
+ records: this.records
44617
+ };
44618
+ }
44619
+ };
44620
+ function createIndex(keys, docs, {
44621
+ getFn = Config.getFn,
44622
+ fieldNormWeight = Config.fieldNormWeight
44623
+ } = {}) {
44624
+ const myIndex = new FuseIndex({
44625
+ getFn,
44626
+ fieldNormWeight
44627
+ });
44628
+ myIndex.setKeys(keys.map(createKey));
44629
+ myIndex.setSources(docs);
44630
+ myIndex.create();
44631
+ return myIndex;
44632
+ }
44633
+ function parseIndex(data, {
44634
+ getFn = Config.getFn,
44635
+ fieldNormWeight = Config.fieldNormWeight
44636
+ } = {}) {
44637
+ const {
44638
+ keys,
44639
+ records
44640
+ } = data;
44641
+ const myIndex = new FuseIndex({
44642
+ getFn,
44643
+ fieldNormWeight
44644
+ });
44645
+ myIndex.setKeys(keys);
44646
+ myIndex.setIndexRecords(records);
44647
+ return myIndex;
44648
+ }
44649
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
44650
+ const indices = [];
44651
+ let start = -1;
44652
+ let end = -1;
44653
+ let i = 0;
44654
+ for (let len = matchmask.length; i < len; i += 1) {
44655
+ const match = matchmask[i];
44656
+ if (match && start === -1) {
44657
+ start = i;
44658
+ } else if (!match && start !== -1) {
44659
+ end = i - 1;
44660
+ if (end - start + 1 >= minMatchCharLength) {
44661
+ indices.push([start, end]);
44662
+ }
44663
+ start = -1;
44664
+ }
44665
+ }
44666
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
44667
+ indices.push([start, i - 1]);
44668
+ }
44669
+ return indices;
44670
+ }
44671
+ var MAX_BITS = 32;
44672
+ function search(text, pattern, patternAlphabet, {
44673
+ location = Config.location,
44674
+ distance = Config.distance,
44675
+ threshold = Config.threshold,
44676
+ findAllMatches = Config.findAllMatches,
44677
+ minMatchCharLength = Config.minMatchCharLength,
44678
+ includeMatches = Config.includeMatches,
44679
+ ignoreLocation = Config.ignoreLocation
44680
+ } = {}) {
44681
+ if (pattern.length > MAX_BITS) {
44682
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
44683
+ }
44684
+ const patternLen = pattern.length;
44685
+ const textLen = text.length;
44686
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
44687
+ let currentThreshold = threshold;
44688
+ let bestLocation = expectedLocation;
44689
+ const calcScore = (errors, currentLocation) => {
44690
+ const accuracy = errors / patternLen;
44691
+ if (ignoreLocation) return accuracy;
44692
+ const proximity = Math.abs(expectedLocation - currentLocation);
44693
+ if (!distance) return proximity ? 1 : accuracy;
44694
+ return accuracy + proximity / distance;
44695
+ };
44696
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
44697
+ const matchMask = computeMatches ? Array(textLen) : [];
44698
+ let index2;
44699
+ while ((index2 = text.indexOf(pattern, bestLocation)) > -1) {
44700
+ const score = calcScore(0, index2);
44701
+ currentThreshold = Math.min(score, currentThreshold);
44702
+ bestLocation = index2 + patternLen;
44703
+ if (computeMatches) {
44704
+ let i = 0;
44705
+ while (i < patternLen) {
44706
+ matchMask[index2 + i] = 1;
44707
+ i += 1;
44708
+ }
44709
+ }
44710
+ }
44711
+ bestLocation = -1;
44712
+ let lastBitArr = [];
44713
+ let finalScore = 1;
44714
+ let bestErrors = 0;
44715
+ let binMax = patternLen + textLen;
44716
+ const mask = 1 << patternLen - 1;
44717
+ for (let i = 0; i < patternLen; i += 1) {
44718
+ let binMin = 0;
44719
+ let binMid = binMax;
44720
+ while (binMin < binMid) {
44721
+ const score2 = calcScore(i, expectedLocation + binMid);
44722
+ if (score2 <= currentThreshold) {
44723
+ binMin = binMid;
44724
+ } else {
44725
+ binMax = binMid;
44726
+ }
44727
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
44728
+ }
44729
+ binMax = binMid;
44730
+ let start = Math.max(1, expectedLocation - binMid + 1);
44731
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
44732
+ const bitArr = Array(finish + 2);
44733
+ bitArr[finish + 1] = (1 << i) - 1;
44734
+ for (let j = finish; j >= start; j -= 1) {
44735
+ const currentLocation = j - 1;
44736
+ const charMatch = patternAlphabet[text[currentLocation]];
44737
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
44738
+ if (i) {
44739
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
44740
+ }
44741
+ if (bitArr[j] & mask) {
44742
+ finalScore = calcScore(i, currentLocation);
44743
+ if (finalScore <= currentThreshold) {
44744
+ currentThreshold = finalScore;
44745
+ bestLocation = currentLocation;
44746
+ bestErrors = i;
44747
+ if (bestLocation <= expectedLocation) {
44748
+ break;
44749
+ }
44750
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
44751
+ }
44752
+ }
44753
+ }
44754
+ const score = calcScore(i + 1, expectedLocation);
44755
+ if (score > currentThreshold) {
44756
+ break;
44757
+ }
44758
+ lastBitArr = bitArr;
44759
+ }
44760
+ if (computeMatches && bestLocation >= 0) {
44761
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
44762
+ for (let k = bestLocation; k <= matchEnd; k += 1) {
44763
+ if (patternAlphabet[text[k]]) {
44764
+ matchMask[k] = 1;
44765
+ }
44766
+ }
44767
+ }
44768
+ const result = {
44769
+ isMatch: bestLocation >= 0,
44770
+ // Count exact matches (those with a score of 0) to be "almost" exact
44771
+ score: Math.max(1e-3, finalScore)
44772
+ };
44773
+ if (computeMatches) {
44774
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
44775
+ if (!indices.length) {
44776
+ result.isMatch = false;
44777
+ } else if (includeMatches) {
44778
+ result.indices = indices;
44779
+ }
44780
+ }
44781
+ return result;
44782
+ }
44783
+ function createPatternAlphabet(pattern) {
44784
+ const mask = {};
44785
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
44786
+ const char = pattern.charAt(i);
44787
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
44788
+ }
44789
+ return mask;
44790
+ }
44791
+ function mergeIndices(indices) {
44792
+ if (indices.length <= 1) return indices;
44793
+ indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
44794
+ const merged = [indices[0]];
44795
+ for (let i = 1, len = indices.length; i < len; i += 1) {
44796
+ const last = merged[merged.length - 1];
44797
+ const curr = indices[i];
44798
+ if (curr[0] <= last[1] + 1) {
44799
+ last[1] = Math.max(last[1], curr[1]);
44800
+ } else {
44801
+ merged.push(curr);
44802
+ }
44803
+ }
44804
+ return merged;
44805
+ }
44806
+ var NON_DECOMPOSABLE_MAP = {
44807
+ "\u0142": "l",
44808
+ // ł
44809
+ "\u0141": "L",
44810
+ // Ł
44811
+ "\u0111": "d",
44812
+ // đ
44813
+ "\u0110": "D",
44814
+ // Đ
44815
+ "\xF8": "o",
44816
+ // ø
44817
+ "\xD8": "O",
44818
+ // Ø
44819
+ "\u0127": "h",
44820
+ // ħ
44821
+ "\u0126": "H",
44822
+ // Ħ
44823
+ "\u0167": "t",
44824
+ // ŧ
44825
+ "\u0166": "T",
44826
+ // Ŧ
44827
+ "\u0131": "i",
44828
+ // ı
44829
+ "\xDF": "ss"
44830
+ // ß
44831
+ };
44832
+ var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
44833
+ 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;
44834
+ var BitapSearch = class {
44835
+ constructor(pattern, {
44836
+ location = Config.location,
44837
+ threshold = Config.threshold,
44838
+ distance = Config.distance,
44839
+ includeMatches = Config.includeMatches,
44840
+ findAllMatches = Config.findAllMatches,
44841
+ minMatchCharLength = Config.minMatchCharLength,
44842
+ isCaseSensitive = Config.isCaseSensitive,
44843
+ ignoreDiacritics = Config.ignoreDiacritics,
44844
+ ignoreLocation = Config.ignoreLocation
44845
+ } = {}) {
44846
+ this.options = {
44847
+ location,
44848
+ threshold,
44849
+ distance,
44850
+ includeMatches,
44851
+ findAllMatches,
44852
+ minMatchCharLength,
44853
+ isCaseSensitive,
44854
+ ignoreDiacritics,
44855
+ ignoreLocation
44856
+ };
44857
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
44858
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
44859
+ this.pattern = pattern;
44860
+ this.chunks = [];
44861
+ if (!this.pattern.length) {
44862
+ return;
44863
+ }
44864
+ const addChunk = (pattern2, startIndex) => {
44865
+ this.chunks.push({
44866
+ pattern: pattern2,
44867
+ alphabet: createPatternAlphabet(pattern2),
44868
+ startIndex
44869
+ });
44870
+ };
44871
+ const len = this.pattern.length;
44872
+ if (len > MAX_BITS) {
44873
+ let i = 0;
44874
+ const remainder = len % MAX_BITS;
44875
+ const end = len - remainder;
44876
+ while (i < end) {
44877
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
44878
+ i += MAX_BITS;
44879
+ }
44880
+ if (remainder) {
44881
+ const startIndex = len - MAX_BITS;
44882
+ addChunk(this.pattern.substr(startIndex), startIndex);
44883
+ }
44884
+ } else {
44885
+ addChunk(this.pattern, 0);
44886
+ }
44887
+ }
44888
+ searchIn(text) {
44889
+ const {
44890
+ isCaseSensitive,
44891
+ ignoreDiacritics,
44892
+ includeMatches
44893
+ } = this.options;
44894
+ text = isCaseSensitive ? text : text.toLowerCase();
44895
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
44896
+ if (this.pattern === text) {
44897
+ const result2 = {
44898
+ isMatch: true,
44899
+ score: 0
44900
+ };
44901
+ if (includeMatches) {
44902
+ result2.indices = [[0, text.length - 1]];
44903
+ }
44904
+ return result2;
44905
+ }
44906
+ const {
44907
+ location,
44908
+ distance,
44909
+ threshold,
44910
+ findAllMatches,
44911
+ minMatchCharLength,
44912
+ ignoreLocation
44913
+ } = this.options;
44914
+ const allIndices = [];
44915
+ let totalScore = 0;
44916
+ let hasMatches = false;
44917
+ this.chunks.forEach(({
44918
+ pattern,
44919
+ alphabet,
44920
+ startIndex
44921
+ }) => {
44922
+ const {
44923
+ isMatch,
44924
+ score,
44925
+ indices
44926
+ } = search(text, pattern, alphabet, {
44927
+ location: location + startIndex,
44928
+ distance,
44929
+ threshold,
44930
+ findAllMatches,
44931
+ minMatchCharLength,
44932
+ includeMatches,
44933
+ ignoreLocation
44934
+ });
44935
+ if (isMatch) {
44936
+ hasMatches = true;
44937
+ }
44938
+ totalScore += score;
44939
+ if (isMatch && indices) {
44940
+ allIndices.push(...indices);
44941
+ }
44942
+ });
44943
+ const result = {
44944
+ isMatch: hasMatches,
44945
+ score: hasMatches ? totalScore / this.chunks.length : 1
44946
+ };
44947
+ if (hasMatches && includeMatches) {
44948
+ result.indices = mergeIndices(allIndices);
44949
+ }
44950
+ return result;
44951
+ }
44952
+ };
44953
+ var MULTI_MATCH_TYPES = /* @__PURE__ */ new Set(["fuzzy", "include"]);
44954
+ function isInverse(type) {
44955
+ return type.startsWith("inverse");
44956
+ }
44957
+ var matchers = [
44958
+ // =term — exact match
44959
+ {
44960
+ type: "exact",
44961
+ multiRegex: /^="(.*)"$/,
44962
+ singleRegex: /^=(.*)$/,
44963
+ create: (pattern) => ({
44964
+ type: "exact",
44965
+ search(text) {
44966
+ const isMatch = text === pattern;
44967
+ return {
44968
+ isMatch,
44969
+ score: isMatch ? 0 : 1,
44970
+ indices: [0, pattern.length - 1]
44971
+ };
44972
+ }
44973
+ })
44974
+ },
44975
+ // 'term — include (substring) match
44976
+ {
44977
+ type: "include",
44978
+ multiRegex: /^'"(.*)"$/,
44979
+ singleRegex: /^'(.*)$/,
44980
+ create: (pattern) => ({
44981
+ type: "include",
44982
+ search(text) {
44983
+ let location = 0;
44984
+ let index2;
44985
+ const indices = [];
44986
+ const patternLen = pattern.length;
44987
+ while ((index2 = text.indexOf(pattern, location)) > -1) {
44988
+ location = index2 + patternLen;
44989
+ indices.push([index2, location - 1]);
44990
+ }
44991
+ const isMatch = !!indices.length;
44992
+ return {
44993
+ isMatch,
44994
+ score: isMatch ? 0 : 1,
44995
+ indices
44996
+ };
44997
+ }
44998
+ })
44999
+ },
45000
+ // ^term — prefix match
45001
+ {
45002
+ type: "prefix-exact",
45003
+ multiRegex: /^\^"(.*)"$/,
45004
+ singleRegex: /^\^(.*)$/,
45005
+ create: (pattern) => ({
45006
+ type: "prefix-exact",
45007
+ search(text) {
45008
+ const isMatch = text.startsWith(pattern);
45009
+ return {
45010
+ isMatch,
45011
+ score: isMatch ? 0 : 1,
45012
+ indices: [0, pattern.length - 1]
45013
+ };
45014
+ }
45015
+ })
45016
+ },
45017
+ // !^term — inverse prefix match
45018
+ {
45019
+ type: "inverse-prefix-exact",
45020
+ multiRegex: /^!\^"(.*)"$/,
45021
+ singleRegex: /^!\^(.*)$/,
45022
+ create: (pattern) => ({
45023
+ type: "inverse-prefix-exact",
45024
+ search(text) {
45025
+ const isMatch = !text.startsWith(pattern);
45026
+ return {
45027
+ isMatch,
45028
+ score: isMatch ? 0 : 1,
45029
+ indices: [0, text.length - 1]
45030
+ };
45031
+ }
45032
+ })
45033
+ },
45034
+ // !term$ — inverse suffix match
45035
+ {
45036
+ type: "inverse-suffix-exact",
45037
+ multiRegex: /^!"(.*)"\$$/,
45038
+ singleRegex: /^!(.*)\$$/,
45039
+ create: (pattern) => ({
45040
+ type: "inverse-suffix-exact",
45041
+ search(text) {
45042
+ const isMatch = !text.endsWith(pattern);
45043
+ return {
45044
+ isMatch,
45045
+ score: isMatch ? 0 : 1,
45046
+ indices: [0, text.length - 1]
45047
+ };
45048
+ }
45049
+ })
45050
+ },
45051
+ // term$ — suffix match
45052
+ {
45053
+ type: "suffix-exact",
45054
+ multiRegex: /^"(.*)"\$$/,
45055
+ singleRegex: /^(.*)\$$/,
45056
+ create: (pattern) => ({
45057
+ type: "suffix-exact",
45058
+ search(text) {
45059
+ const isMatch = text.endsWith(pattern);
45060
+ return {
45061
+ isMatch,
45062
+ score: isMatch ? 0 : 1,
45063
+ indices: [text.length - pattern.length, text.length - 1]
45064
+ };
45065
+ }
45066
+ })
45067
+ },
45068
+ // !term — inverse exact (does not contain)
45069
+ {
45070
+ type: "inverse-exact",
45071
+ multiRegex: /^!"(.*)"$/,
45072
+ singleRegex: /^!(.*)$/,
45073
+ create: (pattern) => ({
45074
+ type: "inverse-exact",
45075
+ search(text) {
45076
+ const isMatch = text.indexOf(pattern) === -1;
45077
+ return {
45078
+ isMatch,
45079
+ score: isMatch ? 0 : 1,
45080
+ indices: [0, text.length - 1]
45081
+ };
45082
+ }
45083
+ })
45084
+ },
45085
+ // term — fuzzy match (catch-all, must be last)
45086
+ {
45087
+ type: "fuzzy",
45088
+ multiRegex: /^"(.*)"$/,
45089
+ singleRegex: /^(.*)$/,
45090
+ create: (pattern, options2 = {}) => {
45091
+ const bitap = new BitapSearch(pattern, {
45092
+ location: options2.location ?? Config.location,
45093
+ threshold: options2.threshold ?? Config.threshold,
45094
+ distance: options2.distance ?? Config.distance,
45095
+ includeMatches: options2.includeMatches ?? Config.includeMatches,
45096
+ findAllMatches: options2.findAllMatches ?? Config.findAllMatches,
45097
+ minMatchCharLength: options2.minMatchCharLength ?? Config.minMatchCharLength,
45098
+ isCaseSensitive: options2.isCaseSensitive ?? Config.isCaseSensitive,
45099
+ ignoreDiacritics: options2.ignoreDiacritics ?? Config.ignoreDiacritics,
45100
+ ignoreLocation: options2.ignoreLocation ?? Config.ignoreLocation
45101
+ });
45102
+ return {
45103
+ type: "fuzzy",
45104
+ search(text) {
45105
+ return bitap.searchIn(text);
45106
+ }
45107
+ };
45108
+ }
45109
+ }
45110
+ ];
45111
+ var matchersLen = matchers.length;
45112
+ var ESCAPED_PIPE = "\0";
45113
+ var OR_TOKEN = "|";
45114
+ function tokenize(pattern) {
45115
+ const tokens = [];
45116
+ const len = pattern.length;
45117
+ let i = 0;
45118
+ while (i < len) {
45119
+ while (i < len && pattern[i] === " ") i++;
45120
+ if (i >= len) break;
45121
+ let j = i;
45122
+ while (j < len && pattern[j] !== " " && pattern[j] !== '"') j++;
45123
+ if (j < len && pattern[j] === '"') {
45124
+ j++;
45125
+ while (j < len) {
45126
+ if (pattern[j] === '"') {
45127
+ const next = j + 1;
45128
+ if (next >= len || pattern[next] === " ") {
45129
+ j++;
45130
+ break;
45131
+ }
45132
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
45133
+ j += 2;
45134
+ break;
45135
+ }
45136
+ }
45137
+ j++;
45138
+ }
45139
+ tokens.push(pattern.substring(i, j));
45140
+ i = j;
45141
+ } else {
45142
+ while (j < len && pattern[j] !== " ") j++;
45143
+ tokens.push(pattern.substring(i, j));
45144
+ i = j;
45145
+ }
45146
+ }
45147
+ return tokens;
45148
+ }
45149
+ function getMatch(pattern, exp) {
45150
+ const matches = pattern.match(exp);
45151
+ return matches ? matches[1] : null;
45152
+ }
45153
+ function parseQuery(pattern, options2 = {}) {
45154
+ const escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
45155
+ return escaped.split(OR_TOKEN).map((item) => {
45156
+ const restored = item.replace(/\u0000/g, "|");
45157
+ const query = tokenize(restored.trim()).filter((item2) => item2 && !!item2.trim());
45158
+ const results = [];
45159
+ for (let i = 0, len = query.length; i < len; i += 1) {
45160
+ const queryItem = query[i];
45161
+ let found = false;
45162
+ let idx = -1;
45163
+ while (!found && ++idx < matchersLen) {
45164
+ const def = matchers[idx];
45165
+ const token = getMatch(queryItem, def.multiRegex);
45166
+ if (token) {
45167
+ results.push(def.create(token, options2));
45168
+ found = true;
45169
+ }
45170
+ }
45171
+ if (found) {
45172
+ continue;
45173
+ }
45174
+ idx = -1;
45175
+ while (++idx < matchersLen) {
45176
+ const def = matchers[idx];
45177
+ const token = getMatch(queryItem, def.singleRegex);
45178
+ if (token) {
45179
+ results.push(def.create(token, options2));
45180
+ break;
45181
+ }
45182
+ }
45183
+ }
45184
+ return results;
45185
+ });
45186
+ }
45187
+ var ExtendedSearch = class {
45188
+ constructor(pattern, {
45189
+ isCaseSensitive = Config.isCaseSensitive,
45190
+ ignoreDiacritics = Config.ignoreDiacritics,
45191
+ includeMatches = Config.includeMatches,
45192
+ minMatchCharLength = Config.minMatchCharLength,
45193
+ ignoreLocation = Config.ignoreLocation,
45194
+ findAllMatches = Config.findAllMatches,
45195
+ location = Config.location,
45196
+ threshold = Config.threshold,
45197
+ distance = Config.distance
45198
+ } = {}) {
45199
+ this.query = null;
45200
+ this.options = {
45201
+ isCaseSensitive,
45202
+ ignoreDiacritics,
45203
+ includeMatches,
45204
+ minMatchCharLength,
45205
+ findAllMatches,
45206
+ ignoreLocation,
45207
+ location,
45208
+ threshold,
45209
+ distance
45210
+ };
45211
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
45212
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
45213
+ this.pattern = pattern;
45214
+ this.query = parseQuery(this.pattern, this.options);
45215
+ }
45216
+ static condition(_, options2) {
45217
+ return options2.useExtendedSearch;
45218
+ }
45219
+ // Note: searchIn operates on a single text value and sets hasInverse on the
45220
+ // result when inverse patterns are involved. _searchObjectList uses this to
45221
+ // switch from "ANY key" to "ALL keys" aggregation. See #712.
45222
+ searchIn(text) {
45223
+ const query = this.query;
45224
+ if (!query) {
45225
+ return {
45226
+ isMatch: false,
45227
+ score: 1
45228
+ };
45229
+ }
45230
+ const {
45231
+ includeMatches,
45232
+ isCaseSensitive,
45233
+ ignoreDiacritics
45234
+ } = this.options;
45235
+ text = isCaseSensitive ? text : text.toLowerCase();
45236
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
45237
+ let numMatches = 0;
45238
+ const allIndices = [];
45239
+ let totalScore = 0;
45240
+ let hasInverse = false;
45241
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
45242
+ const searchers = query[i];
45243
+ allIndices.length = 0;
45244
+ numMatches = 0;
45245
+ hasInverse = false;
45246
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
45247
+ const matcher = searchers[j];
45248
+ const {
45249
+ isMatch,
45250
+ indices,
45251
+ score
45252
+ } = matcher.search(text);
45253
+ if (isMatch) {
45254
+ numMatches += 1;
45255
+ totalScore += score;
45256
+ if (isInverse(matcher.type)) {
45257
+ hasInverse = true;
45258
+ }
45259
+ if (includeMatches) {
45260
+ if (MULTI_MATCH_TYPES.has(matcher.type)) {
45261
+ allIndices.push(...indices);
45262
+ } else {
45263
+ allIndices.push(indices);
45264
+ }
45265
+ }
45266
+ } else {
45267
+ totalScore = 0;
45268
+ numMatches = 0;
45269
+ allIndices.length = 0;
45270
+ hasInverse = false;
45271
+ break;
45272
+ }
45273
+ }
45274
+ if (numMatches) {
45275
+ const result = {
45276
+ isMatch: true,
45277
+ score: totalScore / numMatches
45278
+ };
45279
+ if (hasInverse) {
45280
+ result.hasInverse = true;
45281
+ }
45282
+ if (includeMatches) {
45283
+ result.indices = mergeIndices(allIndices);
45284
+ }
45285
+ return result;
45286
+ }
45287
+ }
45288
+ return {
45289
+ isMatch: false,
45290
+ score: 1
45291
+ };
45292
+ }
45293
+ };
45294
+ var registeredSearchers = [];
45295
+ function register(...args) {
45296
+ registeredSearchers.push(...args);
45297
+ }
45298
+ function createSearcher(pattern, options2) {
45299
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
45300
+ const searcherClass = registeredSearchers[i];
45301
+ if (searcherClass.condition(pattern, options2)) {
45302
+ return new searcherClass(pattern, options2);
45303
+ }
45304
+ }
45305
+ return new BitapSearch(pattern, options2);
45306
+ }
45307
+ var LogicalOperator = {
45308
+ AND: "$and",
45309
+ OR: "$or"
45310
+ };
45311
+ var KeyType = {
45312
+ PATH: "$path",
45313
+ PATTERN: "$val"
45314
+ };
45315
+ var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
45316
+ var isPath = (query) => !!query[KeyType.PATH];
45317
+ var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
45318
+ var convertToExplicit = (query) => ({
45319
+ [LogicalOperator.AND]: Object.keys(query).map((key) => ({
45320
+ [key]: query[key]
45321
+ }))
45322
+ });
45323
+ function parse2(query, options2, {
45324
+ auto = true
45325
+ } = {}) {
45326
+ const next = (query2) => {
45327
+ if (isString(query2)) {
45328
+ const obj = {
45329
+ keyId: null,
45330
+ pattern: query2
45331
+ };
45332
+ if (auto) {
45333
+ obj.searcher = createSearcher(query2, options2);
45334
+ }
45335
+ return obj;
45336
+ }
45337
+ const keys = Object.keys(query2);
45338
+ const isQueryPath = isPath(query2);
45339
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
45340
+ return next(convertToExplicit(query2));
45341
+ }
45342
+ if (isLeaf(query2)) {
45343
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
45344
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
45345
+ if (!isString(pattern)) {
45346
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
45347
+ }
45348
+ const obj = {
45349
+ keyId: createKeyId(key),
45350
+ pattern
45351
+ };
45352
+ if (auto) {
45353
+ obj.searcher = createSearcher(pattern, options2);
45354
+ }
45355
+ return obj;
45356
+ }
45357
+ const node = {
45358
+ children: [],
45359
+ operator: keys[0]
45360
+ };
45361
+ keys.forEach((key) => {
45362
+ const value = query2[key];
45363
+ if (isArray(value)) {
45364
+ value.forEach((item) => {
45365
+ node.children.push(next(item));
45366
+ });
45367
+ }
45368
+ });
45369
+ return node;
45370
+ };
45371
+ if (!isExpression(query)) {
45372
+ query = convertToExplicit(query);
45373
+ }
45374
+ return next(query);
45375
+ }
45376
+ function computeScoreSingle(matches, {
45377
+ ignoreFieldNorm = Config.ignoreFieldNorm
45378
+ }) {
45379
+ let totalScore = 1;
45380
+ matches.forEach(({
45381
+ key,
45382
+ norm: norm2,
45383
+ score
45384
+ }) => {
45385
+ const weight = key ? key.weight : null;
45386
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
45387
+ });
45388
+ return totalScore;
45389
+ }
45390
+ function computeScore(results, {
45391
+ ignoreFieldNorm = Config.ignoreFieldNorm
45392
+ }) {
45393
+ results.forEach((result) => {
45394
+ result.score = computeScoreSingle(result.matches, {
45395
+ ignoreFieldNorm
45396
+ });
45397
+ });
45398
+ }
45399
+ var MaxHeap = class {
45400
+ constructor(limit) {
45401
+ this.limit = limit;
45402
+ this.heap = [];
45403
+ }
45404
+ get size() {
45405
+ return this.heap.length;
45406
+ }
45407
+ shouldInsert(score) {
45408
+ return this.size < this.limit || score < this.heap[0].score;
45409
+ }
45410
+ insert(item) {
45411
+ if (this.size < this.limit) {
45412
+ this.heap.push(item);
45413
+ this._bubbleUp(this.size - 1);
45414
+ } else if (item.score < this.heap[0].score) {
45415
+ this.heap[0] = item;
45416
+ this._sinkDown(0);
45417
+ }
45418
+ }
45419
+ extractSorted(sortFn) {
45420
+ return this.heap.sort(sortFn);
45421
+ }
45422
+ _bubbleUp(i) {
45423
+ const heap = this.heap;
45424
+ while (i > 0) {
45425
+ const parent = i - 1 >> 1;
45426
+ if (heap[i].score <= heap[parent].score) break;
45427
+ const tmp = heap[i];
45428
+ heap[i] = heap[parent];
45429
+ heap[parent] = tmp;
45430
+ i = parent;
45431
+ }
45432
+ }
45433
+ _sinkDown(i) {
45434
+ const heap = this.heap;
45435
+ const len = heap.length;
45436
+ let largest = i;
45437
+ do {
45438
+ i = largest;
45439
+ const left = 2 * i + 1;
45440
+ const right = 2 * i + 2;
45441
+ if (left < len && heap[left].score > heap[largest].score) {
45442
+ largest = left;
45443
+ }
45444
+ if (right < len && heap[right].score > heap[largest].score) {
45445
+ largest = right;
45446
+ }
45447
+ if (largest !== i) {
45448
+ const tmp = heap[i];
45449
+ heap[i] = heap[largest];
45450
+ heap[largest] = tmp;
45451
+ }
45452
+ } while (largest !== i);
45453
+ }
45454
+ };
45455
+ function formatMatches(result) {
45456
+ const matches = [];
45457
+ result.matches.forEach((match) => {
45458
+ if (!isDefined(match.indices) || !match.indices.length) {
45459
+ return;
45460
+ }
45461
+ const obj = {
45462
+ indices: match.indices,
45463
+ value: match.value
45464
+ };
45465
+ if (match.key) {
45466
+ obj.key = match.key.id;
45467
+ }
45468
+ if (match.idx > -1) {
45469
+ obj.refIndex = match.idx;
45470
+ }
45471
+ matches.push(obj);
45472
+ });
45473
+ return matches;
45474
+ }
45475
+ function format(results, docs, {
45476
+ includeMatches = Config.includeMatches,
45477
+ includeScore = Config.includeScore
45478
+ } = {}) {
45479
+ return results.map((result) => {
45480
+ const {
45481
+ idx
45482
+ } = result;
45483
+ const data = {
45484
+ item: docs[idx],
45485
+ refIndex: idx
45486
+ };
45487
+ if (includeMatches) data.matches = formatMatches(result);
45488
+ if (includeScore) data.score = result.score;
45489
+ return data;
45490
+ });
45491
+ }
45492
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
45493
+ var warned = /* @__PURE__ */ new WeakSet();
45494
+ function warnNonGlobal(regex) {
45495
+ if (!warned.has(regex)) {
45496
+ warned.add(regex);
45497
+ console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
45498
+ }
45499
+ }
45500
+ function resolveTokenize(tokenize2) {
45501
+ if (typeof tokenize2 === "function") {
45502
+ let validated = false;
45503
+ return (text) => {
45504
+ const result = tokenize2(text);
45505
+ if (!validated) {
45506
+ validated = true;
45507
+ if (!Array.isArray(result) || result.some((t12) => typeof t12 !== "string")) {
45508
+ throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
45509
+ }
45510
+ }
45511
+ return result;
45512
+ };
45513
+ }
45514
+ if (tokenize2 instanceof RegExp) {
45515
+ if (!tokenize2.global) warnNonGlobal(tokenize2);
45516
+ return (text) => text.match(tokenize2) || [];
45517
+ }
45518
+ return (text) => text.match(DEFAULT_TOKEN) || [];
45519
+ }
45520
+ function createAnalyzer({
45521
+ isCaseSensitive = false,
45522
+ ignoreDiacritics = false,
45523
+ tokenize: tokenize2
45524
+ } = {}) {
45525
+ const tokenizeFn = resolveTokenize(tokenize2);
45526
+ return {
45527
+ tokenize(text) {
45528
+ if (!isCaseSensitive) {
45529
+ text = text.toLowerCase();
45530
+ }
45531
+ if (ignoreDiacritics) {
45532
+ text = stripDiacritics(text);
45533
+ }
45534
+ return tokenizeFn(text);
45535
+ }
45536
+ };
45537
+ }
45538
+ var MAX_MASK_TERMS = 31;
45539
+ var TokenSearch = class {
45540
+ // `tokenMatch: 'all'` (AND) coverage. When true, searchIn reports which
45541
+ // query terms matched each text so the core loop can require record-level
45542
+ // coverage of every term. Bitmask is the ≤31-term fast path; Set is the
45543
+ // ≥32-term fallback (JS bitwise ops are 32-bit signed).
45544
+ static condition(_, options2) {
45545
+ return options2.useTokenSearch;
45546
+ }
45547
+ constructor(pattern, options2) {
45548
+ this.options = options2;
45549
+ this.analyzer = createAnalyzer({
45550
+ isCaseSensitive: options2.isCaseSensitive,
45551
+ ignoreDiacritics: options2.ignoreDiacritics,
45552
+ tokenize: options2.tokenize
45553
+ });
45554
+ const queryTerms = this.analyzer.tokenize(pattern);
45555
+ const invertedIndex = options2._invertedIndex;
45556
+ const {
45557
+ df,
45558
+ fieldCount
45559
+ } = invertedIndex;
45560
+ this.termSearchers = [];
45561
+ this.idfWeights = [];
45562
+ for (const term of queryTerms) {
45563
+ this.termSearchers.push(new BitapSearch(term, {
45564
+ location: options2.location,
45565
+ threshold: options2.threshold,
45566
+ distance: options2.distance,
45567
+ includeMatches: options2.includeMatches,
45568
+ findAllMatches: options2.findAllMatches,
45569
+ minMatchCharLength: options2.minMatchCharLength,
45570
+ isCaseSensitive: options2.isCaseSensitive,
45571
+ ignoreDiacritics: options2.ignoreDiacritics,
45572
+ ignoreLocation: true
45573
+ }));
45574
+ const docFreq = df.get(term) || 0;
45575
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
45576
+ this.idfWeights.push(idf);
45577
+ }
45578
+ this.combineAll = options2.tokenMatch === "all";
45579
+ this.numTerms = this.termSearchers.length;
45580
+ this.useMask = this.numTerms <= MAX_MASK_TERMS;
45581
+ }
45582
+ searchIn(text) {
45583
+ if (!this.termSearchers.length) {
45584
+ return {
45585
+ isMatch: false,
45586
+ score: 1
45587
+ };
45588
+ }
45589
+ const allIndices = [];
45590
+ let weightedScore = 0;
45591
+ let maxPossibleScore = 0;
45592
+ let matchedCount = 0;
45593
+ let matchedMask = 0;
45594
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
45595
+ for (let i = 0; i < this.termSearchers.length; i++) {
45596
+ const result = this.termSearchers[i].searchIn(text);
45597
+ const idf = this.idfWeights[i];
45598
+ maxPossibleScore += idf;
45599
+ if (result.isMatch) {
45600
+ matchedCount++;
45601
+ weightedScore += idf * (1 - result.score);
45602
+ if (result.indices) {
45603
+ allIndices.push(...result.indices);
45604
+ }
45605
+ if (this.combineAll) {
45606
+ if (this.useMask) {
45607
+ matchedMask |= 1 << i;
45608
+ } else {
45609
+ matchedTerms.add(i);
45610
+ }
45611
+ }
45612
+ }
45613
+ }
45614
+ if (matchedCount === 0) {
45615
+ return {
45616
+ isMatch: false,
45617
+ score: 1
45618
+ };
45619
+ }
45620
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
45621
+ const searchResult = {
45622
+ isMatch: true,
45623
+ score: Math.max(1e-3, normalized)
45624
+ };
45625
+ if (this.options.includeMatches && allIndices.length) {
45626
+ searchResult.indices = mergeIndices(allIndices);
45627
+ }
45628
+ if (this.combineAll) {
45629
+ if (this.useMask) {
45630
+ searchResult.matchedMask = matchedMask;
45631
+ } else {
45632
+ searchResult.matchedTerms = matchedTerms;
45633
+ }
45634
+ searchResult.termCount = this.numTerms;
45635
+ }
45636
+ return searchResult;
45637
+ }
45638
+ };
45639
+ function addField(index2, text, docIdx, analyzer) {
45640
+ const tokens = analyzer.tokenize(text);
45641
+ if (!tokens.length) return;
45642
+ index2.fieldCount++;
45643
+ index2.docFieldCount.set(docIdx, (index2.docFieldCount.get(docIdx) || 0) + 1);
45644
+ const distinctTerms = new Set(tokens);
45645
+ let perDocTerms = index2.docTermFieldHits.get(docIdx);
45646
+ if (!perDocTerms) {
45647
+ perDocTerms = /* @__PURE__ */ new Map();
45648
+ index2.docTermFieldHits.set(docIdx, perDocTerms);
45649
+ }
45650
+ for (const term of distinctTerms) {
45651
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
45652
+ index2.df.set(term, (index2.df.get(term) || 0) + 1);
45653
+ }
45654
+ }
45655
+ function ingestRecord(index2, record, keyCount, analyzer) {
45656
+ const {
45657
+ i: docIdx,
45658
+ v,
45659
+ $: fields
45660
+ } = record;
45661
+ if (v !== void 0) {
45662
+ addField(index2, v, docIdx, analyzer);
45663
+ return;
45664
+ }
45665
+ if (!fields) return;
45666
+ for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
45667
+ const value = fields[keyIdx];
45668
+ if (!value) continue;
45669
+ if (Array.isArray(value)) {
45670
+ for (const sub of value) addField(index2, sub.v, docIdx, analyzer);
45671
+ } else {
45672
+ addField(index2, value.v, docIdx, analyzer);
45673
+ }
45674
+ }
45675
+ }
45676
+ function buildInvertedIndex(records, keyCount, analyzer) {
45677
+ const index2 = {
45678
+ fieldCount: 0,
45679
+ df: /* @__PURE__ */ new Map(),
45680
+ docFieldCount: /* @__PURE__ */ new Map(),
45681
+ docTermFieldHits: /* @__PURE__ */ new Map()
45682
+ };
45683
+ for (const record of records) {
45684
+ ingestRecord(index2, record, keyCount, analyzer);
45685
+ }
45686
+ return index2;
45687
+ }
45688
+ function addToInvertedIndex(index2, record, keyCount, analyzer) {
45689
+ ingestRecord(index2, record, keyCount, analyzer);
45690
+ }
45691
+ function removeFromInvertedIndex(index2, docIdx) {
45692
+ const fieldCount = index2.docFieldCount.get(docIdx);
45693
+ if (fieldCount === void 0) return;
45694
+ index2.fieldCount -= fieldCount;
45695
+ index2.docFieldCount.delete(docIdx);
45696
+ const perDocTerms = index2.docTermFieldHits.get(docIdx);
45697
+ if (!perDocTerms) return;
45698
+ for (const [term, hits] of perDocTerms) {
45699
+ const next = (index2.df.get(term) || 0) - hits;
45700
+ if (next <= 0) {
45701
+ index2.df.delete(term);
45702
+ } else {
45703
+ index2.df.set(term, next);
45704
+ }
45705
+ }
45706
+ index2.docTermFieldHits.delete(docIdx);
45707
+ }
45708
+ function removeAndShiftInvertedIndex(index2, removedIndices) {
45709
+ if (removedIndices.length === 0) return;
45710
+ const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
45711
+ for (const idx of sorted) {
45712
+ removeFromInvertedIndex(index2, idx);
45713
+ }
45714
+ const shift4 = (oldIdx) => {
45715
+ let lo = 0;
45716
+ let hi = sorted.length;
45717
+ while (lo < hi) {
45718
+ const mid = lo + hi >>> 1;
45719
+ if (sorted[mid] < oldIdx) lo = mid + 1;
45720
+ else hi = mid;
45721
+ }
45722
+ return oldIdx - lo;
45723
+ };
45724
+ const firstRemoved = sorted[0];
45725
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map();
45726
+ for (const [oldKey, count3] of index2.docFieldCount) {
45727
+ shiftedDocFieldCount.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, count3);
45728
+ }
45729
+ index2.docFieldCount = shiftedDocFieldCount;
45730
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
45731
+ for (const [oldKey, terms] of index2.docTermFieldHits) {
45732
+ shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, terms);
45733
+ }
45734
+ index2.docTermFieldHits = shiftedDocTermFieldHits;
45735
+ }
45736
+ var Fuse = class {
45737
+ // Statics are assigned in entry.ts
45738
+ constructor(docs, options2, index2) {
45739
+ this.options = {
45740
+ ...Config,
45741
+ ...options2
45742
+ };
45743
+ if (this.options.useExtendedSearch && false) ;
45744
+ if (this.options.useTokenSearch && false) ;
45745
+ this._keyStore = new KeyStore(this.options.keys);
45746
+ this._docs = docs;
45747
+ this._myIndex = null;
45748
+ this._invertedIndex = null;
45749
+ this.setCollection(docs, index2);
45750
+ this._lastQuery = null;
45751
+ this._lastSearcher = null;
45752
+ }
45753
+ _getSearcher(query) {
45754
+ if (this._lastQuery === query) {
45755
+ return this._lastSearcher;
45756
+ }
45757
+ const opts = this._invertedIndex ? {
45758
+ ...this.options,
45759
+ _invertedIndex: this._invertedIndex
45760
+ } : this.options;
45761
+ const searcher = createSearcher(query, opts);
45762
+ this._lastQuery = query;
45763
+ this._lastSearcher = searcher;
45764
+ return searcher;
45765
+ }
45766
+ setCollection(docs, index2) {
45767
+ this._docs = docs;
45768
+ if (index2 && !(index2 instanceof FuseIndex)) {
45769
+ throw new Error(INCORRECT_INDEX_TYPE);
45770
+ }
45771
+ this._myIndex = index2 || createIndex(this.options.keys, this._docs, {
45772
+ getFn: this.options.getFn,
45773
+ fieldNormWeight: this.options.fieldNormWeight
45774
+ });
45775
+ if (this.options.useTokenSearch) {
45776
+ const analyzer = createAnalyzer({
45777
+ isCaseSensitive: this.options.isCaseSensitive,
45778
+ ignoreDiacritics: this.options.ignoreDiacritics,
45779
+ tokenize: this.options.tokenize
45780
+ });
45781
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
45782
+ }
45783
+ this._invalidateSearcherCache();
45784
+ }
45785
+ add(doc) {
45786
+ if (!isDefined(doc)) {
45787
+ return;
45788
+ }
45789
+ this._docs.push(doc);
45790
+ const record = this._myIndex.add(doc, this._docs.length - 1);
45791
+ if (this._invertedIndex && record) {
45792
+ const analyzer = createAnalyzer({
45793
+ isCaseSensitive: this.options.isCaseSensitive,
45794
+ ignoreDiacritics: this.options.ignoreDiacritics,
45795
+ tokenize: this.options.tokenize
45796
+ });
45797
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
45798
+ }
45799
+ this._invalidateSearcherCache();
45800
+ }
45801
+ remove(predicate = () => false) {
45802
+ const results = [];
45803
+ const indicesToRemove = [];
45804
+ for (let i = 0, len = this._docs.length; i < len; i += 1) {
45805
+ if (predicate(this._docs[i], i)) {
45806
+ results.push(this._docs[i]);
45807
+ indicesToRemove.push(i);
45808
+ }
45809
+ }
45810
+ if (indicesToRemove.length) {
45811
+ if (this._invertedIndex) {
45812
+ removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
45813
+ }
45814
+ const toRemove = new Set(indicesToRemove);
45815
+ this._docs = this._docs.filter((_, i) => !toRemove.has(i));
45816
+ this._myIndex.removeAll(indicesToRemove);
45817
+ this._invalidateSearcherCache();
45818
+ }
45819
+ return results;
45820
+ }
45821
+ removeAt(idx) {
45822
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) {
45823
+ throw new Error(INVALID_DOC_INDEX);
45824
+ }
45825
+ if (this._invertedIndex) {
45826
+ removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
45827
+ }
45828
+ const doc = this._docs.splice(idx, 1)[0];
45829
+ this._myIndex.removeAt(idx);
45830
+ this._invalidateSearcherCache();
45831
+ return doc;
45832
+ }
45833
+ _invalidateSearcherCache() {
45834
+ this._lastQuery = null;
45835
+ this._lastSearcher = null;
45836
+ }
45837
+ getIndex() {
45838
+ return this._myIndex;
45839
+ }
45840
+ search(query, options2) {
45841
+ const {
45842
+ limit = -1
45843
+ } = options2 || {};
45844
+ const {
45845
+ includeMatches,
45846
+ includeScore,
45847
+ shouldSort,
45848
+ sortFn,
45849
+ ignoreFieldNorm
45850
+ } = this.options;
45851
+ if (isString(query) && !query.trim()) {
45852
+ let docs = this._docs.map((item, idx) => ({
45853
+ item,
45854
+ refIndex: idx
45855
+ }));
45856
+ if (isNumber2(limit) && limit > -1) {
45857
+ docs = docs.slice(0, limit);
45858
+ }
45859
+ return docs;
45860
+ }
45861
+ const useHeap = isNumber2(limit) && limit > 0 && isString(query);
45862
+ let results;
45863
+ if (useHeap) {
45864
+ const heap = new MaxHeap(limit);
45865
+ if (isString(this._docs[0])) {
45866
+ this._searchStringList(query, {
45867
+ heap,
45868
+ ignoreFieldNorm
45869
+ });
45870
+ } else {
45871
+ this._searchObjectList(query, {
45872
+ heap,
45873
+ ignoreFieldNorm
45874
+ });
45875
+ }
45876
+ results = heap.extractSorted(sortFn);
45877
+ } else {
45878
+ results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
45879
+ computeScore(results, {
45880
+ ignoreFieldNorm
45881
+ });
45882
+ if (shouldSort) {
45883
+ results.sort(sortFn);
45884
+ }
45885
+ if (isNumber2(limit) && limit > -1) {
45886
+ results = results.slice(0, limit);
45887
+ }
45888
+ }
45889
+ return format(results, this._docs, {
45890
+ includeMatches,
45891
+ includeScore
45892
+ });
45893
+ }
45894
+ _searchStringList(query, {
45895
+ heap,
45896
+ ignoreFieldNorm
45897
+ } = {}) {
45898
+ const searcher = this._getSearcher(query);
45899
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
45900
+ const {
45901
+ records
45902
+ } = this._myIndex;
45903
+ const results = heap ? null : [];
45904
+ records.forEach(({
45905
+ v: text,
45906
+ i: idx,
45907
+ n: norm2
45908
+ }) => {
45909
+ if (!isDefined(text)) {
45910
+ return;
45911
+ }
45912
+ const searchResult = searcher.searchIn(text);
45913
+ if (searchResult.isMatch) {
45914
+ const match = {
45915
+ score: searchResult.score,
45916
+ value: text,
45917
+ norm: norm2,
45918
+ indices: searchResult.indices
45919
+ };
45920
+ if (requireAllTokens) {
45921
+ match.matchedMask = searchResult.matchedMask;
45922
+ match.matchedTerms = searchResult.matchedTerms;
45923
+ match.termCount = searchResult.termCount;
45924
+ }
45925
+ const matches = [match];
45926
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
45927
+ const result = {
45928
+ item: text,
45929
+ idx,
45930
+ matches
45931
+ };
45932
+ if (heap) {
45933
+ result.score = computeScoreSingle(result.matches, {
45934
+ ignoreFieldNorm
45935
+ });
45936
+ if (heap.shouldInsert(result.score)) {
45937
+ heap.insert(result);
45938
+ }
45939
+ } else {
45940
+ results.push(result);
45941
+ }
45942
+ }
45943
+ }
45944
+ });
45945
+ return results;
45946
+ }
45947
+ _searchLogical(query) {
45948
+ const expression = parse2(query, this.options);
45949
+ const evaluate2 = (node, item, idx) => {
45950
+ if (!("children" in node)) {
45951
+ const {
45952
+ keyId,
45953
+ searcher
45954
+ } = node;
45955
+ let matches;
45956
+ if (keyId === null) {
45957
+ matches = [];
45958
+ this._myIndex.keys.forEach((key, keyIndex) => {
45959
+ matches.push(...this._findMatches({
45960
+ key,
45961
+ value: item[keyIndex],
45962
+ searcher
45963
+ }));
45964
+ });
45965
+ } else {
45966
+ matches = this._findMatches({
45967
+ key: this._keyStore.get(keyId),
45968
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
45969
+ searcher
45970
+ });
45971
+ }
45972
+ if (matches && matches.length) {
45973
+ return [{
45974
+ idx,
45975
+ item,
45976
+ matches
45977
+ }];
45978
+ }
45979
+ return [];
45980
+ }
45981
+ const {
45982
+ children,
45983
+ operator
45984
+ } = node;
45985
+ const res = [];
45986
+ for (let i = 0, len = children.length; i < len; i += 1) {
45987
+ const child = children[i];
45988
+ const result = evaluate2(child, item, idx);
45989
+ if (result.length) {
45990
+ res.push(...result);
45991
+ } else if (operator === LogicalOperator.AND) {
45992
+ return [];
45993
+ }
45994
+ }
45995
+ return res;
45996
+ };
45997
+ const records = this._myIndex.records;
45998
+ const resultMap = /* @__PURE__ */ new Map();
45999
+ const results = [];
46000
+ records.forEach(({
46001
+ $: item,
46002
+ i: idx
46003
+ }) => {
46004
+ if (isDefined(item)) {
46005
+ const expResults = evaluate2(expression, item, idx);
46006
+ if (expResults.length) {
46007
+ if (!resultMap.has(idx)) {
46008
+ resultMap.set(idx, {
46009
+ idx,
46010
+ item,
46011
+ matches: []
46012
+ });
46013
+ results.push(resultMap.get(idx));
46014
+ }
46015
+ expResults.forEach(({
46016
+ matches
46017
+ }) => {
46018
+ resultMap.get(idx).matches.push(...matches);
46019
+ });
46020
+ }
46021
+ }
46022
+ });
46023
+ return results;
46024
+ }
46025
+ // When a search involves inverse patterns (e.g. !Syrup), the aggregation
46026
+ // across keys switches from "ANY key matches" to "ALL keys must match."
46027
+ // This is signaled by hasInverse on the SearchResult from ExtendedSearch.
46028
+ //
46029
+ // For mixed patterns like "^hello !Syrup", a key failure is ambiguous —
46030
+ // it could be the positive or inverse term that failed. In that case we
46031
+ // conservatively exclude the item, which is strictly better than the old
46032
+ // behavior of including it. See: https://github.com/krisk/Fuse/issues/712
46033
+ _searchObjectList(query, {
46034
+ heap,
46035
+ ignoreFieldNorm
46036
+ } = {}) {
46037
+ const searcher = this._getSearcher(query);
46038
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
46039
+ const {
46040
+ keys,
46041
+ records
46042
+ } = this._myIndex;
46043
+ const results = heap ? null : [];
46044
+ records.forEach(({
46045
+ $: item,
46046
+ i: idx
46047
+ }) => {
46048
+ if (!isDefined(item)) {
46049
+ return;
46050
+ }
46051
+ const matches = [];
46052
+ let anyKeyFailed = false;
46053
+ let hasInverse = false;
46054
+ keys.forEach((key, keyIndex) => {
46055
+ const keyMatches = this._findMatches({
46056
+ key,
46057
+ value: item[keyIndex],
46058
+ searcher
46059
+ });
46060
+ if (keyMatches.length) {
46061
+ matches.push(...keyMatches);
46062
+ if (keyMatches[0].hasInverse) {
46063
+ hasInverse = true;
46064
+ }
46065
+ } else {
46066
+ anyKeyFailed = true;
46067
+ }
46068
+ });
46069
+ if (hasInverse && anyKeyFailed) {
46070
+ return;
46071
+ }
46072
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
46073
+ const result = {
46074
+ idx,
46075
+ item,
46076
+ matches
46077
+ };
46078
+ if (heap) {
46079
+ result.score = computeScoreSingle(result.matches, {
46080
+ ignoreFieldNorm
46081
+ });
46082
+ if (heap.shouldInsert(result.score)) {
46083
+ heap.insert(result);
46084
+ }
46085
+ } else {
46086
+ results.push(result);
46087
+ }
46088
+ }
46089
+ });
46090
+ return results;
46091
+ }
46092
+ _findMatches({
46093
+ key,
46094
+ value,
46095
+ searcher
46096
+ }) {
46097
+ if (!isDefined(value)) {
46098
+ return [];
46099
+ }
46100
+ const matches = [];
46101
+ if (isArray(value)) {
46102
+ value.forEach(({
46103
+ v: text,
46104
+ i: idx,
46105
+ n: norm2
46106
+ }) => {
46107
+ if (!isDefined(text)) {
46108
+ return;
46109
+ }
46110
+ const searchResult = searcher.searchIn(text);
46111
+ if (searchResult.isMatch) {
46112
+ const match = {
46113
+ score: searchResult.score,
46114
+ key,
46115
+ value: text,
46116
+ idx,
46117
+ norm: norm2,
46118
+ indices: searchResult.indices,
46119
+ hasInverse: searchResult.hasInverse
46120
+ };
46121
+ if (searchResult.termCount !== void 0) {
46122
+ match.matchedMask = searchResult.matchedMask;
46123
+ match.matchedTerms = searchResult.matchedTerms;
46124
+ match.termCount = searchResult.termCount;
46125
+ }
46126
+ matches.push(match);
46127
+ }
46128
+ });
46129
+ } else {
46130
+ const {
46131
+ v: text,
46132
+ n: norm2
46133
+ } = value;
46134
+ const searchResult = searcher.searchIn(text);
46135
+ if (searchResult.isMatch) {
46136
+ const match = {
46137
+ score: searchResult.score,
46138
+ key,
46139
+ value: text,
46140
+ norm: norm2,
46141
+ indices: searchResult.indices,
46142
+ hasInverse: searchResult.hasInverse
46143
+ };
46144
+ if (searchResult.termCount !== void 0) {
46145
+ match.matchedMask = searchResult.matchedMask;
46146
+ match.matchedTerms = searchResult.matchedTerms;
46147
+ match.termCount = searchResult.termCount;
46148
+ }
46149
+ matches.push(match);
46150
+ }
46151
+ }
46152
+ return matches;
46153
+ }
46154
+ // Record-level AND gate for token search (`tokenMatch: 'all'`). Returns true
46155
+ // unless the matched terms across ALL of a record's field/array-element
46156
+ // matches fail to cover every query term. `termCount` is only set by
46157
+ // TokenSearch in 'all' mode, so non-token / 'any' searches always pass.
46158
+ _coversAllTokens(matches) {
46159
+ const termCount = matches.length ? matches[0].termCount : void 0;
46160
+ if (termCount === void 0) {
46161
+ return true;
46162
+ }
46163
+ if (termCount <= MAX_MASK_TERMS) {
46164
+ let coverage2 = 0;
46165
+ for (let i = 0; i < matches.length; i++) {
46166
+ coverage2 |= matches[i].matchedMask || 0;
46167
+ }
46168
+ return coverage2 === 2 ** termCount - 1;
46169
+ }
46170
+ const coverage = /* @__PURE__ */ new Set();
46171
+ for (let i = 0; i < matches.length; i++) {
46172
+ const terms = matches[i].matchedTerms;
46173
+ if (terms) {
46174
+ for (const t12 of terms) {
46175
+ coverage.add(t12);
46176
+ }
46177
+ }
46178
+ }
46179
+ return coverage.size === termCount;
46180
+ }
46181
+ };
46182
+ Fuse.version = "7.4.0";
46183
+ Fuse.createIndex = createIndex;
46184
+ Fuse.parseIndex = parseIndex;
46185
+ Fuse.config = Config;
46186
+ Fuse.match = function(pattern, text, options2) {
46187
+ if (options2 && options2.useTokenSearch) {
46188
+ throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
46189
+ }
46190
+ const searcher = createSearcher(pattern, {
46191
+ ...Config,
46192
+ ...options2
46193
+ });
46194
+ return searcher.searchIn(text);
46195
+ };
46196
+ {
46197
+ Fuse.parseQuery = parse2;
46198
+ }
46199
+ {
46200
+ register(ExtendedSearch);
46201
+ }
46202
+ {
46203
+ register(TokenSearch);
46204
+ }
46205
+ Fuse.use = function(...plugins) {
46206
+ plugins.forEach((plugin) => register(plugin));
46207
+ };
44162
46208
  var sides = ["top", "right", "bottom", "left"];
44163
46209
  var min = Math.min;
44164
46210
  var max = Math.max;
@@ -47057,10 +49103,10 @@ var SelectTrigger = React35.forwardRef(
47057
49103
  const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
47058
49104
  const getItems = useCollection(__scopeSelect);
47059
49105
  const pointerTypeRef = React35.useRef("touch");
47060
- const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
49106
+ const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search2) => {
47061
49107
  const enabledItems = getItems().filter((item) => !item.disabled);
47062
49108
  const currentItem = enabledItems.find((item) => item.value === context.value);
47063
- const nextItem = findNextItem(enabledItems, search, currentItem);
49109
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47064
49110
  if (nextItem !== void 0) {
47065
49111
  context.onValueChange(nextItem.value);
47066
49112
  }
@@ -47287,10 +49333,10 @@ var SelectContentImpl = React35.forwardRef(
47287
49333
  window.removeEventListener("resize", close);
47288
49334
  };
47289
49335
  }, [onOpenChange]);
47290
- const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
49336
+ const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search2) => {
47291
49337
  const enabledItems = getItems().filter((item) => !item.disabled);
47292
49338
  const currentItem = enabledItems.find((item) => item.ref.current === document.activeElement);
47293
- const nextItem = findNextItem(enabledItems, search, currentItem);
49339
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47294
49340
  if (nextItem) {
47295
49341
  setTimeout(() => nextItem.ref.current.focus());
47296
49342
  }
@@ -48019,13 +50065,13 @@ function useTypeaheadSearch(onSearchChange) {
48019
50065
  const timerRef = React35.useRef(0);
48020
50066
  const handleTypeaheadSearch = React35.useCallback(
48021
50067
  (key) => {
48022
- const search = searchRef.current + key;
48023
- handleSearchChange(search);
50068
+ const search2 = searchRef.current + key;
50069
+ handleSearchChange(search2);
48024
50070
  (function updateSearch(value) {
48025
50071
  searchRef.current = value;
48026
50072
  window.clearTimeout(timerRef.current);
48027
50073
  if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
48028
- })(search);
50074
+ })(search2);
48029
50075
  },
48030
50076
  [handleSearchChange]
48031
50077
  );
@@ -48038,9 +50084,9 @@ function useTypeaheadSearch(onSearchChange) {
48038
50084
  }, []);
48039
50085
  return [searchRef, handleTypeaheadSearch, resetTypeahead];
48040
50086
  }
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;
50087
+ function findNextItem(items, search2, currentItem) {
50088
+ const isRepeated = search2.length > 1 && Array.from(search2).every((char) => char === search2[0]);
50089
+ const normalizedSearch = isRepeated ? search2[0] : search2;
48044
50090
  const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
48045
50091
  let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
48046
50092
  const excludeCurrentItem = normalizedSearch.length === 1;
@@ -49456,7 +51502,7 @@ function interpolate(template, params) {
49456
51502
  }
49457
51503
  var DEPOSIT_CONFIRM_DELAY_MS = 5e3;
49458
51504
  var POLL_INTERVAL_MS = 2500;
49459
- var POLL_ENDPOINT_INTERVAL_MS = 3e3;
51505
+ var POLL_ENDPOINT_INTERVAL_MS = 5e3;
49460
51506
  var CUTOFF_BUFFER_MS = 6e4;
49461
51507
  function useDepositPolling({
49462
51508
  userId,
@@ -53098,6 +55144,53 @@ function CashAppButton({
53098
55144
  }
53099
55145
  );
53100
55146
  }
55147
+ var _store = null;
55148
+ function getEip6963Store() {
55149
+ if (typeof window === "undefined") return null;
55150
+ if (!_store) {
55151
+ _store = createStore();
55152
+ }
55153
+ return _store;
55154
+ }
55155
+ var RDNS_TO_WALLET_ID = {
55156
+ "io.metamask": "metamask",
55157
+ "io.metamask.flask": "metamask",
55158
+ "io.metamask.mmi": "metamask",
55159
+ "app.phantom": "phantom",
55160
+ "com.coinbase.wallet": "coinbase",
55161
+ "com.okex.wallet": "okx",
55162
+ "io.rabby": "rabby",
55163
+ "com.trustwallet.app": "trust",
55164
+ "me.rainbow": "rainbow"
55165
+ };
55166
+ function rdnsToWalletId(rdns) {
55167
+ if (RDNS_TO_WALLET_ID[rdns]) return RDNS_TO_WALLET_ID[rdns];
55168
+ if (rdns.includes("metamask")) return "metamask";
55169
+ if (rdns.includes("phantom")) return "phantom";
55170
+ if (rdns.includes("coinbase")) return "coinbase";
55171
+ if (rdns.includes("okx") || rdns.includes("okex")) return "okx";
55172
+ if (rdns.includes("rabby")) return "rabby";
55173
+ if (rdns.includes("trust")) return "trust";
55174
+ if (rdns.includes("rainbow")) return "rainbow";
55175
+ return "unknown";
55176
+ }
55177
+ function getEip6963Providers() {
55178
+ const store = getEip6963Store();
55179
+ if (!store) return [];
55180
+ return store.getProviders().map((detail) => ({
55181
+ walletId: rdnsToWalletId(detail.info.rdns),
55182
+ provider: detail.provider,
55183
+ info: detail.info
55184
+ }));
55185
+ }
55186
+ function findProviderByWalletId(walletId) {
55187
+ return getEip6963Providers().find((p) => p.walletId === walletId);
55188
+ }
55189
+ function collectAllEip6963EthProviders() {
55190
+ const store = getEip6963Store();
55191
+ if (!store) return [];
55192
+ return store.getProviders().map((d) => d.provider);
55193
+ }
53101
55194
  var SOLANA_DISCONNECT_TYPES = [
53102
55195
  "phantom-solana",
53103
55196
  "solflare",
@@ -53137,8 +55230,9 @@ function collectEthereumProvidersForDisconnect(win) {
53137
55230
  out.push(p);
53138
55231
  }
53139
55232
  };
53140
- const list = anyWin.__eip6963Providers || [];
53141
- for (const d of list) add(d.provider);
55233
+ for (const p of collectAllEip6963EthProviders()) {
55234
+ add(p);
55235
+ }
53142
55236
  add(win.ethereum);
53143
55237
  add(
53144
55238
  win.phantom?.ethereum
@@ -55144,30 +57238,13 @@ function BrowserWalletButton({
55144
57238
  }, []);
55145
57239
  const [eip6963ProviderCount, setEip6963ProviderCount] = React242.useState(0);
55146
57240
  React242.useEffect(() => {
55147
- if (typeof window === "undefined") return;
55148
- const anyWin = window;
55149
- if (!anyWin.__eip6963Providers) {
55150
- anyWin.__eip6963Providers = [];
55151
- }
55152
- const handleAnnouncement = (event) => {
55153
- const { detail } = event;
55154
- if (!detail?.info || !detail?.provider) return;
55155
- const exists = anyWin.__eip6963Providers.some(
55156
- (p) => p.info.uuid === detail.info.uuid
55157
- );
55158
- if (!exists) {
55159
- anyWin.__eip6963Providers.push(detail);
55160
- setEip6963ProviderCount(anyWin.__eip6963Providers.length);
55161
- }
55162
- };
55163
- window.addEventListener("eip6963:announceProvider", handleAnnouncement);
55164
- window.dispatchEvent(new Event("eip6963:requestProvider"));
55165
- return () => {
55166
- window.removeEventListener(
55167
- "eip6963:announceProvider",
55168
- handleAnnouncement
55169
- );
55170
- };
57241
+ const store = getEip6963Store();
57242
+ if (!store) return;
57243
+ setEip6963ProviderCount(store.getProviders().length);
57244
+ const unsubscribe = store.subscribe((providers) => {
57245
+ setEip6963ProviderCount(providers.length);
57246
+ });
57247
+ return unsubscribe;
55171
57248
  }, []);
55172
57249
  React242.useEffect(() => {
55173
57250
  if (!wallet || !publishableKey) {
@@ -55226,7 +57303,7 @@ function BrowserWalletButton({
55226
57303
  return;
55227
57304
  }
55228
57305
  if (!chainType || chainType === "solana") {
55229
- const anyWin2 = win;
57306
+ const anyWin = win;
55230
57307
  const trySilentSolana = async (provider, type, name, icon) => {
55231
57308
  if (!provider) return false;
55232
57309
  if (provider.isConnected && provider.publicKey) {
@@ -55265,21 +57342,21 @@ function BrowserWalletButton({
55265
57342
  ))
55266
57343
  return;
55267
57344
  if (await trySilentSolana(
55268
- anyWin2.solflare,
57345
+ anyWin.solflare,
55269
57346
  "solflare",
55270
57347
  "Solflare",
55271
57348
  "solflare"
55272
57349
  ))
55273
57350
  return;
55274
57351
  if (await trySilentSolana(
55275
- anyWin2.backpack,
57352
+ anyWin.backpack,
55276
57353
  "backpack",
55277
57354
  "Backpack",
55278
57355
  "backpack"
55279
57356
  ))
55280
57357
  return;
55281
57358
  if (await trySilentSolana(
55282
- anyWin2.glow,
57359
+ anyWin.glow,
55283
57360
  "glow",
55284
57361
  "Glow",
55285
57362
  "glow"
@@ -55287,19 +57364,14 @@ function BrowserWalletButton({
55287
57364
  return;
55288
57365
  }
55289
57366
  if (!chainType || chainType === "ethereum") {
55290
- const anyWin2 = win;
57367
+ const anyWin = win;
55291
57368
  const allProviders = [];
55292
- const eip6963Providers = anyWin2.__eip6963Providers || [];
55293
- for (const { info, provider } of eip6963Providers) {
55294
- let walletId = "default";
55295
- if (info.rdns.includes("metamask")) walletId = "metamask";
55296
- else if (info.rdns.includes("phantom")) walletId = "phantom";
55297
- else if (info.rdns.includes("coinbase")) walletId = "coinbase";
55298
- else if (info.rdns.includes("okx")) walletId = "okx";
55299
- else if (info.rdns.includes("rabby")) walletId = "rabby";
55300
- else if (info.rdns.includes("trust")) walletId = "trust";
55301
- else if (info.rdns.includes("rainbow")) walletId = "rainbow";
55302
- allProviders.push({ provider, walletId });
57369
+ const eip6963 = getEip6963Providers();
57370
+ for (const { provider, walletId } of eip6963) {
57371
+ allProviders.push({
57372
+ provider,
57373
+ walletId: walletId === "unknown" ? "default" : walletId
57374
+ });
55303
57375
  }
55304
57376
  if (allProviders.length === 0) {
55305
57377
  if (win.phantom?.ethereum) {
@@ -55308,15 +57380,15 @@ function BrowserWalletButton({
55308
57380
  walletId: "phantom"
55309
57381
  });
55310
57382
  }
55311
- if (anyWin2.okxwallet) {
57383
+ if (anyWin.okxwallet) {
55312
57384
  allProviders.push({
55313
- provider: anyWin2.okxwallet,
57385
+ provider: anyWin.okxwallet,
55314
57386
  walletId: "okx"
55315
57387
  });
55316
57388
  }
55317
- if (anyWin2.coinbaseWalletExtension) {
57389
+ if (anyWin.coinbaseWalletExtension) {
55318
57390
  allProviders.push({
55319
- provider: anyWin2.coinbaseWalletExtension,
57391
+ provider: anyWin.coinbaseWalletExtension,
55320
57392
  walletId: "coinbase"
55321
57393
  });
55322
57394
  }
@@ -55340,7 +57412,7 @@ function BrowserWalletButton({
55340
57412
  });
55341
57413
  if (!accounts || accounts.length === 0) continue;
55342
57414
  const address = accounts[0];
55343
- const resolved = identifyEthWallet(provider, anyWin2, walletId);
57415
+ const resolved = identifyEthWallet(provider, anyWin, walletId);
55344
57416
  if (mounted) {
55345
57417
  setWallet({ ...resolved, address });
55346
57418
  setIsLoading(false);
@@ -55382,15 +57454,11 @@ function BrowserWalletButton({
55382
57454
  solanaProvider.on("disconnect", handleDisconnect);
55383
57455
  solanaProvider.on("accountChanged", handleAccountsChanged);
55384
57456
  }
55385
- const anyWin = window;
55386
57457
  const ethProviders = [];
55387
- if (anyWin.__eip6963Providers) {
55388
- for (const {
55389
- provider
55390
- } of anyWin.__eip6963Providers) {
55391
- if (provider && !ethProviders.includes(provider)) {
55392
- ethProviders.push(provider);
55393
- }
57458
+ for (const { provider } of getEip6963Providers()) {
57459
+ const p = provider;
57460
+ if (p && !ethProviders.includes(p)) {
57461
+ ethProviders.push(p);
55394
57462
  }
55395
57463
  }
55396
57464
  if (window.ethereum && !ethProviders.includes(window.ethereum)) {
@@ -55492,7 +57560,7 @@ function BrowserWalletButton({
55492
57560
  if (isLoading) {
55493
57561
  return null;
55494
57562
  }
55495
- const hasWalletExtension = (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom) ? true : (!chainType || chainType === "ethereum") && (window.phantom?.ethereum || window.ethereum) ? true : false;
57563
+ const hasWalletExtension = (!chainType || chainType === "ethereum") && getEip6963Providers().length > 0 || (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom) || (!chainType || chainType === "ethereum") && (window.phantom?.ethereum || window.ethereum);
55496
57564
  if (!onConnectClick && !wallet && !hasWalletExtension) {
55497
57565
  return null;
55498
57566
  }
@@ -58067,13 +60135,25 @@ function TokenSelectorSheet({
58067
60135
  });
58068
60136
  setRecentTokens(updated);
58069
60137
  };
60138
+ const fuse = (0, import_react21.useMemo)(
60139
+ () => new Fuse(allOptions, {
60140
+ keys: [
60141
+ { name: "token.symbol", weight: 2 },
60142
+ { name: "token.name", weight: 1 },
60143
+ { name: "chain.chain_name", weight: 0.5 }
60144
+ ],
60145
+ threshold: 0.2,
60146
+ ignoreLocation: true,
60147
+ minMatchCharLength: 2
60148
+ }),
60149
+ [allOptions]
60150
+ );
58070
60151
  const filteredOptions = (0, import_react21.useMemo)(() => {
58071
60152
  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]);
60153
+ const query = searchQuery.trim();
60154
+ const results = fuse.search(query);
60155
+ return results.map((r2) => r2.item);
60156
+ }, [fuse, allOptions, searchQuery]);
58077
60157
  const isCommonToken = (symbol, chainType, chainId) => {
58078
60158
  return COMMON_TOKENS.some(
58079
60159
  (ct) => ct.symbol === symbol && ct.chainType === chainType && ct.chainId === chainId
@@ -60988,15 +63068,10 @@ var WALLET_DEFINITIONS = [
60988
63068
  { id: "backpack", name: "Backpack", networks: ["solana"], installUrl: "https://backpack.app/" },
60989
63069
  { id: "glow", name: "Glow", networks: ["solana"], installUrl: "https://glow.app/" }
60990
63070
  ];
60991
- function getWalletProviders() {
63071
+ function getSolanaProviders() {
60992
63072
  if (typeof window === "undefined") return {};
60993
63073
  const win = window;
60994
63074
  return {
60995
- ethereum: win.ethereum,
60996
- phantomEthereum: win.phantom?.ethereum,
60997
- coinbaseEthereum: win.coinbaseWalletExtension,
60998
- trustEthereum: win.trustwallet?.ethereum,
60999
- okxEthereum: win.okxwallet,
61000
63075
  phantomSolana: win.phantom?.solana,
61001
63076
  solflare: win.solflare,
61002
63077
  backpack: win.backpack,
@@ -61004,37 +63079,71 @@ function getWalletProviders() {
61004
63079
  coinbaseSolana: win.coinbaseSolana || win.coinbaseWalletExtension?.solana
61005
63080
  };
61006
63081
  }
63082
+ function getLegacyEvmProviders() {
63083
+ if (typeof window === "undefined") return {};
63084
+ const win = window;
63085
+ return {
63086
+ ethereum: win.ethereum,
63087
+ phantomEthereum: win.phantom?.ethereum,
63088
+ coinbaseEthereum: win.coinbaseWalletExtension,
63089
+ trustEthereum: win.trustwallet?.ethereum,
63090
+ okxEthereum: win.okxwallet
63091
+ };
63092
+ }
61007
63093
  function detectAvailableWallets(filterChainType) {
61008
- const providers = getWalletProviders();
63094
+ const solProviders = getSolanaProviders();
63095
+ const legacyEvm = getLegacyEvmProviders();
63096
+ const eip6963List = getEip6963Providers();
61009
63097
  const win = typeof window !== "undefined" ? window : null;
63098
+ const hasEip6963 = (walletId) => eip6963List.some((d) => {
63099
+ const rdns = d.info?.rdns || "";
63100
+ switch (walletId) {
63101
+ case "metamask":
63102
+ return rdns.includes("metamask");
63103
+ case "phantom":
63104
+ return rdns.includes("phantom");
63105
+ case "coinbase":
63106
+ return rdns.includes("coinbase");
63107
+ case "trust":
63108
+ return rdns.includes("trust");
63109
+ case "rainbow":
63110
+ return rdns.includes("rainbow");
63111
+ case "rabby":
63112
+ return rdns.includes("rabby");
63113
+ case "okx":
63114
+ return rdns.includes("okx") || rdns.includes("okex");
63115
+ default:
63116
+ return false;
63117
+ }
63118
+ });
61010
63119
  return WALLET_DEFINITIONS.filter((w) => !filterChainType || w.networks.includes(filterChainType)).map((wallet) => {
61011
63120
  let isInstalled = false;
61012
63121
  const detectedNetworks = [];
61013
63122
  switch (wallet.id) {
61014
63123
  case "metamask":
61015
- isInstalled = !!(providers.ethereum?.isMetaMask && !providers.ethereum?.isPhantom && !providers.ethereum?.isRabby && !providers.ethereum?.isOkxWallet);
63124
+ isInstalled = hasEip6963("metamask") || !!(legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom && !legacyEvm.ethereum?.isRabby && !legacyEvm.ethereum?.isOkxWallet);
61016
63125
  if (isInstalled) detectedNetworks.push("ethereum");
61017
63126
  break;
61018
63127
  case "phantom":
61019
- if (providers.phantomSolana?.isPhantom) {
63128
+ if (solProviders.phantomSolana?.isPhantom) {
61020
63129
  isInstalled = true;
61021
63130
  detectedNetworks.push("solana");
61022
63131
  }
61023
- if (providers.phantomEthereum?.isPhantom) {
63132
+ if (hasEip6963("phantom") || legacyEvm.phantomEthereum?.isPhantom) {
61024
63133
  isInstalled = true;
61025
63134
  detectedNetworks.push("ethereum");
61026
63135
  }
61027
63136
  break;
61028
63137
  case "coinbase":
61029
- if (providers.coinbaseEthereum || providers.ethereum?.isCoinbaseWallet) {
63138
+ if (hasEip6963("coinbase") || legacyEvm.coinbaseEthereum || legacyEvm.ethereum?.isCoinbaseWallet) {
61030
63139
  isInstalled = true;
61031
63140
  detectedNetworks.push("ethereum");
61032
63141
  }
61033
- if (providers.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
63142
+ if (solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
61034
63143
  if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
61035
63144
  break;
61036
63145
  case "trust":
61037
- if (providers.trustEthereum || providers.ethereum?.isTrust || win?.trustwallet) {
63146
+ if (hasEip6963("trust") || legacyEvm.trustEthereum || legacyEvm.ethereum?.isTrust || win?.trustwallet) {
61038
63147
  isInstalled = true;
61039
63148
  detectedNetworks.push("ethereum");
61040
63149
  }
@@ -61042,27 +63151,27 @@ function detectAvailableWallets(filterChainType) {
61042
63151
  if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
61043
63152
  break;
61044
63153
  case "rainbow":
61045
- isInstalled = !!providers.ethereum?.isRainbow;
63154
+ isInstalled = hasEip6963("rainbow") || !!legacyEvm.ethereum?.isRainbow;
61046
63155
  if (isInstalled) detectedNetworks.push("ethereum");
61047
63156
  break;
61048
63157
  case "rabby":
61049
- isInstalled = !!providers.ethereum?.isRabby;
63158
+ isInstalled = hasEip6963("rabby") || !!legacyEvm.ethereum?.isRabby;
61050
63159
  if (isInstalled) detectedNetworks.push("ethereum");
61051
63160
  break;
61052
63161
  case "okx":
61053
- isInstalled = !!(providers.okxEthereum || providers.ethereum?.isOkxWallet);
63162
+ isInstalled = hasEip6963("okx") || !!(legacyEvm.okxEthereum || legacyEvm.ethereum?.isOkxWallet);
61054
63163
  if (isInstalled) detectedNetworks.push("ethereum");
61055
63164
  break;
61056
63165
  case "solflare":
61057
- isInstalled = !!providers.solflare?.isSolflare;
63166
+ isInstalled = !!solProviders.solflare?.isSolflare;
61058
63167
  if (isInstalled) detectedNetworks.push("solana");
61059
63168
  break;
61060
63169
  case "backpack":
61061
- isInstalled = !!(providers.backpack?.isBackpack || win?.backpack);
63170
+ isInstalled = !!(solProviders.backpack?.isBackpack || win?.backpack);
61062
63171
  if (isInstalled) detectedNetworks.push("solana");
61063
63172
  break;
61064
63173
  case "glow":
61065
- isInstalled = !!(providers.glow?.isGlow || win?.glow);
63174
+ isInstalled = !!(solProviders.glow?.isGlow || win?.glow);
61066
63175
  if (isInstalled) detectedNetworks.push("solana");
61067
63176
  break;
61068
63177
  }
@@ -61117,7 +63226,16 @@ function WalletConnect({
61117
63226
  const [connectingNetwork, setConnectingNetwork] = React292.useState(null);
61118
63227
  const [walletError, setWalletError] = React292.useState(null);
61119
63228
  const [isWalletConnecting, setIsWalletConnecting] = React292.useState(false);
61120
- const availableWallets = React292.useMemo(() => detectAvailableWallets(), []);
63229
+ const [eip6963ProviderCount, setEip6963ProviderCount] = React292.useState(0);
63230
+ React292.useEffect(() => {
63231
+ const store = getEip6963Store();
63232
+ if (!store) return;
63233
+ setEip6963ProviderCount(store.getProviders().length);
63234
+ return store.subscribe((providers) => {
63235
+ setEip6963ProviderCount(providers.length);
63236
+ });
63237
+ }, []);
63238
+ const availableWallets = React292.useMemo(() => detectAvailableWallets(), [eip6963ProviderCount]);
61121
63239
  const [balances, setBalances] = React292.useState([]);
61122
63240
  const [isLoading, setIsLoading] = React292.useState(false);
61123
63241
  const [selectedBalance, setSelectedBalance] = React292.useState(null);
@@ -61176,59 +63294,72 @@ function WalletConnect({
61176
63294
  setWalletError(null);
61177
63295
  setIsWalletConnecting(true);
61178
63296
  try {
61179
- const providers = getWalletProviders();
61180
63297
  const win = typeof window !== "undefined" ? window : null;
61181
63298
  let connectedInfo;
61182
63299
  if (network === "ethereum") {
61183
- let provider;
61184
- switch (wallet.id) {
61185
- case "metamask":
61186
- if (providers.ethereum?.isMetaMask && !providers.ethereum?.isPhantom) provider = providers.ethereum;
61187
- break;
61188
- case "phantom":
61189
- provider = providers.phantomEthereum;
61190
- break;
61191
- case "coinbase":
61192
- provider = providers.coinbaseEthereum || (providers.ethereum?.isCoinbaseWallet ? providers.ethereum : void 0);
61193
- break;
61194
- case "trust":
61195
- provider = providers.trustEthereum || (providers.ethereum?.isTrust ? providers.ethereum : void 0);
61196
- break;
61197
- case "rainbow":
61198
- if (providers.ethereum?.isRainbow) provider = providers.ethereum;
61199
- break;
61200
- case "rabby":
61201
- if (providers.ethereum?.isRabby) provider = providers.ethereum;
61202
- break;
61203
- case "okx":
61204
- provider = providers.okxEthereum || (providers.ethereum?.isOkxWallet ? providers.ethereum : void 0);
61205
- break;
61206
- default:
61207
- provider = providers.ethereum;
63300
+ const eip6963Match = findProviderByWalletId(wallet.id);
63301
+ let provider = eip6963Match?.provider;
63302
+ if (!provider) {
63303
+ const legacyEvm = getLegacyEvmProviders();
63304
+ switch (wallet.id) {
63305
+ case "metamask":
63306
+ if (legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom) provider = legacyEvm.ethereum;
63307
+ break;
63308
+ case "phantom":
63309
+ provider = legacyEvm.phantomEthereum;
63310
+ break;
63311
+ case "coinbase":
63312
+ provider = legacyEvm.coinbaseEthereum || (legacyEvm.ethereum?.isCoinbaseWallet ? legacyEvm.ethereum : void 0);
63313
+ break;
63314
+ case "trust":
63315
+ provider = legacyEvm.trustEthereum || (legacyEvm.ethereum?.isTrust ? legacyEvm.ethereum : void 0);
63316
+ break;
63317
+ case "rainbow":
63318
+ if (legacyEvm.ethereum?.isRainbow) provider = legacyEvm.ethereum;
63319
+ break;
63320
+ case "rabby":
63321
+ if (legacyEvm.ethereum?.isRabby) provider = legacyEvm.ethereum;
63322
+ break;
63323
+ case "okx":
63324
+ provider = legacyEvm.okxEthereum || (legacyEvm.ethereum?.isOkxWallet ? legacyEvm.ethereum : void 0);
63325
+ break;
63326
+ default:
63327
+ provider = legacyEvm.ethereum;
63328
+ }
61208
63329
  }
61209
63330
  if (!provider) throw new Error(`${wallet.name} wallet not found. Please install it.`);
61210
63331
  const accounts = await provider.request({ method: "eth_requestAccounts" });
61211
63332
  if (!accounts?.length) throw new Error("No accounts returned from wallet");
61212
63333
  setUserDisconnectedWallet(false);
61213
- const walletType = wallet.id === "phantom" ? "phantom-ethereum" : wallet.id === "coinbase" ? "coinbase" : "metamask";
63334
+ const walletIdToType = {
63335
+ phantom: "phantom-ethereum",
63336
+ coinbase: "coinbase",
63337
+ trust: "trust",
63338
+ rainbow: "rainbow",
63339
+ rabby: "rabby",
63340
+ okx: "okx",
63341
+ metamask: "metamask"
63342
+ };
63343
+ const walletType = walletIdToType[wallet.id] || "metamask";
61214
63344
  connectedInfo = { type: walletType, name: wallet.name, address: accounts[0], icon: wallet.id };
61215
63345
  } else {
63346
+ const solProviders = getSolanaProviders();
61216
63347
  let provider;
61217
63348
  switch (wallet.id) {
61218
63349
  case "phantom":
61219
- provider = providers.phantomSolana;
63350
+ provider = solProviders.phantomSolana;
61220
63351
  break;
61221
63352
  case "solflare":
61222
- provider = providers.solflare;
63353
+ provider = solProviders.solflare;
61223
63354
  break;
61224
63355
  case "backpack":
61225
- provider = providers.backpack || win?.backpack;
63356
+ provider = solProviders.backpack || win?.backpack;
61226
63357
  break;
61227
63358
  case "glow":
61228
- provider = providers.glow || win?.glow;
63359
+ provider = solProviders.glow || win?.glow;
61229
63360
  break;
61230
63361
  case "coinbase":
61231
- provider = providers.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
63362
+ provider = solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
61232
63363
  break;
61233
63364
  case "trust":
61234
63365
  provider = win?.trustwallet?.solana;
@@ -61474,10 +63605,15 @@ function WalletConnect({
61474
63605
  };
61475
63606
  const sendEthereumTransaction = async (token, amountStr) => {
61476
63607
  if (!recipientAddress || !/^0x[a-fA-F0-9]{40}$/.test(recipientAddress)) throw new Error(`Invalid recipient address.`);
61477
- let provider;
61478
- if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
61479
- else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
61480
- else provider = window.ethereum;
63608
+ const walletIdMap = { "phantom-ethereum": "phantom", coinbase: "coinbase", trust: "trust", okx: "okx", rainbow: "rainbow", rabby: "rabby", metamask: "metamask" };
63609
+ const lookupId = walletIdMap[walletInfo.type] || walletInfo.type;
63610
+ const eip6963Match = findProviderByWalletId(lookupId);
63611
+ let provider = eip6963Match?.provider;
63612
+ if (!provider) {
63613
+ if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
63614
+ else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
63615
+ else provider = window.ethereum;
63616
+ }
61481
63617
  if (!provider) throw new Error("Ethereum wallet not found");
61482
63618
  const currentChainIdHex = await provider.request({ method: "eth_chainId", params: [] });
61483
63619
  if (parseInt(currentChainIdHex, 16).toString() !== token.chain_id) {
@@ -61716,6 +63852,7 @@ function DepositModal({
61716
63852
  enableConnectWallet = false,
61717
63853
  browserWalletAmountQuickSelect = "percentage",
61718
63854
  enablePayWithExchange,
63855
+ enableFiatOnramp,
61719
63856
  enableConnectExchange = false,
61720
63857
  enableCashApp = false,
61721
63858
  hideDepositFlowInfo = false,
@@ -61737,8 +63874,9 @@ function DepositModal({
61737
63874
  const s = initialScreen ?? "main";
61738
63875
  if (s === "tracker" && hideDepositTracker) return "main";
61739
63876
  if (s === "cashapp" && !enableCashApp) return "main";
63877
+ if (s === "card" && enableFiatOnramp === false) return "main";
61740
63878
  return s;
61741
- }, [initialScreen, hideDepositTracker, enableCashApp]);
63879
+ }, [initialScreen, hideDepositTracker, enableCashApp, enableFiatOnramp]);
61742
63880
  const [containerEl, setContainerEl] = (0, import_react3.useState)(null);
61743
63881
  const containerCallbackRef = (0, import_react3.useCallback)((el) => {
61744
63882
  setContainerEl(el);
@@ -61854,6 +63992,13 @@ function DepositModal({
61854
63992
  enabled: open
61855
63993
  });
61856
63994
  const showPayWithExchange = enablePayWithExchange ?? projectConfig?.pay_with_exchange?.enabled ?? true;
63995
+ const showFiatOnramp = enableFiatOnramp ?? projectConfig?.fiat_onramp?.enabled ?? true;
63996
+ (0, import_react3.useEffect)(() => {
63997
+ if (view === "card" && !showFiatOnramp) {
63998
+ setView("main");
63999
+ setCardView("amount");
64000
+ }
64001
+ }, [view, showFiatOnramp]);
61857
64002
  const { exchanges, isLoading: exchangesLoading } = useExchanges({
61858
64003
  publishableKey,
61859
64004
  enabled: open && showPayWithExchange
@@ -62163,7 +64308,7 @@ function DepositModal({
62163
64308
  featuredWallets: projectConfig?.connect_wallet?.wallets
62164
64309
  }
62165
64310
  ),
62166
- /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
64311
+ showFiatOnramp && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
62167
64312
  DepositWithCardButton,
62168
64313
  {
62169
64314
  onClick: () => setView("card"),
@@ -63302,7 +65447,7 @@ function useExecutions(userId, publishableKey, options2) {
63302
65447
  });
63303
65448
  }
63304
65449
  var POLL_INTERVAL_MS3 = 2500;
63305
- var POLL_ENDPOINT_INTERVAL_MS2 = 3e3;
65450
+ var POLL_ENDPOINT_INTERVAL_MS2 = 5e3;
63306
65451
  var CUTOFF_BUFFER_MS2 = 6e4;
63307
65452
  function useWithdrawPolling({
63308
65453
  userId,
@@ -65162,6 +67307,7 @@ function UnifoldProvider2({
65162
67307
  transferInputVariant: config?.transferInputVariant,
65163
67308
  enableConnectWallet: config?.enableConnectWallet,
65164
67309
  enablePayWithExchange: config?.enablePayWithExchange,
67310
+ enableFiatOnramp: config?.enableFiatOnramp,
65165
67311
  enableConnectExchange: config?.enableConnectExchange,
65166
67312
  enableCashApp: config?.enableCashApp,
65167
67313
  onDepositSuccess: handleDepositSuccess,
@@ -65281,7 +67427,11 @@ function createUnifold(publishableKey, config) {
65281
67427
  return resolvedHandle.beginWithdraw(withdrawConfig);
65282
67428
  },
65283
67429
  closeWithdraw: () => resolvedHandle?.closeWithdraw(),
65284
- destroy: cleanup
67430
+ destroy: () => {
67431
+ resolvedHandle?.closeDeposit();
67432
+ resolvedHandle?.closeWithdraw();
67433
+ cleanup();
67434
+ }
65285
67435
  };
65286
67436
  const refCallback = (handle) => {
65287
67437
  if (handle) {