@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.mjs CHANGED
@@ -3242,11 +3242,11 @@ var require_react_dom_client_production = __commonJS({
3242
3242
  valueField
3243
3243
  );
3244
3244
  if (!node.hasOwnProperty(valueField) && "undefined" !== typeof descriptor && "function" === typeof descriptor.get && "function" === typeof descriptor.set) {
3245
- var get = descriptor.get, set = descriptor.set;
3245
+ var get2 = descriptor.get, set = descriptor.set;
3246
3246
  Object.defineProperty(node, valueField, {
3247
3247
  configurable: true,
3248
3248
  get: function() {
3249
- return get.call(this);
3249
+ return get2.call(this);
3250
3250
  },
3251
3251
  set: function(value) {
3252
3252
  currentValue = "" + value;
@@ -15396,11 +15396,11 @@ var require_react_dom_client_development = __commonJS({
15396
15396
  valueField
15397
15397
  );
15398
15398
  if (!node.hasOwnProperty(valueField) && "undefined" !== typeof descriptor && "function" === typeof descriptor.get && "function" === typeof descriptor.set) {
15399
- var get = descriptor.get, set = descriptor.set;
15399
+ var get2 = descriptor.get, set = descriptor.set;
15400
15400
  Object.defineProperty(node, valueField, {
15401
15401
  configurable: true,
15402
15402
  get: function() {
15403
- return get.call(this);
15403
+ return get2.call(this);
15404
15404
  },
15405
15405
  set: function(value) {
15406
15406
  checkFormFieldValueStringCoercion(value);
@@ -43232,12 +43232,12 @@ var ExecutionStatus = /* @__PURE__ */ ((ExecutionStatus2) => {
43232
43232
  ExecutionStatus2["WAITING"] = "waiting";
43233
43233
  return ExecutionStatus2;
43234
43234
  })(ExecutionStatus || {});
43235
- async function queryExecutions(externalUserId, publishableKey, actionType) {
43235
+ async function queryExecutions(externalUserId, publishableKey, actionType = "deposit") {
43236
43236
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
43237
43237
  validatePublishableKey(pk);
43238
43238
  const body = {
43239
43239
  external_user_id: externalUserId,
43240
- ...actionType ? { action_type: actionType } : {}
43240
+ action_type: actionType
43241
43241
  };
43242
43242
  const response = await fetch(
43243
43243
  `${API_BASE_URL}/v1/public/direct_executions/query`,
@@ -44146,6 +44146,2052 @@ var cva = (base, config) => (props) => {
44146
44146
  }, []);
44147
44147
  return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
44148
44148
  };
44149
+ function requestProviders(listener) {
44150
+ if (typeof window === "undefined")
44151
+ return;
44152
+ const handler = (event) => listener(event.detail);
44153
+ window.addEventListener("eip6963:announceProvider", handler);
44154
+ window.dispatchEvent(new CustomEvent("eip6963:requestProvider"));
44155
+ return () => window.removeEventListener("eip6963:announceProvider", handler);
44156
+ }
44157
+ function createStore() {
44158
+ const listeners = /* @__PURE__ */ new Set();
44159
+ let providerDetails = [];
44160
+ const request = () => requestProviders((providerDetail) => {
44161
+ if (providerDetails.some(({ info }) => info.uuid === providerDetail.info.uuid))
44162
+ return;
44163
+ providerDetails = [...providerDetails, providerDetail];
44164
+ listeners.forEach((listener) => listener(providerDetails, { added: [providerDetail] }));
44165
+ });
44166
+ let unwatch = request();
44167
+ return {
44168
+ _listeners() {
44169
+ return listeners;
44170
+ },
44171
+ clear() {
44172
+ listeners.forEach((listener) => listener([], { removed: [...providerDetails] }));
44173
+ providerDetails = [];
44174
+ },
44175
+ destroy() {
44176
+ this.clear();
44177
+ listeners.clear();
44178
+ unwatch?.();
44179
+ },
44180
+ findProvider({ rdns }) {
44181
+ return providerDetails.find((providerDetail) => providerDetail.info.rdns === rdns);
44182
+ },
44183
+ getProviders() {
44184
+ return providerDetails;
44185
+ },
44186
+ reset() {
44187
+ this.clear();
44188
+ unwatch?.();
44189
+ unwatch = request();
44190
+ },
44191
+ subscribe(listener, { emitImmediately } = {}) {
44192
+ listeners.add(listener);
44193
+ if (emitImmediately)
44194
+ listener(providerDetails, { added: providerDetails });
44195
+ return () => listeners.delete(listener);
44196
+ }
44197
+ };
44198
+ }
44199
+ function isArray(value) {
44200
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
44201
+ }
44202
+ function baseToString(value) {
44203
+ if (typeof value == "string") {
44204
+ return value;
44205
+ }
44206
+ if (typeof value === "bigint") {
44207
+ return value.toString();
44208
+ }
44209
+ const result = value + "";
44210
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
44211
+ }
44212
+ function toString(value) {
44213
+ return value == null ? "" : baseToString(value);
44214
+ }
44215
+ function isString(value) {
44216
+ return typeof value === "string";
44217
+ }
44218
+ function isNumber2(value) {
44219
+ return typeof value === "number";
44220
+ }
44221
+ function isBoolean(value) {
44222
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
44223
+ }
44224
+ function isObject(value) {
44225
+ return typeof value === "object";
44226
+ }
44227
+ function isObjectLike(value) {
44228
+ return isObject(value) && value !== null;
44229
+ }
44230
+ function isDefined(value) {
44231
+ return value !== void 0 && value !== null;
44232
+ }
44233
+ function isBlank(value) {
44234
+ return !value.trim().length;
44235
+ }
44236
+ function getTag(value) {
44237
+ return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
44238
+ }
44239
+ var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
44240
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
44241
+ var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
44242
+ var PATTERN_LENGTH_TOO_LARGE = (max2) => `Pattern length exceeds max of ${max2}.`;
44243
+ var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
44244
+ var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
44245
+ 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.`;
44246
+ var hasOwn2 = Object.prototype.hasOwnProperty;
44247
+ var KeyStore = class {
44248
+ constructor(keys) {
44249
+ this._keys = [];
44250
+ this._keyMap = {};
44251
+ let totalWeight = 0;
44252
+ keys.forEach((key) => {
44253
+ const obj = createKey(key);
44254
+ this._keys.push(obj);
44255
+ this._keyMap[obj.id] = obj;
44256
+ totalWeight += obj.weight;
44257
+ });
44258
+ this._keys.forEach((key) => {
44259
+ key.weight /= totalWeight;
44260
+ });
44261
+ }
44262
+ get(keyId) {
44263
+ return this._keyMap[keyId];
44264
+ }
44265
+ keys() {
44266
+ return this._keys;
44267
+ }
44268
+ toJSON() {
44269
+ return JSON.stringify(this._keys);
44270
+ }
44271
+ };
44272
+ function createKey(key) {
44273
+ let path = null;
44274
+ let id = null;
44275
+ let src = null;
44276
+ let weight = 1;
44277
+ let getFn = null;
44278
+ if (isString(key) || isArray(key)) {
44279
+ src = key;
44280
+ path = createKeyPath(key);
44281
+ id = createKeyId(key);
44282
+ } else {
44283
+ if (!hasOwn2.call(key, "name")) {
44284
+ throw new Error(MISSING_KEY_PROPERTY("name"));
44285
+ }
44286
+ const name = key.name;
44287
+ src = name;
44288
+ if (hasOwn2.call(key, "weight") && key.weight !== void 0) {
44289
+ weight = key.weight;
44290
+ if (weight <= 0) {
44291
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
44292
+ }
44293
+ }
44294
+ path = createKeyPath(name);
44295
+ id = createKeyId(name);
44296
+ getFn = key.getFn ?? null;
44297
+ }
44298
+ return {
44299
+ path,
44300
+ id,
44301
+ weight,
44302
+ src,
44303
+ getFn
44304
+ };
44305
+ }
44306
+ function createKeyPath(key) {
44307
+ return isArray(key) ? key : key.split(".");
44308
+ }
44309
+ function createKeyId(key) {
44310
+ return isArray(key) ? key.join(".") : key;
44311
+ }
44312
+ function get(obj, path) {
44313
+ const list = [];
44314
+ let arr = false;
44315
+ const deepGet = (obj2, path2, index2, arrayIndex) => {
44316
+ if (!isDefined(obj2)) {
44317
+ return;
44318
+ }
44319
+ if (!path2[index2]) {
44320
+ list.push(arrayIndex !== void 0 ? {
44321
+ v: obj2,
44322
+ i: arrayIndex
44323
+ } : obj2);
44324
+ } else {
44325
+ const key = path2[index2];
44326
+ const value = obj2[key];
44327
+ if (!isDefined(value)) {
44328
+ return;
44329
+ }
44330
+ if (index2 === path2.length - 1 && (isString(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
44331
+ list.push(arrayIndex !== void 0 ? {
44332
+ v: toString(value),
44333
+ i: arrayIndex
44334
+ } : toString(value));
44335
+ } else if (isArray(value)) {
44336
+ arr = true;
44337
+ for (let i = 0, len = value.length; i < len; i += 1) {
44338
+ deepGet(value[i], path2, index2 + 1, i);
44339
+ }
44340
+ } else if (path2.length) {
44341
+ deepGet(value, path2, index2 + 1, arrayIndex);
44342
+ }
44343
+ }
44344
+ };
44345
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
44346
+ return arr ? list : list[0];
44347
+ }
44348
+ var MatchOptions = {
44349
+ includeMatches: false,
44350
+ findAllMatches: false,
44351
+ minMatchCharLength: 1
44352
+ };
44353
+ var BasicOptions = {
44354
+ isCaseSensitive: false,
44355
+ ignoreDiacritics: false,
44356
+ includeScore: false,
44357
+ keys: [],
44358
+ shouldSort: true,
44359
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
44360
+ };
44361
+ var FuzzyOptions = {
44362
+ location: 0,
44363
+ threshold: 0.6,
44364
+ distance: 100
44365
+ };
44366
+ var AdvancedOptions = {
44367
+ useExtendedSearch: false,
44368
+ useTokenSearch: false,
44369
+ tokenize: void 0,
44370
+ tokenMatch: "any",
44371
+ getFn: get,
44372
+ ignoreLocation: false,
44373
+ ignoreFieldNorm: false,
44374
+ fieldNormWeight: 1
44375
+ };
44376
+ var Config = Object.freeze({
44377
+ ...BasicOptions,
44378
+ ...MatchOptions,
44379
+ ...FuzzyOptions,
44380
+ ...AdvancedOptions
44381
+ });
44382
+ function norm(weight = 1, mantissa = 3) {
44383
+ const cache = /* @__PURE__ */ new Map();
44384
+ const m = Math.pow(10, mantissa);
44385
+ return {
44386
+ get(value) {
44387
+ let numTokens = 1;
44388
+ let inSpace = false;
44389
+ for (let i = 0; i < value.length; i++) {
44390
+ if (value.charCodeAt(i) === 32) {
44391
+ if (!inSpace) {
44392
+ numTokens++;
44393
+ inSpace = true;
44394
+ }
44395
+ } else {
44396
+ inSpace = false;
44397
+ }
44398
+ }
44399
+ if (cache.has(numTokens)) {
44400
+ return cache.get(numTokens);
44401
+ }
44402
+ const n = Math.round(m / Math.pow(numTokens, 0.5 * weight)) / m;
44403
+ cache.set(numTokens, n);
44404
+ return n;
44405
+ },
44406
+ clear() {
44407
+ cache.clear();
44408
+ }
44409
+ };
44410
+ }
44411
+ var FuseIndex = class {
44412
+ constructor({
44413
+ getFn = Config.getFn,
44414
+ fieldNormWeight = Config.fieldNormWeight
44415
+ } = {}) {
44416
+ this.norm = norm(fieldNormWeight, 3);
44417
+ this.getFn = getFn;
44418
+ this.isCreated = false;
44419
+ this.docs = [];
44420
+ this.keys = [];
44421
+ this._keysMap = {};
44422
+ this.setIndexRecords();
44423
+ }
44424
+ setSources(docs = []) {
44425
+ this.docs = docs;
44426
+ }
44427
+ setIndexRecords(records = []) {
44428
+ this.records = records;
44429
+ }
44430
+ setKeys(keys = []) {
44431
+ this.keys = keys;
44432
+ this._keysMap = {};
44433
+ keys.forEach((key, idx) => {
44434
+ this._keysMap[key.id] = idx;
44435
+ });
44436
+ }
44437
+ create() {
44438
+ if (this.isCreated || !this.docs.length) {
44439
+ return;
44440
+ }
44441
+ this.isCreated = true;
44442
+ const len = this.docs.length;
44443
+ this.records = new Array(len);
44444
+ let recordCount = 0;
44445
+ if (isString(this.docs[0])) {
44446
+ for (let i = 0; i < len; i++) {
44447
+ const record = this._createStringRecord(this.docs[i], i);
44448
+ if (record) {
44449
+ this.records[recordCount++] = record;
44450
+ }
44451
+ }
44452
+ } else {
44453
+ for (let i = 0; i < len; i++) {
44454
+ this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
44455
+ }
44456
+ }
44457
+ this.records.length = recordCount;
44458
+ this.norm.clear();
44459
+ }
44460
+ // Appends a record for `doc` at `docIndex` (the doc's position in the source
44461
+ // array). Returns the appended record, or null when `doc` is a blank string
44462
+ // (those are skipped at record creation; see `_createStringRecord`). Callers
44463
+ // use the return value to gate downstream bookkeeping like the inverted
44464
+ // index, which must not be touched when no record was produced.
44465
+ add(doc, docIndex) {
44466
+ if (!Number.isInteger(docIndex) || docIndex < 0) {
44467
+ throw new Error(INVALID_DOC_INDEX);
44468
+ }
44469
+ if (isString(doc)) {
44470
+ const record2 = this._createStringRecord(doc, docIndex);
44471
+ if (record2) {
44472
+ this.records.push(record2);
44473
+ }
44474
+ return record2;
44475
+ }
44476
+ const record = this._createObjectRecord(doc, docIndex);
44477
+ this.records.push(record);
44478
+ return record;
44479
+ }
44480
+ // Removes the record for the doc at the specified source-array (docs) index.
44481
+ // Blank string docs have no record; callers may pass such an index and the
44482
+ // splice is a no-op, but subsequent records still need their .i decremented
44483
+ // to track the docs array that the caller is splicing in parallel.
44484
+ removeAt(idx) {
44485
+ if (!Number.isInteger(idx) || idx < 0) {
44486
+ throw new Error(INVALID_DOC_INDEX);
44487
+ }
44488
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44489
+ if (this.records[i].i === idx) {
44490
+ this.records.splice(i, 1);
44491
+ break;
44492
+ }
44493
+ }
44494
+ for (let i = 0, len = this.records.length; i < len; i += 1) {
44495
+ if (this.records[i].i > idx) {
44496
+ this.records[i].i -= 1;
44497
+ }
44498
+ }
44499
+ }
44500
+ // Removes records for the docs at the specified source-array indices, then
44501
+ // shifts every surviving record's .i down by the count of removed indices
44502
+ // strictly less than it (mirrors removeAndShiftInvertedIndex's shift math).
44503
+ // Invalid entries (non-integer, negative) in `indices` are dropped silently
44504
+ // — removeAll's natural use case is "caller passed a list of matched doc
44505
+ // indices"; asymmetric throw-vs-no-op would be more surprising than a clean
44506
+ // filter.
44507
+ removeAll(indices) {
44508
+ const toRemove = /* @__PURE__ */ new Set();
44509
+ for (const v of indices) {
44510
+ if (Number.isInteger(v) && v >= 0) {
44511
+ toRemove.add(v);
44512
+ }
44513
+ }
44514
+ if (toRemove.size === 0) {
44515
+ return;
44516
+ }
44517
+ this.records = this.records.filter((r2) => !toRemove.has(r2.i));
44518
+ const sorted = Array.from(toRemove).sort((a, b) => a - b);
44519
+ for (const record of this.records) {
44520
+ let lo = 0;
44521
+ let hi = sorted.length;
44522
+ while (lo < hi) {
44523
+ const mid = lo + hi >>> 1;
44524
+ if (sorted[mid] < record.i) lo = mid + 1;
44525
+ else hi = mid;
44526
+ }
44527
+ record.i -= lo;
44528
+ }
44529
+ }
44530
+ getValueForItemAtKeyId(item, keyId) {
44531
+ return item[this._keysMap[keyId]];
44532
+ }
44533
+ size() {
44534
+ return this.records.length;
44535
+ }
44536
+ _createStringRecord(doc, docIndex) {
44537
+ if (!isDefined(doc) || isBlank(doc)) {
44538
+ return null;
44539
+ }
44540
+ return {
44541
+ v: doc,
44542
+ i: docIndex,
44543
+ n: this.norm.get(doc)
44544
+ };
44545
+ }
44546
+ _createObjectRecord(doc, docIndex) {
44547
+ const record = {
44548
+ i: docIndex,
44549
+ $: {}
44550
+ };
44551
+ for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
44552
+ const key = this.keys[keyIndex];
44553
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
44554
+ if (!isDefined(value)) {
44555
+ continue;
44556
+ }
44557
+ if (isArray(value)) {
44558
+ const subRecords = [];
44559
+ for (let i = 0, len = value.length; i < len; i += 1) {
44560
+ const item = value[i];
44561
+ if (!isDefined(item)) {
44562
+ continue;
44563
+ }
44564
+ if (isString(item)) {
44565
+ if (!isBlank(item)) {
44566
+ const subRecord = {
44567
+ v: item,
44568
+ i,
44569
+ n: this.norm.get(item)
44570
+ };
44571
+ subRecords.push(subRecord);
44572
+ }
44573
+ } else if (isDefined(item.v)) {
44574
+ const text = isString(item.v) ? item.v : toString(item.v);
44575
+ if (!isBlank(text)) {
44576
+ const subRecord = {
44577
+ v: text,
44578
+ i: item.i,
44579
+ n: this.norm.get(text)
44580
+ };
44581
+ subRecords.push(subRecord);
44582
+ }
44583
+ }
44584
+ }
44585
+ record.$[keyIndex] = subRecords;
44586
+ } else if (isString(value) && !isBlank(value)) {
44587
+ const subRecord = {
44588
+ v: value,
44589
+ n: this.norm.get(value)
44590
+ };
44591
+ record.$[keyIndex] = subRecord;
44592
+ }
44593
+ }
44594
+ return record;
44595
+ }
44596
+ toJSON() {
44597
+ return {
44598
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
44599
+ keys: this.keys.map(({
44600
+ getFn,
44601
+ ...key
44602
+ }) => key),
44603
+ records: this.records
44604
+ };
44605
+ }
44606
+ };
44607
+ function createIndex(keys, docs, {
44608
+ getFn = Config.getFn,
44609
+ fieldNormWeight = Config.fieldNormWeight
44610
+ } = {}) {
44611
+ const myIndex = new FuseIndex({
44612
+ getFn,
44613
+ fieldNormWeight
44614
+ });
44615
+ myIndex.setKeys(keys.map(createKey));
44616
+ myIndex.setSources(docs);
44617
+ myIndex.create();
44618
+ return myIndex;
44619
+ }
44620
+ function parseIndex(data, {
44621
+ getFn = Config.getFn,
44622
+ fieldNormWeight = Config.fieldNormWeight
44623
+ } = {}) {
44624
+ const {
44625
+ keys,
44626
+ records
44627
+ } = data;
44628
+ const myIndex = new FuseIndex({
44629
+ getFn,
44630
+ fieldNormWeight
44631
+ });
44632
+ myIndex.setKeys(keys);
44633
+ myIndex.setIndexRecords(records);
44634
+ return myIndex;
44635
+ }
44636
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
44637
+ const indices = [];
44638
+ let start = -1;
44639
+ let end = -1;
44640
+ let i = 0;
44641
+ for (let len = matchmask.length; i < len; i += 1) {
44642
+ const match = matchmask[i];
44643
+ if (match && start === -1) {
44644
+ start = i;
44645
+ } else if (!match && start !== -1) {
44646
+ end = i - 1;
44647
+ if (end - start + 1 >= minMatchCharLength) {
44648
+ indices.push([start, end]);
44649
+ }
44650
+ start = -1;
44651
+ }
44652
+ }
44653
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
44654
+ indices.push([start, i - 1]);
44655
+ }
44656
+ return indices;
44657
+ }
44658
+ var MAX_BITS = 32;
44659
+ function search(text, pattern, patternAlphabet, {
44660
+ location = Config.location,
44661
+ distance = Config.distance,
44662
+ threshold = Config.threshold,
44663
+ findAllMatches = Config.findAllMatches,
44664
+ minMatchCharLength = Config.minMatchCharLength,
44665
+ includeMatches = Config.includeMatches,
44666
+ ignoreLocation = Config.ignoreLocation
44667
+ } = {}) {
44668
+ if (pattern.length > MAX_BITS) {
44669
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
44670
+ }
44671
+ const patternLen = pattern.length;
44672
+ const textLen = text.length;
44673
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
44674
+ let currentThreshold = threshold;
44675
+ let bestLocation = expectedLocation;
44676
+ const calcScore = (errors, currentLocation) => {
44677
+ const accuracy = errors / patternLen;
44678
+ if (ignoreLocation) return accuracy;
44679
+ const proximity = Math.abs(expectedLocation - currentLocation);
44680
+ if (!distance) return proximity ? 1 : accuracy;
44681
+ return accuracy + proximity / distance;
44682
+ };
44683
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
44684
+ const matchMask = computeMatches ? Array(textLen) : [];
44685
+ let index2;
44686
+ while ((index2 = text.indexOf(pattern, bestLocation)) > -1) {
44687
+ const score = calcScore(0, index2);
44688
+ currentThreshold = Math.min(score, currentThreshold);
44689
+ bestLocation = index2 + patternLen;
44690
+ if (computeMatches) {
44691
+ let i = 0;
44692
+ while (i < patternLen) {
44693
+ matchMask[index2 + i] = 1;
44694
+ i += 1;
44695
+ }
44696
+ }
44697
+ }
44698
+ bestLocation = -1;
44699
+ let lastBitArr = [];
44700
+ let finalScore = 1;
44701
+ let bestErrors = 0;
44702
+ let binMax = patternLen + textLen;
44703
+ const mask = 1 << patternLen - 1;
44704
+ for (let i = 0; i < patternLen; i += 1) {
44705
+ let binMin = 0;
44706
+ let binMid = binMax;
44707
+ while (binMin < binMid) {
44708
+ const score2 = calcScore(i, expectedLocation + binMid);
44709
+ if (score2 <= currentThreshold) {
44710
+ binMin = binMid;
44711
+ } else {
44712
+ binMax = binMid;
44713
+ }
44714
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
44715
+ }
44716
+ binMax = binMid;
44717
+ let start = Math.max(1, expectedLocation - binMid + 1);
44718
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
44719
+ const bitArr = Array(finish + 2);
44720
+ bitArr[finish + 1] = (1 << i) - 1;
44721
+ for (let j = finish; j >= start; j -= 1) {
44722
+ const currentLocation = j - 1;
44723
+ const charMatch = patternAlphabet[text[currentLocation]];
44724
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
44725
+ if (i) {
44726
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
44727
+ }
44728
+ if (bitArr[j] & mask) {
44729
+ finalScore = calcScore(i, currentLocation);
44730
+ if (finalScore <= currentThreshold) {
44731
+ currentThreshold = finalScore;
44732
+ bestLocation = currentLocation;
44733
+ bestErrors = i;
44734
+ if (bestLocation <= expectedLocation) {
44735
+ break;
44736
+ }
44737
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
44738
+ }
44739
+ }
44740
+ }
44741
+ const score = calcScore(i + 1, expectedLocation);
44742
+ if (score > currentThreshold) {
44743
+ break;
44744
+ }
44745
+ lastBitArr = bitArr;
44746
+ }
44747
+ if (computeMatches && bestLocation >= 0) {
44748
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
44749
+ for (let k = bestLocation; k <= matchEnd; k += 1) {
44750
+ if (patternAlphabet[text[k]]) {
44751
+ matchMask[k] = 1;
44752
+ }
44753
+ }
44754
+ }
44755
+ const result = {
44756
+ isMatch: bestLocation >= 0,
44757
+ // Count exact matches (those with a score of 0) to be "almost" exact
44758
+ score: Math.max(1e-3, finalScore)
44759
+ };
44760
+ if (computeMatches) {
44761
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
44762
+ if (!indices.length) {
44763
+ result.isMatch = false;
44764
+ } else if (includeMatches) {
44765
+ result.indices = indices;
44766
+ }
44767
+ }
44768
+ return result;
44769
+ }
44770
+ function createPatternAlphabet(pattern) {
44771
+ const mask = {};
44772
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
44773
+ const char = pattern.charAt(i);
44774
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
44775
+ }
44776
+ return mask;
44777
+ }
44778
+ function mergeIndices(indices) {
44779
+ if (indices.length <= 1) return indices;
44780
+ indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
44781
+ const merged = [indices[0]];
44782
+ for (let i = 1, len = indices.length; i < len; i += 1) {
44783
+ const last = merged[merged.length - 1];
44784
+ const curr = indices[i];
44785
+ if (curr[0] <= last[1] + 1) {
44786
+ last[1] = Math.max(last[1], curr[1]);
44787
+ } else {
44788
+ merged.push(curr);
44789
+ }
44790
+ }
44791
+ return merged;
44792
+ }
44793
+ var NON_DECOMPOSABLE_MAP = {
44794
+ "\u0142": "l",
44795
+ // ł
44796
+ "\u0141": "L",
44797
+ // Ł
44798
+ "\u0111": "d",
44799
+ // đ
44800
+ "\u0110": "D",
44801
+ // Đ
44802
+ "\xF8": "o",
44803
+ // ø
44804
+ "\xD8": "O",
44805
+ // Ø
44806
+ "\u0127": "h",
44807
+ // ħ
44808
+ "\u0126": "H",
44809
+ // Ħ
44810
+ "\u0167": "t",
44811
+ // ŧ
44812
+ "\u0166": "T",
44813
+ // Ŧ
44814
+ "\u0131": "i",
44815
+ // ı
44816
+ "\xDF": "ss"
44817
+ // ß
44818
+ };
44819
+ var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
44820
+ 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;
44821
+ var BitapSearch = class {
44822
+ constructor(pattern, {
44823
+ location = Config.location,
44824
+ threshold = Config.threshold,
44825
+ distance = Config.distance,
44826
+ includeMatches = Config.includeMatches,
44827
+ findAllMatches = Config.findAllMatches,
44828
+ minMatchCharLength = Config.minMatchCharLength,
44829
+ isCaseSensitive = Config.isCaseSensitive,
44830
+ ignoreDiacritics = Config.ignoreDiacritics,
44831
+ ignoreLocation = Config.ignoreLocation
44832
+ } = {}) {
44833
+ this.options = {
44834
+ location,
44835
+ threshold,
44836
+ distance,
44837
+ includeMatches,
44838
+ findAllMatches,
44839
+ minMatchCharLength,
44840
+ isCaseSensitive,
44841
+ ignoreDiacritics,
44842
+ ignoreLocation
44843
+ };
44844
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
44845
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
44846
+ this.pattern = pattern;
44847
+ this.chunks = [];
44848
+ if (!this.pattern.length) {
44849
+ return;
44850
+ }
44851
+ const addChunk = (pattern2, startIndex) => {
44852
+ this.chunks.push({
44853
+ pattern: pattern2,
44854
+ alphabet: createPatternAlphabet(pattern2),
44855
+ startIndex
44856
+ });
44857
+ };
44858
+ const len = this.pattern.length;
44859
+ if (len > MAX_BITS) {
44860
+ let i = 0;
44861
+ const remainder = len % MAX_BITS;
44862
+ const end = len - remainder;
44863
+ while (i < end) {
44864
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
44865
+ i += MAX_BITS;
44866
+ }
44867
+ if (remainder) {
44868
+ const startIndex = len - MAX_BITS;
44869
+ addChunk(this.pattern.substr(startIndex), startIndex);
44870
+ }
44871
+ } else {
44872
+ addChunk(this.pattern, 0);
44873
+ }
44874
+ }
44875
+ searchIn(text) {
44876
+ const {
44877
+ isCaseSensitive,
44878
+ ignoreDiacritics,
44879
+ includeMatches
44880
+ } = this.options;
44881
+ text = isCaseSensitive ? text : text.toLowerCase();
44882
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
44883
+ if (this.pattern === text) {
44884
+ const result2 = {
44885
+ isMatch: true,
44886
+ score: 0
44887
+ };
44888
+ if (includeMatches) {
44889
+ result2.indices = [[0, text.length - 1]];
44890
+ }
44891
+ return result2;
44892
+ }
44893
+ const {
44894
+ location,
44895
+ distance,
44896
+ threshold,
44897
+ findAllMatches,
44898
+ minMatchCharLength,
44899
+ ignoreLocation
44900
+ } = this.options;
44901
+ const allIndices = [];
44902
+ let totalScore = 0;
44903
+ let hasMatches = false;
44904
+ this.chunks.forEach(({
44905
+ pattern,
44906
+ alphabet,
44907
+ startIndex
44908
+ }) => {
44909
+ const {
44910
+ isMatch,
44911
+ score,
44912
+ indices
44913
+ } = search(text, pattern, alphabet, {
44914
+ location: location + startIndex,
44915
+ distance,
44916
+ threshold,
44917
+ findAllMatches,
44918
+ minMatchCharLength,
44919
+ includeMatches,
44920
+ ignoreLocation
44921
+ });
44922
+ if (isMatch) {
44923
+ hasMatches = true;
44924
+ }
44925
+ totalScore += score;
44926
+ if (isMatch && indices) {
44927
+ allIndices.push(...indices);
44928
+ }
44929
+ });
44930
+ const result = {
44931
+ isMatch: hasMatches,
44932
+ score: hasMatches ? totalScore / this.chunks.length : 1
44933
+ };
44934
+ if (hasMatches && includeMatches) {
44935
+ result.indices = mergeIndices(allIndices);
44936
+ }
44937
+ return result;
44938
+ }
44939
+ };
44940
+ var MULTI_MATCH_TYPES = /* @__PURE__ */ new Set(["fuzzy", "include"]);
44941
+ function isInverse(type) {
44942
+ return type.startsWith("inverse");
44943
+ }
44944
+ var matchers = [
44945
+ // =term — exact match
44946
+ {
44947
+ type: "exact",
44948
+ multiRegex: /^="(.*)"$/,
44949
+ singleRegex: /^=(.*)$/,
44950
+ create: (pattern) => ({
44951
+ type: "exact",
44952
+ search(text) {
44953
+ const isMatch = text === pattern;
44954
+ return {
44955
+ isMatch,
44956
+ score: isMatch ? 0 : 1,
44957
+ indices: [0, pattern.length - 1]
44958
+ };
44959
+ }
44960
+ })
44961
+ },
44962
+ // 'term — include (substring) match
44963
+ {
44964
+ type: "include",
44965
+ multiRegex: /^'"(.*)"$/,
44966
+ singleRegex: /^'(.*)$/,
44967
+ create: (pattern) => ({
44968
+ type: "include",
44969
+ search(text) {
44970
+ let location = 0;
44971
+ let index2;
44972
+ const indices = [];
44973
+ const patternLen = pattern.length;
44974
+ while ((index2 = text.indexOf(pattern, location)) > -1) {
44975
+ location = index2 + patternLen;
44976
+ indices.push([index2, location - 1]);
44977
+ }
44978
+ const isMatch = !!indices.length;
44979
+ return {
44980
+ isMatch,
44981
+ score: isMatch ? 0 : 1,
44982
+ indices
44983
+ };
44984
+ }
44985
+ })
44986
+ },
44987
+ // ^term — prefix match
44988
+ {
44989
+ type: "prefix-exact",
44990
+ multiRegex: /^\^"(.*)"$/,
44991
+ singleRegex: /^\^(.*)$/,
44992
+ create: (pattern) => ({
44993
+ type: "prefix-exact",
44994
+ search(text) {
44995
+ const isMatch = text.startsWith(pattern);
44996
+ return {
44997
+ isMatch,
44998
+ score: isMatch ? 0 : 1,
44999
+ indices: [0, pattern.length - 1]
45000
+ };
45001
+ }
45002
+ })
45003
+ },
45004
+ // !^term — inverse prefix match
45005
+ {
45006
+ type: "inverse-prefix-exact",
45007
+ multiRegex: /^!\^"(.*)"$/,
45008
+ singleRegex: /^!\^(.*)$/,
45009
+ create: (pattern) => ({
45010
+ type: "inverse-prefix-exact",
45011
+ search(text) {
45012
+ const isMatch = !text.startsWith(pattern);
45013
+ return {
45014
+ isMatch,
45015
+ score: isMatch ? 0 : 1,
45016
+ indices: [0, text.length - 1]
45017
+ };
45018
+ }
45019
+ })
45020
+ },
45021
+ // !term$ — inverse suffix match
45022
+ {
45023
+ type: "inverse-suffix-exact",
45024
+ multiRegex: /^!"(.*)"\$$/,
45025
+ singleRegex: /^!(.*)\$$/,
45026
+ create: (pattern) => ({
45027
+ type: "inverse-suffix-exact",
45028
+ search(text) {
45029
+ const isMatch = !text.endsWith(pattern);
45030
+ return {
45031
+ isMatch,
45032
+ score: isMatch ? 0 : 1,
45033
+ indices: [0, text.length - 1]
45034
+ };
45035
+ }
45036
+ })
45037
+ },
45038
+ // term$ — suffix match
45039
+ {
45040
+ type: "suffix-exact",
45041
+ multiRegex: /^"(.*)"\$$/,
45042
+ singleRegex: /^(.*)\$$/,
45043
+ create: (pattern) => ({
45044
+ type: "suffix-exact",
45045
+ search(text) {
45046
+ const isMatch = text.endsWith(pattern);
45047
+ return {
45048
+ isMatch,
45049
+ score: isMatch ? 0 : 1,
45050
+ indices: [text.length - pattern.length, text.length - 1]
45051
+ };
45052
+ }
45053
+ })
45054
+ },
45055
+ // !term — inverse exact (does not contain)
45056
+ {
45057
+ type: "inverse-exact",
45058
+ multiRegex: /^!"(.*)"$/,
45059
+ singleRegex: /^!(.*)$/,
45060
+ create: (pattern) => ({
45061
+ type: "inverse-exact",
45062
+ search(text) {
45063
+ const isMatch = text.indexOf(pattern) === -1;
45064
+ return {
45065
+ isMatch,
45066
+ score: isMatch ? 0 : 1,
45067
+ indices: [0, text.length - 1]
45068
+ };
45069
+ }
45070
+ })
45071
+ },
45072
+ // term — fuzzy match (catch-all, must be last)
45073
+ {
45074
+ type: "fuzzy",
45075
+ multiRegex: /^"(.*)"$/,
45076
+ singleRegex: /^(.*)$/,
45077
+ create: (pattern, options2 = {}) => {
45078
+ const bitap = new BitapSearch(pattern, {
45079
+ location: options2.location ?? Config.location,
45080
+ threshold: options2.threshold ?? Config.threshold,
45081
+ distance: options2.distance ?? Config.distance,
45082
+ includeMatches: options2.includeMatches ?? Config.includeMatches,
45083
+ findAllMatches: options2.findAllMatches ?? Config.findAllMatches,
45084
+ minMatchCharLength: options2.minMatchCharLength ?? Config.minMatchCharLength,
45085
+ isCaseSensitive: options2.isCaseSensitive ?? Config.isCaseSensitive,
45086
+ ignoreDiacritics: options2.ignoreDiacritics ?? Config.ignoreDiacritics,
45087
+ ignoreLocation: options2.ignoreLocation ?? Config.ignoreLocation
45088
+ });
45089
+ return {
45090
+ type: "fuzzy",
45091
+ search(text) {
45092
+ return bitap.searchIn(text);
45093
+ }
45094
+ };
45095
+ }
45096
+ }
45097
+ ];
45098
+ var matchersLen = matchers.length;
45099
+ var ESCAPED_PIPE = "\0";
45100
+ var OR_TOKEN = "|";
45101
+ function tokenize(pattern) {
45102
+ const tokens = [];
45103
+ const len = pattern.length;
45104
+ let i = 0;
45105
+ while (i < len) {
45106
+ while (i < len && pattern[i] === " ") i++;
45107
+ if (i >= len) break;
45108
+ let j = i;
45109
+ while (j < len && pattern[j] !== " " && pattern[j] !== '"') j++;
45110
+ if (j < len && pattern[j] === '"') {
45111
+ j++;
45112
+ while (j < len) {
45113
+ if (pattern[j] === '"') {
45114
+ const next = j + 1;
45115
+ if (next >= len || pattern[next] === " ") {
45116
+ j++;
45117
+ break;
45118
+ }
45119
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
45120
+ j += 2;
45121
+ break;
45122
+ }
45123
+ }
45124
+ j++;
45125
+ }
45126
+ tokens.push(pattern.substring(i, j));
45127
+ i = j;
45128
+ } else {
45129
+ while (j < len && pattern[j] !== " ") j++;
45130
+ tokens.push(pattern.substring(i, j));
45131
+ i = j;
45132
+ }
45133
+ }
45134
+ return tokens;
45135
+ }
45136
+ function getMatch(pattern, exp) {
45137
+ const matches = pattern.match(exp);
45138
+ return matches ? matches[1] : null;
45139
+ }
45140
+ function parseQuery(pattern, options2 = {}) {
45141
+ const escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
45142
+ return escaped.split(OR_TOKEN).map((item) => {
45143
+ const restored = item.replace(/\u0000/g, "|");
45144
+ const query = tokenize(restored.trim()).filter((item2) => item2 && !!item2.trim());
45145
+ const results = [];
45146
+ for (let i = 0, len = query.length; i < len; i += 1) {
45147
+ const queryItem = query[i];
45148
+ let found = false;
45149
+ let idx = -1;
45150
+ while (!found && ++idx < matchersLen) {
45151
+ const def = matchers[idx];
45152
+ const token = getMatch(queryItem, def.multiRegex);
45153
+ if (token) {
45154
+ results.push(def.create(token, options2));
45155
+ found = true;
45156
+ }
45157
+ }
45158
+ if (found) {
45159
+ continue;
45160
+ }
45161
+ idx = -1;
45162
+ while (++idx < matchersLen) {
45163
+ const def = matchers[idx];
45164
+ const token = getMatch(queryItem, def.singleRegex);
45165
+ if (token) {
45166
+ results.push(def.create(token, options2));
45167
+ break;
45168
+ }
45169
+ }
45170
+ }
45171
+ return results;
45172
+ });
45173
+ }
45174
+ var ExtendedSearch = class {
45175
+ constructor(pattern, {
45176
+ isCaseSensitive = Config.isCaseSensitive,
45177
+ ignoreDiacritics = Config.ignoreDiacritics,
45178
+ includeMatches = Config.includeMatches,
45179
+ minMatchCharLength = Config.minMatchCharLength,
45180
+ ignoreLocation = Config.ignoreLocation,
45181
+ findAllMatches = Config.findAllMatches,
45182
+ location = Config.location,
45183
+ threshold = Config.threshold,
45184
+ distance = Config.distance
45185
+ } = {}) {
45186
+ this.query = null;
45187
+ this.options = {
45188
+ isCaseSensitive,
45189
+ ignoreDiacritics,
45190
+ includeMatches,
45191
+ minMatchCharLength,
45192
+ findAllMatches,
45193
+ ignoreLocation,
45194
+ location,
45195
+ threshold,
45196
+ distance
45197
+ };
45198
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
45199
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
45200
+ this.pattern = pattern;
45201
+ this.query = parseQuery(this.pattern, this.options);
45202
+ }
45203
+ static condition(_, options2) {
45204
+ return options2.useExtendedSearch;
45205
+ }
45206
+ // Note: searchIn operates on a single text value and sets hasInverse on the
45207
+ // result when inverse patterns are involved. _searchObjectList uses this to
45208
+ // switch from "ANY key" to "ALL keys" aggregation. See #712.
45209
+ searchIn(text) {
45210
+ const query = this.query;
45211
+ if (!query) {
45212
+ return {
45213
+ isMatch: false,
45214
+ score: 1
45215
+ };
45216
+ }
45217
+ const {
45218
+ includeMatches,
45219
+ isCaseSensitive,
45220
+ ignoreDiacritics
45221
+ } = this.options;
45222
+ text = isCaseSensitive ? text : text.toLowerCase();
45223
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
45224
+ let numMatches = 0;
45225
+ const allIndices = [];
45226
+ let totalScore = 0;
45227
+ let hasInverse = false;
45228
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
45229
+ const searchers = query[i];
45230
+ allIndices.length = 0;
45231
+ numMatches = 0;
45232
+ hasInverse = false;
45233
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
45234
+ const matcher = searchers[j];
45235
+ const {
45236
+ isMatch,
45237
+ indices,
45238
+ score
45239
+ } = matcher.search(text);
45240
+ if (isMatch) {
45241
+ numMatches += 1;
45242
+ totalScore += score;
45243
+ if (isInverse(matcher.type)) {
45244
+ hasInverse = true;
45245
+ }
45246
+ if (includeMatches) {
45247
+ if (MULTI_MATCH_TYPES.has(matcher.type)) {
45248
+ allIndices.push(...indices);
45249
+ } else {
45250
+ allIndices.push(indices);
45251
+ }
45252
+ }
45253
+ } else {
45254
+ totalScore = 0;
45255
+ numMatches = 0;
45256
+ allIndices.length = 0;
45257
+ hasInverse = false;
45258
+ break;
45259
+ }
45260
+ }
45261
+ if (numMatches) {
45262
+ const result = {
45263
+ isMatch: true,
45264
+ score: totalScore / numMatches
45265
+ };
45266
+ if (hasInverse) {
45267
+ result.hasInverse = true;
45268
+ }
45269
+ if (includeMatches) {
45270
+ result.indices = mergeIndices(allIndices);
45271
+ }
45272
+ return result;
45273
+ }
45274
+ }
45275
+ return {
45276
+ isMatch: false,
45277
+ score: 1
45278
+ };
45279
+ }
45280
+ };
45281
+ var registeredSearchers = [];
45282
+ function register(...args) {
45283
+ registeredSearchers.push(...args);
45284
+ }
45285
+ function createSearcher(pattern, options2) {
45286
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
45287
+ const searcherClass = registeredSearchers[i];
45288
+ if (searcherClass.condition(pattern, options2)) {
45289
+ return new searcherClass(pattern, options2);
45290
+ }
45291
+ }
45292
+ return new BitapSearch(pattern, options2);
45293
+ }
45294
+ var LogicalOperator = {
45295
+ AND: "$and",
45296
+ OR: "$or"
45297
+ };
45298
+ var KeyType = {
45299
+ PATH: "$path",
45300
+ PATTERN: "$val"
45301
+ };
45302
+ var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
45303
+ var isPath = (query) => !!query[KeyType.PATH];
45304
+ var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
45305
+ var convertToExplicit = (query) => ({
45306
+ [LogicalOperator.AND]: Object.keys(query).map((key) => ({
45307
+ [key]: query[key]
45308
+ }))
45309
+ });
45310
+ function parse2(query, options2, {
45311
+ auto = true
45312
+ } = {}) {
45313
+ const next = (query2) => {
45314
+ if (isString(query2)) {
45315
+ const obj = {
45316
+ keyId: null,
45317
+ pattern: query2
45318
+ };
45319
+ if (auto) {
45320
+ obj.searcher = createSearcher(query2, options2);
45321
+ }
45322
+ return obj;
45323
+ }
45324
+ const keys = Object.keys(query2);
45325
+ const isQueryPath = isPath(query2);
45326
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
45327
+ return next(convertToExplicit(query2));
45328
+ }
45329
+ if (isLeaf(query2)) {
45330
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
45331
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
45332
+ if (!isString(pattern)) {
45333
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
45334
+ }
45335
+ const obj = {
45336
+ keyId: createKeyId(key),
45337
+ pattern
45338
+ };
45339
+ if (auto) {
45340
+ obj.searcher = createSearcher(pattern, options2);
45341
+ }
45342
+ return obj;
45343
+ }
45344
+ const node = {
45345
+ children: [],
45346
+ operator: keys[0]
45347
+ };
45348
+ keys.forEach((key) => {
45349
+ const value = query2[key];
45350
+ if (isArray(value)) {
45351
+ value.forEach((item) => {
45352
+ node.children.push(next(item));
45353
+ });
45354
+ }
45355
+ });
45356
+ return node;
45357
+ };
45358
+ if (!isExpression(query)) {
45359
+ query = convertToExplicit(query);
45360
+ }
45361
+ return next(query);
45362
+ }
45363
+ function computeScoreSingle(matches, {
45364
+ ignoreFieldNorm = Config.ignoreFieldNorm
45365
+ }) {
45366
+ let totalScore = 1;
45367
+ matches.forEach(({
45368
+ key,
45369
+ norm: norm2,
45370
+ score
45371
+ }) => {
45372
+ const weight = key ? key.weight : null;
45373
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
45374
+ });
45375
+ return totalScore;
45376
+ }
45377
+ function computeScore(results, {
45378
+ ignoreFieldNorm = Config.ignoreFieldNorm
45379
+ }) {
45380
+ results.forEach((result) => {
45381
+ result.score = computeScoreSingle(result.matches, {
45382
+ ignoreFieldNorm
45383
+ });
45384
+ });
45385
+ }
45386
+ var MaxHeap = class {
45387
+ constructor(limit) {
45388
+ this.limit = limit;
45389
+ this.heap = [];
45390
+ }
45391
+ get size() {
45392
+ return this.heap.length;
45393
+ }
45394
+ shouldInsert(score) {
45395
+ return this.size < this.limit || score < this.heap[0].score;
45396
+ }
45397
+ insert(item) {
45398
+ if (this.size < this.limit) {
45399
+ this.heap.push(item);
45400
+ this._bubbleUp(this.size - 1);
45401
+ } else if (item.score < this.heap[0].score) {
45402
+ this.heap[0] = item;
45403
+ this._sinkDown(0);
45404
+ }
45405
+ }
45406
+ extractSorted(sortFn) {
45407
+ return this.heap.sort(sortFn);
45408
+ }
45409
+ _bubbleUp(i) {
45410
+ const heap = this.heap;
45411
+ while (i > 0) {
45412
+ const parent = i - 1 >> 1;
45413
+ if (heap[i].score <= heap[parent].score) break;
45414
+ const tmp = heap[i];
45415
+ heap[i] = heap[parent];
45416
+ heap[parent] = tmp;
45417
+ i = parent;
45418
+ }
45419
+ }
45420
+ _sinkDown(i) {
45421
+ const heap = this.heap;
45422
+ const len = heap.length;
45423
+ let largest = i;
45424
+ do {
45425
+ i = largest;
45426
+ const left = 2 * i + 1;
45427
+ const right = 2 * i + 2;
45428
+ if (left < len && heap[left].score > heap[largest].score) {
45429
+ largest = left;
45430
+ }
45431
+ if (right < len && heap[right].score > heap[largest].score) {
45432
+ largest = right;
45433
+ }
45434
+ if (largest !== i) {
45435
+ const tmp = heap[i];
45436
+ heap[i] = heap[largest];
45437
+ heap[largest] = tmp;
45438
+ }
45439
+ } while (largest !== i);
45440
+ }
45441
+ };
45442
+ function formatMatches(result) {
45443
+ const matches = [];
45444
+ result.matches.forEach((match) => {
45445
+ if (!isDefined(match.indices) || !match.indices.length) {
45446
+ return;
45447
+ }
45448
+ const obj = {
45449
+ indices: match.indices,
45450
+ value: match.value
45451
+ };
45452
+ if (match.key) {
45453
+ obj.key = match.key.id;
45454
+ }
45455
+ if (match.idx > -1) {
45456
+ obj.refIndex = match.idx;
45457
+ }
45458
+ matches.push(obj);
45459
+ });
45460
+ return matches;
45461
+ }
45462
+ function format(results, docs, {
45463
+ includeMatches = Config.includeMatches,
45464
+ includeScore = Config.includeScore
45465
+ } = {}) {
45466
+ return results.map((result) => {
45467
+ const {
45468
+ idx
45469
+ } = result;
45470
+ const data = {
45471
+ item: docs[idx],
45472
+ refIndex: idx
45473
+ };
45474
+ if (includeMatches) data.matches = formatMatches(result);
45475
+ if (includeScore) data.score = result.score;
45476
+ return data;
45477
+ });
45478
+ }
45479
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
45480
+ var warned = /* @__PURE__ */ new WeakSet();
45481
+ function warnNonGlobal(regex) {
45482
+ if (!warned.has(regex)) {
45483
+ warned.add(regex);
45484
+ console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
45485
+ }
45486
+ }
45487
+ function resolveTokenize(tokenize2) {
45488
+ if (typeof tokenize2 === "function") {
45489
+ let validated = false;
45490
+ return (text) => {
45491
+ const result = tokenize2(text);
45492
+ if (!validated) {
45493
+ validated = true;
45494
+ if (!Array.isArray(result) || result.some((t12) => typeof t12 !== "string")) {
45495
+ throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
45496
+ }
45497
+ }
45498
+ return result;
45499
+ };
45500
+ }
45501
+ if (tokenize2 instanceof RegExp) {
45502
+ if (!tokenize2.global) warnNonGlobal(tokenize2);
45503
+ return (text) => text.match(tokenize2) || [];
45504
+ }
45505
+ return (text) => text.match(DEFAULT_TOKEN) || [];
45506
+ }
45507
+ function createAnalyzer({
45508
+ isCaseSensitive = false,
45509
+ ignoreDiacritics = false,
45510
+ tokenize: tokenize2
45511
+ } = {}) {
45512
+ const tokenizeFn = resolveTokenize(tokenize2);
45513
+ return {
45514
+ tokenize(text) {
45515
+ if (!isCaseSensitive) {
45516
+ text = text.toLowerCase();
45517
+ }
45518
+ if (ignoreDiacritics) {
45519
+ text = stripDiacritics(text);
45520
+ }
45521
+ return tokenizeFn(text);
45522
+ }
45523
+ };
45524
+ }
45525
+ var MAX_MASK_TERMS = 31;
45526
+ var TokenSearch = class {
45527
+ // `tokenMatch: 'all'` (AND) coverage. When true, searchIn reports which
45528
+ // query terms matched each text so the core loop can require record-level
45529
+ // coverage of every term. Bitmask is the ≤31-term fast path; Set is the
45530
+ // ≥32-term fallback (JS bitwise ops are 32-bit signed).
45531
+ static condition(_, options2) {
45532
+ return options2.useTokenSearch;
45533
+ }
45534
+ constructor(pattern, options2) {
45535
+ this.options = options2;
45536
+ this.analyzer = createAnalyzer({
45537
+ isCaseSensitive: options2.isCaseSensitive,
45538
+ ignoreDiacritics: options2.ignoreDiacritics,
45539
+ tokenize: options2.tokenize
45540
+ });
45541
+ const queryTerms = this.analyzer.tokenize(pattern);
45542
+ const invertedIndex = options2._invertedIndex;
45543
+ const {
45544
+ df,
45545
+ fieldCount
45546
+ } = invertedIndex;
45547
+ this.termSearchers = [];
45548
+ this.idfWeights = [];
45549
+ for (const term of queryTerms) {
45550
+ this.termSearchers.push(new BitapSearch(term, {
45551
+ location: options2.location,
45552
+ threshold: options2.threshold,
45553
+ distance: options2.distance,
45554
+ includeMatches: options2.includeMatches,
45555
+ findAllMatches: options2.findAllMatches,
45556
+ minMatchCharLength: options2.minMatchCharLength,
45557
+ isCaseSensitive: options2.isCaseSensitive,
45558
+ ignoreDiacritics: options2.ignoreDiacritics,
45559
+ ignoreLocation: true
45560
+ }));
45561
+ const docFreq = df.get(term) || 0;
45562
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
45563
+ this.idfWeights.push(idf);
45564
+ }
45565
+ this.combineAll = options2.tokenMatch === "all";
45566
+ this.numTerms = this.termSearchers.length;
45567
+ this.useMask = this.numTerms <= MAX_MASK_TERMS;
45568
+ }
45569
+ searchIn(text) {
45570
+ if (!this.termSearchers.length) {
45571
+ return {
45572
+ isMatch: false,
45573
+ score: 1
45574
+ };
45575
+ }
45576
+ const allIndices = [];
45577
+ let weightedScore = 0;
45578
+ let maxPossibleScore = 0;
45579
+ let matchedCount = 0;
45580
+ let matchedMask = 0;
45581
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
45582
+ for (let i = 0; i < this.termSearchers.length; i++) {
45583
+ const result = this.termSearchers[i].searchIn(text);
45584
+ const idf = this.idfWeights[i];
45585
+ maxPossibleScore += idf;
45586
+ if (result.isMatch) {
45587
+ matchedCount++;
45588
+ weightedScore += idf * (1 - result.score);
45589
+ if (result.indices) {
45590
+ allIndices.push(...result.indices);
45591
+ }
45592
+ if (this.combineAll) {
45593
+ if (this.useMask) {
45594
+ matchedMask |= 1 << i;
45595
+ } else {
45596
+ matchedTerms.add(i);
45597
+ }
45598
+ }
45599
+ }
45600
+ }
45601
+ if (matchedCount === 0) {
45602
+ return {
45603
+ isMatch: false,
45604
+ score: 1
45605
+ };
45606
+ }
45607
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
45608
+ const searchResult = {
45609
+ isMatch: true,
45610
+ score: Math.max(1e-3, normalized)
45611
+ };
45612
+ if (this.options.includeMatches && allIndices.length) {
45613
+ searchResult.indices = mergeIndices(allIndices);
45614
+ }
45615
+ if (this.combineAll) {
45616
+ if (this.useMask) {
45617
+ searchResult.matchedMask = matchedMask;
45618
+ } else {
45619
+ searchResult.matchedTerms = matchedTerms;
45620
+ }
45621
+ searchResult.termCount = this.numTerms;
45622
+ }
45623
+ return searchResult;
45624
+ }
45625
+ };
45626
+ function addField(index2, text, docIdx, analyzer) {
45627
+ const tokens = analyzer.tokenize(text);
45628
+ if (!tokens.length) return;
45629
+ index2.fieldCount++;
45630
+ index2.docFieldCount.set(docIdx, (index2.docFieldCount.get(docIdx) || 0) + 1);
45631
+ const distinctTerms = new Set(tokens);
45632
+ let perDocTerms = index2.docTermFieldHits.get(docIdx);
45633
+ if (!perDocTerms) {
45634
+ perDocTerms = /* @__PURE__ */ new Map();
45635
+ index2.docTermFieldHits.set(docIdx, perDocTerms);
45636
+ }
45637
+ for (const term of distinctTerms) {
45638
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
45639
+ index2.df.set(term, (index2.df.get(term) || 0) + 1);
45640
+ }
45641
+ }
45642
+ function ingestRecord(index2, record, keyCount, analyzer) {
45643
+ const {
45644
+ i: docIdx,
45645
+ v,
45646
+ $: fields
45647
+ } = record;
45648
+ if (v !== void 0) {
45649
+ addField(index2, v, docIdx, analyzer);
45650
+ return;
45651
+ }
45652
+ if (!fields) return;
45653
+ for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
45654
+ const value = fields[keyIdx];
45655
+ if (!value) continue;
45656
+ if (Array.isArray(value)) {
45657
+ for (const sub of value) addField(index2, sub.v, docIdx, analyzer);
45658
+ } else {
45659
+ addField(index2, value.v, docIdx, analyzer);
45660
+ }
45661
+ }
45662
+ }
45663
+ function buildInvertedIndex(records, keyCount, analyzer) {
45664
+ const index2 = {
45665
+ fieldCount: 0,
45666
+ df: /* @__PURE__ */ new Map(),
45667
+ docFieldCount: /* @__PURE__ */ new Map(),
45668
+ docTermFieldHits: /* @__PURE__ */ new Map()
45669
+ };
45670
+ for (const record of records) {
45671
+ ingestRecord(index2, record, keyCount, analyzer);
45672
+ }
45673
+ return index2;
45674
+ }
45675
+ function addToInvertedIndex(index2, record, keyCount, analyzer) {
45676
+ ingestRecord(index2, record, keyCount, analyzer);
45677
+ }
45678
+ function removeFromInvertedIndex(index2, docIdx) {
45679
+ const fieldCount = index2.docFieldCount.get(docIdx);
45680
+ if (fieldCount === void 0) return;
45681
+ index2.fieldCount -= fieldCount;
45682
+ index2.docFieldCount.delete(docIdx);
45683
+ const perDocTerms = index2.docTermFieldHits.get(docIdx);
45684
+ if (!perDocTerms) return;
45685
+ for (const [term, hits] of perDocTerms) {
45686
+ const next = (index2.df.get(term) || 0) - hits;
45687
+ if (next <= 0) {
45688
+ index2.df.delete(term);
45689
+ } else {
45690
+ index2.df.set(term, next);
45691
+ }
45692
+ }
45693
+ index2.docTermFieldHits.delete(docIdx);
45694
+ }
45695
+ function removeAndShiftInvertedIndex(index2, removedIndices) {
45696
+ if (removedIndices.length === 0) return;
45697
+ const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
45698
+ for (const idx of sorted) {
45699
+ removeFromInvertedIndex(index2, idx);
45700
+ }
45701
+ const shift4 = (oldIdx) => {
45702
+ let lo = 0;
45703
+ let hi = sorted.length;
45704
+ while (lo < hi) {
45705
+ const mid = lo + hi >>> 1;
45706
+ if (sorted[mid] < oldIdx) lo = mid + 1;
45707
+ else hi = mid;
45708
+ }
45709
+ return oldIdx - lo;
45710
+ };
45711
+ const firstRemoved = sorted[0];
45712
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map();
45713
+ for (const [oldKey, count3] of index2.docFieldCount) {
45714
+ shiftedDocFieldCount.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, count3);
45715
+ }
45716
+ index2.docFieldCount = shiftedDocFieldCount;
45717
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
45718
+ for (const [oldKey, terms] of index2.docTermFieldHits) {
45719
+ shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift4(oldKey) : oldKey, terms);
45720
+ }
45721
+ index2.docTermFieldHits = shiftedDocTermFieldHits;
45722
+ }
45723
+ var Fuse = class {
45724
+ // Statics are assigned in entry.ts
45725
+ constructor(docs, options2, index2) {
45726
+ this.options = {
45727
+ ...Config,
45728
+ ...options2
45729
+ };
45730
+ if (this.options.useExtendedSearch && false) ;
45731
+ if (this.options.useTokenSearch && false) ;
45732
+ this._keyStore = new KeyStore(this.options.keys);
45733
+ this._docs = docs;
45734
+ this._myIndex = null;
45735
+ this._invertedIndex = null;
45736
+ this.setCollection(docs, index2);
45737
+ this._lastQuery = null;
45738
+ this._lastSearcher = null;
45739
+ }
45740
+ _getSearcher(query) {
45741
+ if (this._lastQuery === query) {
45742
+ return this._lastSearcher;
45743
+ }
45744
+ const opts = this._invertedIndex ? {
45745
+ ...this.options,
45746
+ _invertedIndex: this._invertedIndex
45747
+ } : this.options;
45748
+ const searcher = createSearcher(query, opts);
45749
+ this._lastQuery = query;
45750
+ this._lastSearcher = searcher;
45751
+ return searcher;
45752
+ }
45753
+ setCollection(docs, index2) {
45754
+ this._docs = docs;
45755
+ if (index2 && !(index2 instanceof FuseIndex)) {
45756
+ throw new Error(INCORRECT_INDEX_TYPE);
45757
+ }
45758
+ this._myIndex = index2 || createIndex(this.options.keys, this._docs, {
45759
+ getFn: this.options.getFn,
45760
+ fieldNormWeight: this.options.fieldNormWeight
45761
+ });
45762
+ if (this.options.useTokenSearch) {
45763
+ const analyzer = createAnalyzer({
45764
+ isCaseSensitive: this.options.isCaseSensitive,
45765
+ ignoreDiacritics: this.options.ignoreDiacritics,
45766
+ tokenize: this.options.tokenize
45767
+ });
45768
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
45769
+ }
45770
+ this._invalidateSearcherCache();
45771
+ }
45772
+ add(doc) {
45773
+ if (!isDefined(doc)) {
45774
+ return;
45775
+ }
45776
+ this._docs.push(doc);
45777
+ const record = this._myIndex.add(doc, this._docs.length - 1);
45778
+ if (this._invertedIndex && record) {
45779
+ const analyzer = createAnalyzer({
45780
+ isCaseSensitive: this.options.isCaseSensitive,
45781
+ ignoreDiacritics: this.options.ignoreDiacritics,
45782
+ tokenize: this.options.tokenize
45783
+ });
45784
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
45785
+ }
45786
+ this._invalidateSearcherCache();
45787
+ }
45788
+ remove(predicate = () => false) {
45789
+ const results = [];
45790
+ const indicesToRemove = [];
45791
+ for (let i = 0, len = this._docs.length; i < len; i += 1) {
45792
+ if (predicate(this._docs[i], i)) {
45793
+ results.push(this._docs[i]);
45794
+ indicesToRemove.push(i);
45795
+ }
45796
+ }
45797
+ if (indicesToRemove.length) {
45798
+ if (this._invertedIndex) {
45799
+ removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
45800
+ }
45801
+ const toRemove = new Set(indicesToRemove);
45802
+ this._docs = this._docs.filter((_, i) => !toRemove.has(i));
45803
+ this._myIndex.removeAll(indicesToRemove);
45804
+ this._invalidateSearcherCache();
45805
+ }
45806
+ return results;
45807
+ }
45808
+ removeAt(idx) {
45809
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) {
45810
+ throw new Error(INVALID_DOC_INDEX);
45811
+ }
45812
+ if (this._invertedIndex) {
45813
+ removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
45814
+ }
45815
+ const doc = this._docs.splice(idx, 1)[0];
45816
+ this._myIndex.removeAt(idx);
45817
+ this._invalidateSearcherCache();
45818
+ return doc;
45819
+ }
45820
+ _invalidateSearcherCache() {
45821
+ this._lastQuery = null;
45822
+ this._lastSearcher = null;
45823
+ }
45824
+ getIndex() {
45825
+ return this._myIndex;
45826
+ }
45827
+ search(query, options2) {
45828
+ const {
45829
+ limit = -1
45830
+ } = options2 || {};
45831
+ const {
45832
+ includeMatches,
45833
+ includeScore,
45834
+ shouldSort,
45835
+ sortFn,
45836
+ ignoreFieldNorm
45837
+ } = this.options;
45838
+ if (isString(query) && !query.trim()) {
45839
+ let docs = this._docs.map((item, idx) => ({
45840
+ item,
45841
+ refIndex: idx
45842
+ }));
45843
+ if (isNumber2(limit) && limit > -1) {
45844
+ docs = docs.slice(0, limit);
45845
+ }
45846
+ return docs;
45847
+ }
45848
+ const useHeap = isNumber2(limit) && limit > 0 && isString(query);
45849
+ let results;
45850
+ if (useHeap) {
45851
+ const heap = new MaxHeap(limit);
45852
+ if (isString(this._docs[0])) {
45853
+ this._searchStringList(query, {
45854
+ heap,
45855
+ ignoreFieldNorm
45856
+ });
45857
+ } else {
45858
+ this._searchObjectList(query, {
45859
+ heap,
45860
+ ignoreFieldNorm
45861
+ });
45862
+ }
45863
+ results = heap.extractSorted(sortFn);
45864
+ } else {
45865
+ results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
45866
+ computeScore(results, {
45867
+ ignoreFieldNorm
45868
+ });
45869
+ if (shouldSort) {
45870
+ results.sort(sortFn);
45871
+ }
45872
+ if (isNumber2(limit) && limit > -1) {
45873
+ results = results.slice(0, limit);
45874
+ }
45875
+ }
45876
+ return format(results, this._docs, {
45877
+ includeMatches,
45878
+ includeScore
45879
+ });
45880
+ }
45881
+ _searchStringList(query, {
45882
+ heap,
45883
+ ignoreFieldNorm
45884
+ } = {}) {
45885
+ const searcher = this._getSearcher(query);
45886
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
45887
+ const {
45888
+ records
45889
+ } = this._myIndex;
45890
+ const results = heap ? null : [];
45891
+ records.forEach(({
45892
+ v: text,
45893
+ i: idx,
45894
+ n: norm2
45895
+ }) => {
45896
+ if (!isDefined(text)) {
45897
+ return;
45898
+ }
45899
+ const searchResult = searcher.searchIn(text);
45900
+ if (searchResult.isMatch) {
45901
+ const match = {
45902
+ score: searchResult.score,
45903
+ value: text,
45904
+ norm: norm2,
45905
+ indices: searchResult.indices
45906
+ };
45907
+ if (requireAllTokens) {
45908
+ match.matchedMask = searchResult.matchedMask;
45909
+ match.matchedTerms = searchResult.matchedTerms;
45910
+ match.termCount = searchResult.termCount;
45911
+ }
45912
+ const matches = [match];
45913
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
45914
+ const result = {
45915
+ item: text,
45916
+ idx,
45917
+ matches
45918
+ };
45919
+ if (heap) {
45920
+ result.score = computeScoreSingle(result.matches, {
45921
+ ignoreFieldNorm
45922
+ });
45923
+ if (heap.shouldInsert(result.score)) {
45924
+ heap.insert(result);
45925
+ }
45926
+ } else {
45927
+ results.push(result);
45928
+ }
45929
+ }
45930
+ }
45931
+ });
45932
+ return results;
45933
+ }
45934
+ _searchLogical(query) {
45935
+ const expression = parse2(query, this.options);
45936
+ const evaluate2 = (node, item, idx) => {
45937
+ if (!("children" in node)) {
45938
+ const {
45939
+ keyId,
45940
+ searcher
45941
+ } = node;
45942
+ let matches;
45943
+ if (keyId === null) {
45944
+ matches = [];
45945
+ this._myIndex.keys.forEach((key, keyIndex) => {
45946
+ matches.push(...this._findMatches({
45947
+ key,
45948
+ value: item[keyIndex],
45949
+ searcher
45950
+ }));
45951
+ });
45952
+ } else {
45953
+ matches = this._findMatches({
45954
+ key: this._keyStore.get(keyId),
45955
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
45956
+ searcher
45957
+ });
45958
+ }
45959
+ if (matches && matches.length) {
45960
+ return [{
45961
+ idx,
45962
+ item,
45963
+ matches
45964
+ }];
45965
+ }
45966
+ return [];
45967
+ }
45968
+ const {
45969
+ children,
45970
+ operator
45971
+ } = node;
45972
+ const res = [];
45973
+ for (let i = 0, len = children.length; i < len; i += 1) {
45974
+ const child = children[i];
45975
+ const result = evaluate2(child, item, idx);
45976
+ if (result.length) {
45977
+ res.push(...result);
45978
+ } else if (operator === LogicalOperator.AND) {
45979
+ return [];
45980
+ }
45981
+ }
45982
+ return res;
45983
+ };
45984
+ const records = this._myIndex.records;
45985
+ const resultMap = /* @__PURE__ */ new Map();
45986
+ const results = [];
45987
+ records.forEach(({
45988
+ $: item,
45989
+ i: idx
45990
+ }) => {
45991
+ if (isDefined(item)) {
45992
+ const expResults = evaluate2(expression, item, idx);
45993
+ if (expResults.length) {
45994
+ if (!resultMap.has(idx)) {
45995
+ resultMap.set(idx, {
45996
+ idx,
45997
+ item,
45998
+ matches: []
45999
+ });
46000
+ results.push(resultMap.get(idx));
46001
+ }
46002
+ expResults.forEach(({
46003
+ matches
46004
+ }) => {
46005
+ resultMap.get(idx).matches.push(...matches);
46006
+ });
46007
+ }
46008
+ }
46009
+ });
46010
+ return results;
46011
+ }
46012
+ // When a search involves inverse patterns (e.g. !Syrup), the aggregation
46013
+ // across keys switches from "ANY key matches" to "ALL keys must match."
46014
+ // This is signaled by hasInverse on the SearchResult from ExtendedSearch.
46015
+ //
46016
+ // For mixed patterns like "^hello !Syrup", a key failure is ambiguous —
46017
+ // it could be the positive or inverse term that failed. In that case we
46018
+ // conservatively exclude the item, which is strictly better than the old
46019
+ // behavior of including it. See: https://github.com/krisk/Fuse/issues/712
46020
+ _searchObjectList(query, {
46021
+ heap,
46022
+ ignoreFieldNorm
46023
+ } = {}) {
46024
+ const searcher = this._getSearcher(query);
46025
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
46026
+ const {
46027
+ keys,
46028
+ records
46029
+ } = this._myIndex;
46030
+ const results = heap ? null : [];
46031
+ records.forEach(({
46032
+ $: item,
46033
+ i: idx
46034
+ }) => {
46035
+ if (!isDefined(item)) {
46036
+ return;
46037
+ }
46038
+ const matches = [];
46039
+ let anyKeyFailed = false;
46040
+ let hasInverse = false;
46041
+ keys.forEach((key, keyIndex) => {
46042
+ const keyMatches = this._findMatches({
46043
+ key,
46044
+ value: item[keyIndex],
46045
+ searcher
46046
+ });
46047
+ if (keyMatches.length) {
46048
+ matches.push(...keyMatches);
46049
+ if (keyMatches[0].hasInverse) {
46050
+ hasInverse = true;
46051
+ }
46052
+ } else {
46053
+ anyKeyFailed = true;
46054
+ }
46055
+ });
46056
+ if (hasInverse && anyKeyFailed) {
46057
+ return;
46058
+ }
46059
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
46060
+ const result = {
46061
+ idx,
46062
+ item,
46063
+ matches
46064
+ };
46065
+ if (heap) {
46066
+ result.score = computeScoreSingle(result.matches, {
46067
+ ignoreFieldNorm
46068
+ });
46069
+ if (heap.shouldInsert(result.score)) {
46070
+ heap.insert(result);
46071
+ }
46072
+ } else {
46073
+ results.push(result);
46074
+ }
46075
+ }
46076
+ });
46077
+ return results;
46078
+ }
46079
+ _findMatches({
46080
+ key,
46081
+ value,
46082
+ searcher
46083
+ }) {
46084
+ if (!isDefined(value)) {
46085
+ return [];
46086
+ }
46087
+ const matches = [];
46088
+ if (isArray(value)) {
46089
+ value.forEach(({
46090
+ v: text,
46091
+ i: idx,
46092
+ n: norm2
46093
+ }) => {
46094
+ if (!isDefined(text)) {
46095
+ return;
46096
+ }
46097
+ const searchResult = searcher.searchIn(text);
46098
+ if (searchResult.isMatch) {
46099
+ const match = {
46100
+ score: searchResult.score,
46101
+ key,
46102
+ value: text,
46103
+ idx,
46104
+ norm: norm2,
46105
+ indices: searchResult.indices,
46106
+ hasInverse: searchResult.hasInverse
46107
+ };
46108
+ if (searchResult.termCount !== void 0) {
46109
+ match.matchedMask = searchResult.matchedMask;
46110
+ match.matchedTerms = searchResult.matchedTerms;
46111
+ match.termCount = searchResult.termCount;
46112
+ }
46113
+ matches.push(match);
46114
+ }
46115
+ });
46116
+ } else {
46117
+ const {
46118
+ v: text,
46119
+ n: norm2
46120
+ } = value;
46121
+ const searchResult = searcher.searchIn(text);
46122
+ if (searchResult.isMatch) {
46123
+ const match = {
46124
+ score: searchResult.score,
46125
+ key,
46126
+ value: text,
46127
+ norm: norm2,
46128
+ indices: searchResult.indices,
46129
+ hasInverse: searchResult.hasInverse
46130
+ };
46131
+ if (searchResult.termCount !== void 0) {
46132
+ match.matchedMask = searchResult.matchedMask;
46133
+ match.matchedTerms = searchResult.matchedTerms;
46134
+ match.termCount = searchResult.termCount;
46135
+ }
46136
+ matches.push(match);
46137
+ }
46138
+ }
46139
+ return matches;
46140
+ }
46141
+ // Record-level AND gate for token search (`tokenMatch: 'all'`). Returns true
46142
+ // unless the matched terms across ALL of a record's field/array-element
46143
+ // matches fail to cover every query term. `termCount` is only set by
46144
+ // TokenSearch in 'all' mode, so non-token / 'any' searches always pass.
46145
+ _coversAllTokens(matches) {
46146
+ const termCount = matches.length ? matches[0].termCount : void 0;
46147
+ if (termCount === void 0) {
46148
+ return true;
46149
+ }
46150
+ if (termCount <= MAX_MASK_TERMS) {
46151
+ let coverage2 = 0;
46152
+ for (let i = 0; i < matches.length; i++) {
46153
+ coverage2 |= matches[i].matchedMask || 0;
46154
+ }
46155
+ return coverage2 === 2 ** termCount - 1;
46156
+ }
46157
+ const coverage = /* @__PURE__ */ new Set();
46158
+ for (let i = 0; i < matches.length; i++) {
46159
+ const terms = matches[i].matchedTerms;
46160
+ if (terms) {
46161
+ for (const t12 of terms) {
46162
+ coverage.add(t12);
46163
+ }
46164
+ }
46165
+ }
46166
+ return coverage.size === termCount;
46167
+ }
46168
+ };
46169
+ Fuse.version = "7.4.0";
46170
+ Fuse.createIndex = createIndex;
46171
+ Fuse.parseIndex = parseIndex;
46172
+ Fuse.config = Config;
46173
+ Fuse.match = function(pattern, text, options2) {
46174
+ if (options2 && options2.useTokenSearch) {
46175
+ throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
46176
+ }
46177
+ const searcher = createSearcher(pattern, {
46178
+ ...Config,
46179
+ ...options2
46180
+ });
46181
+ return searcher.searchIn(text);
46182
+ };
46183
+ {
46184
+ Fuse.parseQuery = parse2;
46185
+ }
46186
+ {
46187
+ register(ExtendedSearch);
46188
+ }
46189
+ {
46190
+ register(TokenSearch);
46191
+ }
46192
+ Fuse.use = function(...plugins) {
46193
+ plugins.forEach((plugin) => register(plugin));
46194
+ };
44149
46195
  var sides = ["top", "right", "bottom", "left"];
44150
46196
  var min = Math.min;
44151
46197
  var max = Math.max;
@@ -47044,10 +49090,10 @@ var SelectTrigger = React35.forwardRef(
47044
49090
  const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
47045
49091
  const getItems = useCollection(__scopeSelect);
47046
49092
  const pointerTypeRef = React35.useRef("touch");
47047
- const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
49093
+ const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search2) => {
47048
49094
  const enabledItems = getItems().filter((item) => !item.disabled);
47049
49095
  const currentItem = enabledItems.find((item) => item.value === context.value);
47050
- const nextItem = findNextItem(enabledItems, search, currentItem);
49096
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47051
49097
  if (nextItem !== void 0) {
47052
49098
  context.onValueChange(nextItem.value);
47053
49099
  }
@@ -47274,10 +49320,10 @@ var SelectContentImpl = React35.forwardRef(
47274
49320
  window.removeEventListener("resize", close);
47275
49321
  };
47276
49322
  }, [onOpenChange]);
47277
- const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
49323
+ const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search2) => {
47278
49324
  const enabledItems = getItems().filter((item) => !item.disabled);
47279
49325
  const currentItem = enabledItems.find((item) => item.ref.current === document.activeElement);
47280
- const nextItem = findNextItem(enabledItems, search, currentItem);
49326
+ const nextItem = findNextItem(enabledItems, search2, currentItem);
47281
49327
  if (nextItem) {
47282
49328
  setTimeout(() => nextItem.ref.current.focus());
47283
49329
  }
@@ -48006,13 +50052,13 @@ function useTypeaheadSearch(onSearchChange) {
48006
50052
  const timerRef = React35.useRef(0);
48007
50053
  const handleTypeaheadSearch = React35.useCallback(
48008
50054
  (key) => {
48009
- const search = searchRef.current + key;
48010
- handleSearchChange(search);
50055
+ const search2 = searchRef.current + key;
50056
+ handleSearchChange(search2);
48011
50057
  (function updateSearch(value) {
48012
50058
  searchRef.current = value;
48013
50059
  window.clearTimeout(timerRef.current);
48014
50060
  if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
48015
- })(search);
50061
+ })(search2);
48016
50062
  },
48017
50063
  [handleSearchChange]
48018
50064
  );
@@ -48025,9 +50071,9 @@ function useTypeaheadSearch(onSearchChange) {
48025
50071
  }, []);
48026
50072
  return [searchRef, handleTypeaheadSearch, resetTypeahead];
48027
50073
  }
48028
- function findNextItem(items, search, currentItem) {
48029
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
48030
- const normalizedSearch = isRepeated ? search[0] : search;
50074
+ function findNextItem(items, search2, currentItem) {
50075
+ const isRepeated = search2.length > 1 && Array.from(search2).every((char) => char === search2[0]);
50076
+ const normalizedSearch = isRepeated ? search2[0] : search2;
48031
50077
  const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
48032
50078
  let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
48033
50079
  const excludeCurrentItem = normalizedSearch.length === 1;
@@ -49443,7 +51489,7 @@ function interpolate(template, params) {
49443
51489
  }
49444
51490
  var DEPOSIT_CONFIRM_DELAY_MS = 5e3;
49445
51491
  var POLL_INTERVAL_MS = 2500;
49446
- var POLL_ENDPOINT_INTERVAL_MS = 3e3;
51492
+ var POLL_ENDPOINT_INTERVAL_MS = 5e3;
49447
51493
  var CUTOFF_BUFFER_MS = 6e4;
49448
51494
  function useDepositPolling({
49449
51495
  userId,
@@ -53085,6 +55131,53 @@ function CashAppButton({
53085
55131
  }
53086
55132
  );
53087
55133
  }
55134
+ var _store = null;
55135
+ function getEip6963Store() {
55136
+ if (typeof window === "undefined") return null;
55137
+ if (!_store) {
55138
+ _store = createStore();
55139
+ }
55140
+ return _store;
55141
+ }
55142
+ var RDNS_TO_WALLET_ID = {
55143
+ "io.metamask": "metamask",
55144
+ "io.metamask.flask": "metamask",
55145
+ "io.metamask.mmi": "metamask",
55146
+ "app.phantom": "phantom",
55147
+ "com.coinbase.wallet": "coinbase",
55148
+ "com.okex.wallet": "okx",
55149
+ "io.rabby": "rabby",
55150
+ "com.trustwallet.app": "trust",
55151
+ "me.rainbow": "rainbow"
55152
+ };
55153
+ function rdnsToWalletId(rdns) {
55154
+ if (RDNS_TO_WALLET_ID[rdns]) return RDNS_TO_WALLET_ID[rdns];
55155
+ if (rdns.includes("metamask")) return "metamask";
55156
+ if (rdns.includes("phantom")) return "phantom";
55157
+ if (rdns.includes("coinbase")) return "coinbase";
55158
+ if (rdns.includes("okx") || rdns.includes("okex")) return "okx";
55159
+ if (rdns.includes("rabby")) return "rabby";
55160
+ if (rdns.includes("trust")) return "trust";
55161
+ if (rdns.includes("rainbow")) return "rainbow";
55162
+ return "unknown";
55163
+ }
55164
+ function getEip6963Providers() {
55165
+ const store = getEip6963Store();
55166
+ if (!store) return [];
55167
+ return store.getProviders().map((detail) => ({
55168
+ walletId: rdnsToWalletId(detail.info.rdns),
55169
+ provider: detail.provider,
55170
+ info: detail.info
55171
+ }));
55172
+ }
55173
+ function findProviderByWalletId(walletId) {
55174
+ return getEip6963Providers().find((p) => p.walletId === walletId);
55175
+ }
55176
+ function collectAllEip6963EthProviders() {
55177
+ const store = getEip6963Store();
55178
+ if (!store) return [];
55179
+ return store.getProviders().map((d) => d.provider);
55180
+ }
53088
55181
  var SOLANA_DISCONNECT_TYPES = [
53089
55182
  "phantom-solana",
53090
55183
  "solflare",
@@ -53124,8 +55217,9 @@ function collectEthereumProvidersForDisconnect(win) {
53124
55217
  out.push(p);
53125
55218
  }
53126
55219
  };
53127
- const list = anyWin.__eip6963Providers || [];
53128
- for (const d of list) add(d.provider);
55220
+ for (const p of collectAllEip6963EthProviders()) {
55221
+ add(p);
55222
+ }
53129
55223
  add(win.ethereum);
53130
55224
  add(
53131
55225
  win.phantom?.ethereum
@@ -55131,30 +57225,13 @@ function BrowserWalletButton({
55131
57225
  }, []);
55132
57226
  const [eip6963ProviderCount, setEip6963ProviderCount] = React242.useState(0);
55133
57227
  React242.useEffect(() => {
55134
- if (typeof window === "undefined") return;
55135
- const anyWin = window;
55136
- if (!anyWin.__eip6963Providers) {
55137
- anyWin.__eip6963Providers = [];
55138
- }
55139
- const handleAnnouncement = (event) => {
55140
- const { detail } = event;
55141
- if (!detail?.info || !detail?.provider) return;
55142
- const exists = anyWin.__eip6963Providers.some(
55143
- (p) => p.info.uuid === detail.info.uuid
55144
- );
55145
- if (!exists) {
55146
- anyWin.__eip6963Providers.push(detail);
55147
- setEip6963ProviderCount(anyWin.__eip6963Providers.length);
55148
- }
55149
- };
55150
- window.addEventListener("eip6963:announceProvider", handleAnnouncement);
55151
- window.dispatchEvent(new Event("eip6963:requestProvider"));
55152
- return () => {
55153
- window.removeEventListener(
55154
- "eip6963:announceProvider",
55155
- handleAnnouncement
55156
- );
55157
- };
57228
+ const store = getEip6963Store();
57229
+ if (!store) return;
57230
+ setEip6963ProviderCount(store.getProviders().length);
57231
+ const unsubscribe = store.subscribe((providers) => {
57232
+ setEip6963ProviderCount(providers.length);
57233
+ });
57234
+ return unsubscribe;
55158
57235
  }, []);
55159
57236
  React242.useEffect(() => {
55160
57237
  if (!wallet || !publishableKey) {
@@ -55213,7 +57290,7 @@ function BrowserWalletButton({
55213
57290
  return;
55214
57291
  }
55215
57292
  if (!chainType || chainType === "solana") {
55216
- const anyWin2 = win;
57293
+ const anyWin = win;
55217
57294
  const trySilentSolana = async (provider, type, name, icon) => {
55218
57295
  if (!provider) return false;
55219
57296
  if (provider.isConnected && provider.publicKey) {
@@ -55252,21 +57329,21 @@ function BrowserWalletButton({
55252
57329
  ))
55253
57330
  return;
55254
57331
  if (await trySilentSolana(
55255
- anyWin2.solflare,
57332
+ anyWin.solflare,
55256
57333
  "solflare",
55257
57334
  "Solflare",
55258
57335
  "solflare"
55259
57336
  ))
55260
57337
  return;
55261
57338
  if (await trySilentSolana(
55262
- anyWin2.backpack,
57339
+ anyWin.backpack,
55263
57340
  "backpack",
55264
57341
  "Backpack",
55265
57342
  "backpack"
55266
57343
  ))
55267
57344
  return;
55268
57345
  if (await trySilentSolana(
55269
- anyWin2.glow,
57346
+ anyWin.glow,
55270
57347
  "glow",
55271
57348
  "Glow",
55272
57349
  "glow"
@@ -55274,19 +57351,14 @@ function BrowserWalletButton({
55274
57351
  return;
55275
57352
  }
55276
57353
  if (!chainType || chainType === "ethereum") {
55277
- const anyWin2 = win;
57354
+ const anyWin = win;
55278
57355
  const allProviders = [];
55279
- const eip6963Providers = anyWin2.__eip6963Providers || [];
55280
- for (const { info, provider } of eip6963Providers) {
55281
- let walletId = "default";
55282
- if (info.rdns.includes("metamask")) walletId = "metamask";
55283
- else if (info.rdns.includes("phantom")) walletId = "phantom";
55284
- else if (info.rdns.includes("coinbase")) walletId = "coinbase";
55285
- else if (info.rdns.includes("okx")) walletId = "okx";
55286
- else if (info.rdns.includes("rabby")) walletId = "rabby";
55287
- else if (info.rdns.includes("trust")) walletId = "trust";
55288
- else if (info.rdns.includes("rainbow")) walletId = "rainbow";
55289
- allProviders.push({ provider, walletId });
57356
+ const eip6963 = getEip6963Providers();
57357
+ for (const { provider, walletId } of eip6963) {
57358
+ allProviders.push({
57359
+ provider,
57360
+ walletId: walletId === "unknown" ? "default" : walletId
57361
+ });
55290
57362
  }
55291
57363
  if (allProviders.length === 0) {
55292
57364
  if (win.phantom?.ethereum) {
@@ -55295,15 +57367,15 @@ function BrowserWalletButton({
55295
57367
  walletId: "phantom"
55296
57368
  });
55297
57369
  }
55298
- if (anyWin2.okxwallet) {
57370
+ if (anyWin.okxwallet) {
55299
57371
  allProviders.push({
55300
- provider: anyWin2.okxwallet,
57372
+ provider: anyWin.okxwallet,
55301
57373
  walletId: "okx"
55302
57374
  });
55303
57375
  }
55304
- if (anyWin2.coinbaseWalletExtension) {
57376
+ if (anyWin.coinbaseWalletExtension) {
55305
57377
  allProviders.push({
55306
- provider: anyWin2.coinbaseWalletExtension,
57378
+ provider: anyWin.coinbaseWalletExtension,
55307
57379
  walletId: "coinbase"
55308
57380
  });
55309
57381
  }
@@ -55327,7 +57399,7 @@ function BrowserWalletButton({
55327
57399
  });
55328
57400
  if (!accounts || accounts.length === 0) continue;
55329
57401
  const address = accounts[0];
55330
- const resolved = identifyEthWallet(provider, anyWin2, walletId);
57402
+ const resolved = identifyEthWallet(provider, anyWin, walletId);
55331
57403
  if (mounted) {
55332
57404
  setWallet({ ...resolved, address });
55333
57405
  setIsLoading(false);
@@ -55369,15 +57441,11 @@ function BrowserWalletButton({
55369
57441
  solanaProvider.on("disconnect", handleDisconnect);
55370
57442
  solanaProvider.on("accountChanged", handleAccountsChanged);
55371
57443
  }
55372
- const anyWin = window;
55373
57444
  const ethProviders = [];
55374
- if (anyWin.__eip6963Providers) {
55375
- for (const {
55376
- provider
55377
- } of anyWin.__eip6963Providers) {
55378
- if (provider && !ethProviders.includes(provider)) {
55379
- ethProviders.push(provider);
55380
- }
57445
+ for (const { provider } of getEip6963Providers()) {
57446
+ const p = provider;
57447
+ if (p && !ethProviders.includes(p)) {
57448
+ ethProviders.push(p);
55381
57449
  }
55382
57450
  }
55383
57451
  if (window.ethereum && !ethProviders.includes(window.ethereum)) {
@@ -55479,7 +57547,7 @@ function BrowserWalletButton({
55479
57547
  if (isLoading) {
55480
57548
  return null;
55481
57549
  }
55482
- const hasWalletExtension = (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom) ? true : (!chainType || chainType === "ethereum") && (window.phantom?.ethereum || window.ethereum) ? true : false;
57550
+ 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);
55483
57551
  if (!onConnectClick && !wallet && !hasWalletExtension) {
55484
57552
  return null;
55485
57553
  }
@@ -58054,13 +60122,25 @@ function TokenSelectorSheet({
58054
60122
  });
58055
60123
  setRecentTokens(updated);
58056
60124
  };
60125
+ const fuse = (0, import_react21.useMemo)(
60126
+ () => new Fuse(allOptions, {
60127
+ keys: [
60128
+ { name: "token.symbol", weight: 2 },
60129
+ { name: "token.name", weight: 1 },
60130
+ { name: "chain.chain_name", weight: 0.5 }
60131
+ ],
60132
+ threshold: 0.2,
60133
+ ignoreLocation: true,
60134
+ minMatchCharLength: 2
60135
+ }),
60136
+ [allOptions]
60137
+ );
58057
60138
  const filteredOptions = (0, import_react21.useMemo)(() => {
58058
60139
  if (!searchQuery.trim()) return allOptions;
58059
- const query = searchQuery.toLowerCase();
58060
- return allOptions.filter(
58061
- ({ token, chain }) => token.symbol.toLowerCase().includes(query) || token.name.toLowerCase().includes(query) || chain.chain_name.toLowerCase().includes(query)
58062
- );
58063
- }, [allOptions, searchQuery]);
60140
+ const query = searchQuery.trim();
60141
+ const results = fuse.search(query);
60142
+ return results.map((r2) => r2.item);
60143
+ }, [fuse, allOptions, searchQuery]);
58064
60144
  const isCommonToken = (symbol, chainType, chainId) => {
58065
60145
  return COMMON_TOKENS.some(
58066
60146
  (ct) => ct.symbol === symbol && ct.chainType === chainType && ct.chainId === chainId
@@ -60975,15 +63055,10 @@ var WALLET_DEFINITIONS = [
60975
63055
  { id: "backpack", name: "Backpack", networks: ["solana"], installUrl: "https://backpack.app/" },
60976
63056
  { id: "glow", name: "Glow", networks: ["solana"], installUrl: "https://glow.app/" }
60977
63057
  ];
60978
- function getWalletProviders() {
63058
+ function getSolanaProviders() {
60979
63059
  if (typeof window === "undefined") return {};
60980
63060
  const win = window;
60981
63061
  return {
60982
- ethereum: win.ethereum,
60983
- phantomEthereum: win.phantom?.ethereum,
60984
- coinbaseEthereum: win.coinbaseWalletExtension,
60985
- trustEthereum: win.trustwallet?.ethereum,
60986
- okxEthereum: win.okxwallet,
60987
63062
  phantomSolana: win.phantom?.solana,
60988
63063
  solflare: win.solflare,
60989
63064
  backpack: win.backpack,
@@ -60991,37 +63066,71 @@ function getWalletProviders() {
60991
63066
  coinbaseSolana: win.coinbaseSolana || win.coinbaseWalletExtension?.solana
60992
63067
  };
60993
63068
  }
63069
+ function getLegacyEvmProviders() {
63070
+ if (typeof window === "undefined") return {};
63071
+ const win = window;
63072
+ return {
63073
+ ethereum: win.ethereum,
63074
+ phantomEthereum: win.phantom?.ethereum,
63075
+ coinbaseEthereum: win.coinbaseWalletExtension,
63076
+ trustEthereum: win.trustwallet?.ethereum,
63077
+ okxEthereum: win.okxwallet
63078
+ };
63079
+ }
60994
63080
  function detectAvailableWallets(filterChainType) {
60995
- const providers = getWalletProviders();
63081
+ const solProviders = getSolanaProviders();
63082
+ const legacyEvm = getLegacyEvmProviders();
63083
+ const eip6963List = getEip6963Providers();
60996
63084
  const win = typeof window !== "undefined" ? window : null;
63085
+ const hasEip6963 = (walletId) => eip6963List.some((d) => {
63086
+ const rdns = d.info?.rdns || "";
63087
+ switch (walletId) {
63088
+ case "metamask":
63089
+ return rdns.includes("metamask");
63090
+ case "phantom":
63091
+ return rdns.includes("phantom");
63092
+ case "coinbase":
63093
+ return rdns.includes("coinbase");
63094
+ case "trust":
63095
+ return rdns.includes("trust");
63096
+ case "rainbow":
63097
+ return rdns.includes("rainbow");
63098
+ case "rabby":
63099
+ return rdns.includes("rabby");
63100
+ case "okx":
63101
+ return rdns.includes("okx") || rdns.includes("okex");
63102
+ default:
63103
+ return false;
63104
+ }
63105
+ });
60997
63106
  return WALLET_DEFINITIONS.filter((w) => !filterChainType || w.networks.includes(filterChainType)).map((wallet) => {
60998
63107
  let isInstalled = false;
60999
63108
  const detectedNetworks = [];
61000
63109
  switch (wallet.id) {
61001
63110
  case "metamask":
61002
- isInstalled = !!(providers.ethereum?.isMetaMask && !providers.ethereum?.isPhantom && !providers.ethereum?.isRabby && !providers.ethereum?.isOkxWallet);
63111
+ isInstalled = hasEip6963("metamask") || !!(legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom && !legacyEvm.ethereum?.isRabby && !legacyEvm.ethereum?.isOkxWallet);
61003
63112
  if (isInstalled) detectedNetworks.push("ethereum");
61004
63113
  break;
61005
63114
  case "phantom":
61006
- if (providers.phantomSolana?.isPhantom) {
63115
+ if (solProviders.phantomSolana?.isPhantom) {
61007
63116
  isInstalled = true;
61008
63117
  detectedNetworks.push("solana");
61009
63118
  }
61010
- if (providers.phantomEthereum?.isPhantom) {
63119
+ if (hasEip6963("phantom") || legacyEvm.phantomEthereum?.isPhantom) {
61011
63120
  isInstalled = true;
61012
63121
  detectedNetworks.push("ethereum");
61013
63122
  }
61014
63123
  break;
61015
63124
  case "coinbase":
61016
- if (providers.coinbaseEthereum || providers.ethereum?.isCoinbaseWallet) {
63125
+ if (hasEip6963("coinbase") || legacyEvm.coinbaseEthereum || legacyEvm.ethereum?.isCoinbaseWallet) {
61017
63126
  isInstalled = true;
61018
63127
  detectedNetworks.push("ethereum");
61019
63128
  }
61020
- if (providers.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
63129
+ if (solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
61021
63130
  if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
61022
63131
  break;
61023
63132
  case "trust":
61024
- if (providers.trustEthereum || providers.ethereum?.isTrust || win?.trustwallet) {
63133
+ if (hasEip6963("trust") || legacyEvm.trustEthereum || legacyEvm.ethereum?.isTrust || win?.trustwallet) {
61025
63134
  isInstalled = true;
61026
63135
  detectedNetworks.push("ethereum");
61027
63136
  }
@@ -61029,27 +63138,27 @@ function detectAvailableWallets(filterChainType) {
61029
63138
  if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
61030
63139
  break;
61031
63140
  case "rainbow":
61032
- isInstalled = !!providers.ethereum?.isRainbow;
63141
+ isInstalled = hasEip6963("rainbow") || !!legacyEvm.ethereum?.isRainbow;
61033
63142
  if (isInstalled) detectedNetworks.push("ethereum");
61034
63143
  break;
61035
63144
  case "rabby":
61036
- isInstalled = !!providers.ethereum?.isRabby;
63145
+ isInstalled = hasEip6963("rabby") || !!legacyEvm.ethereum?.isRabby;
61037
63146
  if (isInstalled) detectedNetworks.push("ethereum");
61038
63147
  break;
61039
63148
  case "okx":
61040
- isInstalled = !!(providers.okxEthereum || providers.ethereum?.isOkxWallet);
63149
+ isInstalled = hasEip6963("okx") || !!(legacyEvm.okxEthereum || legacyEvm.ethereum?.isOkxWallet);
61041
63150
  if (isInstalled) detectedNetworks.push("ethereum");
61042
63151
  break;
61043
63152
  case "solflare":
61044
- isInstalled = !!providers.solflare?.isSolflare;
63153
+ isInstalled = !!solProviders.solflare?.isSolflare;
61045
63154
  if (isInstalled) detectedNetworks.push("solana");
61046
63155
  break;
61047
63156
  case "backpack":
61048
- isInstalled = !!(providers.backpack?.isBackpack || win?.backpack);
63157
+ isInstalled = !!(solProviders.backpack?.isBackpack || win?.backpack);
61049
63158
  if (isInstalled) detectedNetworks.push("solana");
61050
63159
  break;
61051
63160
  case "glow":
61052
- isInstalled = !!(providers.glow?.isGlow || win?.glow);
63161
+ isInstalled = !!(solProviders.glow?.isGlow || win?.glow);
61053
63162
  if (isInstalled) detectedNetworks.push("solana");
61054
63163
  break;
61055
63164
  }
@@ -61104,7 +63213,16 @@ function WalletConnect({
61104
63213
  const [connectingNetwork, setConnectingNetwork] = React292.useState(null);
61105
63214
  const [walletError, setWalletError] = React292.useState(null);
61106
63215
  const [isWalletConnecting, setIsWalletConnecting] = React292.useState(false);
61107
- const availableWallets = React292.useMemo(() => detectAvailableWallets(), []);
63216
+ const [eip6963ProviderCount, setEip6963ProviderCount] = React292.useState(0);
63217
+ React292.useEffect(() => {
63218
+ const store = getEip6963Store();
63219
+ if (!store) return;
63220
+ setEip6963ProviderCount(store.getProviders().length);
63221
+ return store.subscribe((providers) => {
63222
+ setEip6963ProviderCount(providers.length);
63223
+ });
63224
+ }, []);
63225
+ const availableWallets = React292.useMemo(() => detectAvailableWallets(), [eip6963ProviderCount]);
61108
63226
  const [balances, setBalances] = React292.useState([]);
61109
63227
  const [isLoading, setIsLoading] = React292.useState(false);
61110
63228
  const [selectedBalance, setSelectedBalance] = React292.useState(null);
@@ -61163,59 +63281,72 @@ function WalletConnect({
61163
63281
  setWalletError(null);
61164
63282
  setIsWalletConnecting(true);
61165
63283
  try {
61166
- const providers = getWalletProviders();
61167
63284
  const win = typeof window !== "undefined" ? window : null;
61168
63285
  let connectedInfo;
61169
63286
  if (network === "ethereum") {
61170
- let provider;
61171
- switch (wallet.id) {
61172
- case "metamask":
61173
- if (providers.ethereum?.isMetaMask && !providers.ethereum?.isPhantom) provider = providers.ethereum;
61174
- break;
61175
- case "phantom":
61176
- provider = providers.phantomEthereum;
61177
- break;
61178
- case "coinbase":
61179
- provider = providers.coinbaseEthereum || (providers.ethereum?.isCoinbaseWallet ? providers.ethereum : void 0);
61180
- break;
61181
- case "trust":
61182
- provider = providers.trustEthereum || (providers.ethereum?.isTrust ? providers.ethereum : void 0);
61183
- break;
61184
- case "rainbow":
61185
- if (providers.ethereum?.isRainbow) provider = providers.ethereum;
61186
- break;
61187
- case "rabby":
61188
- if (providers.ethereum?.isRabby) provider = providers.ethereum;
61189
- break;
61190
- case "okx":
61191
- provider = providers.okxEthereum || (providers.ethereum?.isOkxWallet ? providers.ethereum : void 0);
61192
- break;
61193
- default:
61194
- provider = providers.ethereum;
63287
+ const eip6963Match = findProviderByWalletId(wallet.id);
63288
+ let provider = eip6963Match?.provider;
63289
+ if (!provider) {
63290
+ const legacyEvm = getLegacyEvmProviders();
63291
+ switch (wallet.id) {
63292
+ case "metamask":
63293
+ if (legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom) provider = legacyEvm.ethereum;
63294
+ break;
63295
+ case "phantom":
63296
+ provider = legacyEvm.phantomEthereum;
63297
+ break;
63298
+ case "coinbase":
63299
+ provider = legacyEvm.coinbaseEthereum || (legacyEvm.ethereum?.isCoinbaseWallet ? legacyEvm.ethereum : void 0);
63300
+ break;
63301
+ case "trust":
63302
+ provider = legacyEvm.trustEthereum || (legacyEvm.ethereum?.isTrust ? legacyEvm.ethereum : void 0);
63303
+ break;
63304
+ case "rainbow":
63305
+ if (legacyEvm.ethereum?.isRainbow) provider = legacyEvm.ethereum;
63306
+ break;
63307
+ case "rabby":
63308
+ if (legacyEvm.ethereum?.isRabby) provider = legacyEvm.ethereum;
63309
+ break;
63310
+ case "okx":
63311
+ provider = legacyEvm.okxEthereum || (legacyEvm.ethereum?.isOkxWallet ? legacyEvm.ethereum : void 0);
63312
+ break;
63313
+ default:
63314
+ provider = legacyEvm.ethereum;
63315
+ }
61195
63316
  }
61196
63317
  if (!provider) throw new Error(`${wallet.name} wallet not found. Please install it.`);
61197
63318
  const accounts = await provider.request({ method: "eth_requestAccounts" });
61198
63319
  if (!accounts?.length) throw new Error("No accounts returned from wallet");
61199
63320
  setUserDisconnectedWallet(false);
61200
- const walletType = wallet.id === "phantom" ? "phantom-ethereum" : wallet.id === "coinbase" ? "coinbase" : "metamask";
63321
+ const walletIdToType = {
63322
+ phantom: "phantom-ethereum",
63323
+ coinbase: "coinbase",
63324
+ trust: "trust",
63325
+ rainbow: "rainbow",
63326
+ rabby: "rabby",
63327
+ okx: "okx",
63328
+ metamask: "metamask"
63329
+ };
63330
+ const walletType = walletIdToType[wallet.id] || "metamask";
61201
63331
  connectedInfo = { type: walletType, name: wallet.name, address: accounts[0], icon: wallet.id };
61202
63332
  } else {
63333
+ const solProviders = getSolanaProviders();
61203
63334
  let provider;
61204
63335
  switch (wallet.id) {
61205
63336
  case "phantom":
61206
- provider = providers.phantomSolana;
63337
+ provider = solProviders.phantomSolana;
61207
63338
  break;
61208
63339
  case "solflare":
61209
- provider = providers.solflare;
63340
+ provider = solProviders.solflare;
61210
63341
  break;
61211
63342
  case "backpack":
61212
- provider = providers.backpack || win?.backpack;
63343
+ provider = solProviders.backpack || win?.backpack;
61213
63344
  break;
61214
63345
  case "glow":
61215
- provider = providers.glow || win?.glow;
63346
+ provider = solProviders.glow || win?.glow;
61216
63347
  break;
61217
63348
  case "coinbase":
61218
- provider = providers.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
63349
+ provider = solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
61219
63350
  break;
61220
63351
  case "trust":
61221
63352
  provider = win?.trustwallet?.solana;
@@ -61461,10 +63592,15 @@ function WalletConnect({
61461
63592
  };
61462
63593
  const sendEthereumTransaction = async (token, amountStr) => {
61463
63594
  if (!recipientAddress || !/^0x[a-fA-F0-9]{40}$/.test(recipientAddress)) throw new Error(`Invalid recipient address.`);
61464
- let provider;
61465
- if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
61466
- else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
61467
- else provider = window.ethereum;
63595
+ const walletIdMap = { "phantom-ethereum": "phantom", coinbase: "coinbase", trust: "trust", okx: "okx", rainbow: "rainbow", rabby: "rabby", metamask: "metamask" };
63596
+ const lookupId = walletIdMap[walletInfo.type] || walletInfo.type;
63597
+ const eip6963Match = findProviderByWalletId(lookupId);
63598
+ let provider = eip6963Match?.provider;
63599
+ if (!provider) {
63600
+ if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
63601
+ else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
63602
+ else provider = window.ethereum;
63603
+ }
61468
63604
  if (!provider) throw new Error("Ethereum wallet not found");
61469
63605
  const currentChainIdHex = await provider.request({ method: "eth_chainId", params: [] });
61470
63606
  if (parseInt(currentChainIdHex, 16).toString() !== token.chain_id) {
@@ -61703,6 +63839,7 @@ function DepositModal({
61703
63839
  enableConnectWallet = false,
61704
63840
  browserWalletAmountQuickSelect = "percentage",
61705
63841
  enablePayWithExchange,
63842
+ enableFiatOnramp,
61706
63843
  enableConnectExchange = false,
61707
63844
  enableCashApp = false,
61708
63845
  hideDepositFlowInfo = false,
@@ -61724,8 +63861,9 @@ function DepositModal({
61724
63861
  const s = initialScreen ?? "main";
61725
63862
  if (s === "tracker" && hideDepositTracker) return "main";
61726
63863
  if (s === "cashapp" && !enableCashApp) return "main";
63864
+ if (s === "card" && enableFiatOnramp === false) return "main";
61727
63865
  return s;
61728
- }, [initialScreen, hideDepositTracker, enableCashApp]);
63866
+ }, [initialScreen, hideDepositTracker, enableCashApp, enableFiatOnramp]);
61729
63867
  const [containerEl, setContainerEl] = (0, import_react3.useState)(null);
61730
63868
  const containerCallbackRef = (0, import_react3.useCallback)((el) => {
61731
63869
  setContainerEl(el);
@@ -61841,6 +63979,13 @@ function DepositModal({
61841
63979
  enabled: open
61842
63980
  });
61843
63981
  const showPayWithExchange = enablePayWithExchange ?? projectConfig?.pay_with_exchange?.enabled ?? true;
63982
+ const showFiatOnramp = enableFiatOnramp ?? projectConfig?.fiat_onramp?.enabled ?? true;
63983
+ (0, import_react3.useEffect)(() => {
63984
+ if (view === "card" && !showFiatOnramp) {
63985
+ setView("main");
63986
+ setCardView("amount");
63987
+ }
63988
+ }, [view, showFiatOnramp]);
61844
63989
  const { exchanges, isLoading: exchangesLoading } = useExchanges({
61845
63990
  publishableKey,
61846
63991
  enabled: open && showPayWithExchange
@@ -62150,7 +64295,7 @@ function DepositModal({
62150
64295
  featuredWallets: projectConfig?.connect_wallet?.wallets
62151
64296
  }
62152
64297
  ),
62153
- /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
64298
+ showFiatOnramp && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
62154
64299
  DepositWithCardButton,
62155
64300
  {
62156
64301
  onClick: () => setView("card"),
@@ -63289,7 +65434,7 @@ function useExecutions(userId, publishableKey, options2) {
63289
65434
  });
63290
65435
  }
63291
65436
  var POLL_INTERVAL_MS3 = 2500;
63292
- var POLL_ENDPOINT_INTERVAL_MS2 = 3e3;
65437
+ var POLL_ENDPOINT_INTERVAL_MS2 = 5e3;
63293
65438
  var CUTOFF_BUFFER_MS2 = 6e4;
63294
65439
  function useWithdrawPolling({
63295
65440
  userId,
@@ -65149,6 +67294,7 @@ function UnifoldProvider2({
65149
67294
  transferInputVariant: config?.transferInputVariant,
65150
67295
  enableConnectWallet: config?.enableConnectWallet,
65151
67296
  enablePayWithExchange: config?.enablePayWithExchange,
67297
+ enableFiatOnramp: config?.enableFiatOnramp,
65152
67298
  enableConnectExchange: config?.enableConnectExchange,
65153
67299
  enableCashApp: config?.enableCashApp,
65154
67300
  onDepositSuccess: handleDepositSuccess,
@@ -65268,7 +67414,11 @@ function createUnifold(publishableKey, config) {
65268
67414
  return resolvedHandle.beginWithdraw(withdrawConfig);
65269
67415
  },
65270
67416
  closeWithdraw: () => resolvedHandle?.closeWithdraw(),
65271
- destroy: cleanup
67417
+ destroy: () => {
67418
+ resolvedHandle?.closeDeposit();
67419
+ resolvedHandle?.closeWithdraw();
67420
+ cleanup();
67421
+ }
65272
67422
  };
65273
67423
  const refCallback = (handle) => {
65274
67424
  if (handle) {