@tscircuit/cli 0.1.1398 → 0.1.1399

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.
package/dist/cli/main.js CHANGED
@@ -8366,6 +8366,44 @@ var require_coerce = __commonJS((exports2, module2) => {
8366
8366
  module2.exports = coerce;
8367
8367
  });
8368
8368
 
8369
+ // node_modules/semver/functions/truncate.js
8370
+ var require_truncate = __commonJS((exports2, module2) => {
8371
+ var parse = require_parse();
8372
+ var constants = require_constants();
8373
+ var SemVer = require_semver();
8374
+ var truncate = (version2, truncation, options) => {
8375
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
8376
+ return null;
8377
+ }
8378
+ const clonedVersion = cloneInputVersion(version2, options);
8379
+ return clonedVersion && doTruncation(clonedVersion, truncation);
8380
+ };
8381
+ var cloneInputVersion = (version2, options) => {
8382
+ const versionStringToParse = version2 instanceof SemVer ? version2.version : version2;
8383
+ return parse(versionStringToParse, options);
8384
+ };
8385
+ var doTruncation = (version2, truncation) => {
8386
+ if (isPrerelease(truncation)) {
8387
+ return version2.version;
8388
+ }
8389
+ version2.prerelease = [];
8390
+ switch (truncation) {
8391
+ case "major":
8392
+ version2.minor = 0;
8393
+ version2.patch = 0;
8394
+ break;
8395
+ case "minor":
8396
+ version2.patch = 0;
8397
+ break;
8398
+ }
8399
+ return version2.format();
8400
+ };
8401
+ var isPrerelease = (type) => {
8402
+ return type.startsWith("pre");
8403
+ };
8404
+ module2.exports = truncate;
8405
+ });
8406
+
8369
8407
  // node_modules/semver/internal/lrucache.js
8370
8408
  var require_lrucache = __commonJS((exports2, module2) => {
8371
8409
  class LRUCache {
@@ -9353,6 +9391,7 @@ var require_semver2 = __commonJS((exports2, module2) => {
9353
9391
  var lte = require_lte();
9354
9392
  var cmp = require_cmp();
9355
9393
  var coerce = require_coerce();
9394
+ var truncate = require_truncate();
9356
9395
  var Comparator = require_comparator();
9357
9396
  var Range = require_range();
9358
9397
  var satisfies = require_satisfies();
@@ -9391,6 +9430,7 @@ var require_semver2 = __commonJS((exports2, module2) => {
9391
9430
  lte,
9392
9431
  cmp,
9393
9432
  coerce,
9433
+ truncate,
9394
9434
  Comparator,
9395
9435
  Range,
9396
9436
  satisfies,
@@ -18315,6 +18355,9 @@ var require_data = __commonJS((exports2, module2) => {
18315
18355
  var require_utils5 = __commonJS((exports2, module2) => {
18316
18356
  var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
18317
18357
  var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
18358
+ var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
18359
+ var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
18360
+ var isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
18318
18361
  function stringArrayToHexStripped(input) {
18319
18362
  let acc = "";
18320
18363
  let code = 0;
@@ -18508,27 +18551,77 @@ var require_utils5 = __commonJS((exports2, module2) => {
18508
18551
  }
18509
18552
  return output.join("");
18510
18553
  }
18511
- function normalizeComponentEncoding(component, esc) {
18512
- const func = esc !== true ? escape : unescape;
18513
- if (component.scheme !== undefined) {
18514
- component.scheme = func(component.scheme);
18515
- }
18516
- if (component.userinfo !== undefined) {
18517
- component.userinfo = func(component.userinfo);
18518
- }
18519
- if (component.host !== undefined) {
18520
- component.host = func(component.host);
18554
+ var HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
18555
+ var HOST_DELIM_RE = /[@/?#:]/g;
18556
+ var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
18557
+ function reescapeHostDelimiters(host, isIP) {
18558
+ const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
18559
+ re.lastIndex = 0;
18560
+ return host.replace(re, (ch) => HOST_DELIMS[ch]);
18561
+ }
18562
+ function normalizePercentEncoding(input, decodeUnreserved = false) {
18563
+ if (input.indexOf("%") === -1) {
18564
+ return input;
18521
18565
  }
18522
- if (component.path !== undefined) {
18523
- component.path = func(component.path);
18566
+ let output = "";
18567
+ for (let i = 0;i < input.length; i++) {
18568
+ if (input[i] === "%" && i + 2 < input.length) {
18569
+ const hex = input.slice(i + 1, i + 3);
18570
+ if (isHexPair(hex)) {
18571
+ const normalizedHex = hex.toUpperCase();
18572
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
18573
+ if (decodeUnreserved && isUnreserved(decoded)) {
18574
+ output += decoded;
18575
+ } else {
18576
+ output += "%" + normalizedHex;
18577
+ }
18578
+ i += 2;
18579
+ continue;
18580
+ }
18581
+ }
18582
+ output += input[i];
18524
18583
  }
18525
- if (component.query !== undefined) {
18526
- component.query = func(component.query);
18584
+ return output;
18585
+ }
18586
+ function normalizePathEncoding(input) {
18587
+ let output = "";
18588
+ for (let i = 0;i < input.length; i++) {
18589
+ if (input[i] === "%" && i + 2 < input.length) {
18590
+ const hex = input.slice(i + 1, i + 3);
18591
+ if (isHexPair(hex)) {
18592
+ const normalizedHex = hex.toUpperCase();
18593
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
18594
+ if (decoded !== "." && isUnreserved(decoded)) {
18595
+ output += decoded;
18596
+ } else {
18597
+ output += "%" + normalizedHex;
18598
+ }
18599
+ i += 2;
18600
+ continue;
18601
+ }
18602
+ }
18603
+ if (isPathCharacter(input[i])) {
18604
+ output += input[i];
18605
+ } else {
18606
+ output += escape(input[i]);
18607
+ }
18527
18608
  }
18528
- if (component.fragment !== undefined) {
18529
- component.fragment = func(component.fragment);
18609
+ return output;
18610
+ }
18611
+ function escapePreservingEscapes(input) {
18612
+ let output = "";
18613
+ for (let i = 0;i < input.length; i++) {
18614
+ if (input[i] === "%" && i + 2 < input.length) {
18615
+ const hex = input.slice(i + 1, i + 3);
18616
+ if (isHexPair(hex)) {
18617
+ output += "%" + hex.toUpperCase();
18618
+ i += 2;
18619
+ continue;
18620
+ }
18621
+ }
18622
+ output += escape(input[i]);
18530
18623
  }
18531
- return component;
18624
+ return output;
18532
18625
  }
18533
18626
  function recomposeAuthority(component) {
18534
18627
  const uriTokens = [];
@@ -18543,7 +18636,7 @@ var require_utils5 = __commonJS((exports2, module2) => {
18543
18636
  if (ipV6res.isIPV6 === true) {
18544
18637
  host = `[${ipV6res.escapedHost}]`;
18545
18638
  } else {
18546
- host = component.host;
18639
+ host = reescapeHostDelimiters(host, false);
18547
18640
  }
18548
18641
  }
18549
18642
  uriTokens.push(host);
@@ -18557,7 +18650,10 @@ var require_utils5 = __commonJS((exports2, module2) => {
18557
18650
  module2.exports = {
18558
18651
  nonSimpleDomain,
18559
18652
  recomposeAuthority,
18560
- normalizeComponentEncoding,
18653
+ reescapeHostDelimiters,
18654
+ normalizePercentEncoding,
18655
+ normalizePathEncoding,
18656
+ escapePreservingEscapes,
18561
18657
  removeDotSegments,
18562
18658
  isIPv4,
18563
18659
  isUUID,
@@ -18742,11 +18838,11 @@ var require_schemes = __commonJS((exports2, module2) => {
18742
18838
 
18743
18839
  // node_modules/fast-uri/index.js
18744
18840
  var require_fast_uri = __commonJS((exports2, module2) => {
18745
- var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils5();
18841
+ var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils5();
18746
18842
  var { SCHEMES, getSchemeHandler } = require_schemes();
18747
18843
  function normalize(uri, options) {
18748
18844
  if (typeof uri === "string") {
18749
- uri = serialize(parse(uri, options), options);
18845
+ uri = normalizeString(uri, options);
18750
18846
  } else if (typeof uri === "object") {
18751
18847
  uri = parse(serialize(uri, options), options);
18752
18848
  }
@@ -18812,19 +18908,9 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18812
18908
  return target;
18813
18909
  }
18814
18910
  function equal(uriA, uriB, options) {
18815
- if (typeof uriA === "string") {
18816
- uriA = unescape(uriA);
18817
- uriA = serialize(normalizeComponentEncoding(parse(uriA, options), true), { ...options, skipEscape: true });
18818
- } else if (typeof uriA === "object") {
18819
- uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true });
18820
- }
18821
- if (typeof uriB === "string") {
18822
- uriB = unescape(uriB);
18823
- uriB = serialize(normalizeComponentEncoding(parse(uriB, options), true), { ...options, skipEscape: true });
18824
- } else if (typeof uriB === "object") {
18825
- uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true });
18826
- }
18827
- return uriA.toLowerCase() === uriB.toLowerCase();
18911
+ const normalizedA = normalizeComparableURI(uriA, options);
18912
+ const normalizedB = normalizeComparableURI(uriB, options);
18913
+ return normalizedA !== undefined && normalizedB !== undefined && normalizedA.toLowerCase() === normalizedB.toLowerCase();
18828
18914
  }
18829
18915
  function serialize(cmpts, opts) {
18830
18916
  const component = {
@@ -18850,12 +18936,12 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18850
18936
  schemeHandler.serialize(component, options);
18851
18937
  if (component.path !== undefined) {
18852
18938
  if (!options.skipEscape) {
18853
- component.path = escape(component.path);
18939
+ component.path = escapePreservingEscapes(component.path);
18854
18940
  if (component.scheme !== undefined) {
18855
18941
  component.path = component.path.split("%3A").join(":");
18856
18942
  }
18857
18943
  } else {
18858
- component.path = unescape(component.path);
18944
+ component.path = normalizePercentEncoding(component.path);
18859
18945
  }
18860
18946
  }
18861
18947
  if (options.reference !== "suffix" && component.scheme) {
@@ -18890,7 +18976,16 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18890
18976
  return uriTokens.join("");
18891
18977
  }
18892
18978
  var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
18893
- function parse(uri, opts) {
18979
+ function getParseError(parsed, matches) {
18980
+ if (matches[2] !== undefined && parsed.path && parsed.path[0] !== "/") {
18981
+ return 'URI path must start with "/" when authority is present.';
18982
+ }
18983
+ if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) {
18984
+ return "URI port is malformed.";
18985
+ }
18986
+ return;
18987
+ }
18988
+ function parseWithStatus(uri, opts) {
18894
18989
  const options = Object.assign({}, opts);
18895
18990
  const parsed = {
18896
18991
  scheme: undefined,
@@ -18901,6 +18996,7 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18901
18996
  query: undefined,
18902
18997
  fragment: undefined
18903
18998
  };
18999
+ let malformedAuthorityOrPort = false;
18904
19000
  let isIP = false;
18905
19001
  if (options.reference === "suffix") {
18906
19002
  if (options.scheme) {
@@ -18921,6 +19017,11 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18921
19017
  if (isNaN(parsed.port)) {
18922
19018
  parsed.port = matches[5];
18923
19019
  }
19020
+ const parseError = getParseError(parsed, matches);
19021
+ if (parseError !== undefined) {
19022
+ parsed.error = parsed.error || parseError;
19023
+ malformedAuthorityOrPort = true;
19024
+ }
18924
19025
  if (parsed.host) {
18925
19026
  const ipv4result = isIPv4(parsed.host);
18926
19027
  if (ipv4result === false) {
@@ -18959,14 +19060,18 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18959
19060
  parsed.scheme = unescape(parsed.scheme);
18960
19061
  }
18961
19062
  if (parsed.host !== undefined) {
18962
- parsed.host = unescape(parsed.host);
19063
+ parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
18963
19064
  }
18964
19065
  }
18965
19066
  if (parsed.path) {
18966
- parsed.path = escape(unescape(parsed.path));
19067
+ parsed.path = normalizePathEncoding(parsed.path);
18967
19068
  }
18968
19069
  if (parsed.fragment) {
18969
- parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
19070
+ try {
19071
+ parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
19072
+ } catch {
19073
+ parsed.error = parsed.error || "URI malformed";
19074
+ }
18970
19075
  }
18971
19076
  }
18972
19077
  if (schemeHandler && schemeHandler.parse) {
@@ -18975,7 +19080,29 @@ var require_fast_uri = __commonJS((exports2, module2) => {
18975
19080
  } else {
18976
19081
  parsed.error = parsed.error || "URI can not be parsed.";
18977
19082
  }
18978
- return parsed;
19083
+ return { parsed, malformedAuthorityOrPort };
19084
+ }
19085
+ function parse(uri, opts) {
19086
+ return parseWithStatus(uri, opts).parsed;
19087
+ }
19088
+ function normalizeString(uri, opts) {
19089
+ return normalizeStringWithStatus(uri, opts).normalized;
19090
+ }
19091
+ function normalizeStringWithStatus(uri, opts) {
19092
+ const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
19093
+ return {
19094
+ normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
19095
+ malformedAuthorityOrPort
19096
+ };
19097
+ }
19098
+ function normalizeComparableURI(uri, opts) {
19099
+ if (typeof uri === "string") {
19100
+ const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts);
19101
+ return malformedAuthorityOrPort ? undefined : normalized;
19102
+ }
19103
+ if (typeof uri === "object") {
19104
+ return serialize(uri, opts);
19105
+ }
18979
19106
  }
18980
19107
  var fastUri = {
18981
19108
  SCHEMES,
@@ -19110,7 +19237,7 @@ var require_core = __commonJS((exports2) => {
19110
19237
  constructor(opts = {}) {
19111
19238
  this.schemas = {};
19112
19239
  this.refs = {};
19113
- this.formats = {};
19240
+ this.formats = Object.create(null);
19114
19241
  this._compilations = new Set;
19115
19242
  this._loading = {};
19116
19243
  this._cache = new Map;
@@ -22594,7 +22721,7 @@ var require_isarray = __commonJS((exports2, module2) => {
22594
22721
  };
22595
22722
  });
22596
22723
 
22597
- // node_modules/readable-stream/node_modules/safe-buffer/index.js
22724
+ // node_modules/safe-buffer/index.js
22598
22725
  var require_safe_buffer = __commonJS((exports2, module2) => {
22599
22726
  var buffer = __require("buffer");
22600
22727
  var Buffer2 = buffer.Buffer;
@@ -23448,64 +23575,9 @@ var require__stream_duplex = __commonJS((exports2, module2) => {
23448
23575
  };
23449
23576
  });
23450
23577
 
23451
- // node_modules/string_decoder/node_modules/safe-buffer/index.js
23452
- var require_safe_buffer2 = __commonJS((exports2, module2) => {
23453
- var buffer = __require("buffer");
23454
- var Buffer2 = buffer.Buffer;
23455
- function copyProps(src, dst) {
23456
- for (var key in src) {
23457
- dst[key] = src[key];
23458
- }
23459
- }
23460
- if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
23461
- module2.exports = buffer;
23462
- } else {
23463
- copyProps(buffer, exports2);
23464
- exports2.Buffer = SafeBuffer;
23465
- }
23466
- function SafeBuffer(arg, encodingOrOffset, length) {
23467
- return Buffer2(arg, encodingOrOffset, length);
23468
- }
23469
- copyProps(Buffer2, SafeBuffer);
23470
- SafeBuffer.from = function(arg, encodingOrOffset, length) {
23471
- if (typeof arg === "number") {
23472
- throw new TypeError("Argument must not be a number");
23473
- }
23474
- return Buffer2(arg, encodingOrOffset, length);
23475
- };
23476
- SafeBuffer.alloc = function(size, fill, encoding) {
23477
- if (typeof size !== "number") {
23478
- throw new TypeError("Argument must be a number");
23479
- }
23480
- var buf = Buffer2(size);
23481
- if (fill !== undefined) {
23482
- if (typeof encoding === "string") {
23483
- buf.fill(fill, encoding);
23484
- } else {
23485
- buf.fill(fill);
23486
- }
23487
- } else {
23488
- buf.fill(0);
23489
- }
23490
- return buf;
23491
- };
23492
- SafeBuffer.allocUnsafe = function(size) {
23493
- if (typeof size !== "number") {
23494
- throw new TypeError("Argument must be a number");
23495
- }
23496
- return Buffer2(size);
23497
- };
23498
- SafeBuffer.allocUnsafeSlow = function(size) {
23499
- if (typeof size !== "number") {
23500
- throw new TypeError("Argument must be a number");
23501
- }
23502
- return buffer.SlowBuffer(size);
23503
- };
23504
- });
23505
-
23506
23578
  // node_modules/string_decoder/lib/string_decoder.js
23507
23579
  var require_string_decoder = __commonJS((exports2) => {
23508
- var Buffer2 = require_safe_buffer2().Buffer;
23580
+ var Buffer2 = require_safe_buffer().Buffer;
23509
23581
  var isEncoding = Buffer2.isEncoding || function(encoding) {
23510
23582
  encoding = "" + encoding;
23511
23583
  switch (encoding && encoding.toLowerCase()) {
@@ -100616,7 +100688,7 @@ var import_perfect_cli = __toESM2(require_dist2(), 1);
100616
100688
  // lib/getVersion.ts
100617
100689
  import { createRequire as createRequire2 } from "node:module";
100618
100690
  // package.json
100619
- var version = "0.1.1397";
100691
+ var version = "0.1.1398";
100620
100692
  var package_default = {
100621
100693
  name: "@tscircuit/cli",
100622
100694
  version,
@@ -100657,7 +100729,7 @@ var package_default = {
100657
100729
  "circuit-json-to-pnp-csv": "^0.0.7",
100658
100730
  "circuit-json-to-readable-netlist": "^0.0.15",
100659
100731
  "circuit-json-to-spice": "^0.0.10",
100660
- "circuit-json-to-step": "^0.0.32",
100732
+ "circuit-json-to-step": "^0.0.33",
100661
100733
  "circuit-json-to-tscircuit": "^0.0.9",
100662
100734
  "circuit-json-trace-length-analysis": "github:tscircuit/circuit-json-trace-length-analysis#2b44792a40df0ca83b6bfb6ac95ed5e35e7168b8",
100663
100735
  commander: "^14.0.0",
@@ -100690,7 +100762,7 @@ var package_default = {
100690
100762
  semver: "^7.6.3",
100691
100763
  stepts: "^0.0.3",
100692
100764
  tempy: "^3.1.0",
100693
- tscircuit: "0.0.1590-libonly",
100765
+ tscircuit: "0.0.1772-libonly",
100694
100766
  tsx: "^4.7.1",
100695
100767
  "typed-ky": "^0.0.4",
100696
100768
  zod: "^3.23.8"
@@ -112784,7 +112856,7 @@ function normalizeStepNumericExponents(stepText) {
112784
112856
  var package_default2 = {
112785
112857
  name: "circuit-json-to-step",
112786
112858
  main: "dist/index.js",
112787
- version: "0.0.31",
112859
+ version: "0.0.32",
112788
112860
  type: "module",
112789
112861
  scripts: {
112790
112862
  "pull-reference": `git clone https://github.com/tscircuit/circuit-json.git && find circuit-json/tests -name '*.test.ts' -exec bash -c 'mv "$0" "\${0%.test.ts}.ts"' {} \\; && git clone https://github.com/tscircuit/stepts.git && find stepts/tests -name '*.test.ts' -exec bash -c 'mv "$0" "\${0%.test.ts}.ts"' {} \\;`,
@@ -112814,7 +112886,7 @@ var package_default2 = {
112814
112886
  },
112815
112887
  dependencies: {
112816
112888
  "circuit-json-to-connectivity-map": "^0.0.22",
112817
- "circuit-json-to-gltf": "^0.0.100",
112889
+ "circuit-json-to-gltf": "^0.0.101",
112818
112890
  "circuit-to-svg": "^0.0.345",
112819
112891
  "schematic-symbols": "^0.0.202",
112820
112892
  stepts: "^0.0.4"
@@ -272344,10 +272416,14 @@ function stripAnsi(string) {
272344
272416
  }
272345
272417
 
272346
272418
  // node_modules/get-east-asian-width/lookup-data.js
272419
+ var ambiguousMinimalCodePoint = 161;
272420
+ var ambiguousMaximumCodePoint = 1114109;
272347
272421
  var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
272422
+ var fullwidthMinimalCodePoint = 12288;
272423
+ var fullwidthMaximumCodePoint = 65510;
272348
272424
  var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
272349
- var halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
272350
- var narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
272425
+ var wideMinimalCodePoint = 4352;
272426
+ var wideMaximumCodePoint = 262141;
272351
272427
  var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
272352
272428
 
272353
272429
  // node_modules/get-east-asian-width/utilities.js
@@ -272369,18 +272445,8 @@ var isInRange = (ranges, codePoint) => {
272369
272445
  };
272370
272446
 
272371
272447
  // node_modules/get-east-asian-width/lookup.js
272372
- var minimumAmbiguousCodePoint = ambiguousRanges[0];
272373
- var maximumAmbiguousCodePoint = ambiguousRanges.at(-1);
272374
- var minimumFullWidthCodePoint = fullwidthRanges[0];
272375
- var maximumFullWidthCodePoint = fullwidthRanges.at(-1);
272376
- var minimumHalfWidthCodePoint = halfwidthRanges[0];
272377
- var maximumHalfWidthCodePoint = halfwidthRanges.at(-1);
272378
- var minimumNarrowCodePoint = narrowRanges[0];
272379
- var maximumNarrowCodePoint = narrowRanges.at(-1);
272380
- var minimumWideCodePoint = wideRanges[0];
272381
- var maximumWideCodePoint = wideRanges.at(-1);
272382
272448
  var commonCjkCodePoint = 19968;
272383
- var [wideFastPathStart, wideFastPathEnd] = findWideFastPathRange(wideRanges);
272449
+ var [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
272384
272450
  function findWideFastPathRange(ranges) {
272385
272451
  let fastPathStart = ranges[0];
272386
272452
  let fastPathEnd = ranges[1];
@@ -272398,13 +272464,13 @@ function findWideFastPathRange(ranges) {
272398
272464
  return [fastPathStart, fastPathEnd];
272399
272465
  }
272400
272466
  var isAmbiguous = (codePoint) => {
272401
- if (codePoint < minimumAmbiguousCodePoint || codePoint > maximumAmbiguousCodePoint) {
272467
+ if (codePoint < ambiguousMinimalCodePoint || codePoint > ambiguousMaximumCodePoint) {
272402
272468
  return false;
272403
272469
  }
272404
272470
  return isInRange(ambiguousRanges, codePoint);
272405
272471
  };
272406
272472
  var isFullWidth = (codePoint) => {
272407
- if (codePoint < minimumFullWidthCodePoint || codePoint > maximumFullWidthCodePoint) {
272473
+ if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
272408
272474
  return false;
272409
272475
  }
272410
272476
  return isInRange(fullwidthRanges, codePoint);
@@ -272413,7 +272479,7 @@ var isWide = (codePoint) => {
272413
272479
  if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
272414
272480
  return true;
272415
272481
  }
272416
- if (codePoint < minimumWideCodePoint || codePoint > maximumWideCodePoint) {
272482
+ if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
272417
272483
  return false;
272418
272484
  }
272419
272485
  return isInRange(wideRanges, codePoint);
@@ -273153,6 +273219,55 @@ var updateTsci = async () => {
273153
273219
  return true;
273154
273220
  };
273155
273221
 
273222
+ // lib/telemetry/index.ts
273223
+ import { randomUUID } from "node:crypto";
273224
+ var POSTHOG_HOST = "https://us.i.posthog.com";
273225
+ var TSCI_POSTHOG_PROJECT_API_KEY = "phc_htd8AQjSfVEsFCLQMAiUooG4Q0DKBCjqYuQglc9V3Wo";
273226
+ var POSTHOG_CAPTURE_PATH = "/capture";
273227
+ var isTruthy4 = (value) => value ? ["1", "true", "yes", "on"].includes(value.toLowerCase()) : false;
273228
+ var joinUrl = (host, path65) => `${host.replace(/\/$/, "")}${path65}`;
273229
+ var getTelemetryConfigFromEnv = (env3 = process.env) => {
273230
+ if (isTruthy4(env3.TSCI_TELEMETRY_DISABLED)) {
273231
+ return { enabled: false };
273232
+ }
273233
+ if (env3.TSCI_TEST_MODE === "true" && !isTruthy4(env3.TSCI_TELEMETRY_FORCE)) {
273234
+ return { enabled: false };
273235
+ }
273236
+ if (!TSCI_POSTHOG_PROJECT_API_KEY)
273237
+ return { enabled: false };
273238
+ return {
273239
+ enabled: true,
273240
+ projectApiKey: TSCI_POSTHOG_PROJECT_API_KEY,
273241
+ host: POSTHOG_HOST,
273242
+ distinctId: `tscircuit-cli-${randomUUID()}`
273243
+ };
273244
+ };
273245
+ var captureTelemetryEvent = async (event, properties) => {
273246
+ const telemetryConfig = getTelemetryConfigFromEnv();
273247
+ if (!telemetryConfig.enabled || !telemetryConfig.projectApiKey)
273248
+ return;
273249
+ const url2 = joinUrl(POSTHOG_HOST, POSTHOG_CAPTURE_PATH);
273250
+ const payload = {
273251
+ api_key: telemetryConfig.projectApiKey,
273252
+ distinct_id: telemetryConfig.distinctId,
273253
+ event,
273254
+ properties: {
273255
+ ...properties,
273256
+ cli_version: getVersion(),
273257
+ source: "@tscircuit/cli"
273258
+ }
273259
+ };
273260
+ try {
273261
+ await fetch(url2, {
273262
+ method: "POST",
273263
+ headers: {
273264
+ "Content-Type": "application/json"
273265
+ },
273266
+ body: JSON.stringify(payload)
273267
+ });
273268
+ } catch {}
273269
+ };
273270
+
273156
273271
  // cli/init/register.ts
273157
273272
  var registerInit = (program3) => {
273158
273273
  program3.command("init").description("Initialize a new TSCircuit project in the specified directory (or current directory if none is provided)").argument("[directory]", "Directory name (optional, defaults to current directory)").option("-y, --yes", "Use defaults and skip prompts").option("--no-install", "Skip installing dependencies").action(async (directory, options) => {
@@ -273228,7 +273343,14 @@ export default () => (
273228
273343
  generateTsConfig(projectDir);
273229
273344
  generateGitIgnoreFile(projectDir);
273230
273345
  await setupTscircuitSkill(projectDir, options?.yes);
273231
- setupTsciProject(projectDir, options?.install ? undefined : []);
273346
+ await setupTsciProject(projectDir, options?.install ? undefined : []);
273347
+ await captureTelemetryEvent("tsci_init", {
273348
+ command: "init",
273349
+ directory_provided: directory !== undefined,
273350
+ yes: Boolean(options?.yes),
273351
+ no_install: options?.install === false,
273352
+ status: "success"
273353
+ });
273232
273354
  console.info(`
273233
273355
  `, kleur_default.green("\uD83C\uDF89 Initialization complete!"), "Run ", kleur_default.bold(kleur_default.blue(`${directory ? `${kleur_default.bold(`cd ${directory}`)} && ` : ""}${kleur_default.bold("tsci dev")}`)), " to start developing.");
273234
273356
  process.exit(0);
@@ -273426,13 +273548,15 @@ var registerRegistry = (program3) => {
273426
273548
  function isArray(value) {
273427
273549
  return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
273428
273550
  }
273429
- var INFINITY = 1 / 0;
273430
273551
  function baseToString(value) {
273431
273552
  if (typeof value == "string") {
273432
273553
  return value;
273433
273554
  }
273434
- let result = value + "";
273435
- return result == "0" && 1 / value == -INFINITY ? "-0" : result;
273555
+ if (typeof value === "bigint") {
273556
+ return value.toString();
273557
+ }
273558
+ const result = value + "";
273559
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
273436
273560
  }
273437
273561
  function toString2(value) {
273438
273562
  return value == null ? "" : baseToString(value);
@@ -273474,7 +273598,7 @@ class KeyStore {
273474
273598
  this._keyMap = {};
273475
273599
  let totalWeight = 0;
273476
273600
  keys.forEach((key) => {
273477
- let obj = createKey(key);
273601
+ const obj = createKey(key);
273478
273602
  this._keys.push(obj);
273479
273603
  this._keyMap[obj.id] = obj;
273480
273604
  totalWeight += obj.weight;
@@ -273519,7 +273643,13 @@ function createKey(key) {
273519
273643
  id2 = createKeyId(name);
273520
273644
  getFn = key.getFn;
273521
273645
  }
273522
- return { path: path67, id: id2, weight, src, getFn };
273646
+ return {
273647
+ path: path67,
273648
+ id: id2,
273649
+ weight,
273650
+ src,
273651
+ getFn
273652
+ };
273523
273653
  }
273524
273654
  function createKeyPath(key) {
273525
273655
  return isArray(key) ? key : key.split(".");
@@ -273528,29 +273658,35 @@ function createKeyId(key) {
273528
273658
  return isArray(key) ? key.join(".") : key;
273529
273659
  }
273530
273660
  function get(obj, path67) {
273531
- let list = [];
273661
+ const list = [];
273532
273662
  let arr = false;
273533
- const deepGet = (obj2, path68, index) => {
273663
+ const deepGet = (obj2, path68, index, arrayIndex) => {
273534
273664
  if (!isDefined(obj2)) {
273535
273665
  return;
273536
273666
  }
273537
273667
  if (!path68[index]) {
273538
- list.push(obj2);
273668
+ list.push(arrayIndex !== undefined ? {
273669
+ v: obj2,
273670
+ i: arrayIndex
273671
+ } : obj2);
273539
273672
  } else {
273540
- let key = path68[index];
273673
+ const key = path68[index];
273541
273674
  const value = obj2[key];
273542
273675
  if (!isDefined(value)) {
273543
273676
  return;
273544
273677
  }
273545
- if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value))) {
273546
- list.push(toString2(value));
273678
+ if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
273679
+ list.push(arrayIndex !== undefined ? {
273680
+ v: toString2(value),
273681
+ i: arrayIndex
273682
+ } : toString2(value));
273547
273683
  } else if (isArray(value)) {
273548
273684
  arr = true;
273549
273685
  for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
273550
- deepGet(value[i2], path68, index + 1);
273686
+ deepGet(value[i2], path68, index + 1, i2);
273551
273687
  }
273552
273688
  } else if (path68.length) {
273553
- deepGet(value, path68, index + 1);
273689
+ deepGet(value, path68, index + 1, arrayIndex);
273554
273690
  }
273555
273691
  }
273556
273692
  };
@@ -273577,17 +273713,18 @@ var FuzzyOptions = {
273577
273713
  };
273578
273714
  var AdvancedOptions = {
273579
273715
  useExtendedSearch: false,
273716
+ useTokenSearch: false,
273580
273717
  getFn: get,
273581
273718
  ignoreLocation: false,
273582
273719
  ignoreFieldNorm: false,
273583
273720
  fieldNormWeight: 1
273584
273721
  };
273585
- var Config = {
273722
+ var Config = Object.freeze({
273586
273723
  ...BasicOptions,
273587
273724
  ...MatchOptions,
273588
273725
  ...FuzzyOptions,
273589
273726
  ...AdvancedOptions
273590
- };
273727
+ });
273591
273728
  var SPACE = /[^ ]+/g;
273592
273729
  function norm(weight = 1, mantissa = 3) {
273593
273730
  const cache = new Map;
@@ -273617,6 +273754,9 @@ class FuseIndex {
273617
273754
  this.norm = norm(fieldNormWeight, 3);
273618
273755
  this.getFn = getFn;
273619
273756
  this.isCreated = false;
273757
+ this.docs = [];
273758
+ this.keys = [];
273759
+ this._keysMap = {};
273620
273760
  this.setIndexRecords();
273621
273761
  }
273622
273762
  setSources(docs = []) {
@@ -273662,6 +273802,14 @@ class FuseIndex {
273662
273802
  this.records[i2].i -= 1;
273663
273803
  }
273664
273804
  }
273805
+ removeAll(indices) {
273806
+ for (let i2 = indices.length - 1;i2 >= 0; i2 -= 1) {
273807
+ this.records.splice(indices[i2], 1);
273808
+ }
273809
+ for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1) {
273810
+ this.records[i2].i = i2;
273811
+ }
273812
+ }
273665
273813
  getValueForItemAtKeyId(item, keyId) {
273666
273814
  return item[this._keysMap[keyId]];
273667
273815
  }
@@ -273672,7 +273820,7 @@ class FuseIndex {
273672
273820
  if (!isDefined(doc) || isBlank(doc)) {
273673
273821
  return;
273674
273822
  }
273675
- let record = {
273823
+ const record = {
273676
273824
  v: doc,
273677
273825
  i: docIndex,
273678
273826
  n: this.norm.get(doc)
@@ -273680,39 +273828,46 @@ class FuseIndex {
273680
273828
  this.records.push(record);
273681
273829
  }
273682
273830
  _addObject(doc, docIndex) {
273683
- let record = { i: docIndex, $: {} };
273831
+ const record = {
273832
+ i: docIndex,
273833
+ $: {}
273834
+ };
273684
273835
  this.keys.forEach((key, keyIndex) => {
273685
- let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
273836
+ const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
273686
273837
  if (!isDefined(value)) {
273687
273838
  return;
273688
273839
  }
273689
273840
  if (isArray(value)) {
273690
- let subRecords = [];
273691
- const stack = [{ nestedArrIndex: -1, value }];
273692
- while (stack.length) {
273693
- const { nestedArrIndex, value: value2 } = stack.pop();
273694
- if (!isDefined(value2)) {
273841
+ const subRecords = [];
273842
+ for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
273843
+ const item = value[i2];
273844
+ if (!isDefined(item)) {
273695
273845
  continue;
273696
273846
  }
273697
- if (isString2(value2) && !isBlank(value2)) {
273698
- let subRecord = {
273699
- v: value2,
273700
- i: nestedArrIndex,
273701
- n: this.norm.get(value2)
273702
- };
273703
- subRecords.push(subRecord);
273704
- } else if (isArray(value2)) {
273705
- value2.forEach((item, k4) => {
273706
- stack.push({
273707
- nestedArrIndex: k4,
273708
- value: item
273709
- });
273710
- });
273847
+ if (isString2(item)) {
273848
+ if (!isBlank(item)) {
273849
+ const subRecord = {
273850
+ v: item,
273851
+ i: i2,
273852
+ n: this.norm.get(item)
273853
+ };
273854
+ subRecords.push(subRecord);
273855
+ }
273856
+ } else if (isDefined(item.v)) {
273857
+ const text = isString2(item.v) ? item.v : toString2(item.v);
273858
+ if (!isBlank(text)) {
273859
+ const subRecord = {
273860
+ v: text,
273861
+ i: item.i,
273862
+ n: this.norm.get(text)
273863
+ };
273864
+ subRecords.push(subRecord);
273865
+ }
273711
273866
  }
273712
273867
  }
273713
273868
  record.$[keyIndex] = subRecords;
273714
273869
  } else if (isString2(value) && !isBlank(value)) {
273715
- let subRecord = {
273870
+ const subRecord = {
273716
273871
  v: value,
273717
273872
  n: this.norm.get(value)
273718
273873
  };
@@ -273723,49 +273878,50 @@ class FuseIndex {
273723
273878
  }
273724
273879
  toJSON() {
273725
273880
  return {
273726
- keys: this.keys,
273881
+ keys: this.keys.map(({
273882
+ getFn,
273883
+ ...key
273884
+ }) => key),
273727
273885
  records: this.records
273728
273886
  };
273729
273887
  }
273730
273888
  }
273731
- function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
273732
- const myIndex = new FuseIndex({ getFn, fieldNormWeight });
273889
+ function createIndex(keys, docs, {
273890
+ getFn = Config.getFn,
273891
+ fieldNormWeight = Config.fieldNormWeight
273892
+ } = {}) {
273893
+ const myIndex = new FuseIndex({
273894
+ getFn,
273895
+ fieldNormWeight
273896
+ });
273733
273897
  myIndex.setKeys(keys.map(createKey));
273734
273898
  myIndex.setSources(docs);
273735
273899
  myIndex.create();
273736
273900
  return myIndex;
273737
273901
  }
273738
- function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
273739
- const { keys, records } = data;
273740
- const myIndex = new FuseIndex({ getFn, fieldNormWeight });
273902
+ function parseIndex(data, {
273903
+ getFn = Config.getFn,
273904
+ fieldNormWeight = Config.fieldNormWeight
273905
+ } = {}) {
273906
+ const {
273907
+ keys,
273908
+ records
273909
+ } = data;
273910
+ const myIndex = new FuseIndex({
273911
+ getFn,
273912
+ fieldNormWeight
273913
+ });
273741
273914
  myIndex.setKeys(keys);
273742
273915
  myIndex.setIndexRecords(records);
273743
273916
  return myIndex;
273744
273917
  }
273745
- function computeScore$1(pattern, {
273746
- errors = 0,
273747
- currentLocation = 0,
273748
- expectedLocation = 0,
273749
- distance: distance7 = Config.distance,
273750
- ignoreLocation = Config.ignoreLocation
273751
- } = {}) {
273752
- const accuracy = errors / pattern.length;
273753
- if (ignoreLocation) {
273754
- return accuracy;
273755
- }
273756
- const proximity = Math.abs(expectedLocation - currentLocation);
273757
- if (!distance7) {
273758
- return proximity ? 1 : accuracy;
273759
- }
273760
- return accuracy + proximity / distance7;
273761
- }
273762
273918
  function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
273763
- let indices = [];
273919
+ const indices = [];
273764
273920
  let start = -1;
273765
273921
  let end = -1;
273766
273922
  let i2 = 0;
273767
273923
  for (let len = matchmask.length;i2 < len; i2 += 1) {
273768
- let match = matchmask[i2];
273924
+ const match = matchmask[i2];
273769
273925
  if (match && start === -1) {
273770
273926
  start = i2;
273771
273927
  } else if (!match && start !== -1) {
@@ -273799,16 +273955,20 @@ function search(text, pattern, patternAlphabet, {
273799
273955
  const expectedLocation = Math.max(0, Math.min(location, textLen));
273800
273956
  let currentThreshold = threshold;
273801
273957
  let bestLocation = expectedLocation;
273958
+ const calcScore = (errors, currentLocation) => {
273959
+ const accuracy = errors / patternLen;
273960
+ if (ignoreLocation)
273961
+ return accuracy;
273962
+ const proximity = Math.abs(expectedLocation - currentLocation);
273963
+ if (!distance7)
273964
+ return proximity ? 1 : accuracy;
273965
+ return accuracy + proximity / distance7;
273966
+ };
273802
273967
  const computeMatches = minMatchCharLength > 1 || includeMatches;
273803
273968
  const matchMask = computeMatches ? Array(textLen) : [];
273804
273969
  let index;
273805
273970
  while ((index = text.indexOf(pattern, bestLocation)) > -1) {
273806
- let score = computeScore$1(pattern, {
273807
- currentLocation: index,
273808
- expectedLocation,
273809
- distance: distance7,
273810
- ignoreLocation
273811
- });
273971
+ const score = calcScore(0, index);
273812
273972
  currentThreshold = Math.min(score, currentThreshold);
273813
273973
  bestLocation = index + patternLen;
273814
273974
  if (computeMatches) {
@@ -273828,13 +273988,7 @@ function search(text, pattern, patternAlphabet, {
273828
273988
  let binMin = 0;
273829
273989
  let binMid = binMax;
273830
273990
  while (binMin < binMid) {
273831
- const score2 = computeScore$1(pattern, {
273832
- errors: i2,
273833
- currentLocation: expectedLocation + binMid,
273834
- expectedLocation,
273835
- distance: distance7,
273836
- ignoreLocation
273837
- });
273991
+ const score2 = calcScore(i2, expectedLocation + binMid);
273838
273992
  if (score2 <= currentThreshold) {
273839
273993
  binMin = binMid;
273840
273994
  } else {
@@ -273844,12 +273998,12 @@ function search(text, pattern, patternAlphabet, {
273844
273998
  }
273845
273999
  binMax = binMid;
273846
274000
  let start = Math.max(1, expectedLocation - binMid + 1);
273847
- let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
273848
- let bitArr = Array(finish + 2);
274001
+ const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
274002
+ const bitArr = Array(finish + 2);
273849
274003
  bitArr[finish + 1] = (1 << i2) - 1;
273850
274004
  for (let j4 = finish;j4 >= start; j4 -= 1) {
273851
- let currentLocation = j4 - 1;
273852
- let charMatch = patternAlphabet[text.charAt(currentLocation)];
274005
+ const currentLocation = j4 - 1;
274006
+ const charMatch = patternAlphabet[text[currentLocation]];
273853
274007
  if (computeMatches) {
273854
274008
  matchMask[currentLocation] = +!!charMatch;
273855
274009
  }
@@ -273858,13 +274012,7 @@ function search(text, pattern, patternAlphabet, {
273858
274012
  bitArr[j4] |= (lastBitArr[j4 + 1] | lastBitArr[j4]) << 1 | 1 | lastBitArr[j4 + 1];
273859
274013
  }
273860
274014
  if (bitArr[j4] & mask) {
273861
- finalScore = computeScore$1(pattern, {
273862
- errors: i2,
273863
- currentLocation,
273864
- expectedLocation,
273865
- distance: distance7,
273866
- ignoreLocation
273867
- });
274015
+ finalScore = calcScore(i2, currentLocation);
273868
274016
  if (finalScore <= currentThreshold) {
273869
274017
  currentThreshold = finalScore;
273870
274018
  bestLocation = currentLocation;
@@ -273875,13 +274023,7 @@ function search(text, pattern, patternAlphabet, {
273875
274023
  }
273876
274024
  }
273877
274025
  }
273878
- const score = computeScore$1(pattern, {
273879
- errors: i2 + 1,
273880
- currentLocation: expectedLocation,
273881
- expectedLocation,
273882
- distance: distance7,
273883
- ignoreLocation
273884
- });
274026
+ const score = calcScore(i2 + 1, expectedLocation);
273885
274027
  if (score > currentThreshold) {
273886
274028
  break;
273887
274029
  }
@@ -273902,14 +274044,45 @@ function search(text, pattern, patternAlphabet, {
273902
274044
  return result;
273903
274045
  }
273904
274046
  function createPatternAlphabet(pattern) {
273905
- let mask = {};
274047
+ const mask = {};
273906
274048
  for (let i2 = 0, len = pattern.length;i2 < len; i2 += 1) {
273907
274049
  const char = pattern.charAt(i2);
273908
274050
  mask[char] = (mask[char] || 0) | 1 << len - i2 - 1;
273909
274051
  }
273910
274052
  return mask;
273911
274053
  }
273912
- var stripDiacritics = String.prototype.normalize ? (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, "") : (str) => str;
274054
+ function mergeIndices(indices) {
274055
+ if (indices.length <= 1)
274056
+ return indices;
274057
+ indices.sort((a2, b) => a2[0] - b[0] || a2[1] - b[1]);
274058
+ const merged = [indices[0]];
274059
+ for (let i2 = 1, len = indices.length;i2 < len; i2 += 1) {
274060
+ const last = merged[merged.length - 1];
274061
+ const curr = indices[i2];
274062
+ if (curr[0] <= last[1] + 1) {
274063
+ last[1] = Math.max(last[1], curr[1]);
274064
+ } else {
274065
+ merged.push(curr);
274066
+ }
274067
+ }
274068
+ return merged;
274069
+ }
274070
+ var NON_DECOMPOSABLE_MAP = {
274071
+ "ł": "l",
274072
+ "Ł": "L",
274073
+ "đ": "d",
274074
+ "Đ": "D",
274075
+ "ø": "o",
274076
+ "Ø": "O",
274077
+ "ħ": "h",
274078
+ "Ħ": "H",
274079
+ "ŧ": "t",
274080
+ "Ŧ": "T",
274081
+ "ı": "i",
274082
+ "ß": "ss"
274083
+ };
274084
+ var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
274085
+ var stripDiacritics = String.prototype.normalize ? (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, (ch3) => NON_DECOMPOSABLE_MAP[ch3]) : (str) => str;
273913
274086
 
273914
274087
  class BitapSearch {
273915
274088
  constructor(pattern, {
@@ -273966,11 +274139,15 @@ class BitapSearch {
273966
274139
  }
273967
274140
  }
273968
274141
  searchIn(text) {
273969
- const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
274142
+ const {
274143
+ isCaseSensitive,
274144
+ ignoreDiacritics,
274145
+ includeMatches
274146
+ } = this.options;
273970
274147
  text = isCaseSensitive ? text : text.toLowerCase();
273971
274148
  text = ignoreDiacritics ? stripDiacritics(text) : text;
273972
274149
  if (this.pattern === text) {
273973
- let result2 = {
274150
+ const result2 = {
273974
274151
  isMatch: true,
273975
274152
  score: 0
273976
274153
  };
@@ -273987,11 +274164,19 @@ class BitapSearch {
273987
274164
  minMatchCharLength,
273988
274165
  ignoreLocation
273989
274166
  } = this.options;
273990
- let allIndices = [];
274167
+ const allIndices = [];
273991
274168
  let totalScore = 0;
273992
274169
  let hasMatches = false;
273993
- this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
273994
- const { isMatch, score, indices } = search(text, pattern, alphabet, {
274170
+ this.chunks.forEach(({
274171
+ pattern,
274172
+ alphabet,
274173
+ startIndex
274174
+ }) => {
274175
+ const {
274176
+ isMatch,
274177
+ score,
274178
+ indices
274179
+ } = search(text, pattern, alphabet, {
273995
274180
  location: location + startIndex,
273996
274181
  distance: distance7,
273997
274182
  threshold,
@@ -274005,15 +274190,15 @@ class BitapSearch {
274005
274190
  }
274006
274191
  totalScore += score;
274007
274192
  if (isMatch && indices) {
274008
- allIndices = [...allIndices, ...indices];
274193
+ allIndices.push(...indices);
274009
274194
  }
274010
274195
  });
274011
- let result = {
274196
+ const result = {
274012
274197
  isMatch: hasMatches,
274013
274198
  score: hasMatches ? totalScore / this.chunks.length : 1
274014
274199
  };
274015
274200
  if (hasMatches && includeMatches) {
274016
- result.indices = allIndices;
274201
+ result.indices = mergeIndices(allIndices);
274017
274202
  }
274018
274203
  return result;
274019
274204
  }
@@ -274029,7 +274214,12 @@ class BaseMatch {
274029
274214
  static isSingleMatch(pattern) {
274030
274215
  return getMatch(pattern, this.singleRegex);
274031
274216
  }
274032
- search() {}
274217
+ search(_text) {
274218
+ return {
274219
+ isMatch: false,
274220
+ score: 1
274221
+ };
274222
+ }
274033
274223
  }
274034
274224
  function getMatch(pattern, exp) {
274035
274225
  const matches = pattern.match(exp);
@@ -274244,30 +274434,62 @@ class IncludeMatch extends BaseMatch {
274244
274434
  };
274245
274435
  }
274246
274436
  }
274247
- var searchers = [
274248
- ExactMatch,
274249
- IncludeMatch,
274250
- PrefixExactMatch,
274251
- InversePrefixExactMatch,
274252
- InverseSuffixExactMatch,
274253
- SuffixExactMatch,
274254
- InverseExactMatch,
274255
- FuzzyMatch
274256
- ];
274437
+ var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
274257
274438
  var searchersLen = searchers.length;
274258
- var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
274439
+ var ESCAPED_PIPE = "\x00";
274259
274440
  var OR_TOKEN = "|";
274441
+ function tokenize3(pattern) {
274442
+ const tokens = [];
274443
+ const len = pattern.length;
274444
+ let i2 = 0;
274445
+ while (i2 < len) {
274446
+ while (i2 < len && pattern[i2] === " ")
274447
+ i2++;
274448
+ if (i2 >= len)
274449
+ break;
274450
+ let j4 = i2;
274451
+ while (j4 < len && pattern[j4] !== " " && pattern[j4] !== '"')
274452
+ j4++;
274453
+ if (j4 < len && pattern[j4] === '"') {
274454
+ j4++;
274455
+ while (j4 < len) {
274456
+ if (pattern[j4] === '"') {
274457
+ const next = j4 + 1;
274458
+ if (next >= len || pattern[next] === " ") {
274459
+ j4++;
274460
+ break;
274461
+ }
274462
+ if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
274463
+ j4 += 2;
274464
+ break;
274465
+ }
274466
+ }
274467
+ j4++;
274468
+ }
274469
+ tokens.push(pattern.substring(i2, j4));
274470
+ i2 = j4;
274471
+ } else {
274472
+ while (j4 < len && pattern[j4] !== " ")
274473
+ j4++;
274474
+ tokens.push(pattern.substring(i2, j4));
274475
+ i2 = j4;
274476
+ }
274477
+ }
274478
+ return tokens;
274479
+ }
274260
274480
  function parseQuery(pattern, options = {}) {
274261
- return pattern.split(OR_TOKEN).map((item) => {
274262
- let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
274263
- let results = [];
274481
+ const escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
274482
+ return escaped.split(OR_TOKEN).map((item) => {
274483
+ const restored = item.replace(/\u0000/g, "|");
274484
+ const query = tokenize3(restored.trim()).filter((item2) => item2 && !!item2.trim());
274485
+ const results = [];
274264
274486
  for (let i2 = 0, len = query.length;i2 < len; i2 += 1) {
274265
274487
  const queryItem = query[i2];
274266
274488
  let found = false;
274267
274489
  let idx = -1;
274268
274490
  while (!found && ++idx < searchersLen) {
274269
274491
  const searcher = searchers[idx];
274270
- let token = searcher.isMultiMatch(queryItem);
274492
+ const token = searcher.isMultiMatch(queryItem);
274271
274493
  if (token) {
274272
274494
  results.push(new searcher(token, options));
274273
274495
  found = true;
@@ -274279,7 +274501,7 @@ function parseQuery(pattern, options = {}) {
274279
274501
  idx = -1;
274280
274502
  while (++idx < searchersLen) {
274281
274503
  const searcher = searchers[idx];
274282
- let token = searcher.isSingleMatch(queryItem);
274504
+ const token = searcher.isSingleMatch(queryItem);
274283
274505
  if (token) {
274284
274506
  results.push(new searcher(token, options));
274285
274507
  break;
@@ -274331,26 +274553,39 @@ class ExtendedSearch {
274331
274553
  score: 1
274332
274554
  };
274333
274555
  }
274334
- const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
274556
+ const {
274557
+ includeMatches,
274558
+ isCaseSensitive,
274559
+ ignoreDiacritics
274560
+ } = this.options;
274335
274561
  text = isCaseSensitive ? text : text.toLowerCase();
274336
274562
  text = ignoreDiacritics ? stripDiacritics(text) : text;
274337
274563
  let numMatches = 0;
274338
- let allIndices = [];
274564
+ const allIndices = [];
274339
274565
  let totalScore = 0;
274566
+ let hasInverse = false;
274340
274567
  for (let i2 = 0, qLen = query.length;i2 < qLen; i2 += 1) {
274341
274568
  const searchers2 = query[i2];
274342
274569
  allIndices.length = 0;
274343
274570
  numMatches = 0;
274571
+ hasInverse = false;
274344
274572
  for (let j4 = 0, pLen = searchers2.length;j4 < pLen; j4 += 1) {
274345
274573
  const searcher = searchers2[j4];
274346
- const { isMatch, indices, score } = searcher.search(text);
274574
+ const {
274575
+ isMatch,
274576
+ indices,
274577
+ score
274578
+ } = searcher.search(text);
274347
274579
  if (isMatch) {
274348
274580
  numMatches += 1;
274349
274581
  totalScore += score;
274582
+ const type = searcher.constructor.type;
274583
+ if (type.startsWith("inverse")) {
274584
+ hasInverse = true;
274585
+ }
274350
274586
  if (includeMatches) {
274351
- const type = searcher.constructor.type;
274352
274587
  if (MultiMatchSet.has(type)) {
274353
- allIndices = [...allIndices, ...indices];
274588
+ allIndices.push(...indices);
274354
274589
  } else {
274355
274590
  allIndices.push(indices);
274356
274591
  }
@@ -274359,16 +274594,20 @@ class ExtendedSearch {
274359
274594
  totalScore = 0;
274360
274595
  numMatches = 0;
274361
274596
  allIndices.length = 0;
274597
+ hasInverse = false;
274362
274598
  break;
274363
274599
  }
274364
274600
  }
274365
274601
  if (numMatches) {
274366
- let result = {
274602
+ const result = {
274367
274603
  isMatch: true,
274368
274604
  score: totalScore / numMatches
274369
274605
  };
274606
+ if (hasInverse) {
274607
+ result.hasInverse = true;
274608
+ }
274370
274609
  if (includeMatches) {
274371
- result.indices = allIndices;
274610
+ result.indices = mergeIndices(allIndices);
274372
274611
  }
274373
274612
  return result;
274374
274613
  }
@@ -274385,7 +274624,7 @@ function register2(...args) {
274385
274624
  }
274386
274625
  function createSearcher(pattern, options) {
274387
274626
  for (let i2 = 0, len = registeredSearchers.length;i2 < len; i2 += 1) {
274388
- let searcherClass = registeredSearchers[i2];
274627
+ const searcherClass = registeredSearchers[i2];
274389
274628
  if (searcherClass.condition(pattern, options)) {
274390
274629
  return new searcherClass(pattern, options);
274391
274630
  }
@@ -274408,9 +274647,21 @@ var convertToExplicit = (query) => ({
274408
274647
  [key]: query[key]
274409
274648
  }))
274410
274649
  });
274411
- function parse3(query, options, { auto = true } = {}) {
274650
+ function parse3(query, options, {
274651
+ auto = true
274652
+ } = {}) {
274412
274653
  const next = (query2) => {
274413
- let keys = Object.keys(query2);
274654
+ if (isString2(query2)) {
274655
+ const obj = {
274656
+ keyId: null,
274657
+ pattern: query2
274658
+ };
274659
+ if (auto) {
274660
+ obj.searcher = createSearcher(query2, options);
274661
+ }
274662
+ return obj;
274663
+ }
274664
+ const keys = Object.keys(query2);
274414
274665
  const isQueryPath = isPath(query2);
274415
274666
  if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
274416
274667
  return next(convertToExplicit(query2));
@@ -274430,7 +274681,7 @@ function parse3(query, options, { auto = true } = {}) {
274430
274681
  }
274431
274682
  return obj;
274432
274683
  }
274433
- let node = {
274684
+ const node = {
274434
274685
  children: [],
274435
274686
  operator: keys[0]
274436
274687
  };
@@ -274449,16 +274700,87 @@ function parse3(query, options, { auto = true } = {}) {
274449
274700
  }
274450
274701
  return next(query);
274451
274702
  }
274452
- function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
274703
+ function computeScoreSingle(matches, {
274704
+ ignoreFieldNorm = Config.ignoreFieldNorm
274705
+ }) {
274706
+ let totalScore = 1;
274707
+ matches.forEach(({
274708
+ key,
274709
+ norm: norm2,
274710
+ score
274711
+ }) => {
274712
+ const weight = key ? key.weight : null;
274713
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
274714
+ });
274715
+ return totalScore;
274716
+ }
274717
+ function computeScore(results, {
274718
+ ignoreFieldNorm = Config.ignoreFieldNorm
274719
+ }) {
274453
274720
  results.forEach((result) => {
274454
- let totalScore = 1;
274455
- result.matches.forEach(({ key, norm: norm2, score }) => {
274456
- const weight = key ? key.weight : null;
274457
- totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
274721
+ result.score = computeScoreSingle(result.matches, {
274722
+ ignoreFieldNorm
274458
274723
  });
274459
- result.score = totalScore;
274460
274724
  });
274461
274725
  }
274726
+
274727
+ class MaxHeap {
274728
+ constructor(limit) {
274729
+ this.limit = limit;
274730
+ this.heap = [];
274731
+ }
274732
+ get size() {
274733
+ return this.heap.length;
274734
+ }
274735
+ shouldInsert(score) {
274736
+ return this.size < this.limit || score < this.heap[0].score;
274737
+ }
274738
+ insert(item) {
274739
+ if (this.size < this.limit) {
274740
+ this.heap.push(item);
274741
+ this._bubbleUp(this.size - 1);
274742
+ } else if (item.score < this.heap[0].score) {
274743
+ this.heap[0] = item;
274744
+ this._sinkDown(0);
274745
+ }
274746
+ }
274747
+ extractSorted(sortFn) {
274748
+ return this.heap.sort(sortFn);
274749
+ }
274750
+ _bubbleUp(i2) {
274751
+ const heap = this.heap;
274752
+ while (i2 > 0) {
274753
+ const parent = i2 - 1 >> 1;
274754
+ if (heap[i2].score <= heap[parent].score)
274755
+ break;
274756
+ const tmp = heap[i2];
274757
+ heap[i2] = heap[parent];
274758
+ heap[parent] = tmp;
274759
+ i2 = parent;
274760
+ }
274761
+ }
274762
+ _sinkDown(i2) {
274763
+ const heap = this.heap;
274764
+ const len = heap.length;
274765
+ let largest = i2;
274766
+ do {
274767
+ i2 = largest;
274768
+ const left = 2 * i2 + 1;
274769
+ const right = 2 * i2 + 2;
274770
+ if (left < len && heap[left].score > heap[largest].score) {
274771
+ largest = left;
274772
+ }
274773
+ if (right < len && heap[right].score > heap[largest].score) {
274774
+ largest = right;
274775
+ }
274776
+ if (largest !== i2) {
274777
+ const tmp = heap[i2];
274778
+ heap[i2] = heap[largest];
274779
+ heap[largest] = tmp;
274780
+ }
274781
+ } while (largest !== i2);
274782
+ }
274783
+ }
274462
274784
  function transformMatches(result, data) {
274463
274785
  const matches = result.matches;
274464
274786
  data.matches = [];
@@ -274469,8 +274791,11 @@ function transformMatches(result, data) {
274469
274791
  if (!isDefined(match.indices) || !match.indices.length) {
274470
274792
  return;
274471
274793
  }
274472
- const { indices, value } = match;
274473
- let obj = {
274794
+ const {
274795
+ indices,
274796
+ value
274797
+ } = match;
274798
+ const obj = {
274474
274799
  indices,
274475
274800
  value
274476
274801
  };
@@ -274496,7 +274821,9 @@ function format(results, docs, {
274496
274821
  if (includeScore)
274497
274822
  transformers.push(transformScore);
274498
274823
  return results.map((result) => {
274499
- const { idx } = result;
274824
+ const {
274825
+ idx
274826
+ } = result;
274500
274827
  const data = {
274501
274828
  item: docs[idx],
274502
274829
  refIndex: idx
@@ -274509,13 +274836,180 @@ function format(results, docs, {
274509
274836
  return data;
274510
274837
  });
274511
274838
  }
274839
+ var WORD = /\b\w+\b/g;
274840
+ function createAnalyzer({
274841
+ isCaseSensitive = false,
274842
+ ignoreDiacritics = false
274843
+ } = {}) {
274844
+ return {
274845
+ tokenize(text) {
274846
+ if (!isCaseSensitive) {
274847
+ text = text.toLowerCase();
274848
+ }
274849
+ if (ignoreDiacritics) {
274850
+ text = stripDiacritics(text);
274851
+ }
274852
+ return text.match(WORD) || [];
274853
+ }
274854
+ };
274855
+ }
274856
+ function buildInvertedIndex(records, keyCount, analyzer) {
274857
+ const terms = new Map;
274858
+ const df3 = new Map;
274859
+ let fieldCount = 0;
274860
+ function addField(text, docIdx, keyIdx, subIdx) {
274861
+ const tokens = analyzer.tokenize(text);
274862
+ if (!tokens.length)
274863
+ return;
274864
+ fieldCount++;
274865
+ const termFreqs = new Map;
274866
+ for (const token of tokens) {
274867
+ termFreqs.set(token, (termFreqs.get(token) || 0) + 1);
274868
+ }
274869
+ for (const [term, tf3] of termFreqs) {
274870
+ const posting = {
274871
+ docIdx,
274872
+ keyIdx,
274873
+ subIdx,
274874
+ tf: tf3
274875
+ };
274876
+ let postings = terms.get(term);
274877
+ if (!postings) {
274878
+ postings = [];
274879
+ terms.set(term, postings);
274880
+ }
274881
+ postings.push(posting);
274882
+ df3.set(term, (df3.get(term) || 0) + 1);
274883
+ }
274884
+ }
274885
+ for (const record of records) {
274886
+ const {
274887
+ i: docIdx,
274888
+ v: v3,
274889
+ $: fields
274890
+ } = record;
274891
+ if (v3 !== undefined) {
274892
+ addField(v3, docIdx, -1, -1);
274893
+ continue;
274894
+ }
274895
+ if (fields) {
274896
+ for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
274897
+ const value = fields[keyIdx];
274898
+ if (!value)
274899
+ continue;
274900
+ if (Array.isArray(value)) {
274901
+ for (const sub of value) {
274902
+ addField(sub.v, docIdx, keyIdx, sub.i ?? -1);
274903
+ }
274904
+ } else {
274905
+ addField(value.v, docIdx, keyIdx, -1);
274906
+ }
274907
+ }
274908
+ }
274909
+ }
274910
+ return {
274911
+ terms,
274912
+ fieldCount,
274913
+ df: df3
274914
+ };
274915
+ }
274916
+ function addToInvertedIndex(index, record, keyCount, analyzer) {
274917
+ const {
274918
+ i: docIdx,
274919
+ v: v3,
274920
+ $: fields
274921
+ } = record;
274922
+ function addField(text, keyIdx, subIdx) {
274923
+ const tokens = analyzer.tokenize(text);
274924
+ if (!tokens.length)
274925
+ return;
274926
+ index.fieldCount++;
274927
+ const termFreqs = new Map;
274928
+ for (const token of tokens) {
274929
+ termFreqs.set(token, (termFreqs.get(token) || 0) + 1);
274930
+ }
274931
+ for (const [term, tf3] of termFreqs) {
274932
+ const posting = {
274933
+ docIdx,
274934
+ keyIdx,
274935
+ subIdx,
274936
+ tf: tf3
274937
+ };
274938
+ let postings = index.terms.get(term);
274939
+ if (!postings) {
274940
+ postings = [];
274941
+ index.terms.set(term, postings);
274942
+ }
274943
+ postings.push(posting);
274944
+ index.df.set(term, (index.df.get(term) || 0) + 1);
274945
+ }
274946
+ }
274947
+ if (v3 !== undefined) {
274948
+ addField(v3, -1, -1);
274949
+ return;
274950
+ }
274951
+ if (fields) {
274952
+ for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
274953
+ const value = fields[keyIdx];
274954
+ if (!value)
274955
+ continue;
274956
+ if (Array.isArray(value)) {
274957
+ for (const sub of value) {
274958
+ addField(sub.v, keyIdx, sub.i ?? -1);
274959
+ }
274960
+ } else {
274961
+ addField(value.v, keyIdx, -1);
274962
+ }
274963
+ }
274964
+ }
274965
+ }
274966
+ function removeFromInvertedIndex(index, docIdx) {
274967
+ for (const [term, postings] of index.terms) {
274968
+ const filtered = postings.filter((p3) => p3.docIdx !== docIdx);
274969
+ const removed = postings.length - filtered.length;
274970
+ if (removed > 0) {
274971
+ index.fieldCount -= removed;
274972
+ index.df.set(term, (index.df.get(term) || 0) - removed);
274973
+ if (filtered.length === 0) {
274974
+ index.terms.delete(term);
274975
+ index.df.delete(term);
274976
+ } else {
274977
+ index.terms.set(term, filtered);
274978
+ }
274979
+ }
274980
+ }
274981
+ }
274512
274982
 
274513
274983
  class Fuse2 {
274514
- constructor(docs, options = {}, index) {
274515
- this.options = { ...Config, ...options };
274516
- if (this.options.useExtendedSearch && false) {}
274984
+ constructor(docs, options, index) {
274985
+ this.options = {
274986
+ ...Config,
274987
+ ...options
274988
+ };
274989
+ if (this.options.useExtendedSearch && false)
274990
+ ;
274991
+ if (this.options.useTokenSearch && false)
274992
+ ;
274517
274993
  this._keyStore = new KeyStore(this.options.keys);
274994
+ this._docs = docs;
274995
+ this._myIndex = null;
274996
+ this._invertedIndex = null;
274518
274997
  this.setCollection(docs, index);
274998
+ this._lastQuery = null;
274999
+ this._lastSearcher = null;
275000
+ }
275001
+ _getSearcher(query) {
275002
+ if (this._lastQuery === query) {
275003
+ return this._lastSearcher;
275004
+ }
275005
+ const opts = this._invertedIndex ? {
275006
+ ...this.options,
275007
+ _invertedIndex: this._invertedIndex
275008
+ } : this.options;
275009
+ const searcher = createSearcher(query, opts);
275010
+ this._lastQuery = query;
275011
+ this._lastSearcher = searcher;
275012
+ return searcher;
274519
275013
  }
274520
275014
  setCollection(docs, index) {
274521
275015
  this._docs = docs;
@@ -274526,6 +275020,13 @@ class Fuse2 {
274526
275020
  getFn: this.options.getFn,
274527
275021
  fieldNormWeight: this.options.fieldNormWeight
274528
275022
  });
275023
+ if (this.options.useTokenSearch) {
275024
+ const analyzer = createAnalyzer({
275025
+ isCaseSensitive: this.options.isCaseSensitive,
275026
+ ignoreDiacritics: this.options.ignoreDiacritics
275027
+ });
275028
+ this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
275029
+ }
274529
275030
  }
274530
275031
  add(doc) {
274531
275032
  if (!isDefined(doc)) {
@@ -274533,28 +275034,52 @@ class Fuse2 {
274533
275034
  }
274534
275035
  this._docs.push(doc);
274535
275036
  this._myIndex.add(doc);
275037
+ if (this._invertedIndex) {
275038
+ const record = this._myIndex.records[this._myIndex.records.length - 1];
275039
+ const analyzer = createAnalyzer({
275040
+ isCaseSensitive: this.options.isCaseSensitive,
275041
+ ignoreDiacritics: this.options.ignoreDiacritics
275042
+ });
275043
+ addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
275044
+ }
274536
275045
  }
274537
275046
  remove(predicate = () => false) {
274538
275047
  const results = [];
275048
+ const indicesToRemove = [];
274539
275049
  for (let i2 = 0, len = this._docs.length;i2 < len; i2 += 1) {
274540
- const doc = this._docs[i2];
274541
- if (predicate(doc, i2)) {
274542
- this.removeAt(i2);
274543
- i2 -= 1;
274544
- len -= 1;
274545
- results.push(doc);
275050
+ if (predicate(this._docs[i2], i2)) {
275051
+ results.push(this._docs[i2]);
275052
+ indicesToRemove.push(i2);
274546
275053
  }
274547
275054
  }
275055
+ if (indicesToRemove.length) {
275056
+ if (this._invertedIndex) {
275057
+ for (const idx of indicesToRemove) {
275058
+ removeFromInvertedIndex(this._invertedIndex, idx);
275059
+ }
275060
+ }
275061
+ for (let i2 = indicesToRemove.length - 1;i2 >= 0; i2 -= 1) {
275062
+ this._docs.splice(indicesToRemove[i2], 1);
275063
+ }
275064
+ this._myIndex.removeAll(indicesToRemove);
275065
+ }
274548
275066
  return results;
274549
275067
  }
274550
275068
  removeAt(idx) {
274551
- this._docs.splice(idx, 1);
275069
+ if (this._invertedIndex) {
275070
+ removeFromInvertedIndex(this._invertedIndex, idx);
275071
+ }
275072
+ const doc = this._docs.splice(idx, 1)[0];
274552
275073
  this._myIndex.removeAt(idx);
275074
+ return doc;
274553
275075
  }
274554
275076
  getIndex() {
274555
275077
  return this._myIndex;
274556
275078
  }
274557
- search(query, { limit = -1 } = {}) {
275079
+ search(query, options) {
275080
+ const {
275081
+ limit = -1
275082
+ } = options || {};
274558
275083
  const {
274559
275084
  includeMatches,
274560
275085
  includeScore,
@@ -274562,34 +275087,92 @@ class Fuse2 {
274562
275087
  sortFn,
274563
275088
  ignoreFieldNorm
274564
275089
  } = this.options;
274565
- let results = isString2(query) ? isString2(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
274566
- computeScore(results, { ignoreFieldNorm });
274567
- if (shouldSort) {
274568
- results.sort(sortFn);
274569
- }
274570
- if (isNumber2(limit) && limit > -1) {
274571
- results = results.slice(0, limit);
275090
+ if (isString2(query) && !query.trim()) {
275091
+ let docs = this._docs.map((item, idx) => ({
275092
+ item,
275093
+ refIndex: idx
275094
+ }));
275095
+ if (isNumber2(limit) && limit > -1) {
275096
+ docs = docs.slice(0, limit);
275097
+ }
275098
+ return docs;
275099
+ }
275100
+ const useHeap = isNumber2(limit) && limit > 0 && isString2(query);
275101
+ let results;
275102
+ if (useHeap) {
275103
+ const heap = new MaxHeap(limit);
275104
+ if (isString2(this._docs[0])) {
275105
+ this._searchStringList(query, {
275106
+ heap,
275107
+ ignoreFieldNorm
275108
+ });
275109
+ } else {
275110
+ this._searchObjectList(query, {
275111
+ heap,
275112
+ ignoreFieldNorm
275113
+ });
275114
+ }
275115
+ results = heap.extractSorted(sortFn);
275116
+ } else {
275117
+ results = isString2(query) ? isString2(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
275118
+ computeScore(results, {
275119
+ ignoreFieldNorm
275120
+ });
275121
+ if (shouldSort) {
275122
+ results.sort(sortFn);
275123
+ }
275124
+ if (isNumber2(limit) && limit > -1) {
275125
+ results = results.slice(0, limit);
275126
+ }
274572
275127
  }
274573
275128
  return format(results, this._docs, {
274574
275129
  includeMatches,
274575
275130
  includeScore
274576
275131
  });
274577
275132
  }
274578
- _searchStringList(query) {
274579
- const searcher = createSearcher(query, this.options);
274580
- const { records } = this._myIndex;
274581
- const results = [];
274582
- records.forEach(({ v: text, i: idx, n: norm2 }) => {
275133
+ _searchStringList(query, {
275134
+ heap,
275135
+ ignoreFieldNorm
275136
+ } = {}) {
275137
+ const searcher = this._getSearcher(query);
275138
+ const {
275139
+ records
275140
+ } = this._myIndex;
275141
+ const results = heap ? null : [];
275142
+ records.forEach(({
275143
+ v: text,
275144
+ i: idx,
275145
+ n: norm2
275146
+ }) => {
274583
275147
  if (!isDefined(text)) {
274584
275148
  return;
274585
275149
  }
274586
- const { isMatch, score, indices } = searcher.searchIn(text);
275150
+ const {
275151
+ isMatch,
275152
+ score,
275153
+ indices
275154
+ } = searcher.searchIn(text);
274587
275155
  if (isMatch) {
274588
- results.push({
275156
+ const result = {
274589
275157
  item: text,
274590
275158
  idx,
274591
- matches: [{ score, value: text, norm: norm2, indices }]
274592
- });
275159
+ matches: [{
275160
+ score,
275161
+ value: text,
275162
+ norm: norm2,
275163
+ indices
275164
+ }]
275165
+ };
275166
+ if (heap) {
275167
+ result.score = computeScoreSingle(result.matches, {
275168
+ ignoreFieldNorm
275169
+ });
275170
+ if (heap.shouldInsert(result.score)) {
275171
+ heap.insert(result);
275172
+ }
275173
+ } else {
275174
+ results.push(result);
275175
+ }
274593
275176
  }
274594
275177
  });
274595
275178
  return results;
@@ -274597,92 +275180,163 @@ class Fuse2 {
274597
275180
  _searchLogical(query) {
274598
275181
  const expression = parse3(query, this.options);
274599
275182
  const evaluate = (node, item, idx) => {
274600
- if (!node.children) {
274601
- const { keyId, searcher } = node;
274602
- const matches = this._findMatches({
274603
- key: this._keyStore.get(keyId),
274604
- value: this._myIndex.getValueForItemAtKeyId(item, keyId),
275183
+ if (!("children" in node)) {
275184
+ const {
275185
+ keyId,
274605
275186
  searcher
274606
- });
275187
+ } = node;
275188
+ let matches;
275189
+ if (keyId === null) {
275190
+ matches = [];
275191
+ this._myIndex.keys.forEach((key, keyIndex) => {
275192
+ matches.push(...this._findMatches({
275193
+ key,
275194
+ value: item[keyIndex],
275195
+ searcher
275196
+ }));
275197
+ });
275198
+ } else {
275199
+ matches = this._findMatches({
275200
+ key: this._keyStore.get(keyId),
275201
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
275202
+ searcher
275203
+ });
275204
+ }
274607
275205
  if (matches && matches.length) {
274608
- return [
274609
- {
274610
- idx,
274611
- item,
274612
- matches
274613
- }
274614
- ];
275206
+ return [{
275207
+ idx,
275208
+ item,
275209
+ matches
275210
+ }];
274615
275211
  }
274616
275212
  return [];
274617
275213
  }
275214
+ const {
275215
+ children,
275216
+ operator
275217
+ } = node;
274618
275218
  const res2 = [];
274619
- for (let i2 = 0, len = node.children.length;i2 < len; i2 += 1) {
274620
- const child = node.children[i2];
275219
+ for (let i2 = 0, len = children.length;i2 < len; i2 += 1) {
275220
+ const child = children[i2];
274621
275221
  const result = evaluate(child, item, idx);
274622
275222
  if (result.length) {
274623
275223
  res2.push(...result);
274624
- } else if (node.operator === LogicalOperator.AND) {
275224
+ } else if (operator === LogicalOperator.AND) {
274625
275225
  return [];
274626
275226
  }
274627
275227
  }
274628
275228
  return res2;
274629
275229
  };
274630
275230
  const records = this._myIndex.records;
274631
- const resultMap = {};
275231
+ const resultMap = new Map;
274632
275232
  const results = [];
274633
- records.forEach(({ $: item, i: idx }) => {
275233
+ records.forEach(({
275234
+ $: item,
275235
+ i: idx
275236
+ }) => {
274634
275237
  if (isDefined(item)) {
274635
- let expResults = evaluate(expression, item, idx);
275238
+ const expResults = evaluate(expression, item, idx);
274636
275239
  if (expResults.length) {
274637
- if (!resultMap[idx]) {
274638
- resultMap[idx] = { idx, item, matches: [] };
274639
- results.push(resultMap[idx]);
275240
+ if (!resultMap.has(idx)) {
275241
+ resultMap.set(idx, {
275242
+ idx,
275243
+ item,
275244
+ matches: []
275245
+ });
275246
+ results.push(resultMap.get(idx));
274640
275247
  }
274641
- expResults.forEach(({ matches }) => {
274642
- resultMap[idx].matches.push(...matches);
275248
+ expResults.forEach(({
275249
+ matches
275250
+ }) => {
275251
+ resultMap.get(idx).matches.push(...matches);
274643
275252
  });
274644
275253
  }
274645
275254
  }
274646
275255
  });
274647
275256
  return results;
274648
275257
  }
274649
- _searchObjectList(query) {
274650
- const searcher = createSearcher(query, this.options);
274651
- const { keys, records } = this._myIndex;
274652
- const results = [];
274653
- records.forEach(({ $: item, i: idx }) => {
275258
+ _searchObjectList(query, {
275259
+ heap,
275260
+ ignoreFieldNorm
275261
+ } = {}) {
275262
+ const searcher = this._getSearcher(query);
275263
+ const {
275264
+ keys,
275265
+ records
275266
+ } = this._myIndex;
275267
+ const results = heap ? null : [];
275268
+ records.forEach(({
275269
+ $: item,
275270
+ i: idx
275271
+ }) => {
274654
275272
  if (!isDefined(item)) {
274655
275273
  return;
274656
275274
  }
274657
- let matches = [];
275275
+ const matches = [];
275276
+ let anyKeyFailed = false;
275277
+ let hasInverse = false;
274658
275278
  keys.forEach((key, keyIndex) => {
274659
- matches.push(...this._findMatches({
275279
+ const keyMatches = this._findMatches({
274660
275280
  key,
274661
275281
  value: item[keyIndex],
274662
275282
  searcher
274663
- }));
275283
+ });
275284
+ if (keyMatches.length) {
275285
+ matches.push(...keyMatches);
275286
+ if (keyMatches[0].hasInverse) {
275287
+ hasInverse = true;
275288
+ }
275289
+ } else {
275290
+ anyKeyFailed = true;
275291
+ }
274664
275292
  });
275293
+ if (hasInverse && anyKeyFailed) {
275294
+ return;
275295
+ }
274665
275296
  if (matches.length) {
274666
- results.push({
275297
+ const result = {
274667
275298
  idx,
274668
275299
  item,
274669
275300
  matches
274670
- });
275301
+ };
275302
+ if (heap) {
275303
+ result.score = computeScoreSingle(result.matches, {
275304
+ ignoreFieldNorm
275305
+ });
275306
+ if (heap.shouldInsert(result.score)) {
275307
+ heap.insert(result);
275308
+ }
275309
+ } else {
275310
+ results.push(result);
275311
+ }
274671
275312
  }
274672
275313
  });
274673
275314
  return results;
274674
275315
  }
274675
- _findMatches({ key, value, searcher }) {
275316
+ _findMatches({
275317
+ key,
275318
+ value,
275319
+ searcher
275320
+ }) {
274676
275321
  if (!isDefined(value)) {
274677
275322
  return [];
274678
275323
  }
274679
- let matches = [];
275324
+ const matches = [];
274680
275325
  if (isArray(value)) {
274681
- value.forEach(({ v: text, i: idx, n: norm2 }) => {
275326
+ value.forEach(({
275327
+ v: text,
275328
+ i: idx,
275329
+ n: norm2
275330
+ }) => {
274682
275331
  if (!isDefined(text)) {
274683
275332
  return;
274684
275333
  }
274685
- const { isMatch, score, indices } = searcher.searchIn(text);
275334
+ const {
275335
+ isMatch,
275336
+ score,
275337
+ indices,
275338
+ hasInverse
275339
+ } = searcher.searchIn(text);
274686
275340
  if (isMatch) {
274687
275341
  matches.push({
274688
275342
  score,
@@ -274690,30 +275344,135 @@ class Fuse2 {
274690
275344
  value: text,
274691
275345
  idx,
274692
275346
  norm: norm2,
274693
- indices
275347
+ indices,
275348
+ hasInverse
274694
275349
  });
274695
275350
  }
274696
275351
  });
274697
275352
  } else {
274698
- const { v: text, n: norm2 } = value;
274699
- const { isMatch, score, indices } = searcher.searchIn(text);
275353
+ const {
275354
+ v: text,
275355
+ n: norm2
275356
+ } = value;
275357
+ const {
275358
+ isMatch,
275359
+ score,
275360
+ indices,
275361
+ hasInverse
275362
+ } = searcher.searchIn(text);
274700
275363
  if (isMatch) {
274701
- matches.push({ score, key, value: text, norm: norm2, indices });
275364
+ matches.push({
275365
+ score,
275366
+ key,
275367
+ value: text,
275368
+ norm: norm2,
275369
+ indices,
275370
+ hasInverse
275371
+ });
274702
275372
  }
274703
275373
  }
274704
275374
  return matches;
274705
275375
  }
274706
275376
  }
274707
- Fuse2.version = "7.1.0";
275377
+
275378
+ class TokenSearch {
275379
+ static condition(_4, options) {
275380
+ return options.useTokenSearch;
275381
+ }
275382
+ constructor(pattern, options) {
275383
+ this.options = options;
275384
+ this.analyzer = createAnalyzer({
275385
+ isCaseSensitive: options.isCaseSensitive,
275386
+ ignoreDiacritics: options.ignoreDiacritics
275387
+ });
275388
+ const queryTerms = this.analyzer.tokenize(pattern);
275389
+ const invertedIndex = options._invertedIndex;
275390
+ const {
275391
+ df: df3,
275392
+ fieldCount
275393
+ } = invertedIndex;
275394
+ this.termSearchers = [];
275395
+ this.idfWeights = [];
275396
+ for (const term of queryTerms) {
275397
+ this.termSearchers.push(new BitapSearch(term, {
275398
+ location: options.location,
275399
+ threshold: options.threshold,
275400
+ distance: options.distance,
275401
+ includeMatches: options.includeMatches,
275402
+ findAllMatches: options.findAllMatches,
275403
+ minMatchCharLength: options.minMatchCharLength,
275404
+ isCaseSensitive: options.isCaseSensitive,
275405
+ ignoreDiacritics: options.ignoreDiacritics,
275406
+ ignoreLocation: true
275407
+ }));
275408
+ const docFreq = df3.get(term) || 0;
275409
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
275410
+ this.idfWeights.push(idf);
275411
+ }
275412
+ }
275413
+ searchIn(text) {
275414
+ if (!this.termSearchers.length) {
275415
+ return {
275416
+ isMatch: false,
275417
+ score: 1
275418
+ };
275419
+ }
275420
+ const allIndices = [];
275421
+ let weightedScore = 0;
275422
+ let maxPossibleScore = 0;
275423
+ let matchedCount = 0;
275424
+ for (let i2 = 0;i2 < this.termSearchers.length; i2++) {
275425
+ const result = this.termSearchers[i2].searchIn(text);
275426
+ const idf = this.idfWeights[i2];
275427
+ maxPossibleScore += idf;
275428
+ if (result.isMatch) {
275429
+ matchedCount++;
275430
+ weightedScore += idf * (1 - result.score);
275431
+ if (result.indices) {
275432
+ allIndices.push(...result.indices);
275433
+ }
275434
+ }
275435
+ }
275436
+ if (matchedCount === 0) {
275437
+ return {
275438
+ isMatch: false,
275439
+ score: 1
275440
+ };
275441
+ }
275442
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
275443
+ const searchResult = {
275444
+ isMatch: true,
275445
+ score: Math.max(0.001, normalized)
275446
+ };
275447
+ if (this.options.includeMatches && allIndices.length) {
275448
+ searchResult.indices = mergeIndices(allIndices);
275449
+ }
275450
+ return searchResult;
275451
+ }
275452
+ }
275453
+ Fuse2.version = "7.3.0";
274708
275454
  Fuse2.createIndex = createIndex;
274709
275455
  Fuse2.parseIndex = parseIndex;
274710
275456
  Fuse2.config = Config;
275457
+ Fuse2.match = function(pattern, text, options) {
275458
+ const searcher = createSearcher(pattern, {
275459
+ ...Config,
275460
+ ...options
275461
+ });
275462
+ return searcher.searchIn(text);
275463
+ };
274711
275464
  {
274712
275465
  Fuse2.parseQuery = parse3;
274713
275466
  }
274714
275467
  {
274715
275468
  register2(ExtendedSearch);
274716
275469
  }
275470
+ {
275471
+ register2(TokenSearch);
275472
+ }
275473
+ Fuse2.use = function(...plugins) {
275474
+ plugins.forEach((plugin) => register2(plugin));
275475
+ };
274717
275476
 
274718
275477
  // cli/search/register.ts
274719
275478
  var registerSearch = (program3) => {
@@ -275299,9 +276058,11 @@ function rgb_to_lab(c3) {
275299
276058
  // node_modules/fflate/esm/index.mjs
275300
276059
  import { createRequire as createRequire4 } from "module";
275301
276060
  var require3 = createRequire4("/");
276061
+ var _a3;
275302
276062
  var Worker2;
276063
+ var isMarkedAsUntransferable;
275303
276064
  try {
275304
- Worker2 = require3("worker_threads").Worker;
276065
+ _a3 = require3("worker_threads"), Worker2 = _a3.Worker, isMarkedAsUntransferable = _a3.isMarkedAsUntransferable;
275305
276066
  } catch (e4) {}
275306
276067
  var u8 = Uint8Array;
275307
276068
  var u16 = Uint16Array;