venue-js 1.4.0-next.4 → 1.4.0-next.6
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/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +1383 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1390 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -452,8 +452,8 @@ var createPopulator = ({
|
|
|
452
452
|
anchor_id,
|
|
453
453
|
venue_id,
|
|
454
454
|
local_category_ids,
|
|
455
|
-
promotion_ids,
|
|
456
|
-
privilege_ids,
|
|
455
|
+
promotion_ids = [],
|
|
456
|
+
privilege_ids = [],
|
|
457
457
|
kiosk_id,
|
|
458
458
|
unit_id,
|
|
459
459
|
kiosk_ids = [],
|
|
@@ -578,8 +578,1373 @@ var createPopulator = ({
|
|
|
578
578
|
};
|
|
579
579
|
};
|
|
580
580
|
|
|
581
|
+
// ../../node_modules/fuse.js/dist/fuse.mjs
|
|
582
|
+
function isArray(value) {
|
|
583
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
584
|
+
}
|
|
585
|
+
var INFINITY = 1 / 0;
|
|
586
|
+
function baseToString(value) {
|
|
587
|
+
if (typeof value == "string") {
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
590
|
+
let result = value + "";
|
|
591
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
592
|
+
}
|
|
593
|
+
function toString(value) {
|
|
594
|
+
return value == null ? "" : baseToString(value);
|
|
595
|
+
}
|
|
596
|
+
function isString(value) {
|
|
597
|
+
return typeof value === "string";
|
|
598
|
+
}
|
|
599
|
+
function isNumber(value) {
|
|
600
|
+
return typeof value === "number";
|
|
601
|
+
}
|
|
602
|
+
function isBoolean(value) {
|
|
603
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
604
|
+
}
|
|
605
|
+
function isObject(value) {
|
|
606
|
+
return typeof value === "object";
|
|
607
|
+
}
|
|
608
|
+
function isObjectLike(value) {
|
|
609
|
+
return isObject(value) && value !== null;
|
|
610
|
+
}
|
|
611
|
+
function isDefined(value) {
|
|
612
|
+
return value !== void 0 && value !== null;
|
|
613
|
+
}
|
|
614
|
+
function isBlank(value) {
|
|
615
|
+
return !value.trim().length;
|
|
616
|
+
}
|
|
617
|
+
function getTag(value) {
|
|
618
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
619
|
+
}
|
|
620
|
+
var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
621
|
+
var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
622
|
+
var PATTERN_LENGTH_TOO_LARGE = (max2) => `Pattern length exceeds max of ${max2}.`;
|
|
623
|
+
var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
624
|
+
var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
625
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
626
|
+
var KeyStore = class {
|
|
627
|
+
constructor(keys) {
|
|
628
|
+
this._keys = [];
|
|
629
|
+
this._keyMap = {};
|
|
630
|
+
let totalWeight = 0;
|
|
631
|
+
keys.forEach((key) => {
|
|
632
|
+
let obj = createKey(key);
|
|
633
|
+
this._keys.push(obj);
|
|
634
|
+
this._keyMap[obj.id] = obj;
|
|
635
|
+
totalWeight += obj.weight;
|
|
636
|
+
});
|
|
637
|
+
this._keys.forEach((key) => {
|
|
638
|
+
key.weight /= totalWeight;
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
get(keyId) {
|
|
642
|
+
return this._keyMap[keyId];
|
|
643
|
+
}
|
|
644
|
+
keys() {
|
|
645
|
+
return this._keys;
|
|
646
|
+
}
|
|
647
|
+
toJSON() {
|
|
648
|
+
return JSON.stringify(this._keys);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
function createKey(key) {
|
|
652
|
+
let path = null;
|
|
653
|
+
let id = null;
|
|
654
|
+
let src = null;
|
|
655
|
+
let weight = 1;
|
|
656
|
+
let getFn = null;
|
|
657
|
+
if (isString(key) || isArray(key)) {
|
|
658
|
+
src = key;
|
|
659
|
+
path = createKeyPath(key);
|
|
660
|
+
id = createKeyId(key);
|
|
661
|
+
} else {
|
|
662
|
+
if (!hasOwn.call(key, "name")) {
|
|
663
|
+
throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
664
|
+
}
|
|
665
|
+
const name = key.name;
|
|
666
|
+
src = name;
|
|
667
|
+
if (hasOwn.call(key, "weight")) {
|
|
668
|
+
weight = key.weight;
|
|
669
|
+
if (weight <= 0) {
|
|
670
|
+
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
path = createKeyPath(name);
|
|
674
|
+
id = createKeyId(name);
|
|
675
|
+
getFn = key.getFn;
|
|
676
|
+
}
|
|
677
|
+
return { path, id, weight, src, getFn };
|
|
678
|
+
}
|
|
679
|
+
function createKeyPath(key) {
|
|
680
|
+
return isArray(key) ? key : key.split(".");
|
|
681
|
+
}
|
|
682
|
+
function createKeyId(key) {
|
|
683
|
+
return isArray(key) ? key.join(".") : key;
|
|
684
|
+
}
|
|
685
|
+
function get(obj, path) {
|
|
686
|
+
let list = [];
|
|
687
|
+
let arr = false;
|
|
688
|
+
const deepGet = (obj2, path2, index) => {
|
|
689
|
+
if (!isDefined(obj2)) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (!path2[index]) {
|
|
693
|
+
list.push(obj2);
|
|
694
|
+
} else {
|
|
695
|
+
let key = path2[index];
|
|
696
|
+
const value = obj2[key];
|
|
697
|
+
if (!isDefined(value)) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
701
|
+
list.push(toString(value));
|
|
702
|
+
} else if (isArray(value)) {
|
|
703
|
+
arr = true;
|
|
704
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
705
|
+
deepGet(value[i], path2, index + 1);
|
|
706
|
+
}
|
|
707
|
+
} else if (path2.length) {
|
|
708
|
+
deepGet(value, path2, index + 1);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
713
|
+
return arr ? list : list[0];
|
|
714
|
+
}
|
|
715
|
+
var MatchOptions = {
|
|
716
|
+
// Whether the matches should be included in the result set. When `true`, each record in the result
|
|
717
|
+
// set will include the indices of the matched characters.
|
|
718
|
+
// These can consequently be used for highlighting purposes.
|
|
719
|
+
includeMatches: false,
|
|
720
|
+
// When `true`, the matching function will continue to the end of a search pattern even if
|
|
721
|
+
// a perfect match has already been located in the string.
|
|
722
|
+
findAllMatches: false,
|
|
723
|
+
// Minimum number of characters that must be matched before a result is considered a match
|
|
724
|
+
minMatchCharLength: 1
|
|
725
|
+
};
|
|
726
|
+
var BasicOptions = {
|
|
727
|
+
// When `true`, the algorithm continues searching to the end of the input even if a perfect
|
|
728
|
+
// match is found before the end of the same input.
|
|
729
|
+
isCaseSensitive: false,
|
|
730
|
+
// When `true`, the algorithm will ignore diacritics (accents) in comparisons
|
|
731
|
+
ignoreDiacritics: false,
|
|
732
|
+
// When true, the matching function will continue to the end of a search pattern even if
|
|
733
|
+
includeScore: false,
|
|
734
|
+
// List of properties that will be searched. This also supports nested properties.
|
|
735
|
+
keys: [],
|
|
736
|
+
// Whether to sort the result list, by score
|
|
737
|
+
shouldSort: true,
|
|
738
|
+
// Default sort function: sort by ascending score, ascending index
|
|
739
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
740
|
+
};
|
|
741
|
+
var FuzzyOptions = {
|
|
742
|
+
// Approximately where in the text is the pattern expected to be found?
|
|
743
|
+
location: 0,
|
|
744
|
+
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
|
|
745
|
+
// (of both letters and location), a threshold of '1.0' would match anything.
|
|
746
|
+
threshold: 0.6,
|
|
747
|
+
// Determines how close the match must be to the fuzzy location (specified above).
|
|
748
|
+
// An exact letter match which is 'distance' characters away from the fuzzy location
|
|
749
|
+
// would score as a complete mismatch. A distance of '0' requires the match be at
|
|
750
|
+
// the exact location specified, a threshold of '1000' would require a perfect match
|
|
751
|
+
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
752
|
+
distance: 100
|
|
753
|
+
};
|
|
754
|
+
var AdvancedOptions = {
|
|
755
|
+
// When `true`, it enables the use of unix-like search commands
|
|
756
|
+
useExtendedSearch: false,
|
|
757
|
+
// The get function to use when fetching an object's properties.
|
|
758
|
+
// The default will search nested paths *ie foo.bar.baz*
|
|
759
|
+
getFn: get,
|
|
760
|
+
// When `true`, search will ignore `location` and `distance`, so it won't matter
|
|
761
|
+
// where in the string the pattern appears.
|
|
762
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
|
|
763
|
+
ignoreLocation: false,
|
|
764
|
+
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
765
|
+
// ignore the field-length norm.
|
|
766
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
767
|
+
ignoreFieldNorm: false,
|
|
768
|
+
// The weight to determine how much field length norm effects scoring.
|
|
769
|
+
fieldNormWeight: 1
|
|
770
|
+
};
|
|
771
|
+
var Config = {
|
|
772
|
+
...BasicOptions,
|
|
773
|
+
...MatchOptions,
|
|
774
|
+
...FuzzyOptions,
|
|
775
|
+
...AdvancedOptions
|
|
776
|
+
};
|
|
777
|
+
var SPACE = /[^ ]+/g;
|
|
778
|
+
function norm(weight = 1, mantissa = 3) {
|
|
779
|
+
const cache = /* @__PURE__ */ new Map();
|
|
780
|
+
const m = Math.pow(10, mantissa);
|
|
781
|
+
return {
|
|
782
|
+
get(value) {
|
|
783
|
+
const numTokens = value.match(SPACE).length;
|
|
784
|
+
if (cache.has(numTokens)) {
|
|
785
|
+
return cache.get(numTokens);
|
|
786
|
+
}
|
|
787
|
+
const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
788
|
+
const n = parseFloat(Math.round(norm2 * m) / m);
|
|
789
|
+
cache.set(numTokens, n);
|
|
790
|
+
return n;
|
|
791
|
+
},
|
|
792
|
+
clear() {
|
|
793
|
+
cache.clear();
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
var FuseIndex = class {
|
|
798
|
+
constructor({
|
|
799
|
+
getFn = Config.getFn,
|
|
800
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
801
|
+
} = {}) {
|
|
802
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
803
|
+
this.getFn = getFn;
|
|
804
|
+
this.isCreated = false;
|
|
805
|
+
this.setIndexRecords();
|
|
806
|
+
}
|
|
807
|
+
setSources(docs = []) {
|
|
808
|
+
this.docs = docs;
|
|
809
|
+
}
|
|
810
|
+
setIndexRecords(records = []) {
|
|
811
|
+
this.records = records;
|
|
812
|
+
}
|
|
813
|
+
setKeys(keys = []) {
|
|
814
|
+
this.keys = keys;
|
|
815
|
+
this._keysMap = {};
|
|
816
|
+
keys.forEach((key, idx) => {
|
|
817
|
+
this._keysMap[key.id] = idx;
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
create() {
|
|
821
|
+
if (this.isCreated || !this.docs.length) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
this.isCreated = true;
|
|
825
|
+
if (isString(this.docs[0])) {
|
|
826
|
+
this.docs.forEach((doc, docIndex) => {
|
|
827
|
+
this._addString(doc, docIndex);
|
|
828
|
+
});
|
|
829
|
+
} else {
|
|
830
|
+
this.docs.forEach((doc, docIndex) => {
|
|
831
|
+
this._addObject(doc, docIndex);
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
this.norm.clear();
|
|
835
|
+
}
|
|
836
|
+
// Adds a doc to the end of the index
|
|
837
|
+
add(doc) {
|
|
838
|
+
const idx = this.size();
|
|
839
|
+
if (isString(doc)) {
|
|
840
|
+
this._addString(doc, idx);
|
|
841
|
+
} else {
|
|
842
|
+
this._addObject(doc, idx);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
// Removes the doc at the specified index of the index
|
|
846
|
+
removeAt(idx) {
|
|
847
|
+
this.records.splice(idx, 1);
|
|
848
|
+
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
849
|
+
this.records[i].i -= 1;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
getValueForItemAtKeyId(item, keyId) {
|
|
853
|
+
return item[this._keysMap[keyId]];
|
|
854
|
+
}
|
|
855
|
+
size() {
|
|
856
|
+
return this.records.length;
|
|
857
|
+
}
|
|
858
|
+
_addString(doc, docIndex) {
|
|
859
|
+
if (!isDefined(doc) || isBlank(doc)) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
let record = {
|
|
863
|
+
v: doc,
|
|
864
|
+
i: docIndex,
|
|
865
|
+
n: this.norm.get(doc)
|
|
866
|
+
};
|
|
867
|
+
this.records.push(record);
|
|
868
|
+
}
|
|
869
|
+
_addObject(doc, docIndex) {
|
|
870
|
+
let record = { i: docIndex, $: {} };
|
|
871
|
+
this.keys.forEach((key, keyIndex) => {
|
|
872
|
+
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
873
|
+
if (!isDefined(value)) {
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (isArray(value)) {
|
|
877
|
+
let subRecords = [];
|
|
878
|
+
const stack = [{ nestedArrIndex: -1, value }];
|
|
879
|
+
while (stack.length) {
|
|
880
|
+
const { nestedArrIndex, value: value2 } = stack.pop();
|
|
881
|
+
if (!isDefined(value2)) {
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (isString(value2) && !isBlank(value2)) {
|
|
885
|
+
let subRecord = {
|
|
886
|
+
v: value2,
|
|
887
|
+
i: nestedArrIndex,
|
|
888
|
+
n: this.norm.get(value2)
|
|
889
|
+
};
|
|
890
|
+
subRecords.push(subRecord);
|
|
891
|
+
} else if (isArray(value2)) {
|
|
892
|
+
value2.forEach((item, k) => {
|
|
893
|
+
stack.push({
|
|
894
|
+
nestedArrIndex: k,
|
|
895
|
+
value: item
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
} else ;
|
|
899
|
+
}
|
|
900
|
+
record.$[keyIndex] = subRecords;
|
|
901
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
902
|
+
let subRecord = {
|
|
903
|
+
v: value,
|
|
904
|
+
n: this.norm.get(value)
|
|
905
|
+
};
|
|
906
|
+
record.$[keyIndex] = subRecord;
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
this.records.push(record);
|
|
910
|
+
}
|
|
911
|
+
toJSON() {
|
|
912
|
+
return {
|
|
913
|
+
keys: this.keys,
|
|
914
|
+
records: this.records
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
919
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
920
|
+
myIndex.setKeys(keys.map(createKey));
|
|
921
|
+
myIndex.setSources(docs);
|
|
922
|
+
myIndex.create();
|
|
923
|
+
return myIndex;
|
|
924
|
+
}
|
|
925
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
926
|
+
const { keys, records } = data;
|
|
927
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
928
|
+
myIndex.setKeys(keys);
|
|
929
|
+
myIndex.setIndexRecords(records);
|
|
930
|
+
return myIndex;
|
|
931
|
+
}
|
|
932
|
+
function computeScore$1(pattern, {
|
|
933
|
+
errors = 0,
|
|
934
|
+
currentLocation = 0,
|
|
935
|
+
expectedLocation = 0,
|
|
936
|
+
distance = Config.distance,
|
|
937
|
+
ignoreLocation = Config.ignoreLocation
|
|
938
|
+
} = {}) {
|
|
939
|
+
const accuracy = errors / pattern.length;
|
|
940
|
+
if (ignoreLocation) {
|
|
941
|
+
return accuracy;
|
|
942
|
+
}
|
|
943
|
+
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
944
|
+
if (!distance) {
|
|
945
|
+
return proximity ? 1 : accuracy;
|
|
946
|
+
}
|
|
947
|
+
return accuracy + proximity / distance;
|
|
948
|
+
}
|
|
949
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
950
|
+
let indices = [];
|
|
951
|
+
let start = -1;
|
|
952
|
+
let end = -1;
|
|
953
|
+
let i = 0;
|
|
954
|
+
for (let len = matchmask.length; i < len; i += 1) {
|
|
955
|
+
let match = matchmask[i];
|
|
956
|
+
if (match && start === -1) {
|
|
957
|
+
start = i;
|
|
958
|
+
} else if (!match && start !== -1) {
|
|
959
|
+
end = i - 1;
|
|
960
|
+
if (end - start + 1 >= minMatchCharLength) {
|
|
961
|
+
indices.push([start, end]);
|
|
962
|
+
}
|
|
963
|
+
start = -1;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
967
|
+
indices.push([start, i - 1]);
|
|
968
|
+
}
|
|
969
|
+
return indices;
|
|
970
|
+
}
|
|
971
|
+
var MAX_BITS = 32;
|
|
972
|
+
function search(text, pattern, patternAlphabet, {
|
|
973
|
+
location = Config.location,
|
|
974
|
+
distance = Config.distance,
|
|
975
|
+
threshold = Config.threshold,
|
|
976
|
+
findAllMatches = Config.findAllMatches,
|
|
977
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
978
|
+
includeMatches = Config.includeMatches,
|
|
979
|
+
ignoreLocation = Config.ignoreLocation
|
|
980
|
+
} = {}) {
|
|
981
|
+
if (pattern.length > MAX_BITS) {
|
|
982
|
+
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
983
|
+
}
|
|
984
|
+
const patternLen = pattern.length;
|
|
985
|
+
const textLen = text.length;
|
|
986
|
+
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
987
|
+
let currentThreshold = threshold;
|
|
988
|
+
let bestLocation = expectedLocation;
|
|
989
|
+
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
990
|
+
const matchMask = computeMatches ? Array(textLen) : [];
|
|
991
|
+
let index;
|
|
992
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
993
|
+
let score = computeScore$1(pattern, {
|
|
994
|
+
currentLocation: index,
|
|
995
|
+
expectedLocation,
|
|
996
|
+
distance,
|
|
997
|
+
ignoreLocation
|
|
998
|
+
});
|
|
999
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
1000
|
+
bestLocation = index + patternLen;
|
|
1001
|
+
if (computeMatches) {
|
|
1002
|
+
let i = 0;
|
|
1003
|
+
while (i < patternLen) {
|
|
1004
|
+
matchMask[index + i] = 1;
|
|
1005
|
+
i += 1;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
bestLocation = -1;
|
|
1010
|
+
let lastBitArr = [];
|
|
1011
|
+
let finalScore = 1;
|
|
1012
|
+
let binMax = patternLen + textLen;
|
|
1013
|
+
const mask = 1 << patternLen - 1;
|
|
1014
|
+
for (let i = 0; i < patternLen; i += 1) {
|
|
1015
|
+
let binMin = 0;
|
|
1016
|
+
let binMid = binMax;
|
|
1017
|
+
while (binMin < binMid) {
|
|
1018
|
+
const score2 = computeScore$1(pattern, {
|
|
1019
|
+
errors: i,
|
|
1020
|
+
currentLocation: expectedLocation + binMid,
|
|
1021
|
+
expectedLocation,
|
|
1022
|
+
distance,
|
|
1023
|
+
ignoreLocation
|
|
1024
|
+
});
|
|
1025
|
+
if (score2 <= currentThreshold) {
|
|
1026
|
+
binMin = binMid;
|
|
1027
|
+
} else {
|
|
1028
|
+
binMax = binMid;
|
|
1029
|
+
}
|
|
1030
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1031
|
+
}
|
|
1032
|
+
binMax = binMid;
|
|
1033
|
+
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
1034
|
+
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
1035
|
+
let bitArr = Array(finish + 2);
|
|
1036
|
+
bitArr[finish + 1] = (1 << i) - 1;
|
|
1037
|
+
for (let j = finish; j >= start; j -= 1) {
|
|
1038
|
+
let currentLocation = j - 1;
|
|
1039
|
+
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
1040
|
+
if (computeMatches) {
|
|
1041
|
+
matchMask[currentLocation] = +!!charMatch;
|
|
1042
|
+
}
|
|
1043
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
1044
|
+
if (i) {
|
|
1045
|
+
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
1046
|
+
}
|
|
1047
|
+
if (bitArr[j] & mask) {
|
|
1048
|
+
finalScore = computeScore$1(pattern, {
|
|
1049
|
+
errors: i,
|
|
1050
|
+
currentLocation,
|
|
1051
|
+
expectedLocation,
|
|
1052
|
+
distance,
|
|
1053
|
+
ignoreLocation
|
|
1054
|
+
});
|
|
1055
|
+
if (finalScore <= currentThreshold) {
|
|
1056
|
+
currentThreshold = finalScore;
|
|
1057
|
+
bestLocation = currentLocation;
|
|
1058
|
+
if (bestLocation <= expectedLocation) {
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
const score = computeScore$1(pattern, {
|
|
1066
|
+
errors: i + 1,
|
|
1067
|
+
currentLocation: expectedLocation,
|
|
1068
|
+
expectedLocation,
|
|
1069
|
+
distance,
|
|
1070
|
+
ignoreLocation
|
|
1071
|
+
});
|
|
1072
|
+
if (score > currentThreshold) {
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
lastBitArr = bitArr;
|
|
1076
|
+
}
|
|
1077
|
+
const result = {
|
|
1078
|
+
isMatch: bestLocation >= 0,
|
|
1079
|
+
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
1080
|
+
score: Math.max(1e-3, finalScore)
|
|
1081
|
+
};
|
|
1082
|
+
if (computeMatches) {
|
|
1083
|
+
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
1084
|
+
if (!indices.length) {
|
|
1085
|
+
result.isMatch = false;
|
|
1086
|
+
} else if (includeMatches) {
|
|
1087
|
+
result.indices = indices;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return result;
|
|
1091
|
+
}
|
|
1092
|
+
function createPatternAlphabet(pattern) {
|
|
1093
|
+
let mask = {};
|
|
1094
|
+
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
1095
|
+
const char = pattern.charAt(i);
|
|
1096
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
1097
|
+
}
|
|
1098
|
+
return mask;
|
|
1099
|
+
}
|
|
1100
|
+
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);
|
|
1101
|
+
var BitapSearch = class {
|
|
1102
|
+
constructor(pattern, {
|
|
1103
|
+
location = Config.location,
|
|
1104
|
+
threshold = Config.threshold,
|
|
1105
|
+
distance = Config.distance,
|
|
1106
|
+
includeMatches = Config.includeMatches,
|
|
1107
|
+
findAllMatches = Config.findAllMatches,
|
|
1108
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1109
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1110
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1111
|
+
ignoreLocation = Config.ignoreLocation
|
|
1112
|
+
} = {}) {
|
|
1113
|
+
this.options = {
|
|
1114
|
+
location,
|
|
1115
|
+
threshold,
|
|
1116
|
+
distance,
|
|
1117
|
+
includeMatches,
|
|
1118
|
+
findAllMatches,
|
|
1119
|
+
minMatchCharLength,
|
|
1120
|
+
isCaseSensitive,
|
|
1121
|
+
ignoreDiacritics,
|
|
1122
|
+
ignoreLocation
|
|
1123
|
+
};
|
|
1124
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1125
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1126
|
+
this.pattern = pattern;
|
|
1127
|
+
this.chunks = [];
|
|
1128
|
+
if (!this.pattern.length) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
const addChunk = (pattern2, startIndex) => {
|
|
1132
|
+
this.chunks.push({
|
|
1133
|
+
pattern: pattern2,
|
|
1134
|
+
alphabet: createPatternAlphabet(pattern2),
|
|
1135
|
+
startIndex
|
|
1136
|
+
});
|
|
1137
|
+
};
|
|
1138
|
+
const len = this.pattern.length;
|
|
1139
|
+
if (len > MAX_BITS) {
|
|
1140
|
+
let i = 0;
|
|
1141
|
+
const remainder = len % MAX_BITS;
|
|
1142
|
+
const end = len - remainder;
|
|
1143
|
+
while (i < end) {
|
|
1144
|
+
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
1145
|
+
i += MAX_BITS;
|
|
1146
|
+
}
|
|
1147
|
+
if (remainder) {
|
|
1148
|
+
const startIndex = len - MAX_BITS;
|
|
1149
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
1150
|
+
}
|
|
1151
|
+
} else {
|
|
1152
|
+
addChunk(this.pattern, 0);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
searchIn(text) {
|
|
1156
|
+
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
1157
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1158
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1159
|
+
if (this.pattern === text) {
|
|
1160
|
+
let result2 = {
|
|
1161
|
+
isMatch: true,
|
|
1162
|
+
score: 0
|
|
1163
|
+
};
|
|
1164
|
+
if (includeMatches) {
|
|
1165
|
+
result2.indices = [[0, text.length - 1]];
|
|
1166
|
+
}
|
|
1167
|
+
return result2;
|
|
1168
|
+
}
|
|
1169
|
+
const {
|
|
1170
|
+
location,
|
|
1171
|
+
distance,
|
|
1172
|
+
threshold,
|
|
1173
|
+
findAllMatches,
|
|
1174
|
+
minMatchCharLength,
|
|
1175
|
+
ignoreLocation
|
|
1176
|
+
} = this.options;
|
|
1177
|
+
let allIndices = [];
|
|
1178
|
+
let totalScore = 0;
|
|
1179
|
+
let hasMatches = false;
|
|
1180
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
1181
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
1182
|
+
location: location + startIndex,
|
|
1183
|
+
distance,
|
|
1184
|
+
threshold,
|
|
1185
|
+
findAllMatches,
|
|
1186
|
+
minMatchCharLength,
|
|
1187
|
+
includeMatches,
|
|
1188
|
+
ignoreLocation
|
|
1189
|
+
});
|
|
1190
|
+
if (isMatch) {
|
|
1191
|
+
hasMatches = true;
|
|
1192
|
+
}
|
|
1193
|
+
totalScore += score;
|
|
1194
|
+
if (isMatch && indices) {
|
|
1195
|
+
allIndices = [...allIndices, ...indices];
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
let result = {
|
|
1199
|
+
isMatch: hasMatches,
|
|
1200
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
1201
|
+
};
|
|
1202
|
+
if (hasMatches && includeMatches) {
|
|
1203
|
+
result.indices = allIndices;
|
|
1204
|
+
}
|
|
1205
|
+
return result;
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
var BaseMatch = class {
|
|
1209
|
+
constructor(pattern) {
|
|
1210
|
+
this.pattern = pattern;
|
|
1211
|
+
}
|
|
1212
|
+
static isMultiMatch(pattern) {
|
|
1213
|
+
return getMatch(pattern, this.multiRegex);
|
|
1214
|
+
}
|
|
1215
|
+
static isSingleMatch(pattern) {
|
|
1216
|
+
return getMatch(pattern, this.singleRegex);
|
|
1217
|
+
}
|
|
1218
|
+
search() {
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
function getMatch(pattern, exp) {
|
|
1222
|
+
const matches = pattern.match(exp);
|
|
1223
|
+
return matches ? matches[1] : null;
|
|
1224
|
+
}
|
|
1225
|
+
var ExactMatch = class extends BaseMatch {
|
|
1226
|
+
constructor(pattern) {
|
|
1227
|
+
super(pattern);
|
|
1228
|
+
}
|
|
1229
|
+
static get type() {
|
|
1230
|
+
return "exact";
|
|
1231
|
+
}
|
|
1232
|
+
static get multiRegex() {
|
|
1233
|
+
return /^="(.*)"$/;
|
|
1234
|
+
}
|
|
1235
|
+
static get singleRegex() {
|
|
1236
|
+
return /^=(.*)$/;
|
|
1237
|
+
}
|
|
1238
|
+
search(text) {
|
|
1239
|
+
const isMatch = text === this.pattern;
|
|
1240
|
+
return {
|
|
1241
|
+
isMatch,
|
|
1242
|
+
score: isMatch ? 0 : 1,
|
|
1243
|
+
indices: [0, this.pattern.length - 1]
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
var InverseExactMatch = class extends BaseMatch {
|
|
1248
|
+
constructor(pattern) {
|
|
1249
|
+
super(pattern);
|
|
1250
|
+
}
|
|
1251
|
+
static get type() {
|
|
1252
|
+
return "inverse-exact";
|
|
1253
|
+
}
|
|
1254
|
+
static get multiRegex() {
|
|
1255
|
+
return /^!"(.*)"$/;
|
|
1256
|
+
}
|
|
1257
|
+
static get singleRegex() {
|
|
1258
|
+
return /^!(.*)$/;
|
|
1259
|
+
}
|
|
1260
|
+
search(text) {
|
|
1261
|
+
const index = text.indexOf(this.pattern);
|
|
1262
|
+
const isMatch = index === -1;
|
|
1263
|
+
return {
|
|
1264
|
+
isMatch,
|
|
1265
|
+
score: isMatch ? 0 : 1,
|
|
1266
|
+
indices: [0, text.length - 1]
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
var PrefixExactMatch = class extends BaseMatch {
|
|
1271
|
+
constructor(pattern) {
|
|
1272
|
+
super(pattern);
|
|
1273
|
+
}
|
|
1274
|
+
static get type() {
|
|
1275
|
+
return "prefix-exact";
|
|
1276
|
+
}
|
|
1277
|
+
static get multiRegex() {
|
|
1278
|
+
return /^\^"(.*)"$/;
|
|
1279
|
+
}
|
|
1280
|
+
static get singleRegex() {
|
|
1281
|
+
return /^\^(.*)$/;
|
|
1282
|
+
}
|
|
1283
|
+
search(text) {
|
|
1284
|
+
const isMatch = text.startsWith(this.pattern);
|
|
1285
|
+
return {
|
|
1286
|
+
isMatch,
|
|
1287
|
+
score: isMatch ? 0 : 1,
|
|
1288
|
+
indices: [0, this.pattern.length - 1]
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
var InversePrefixExactMatch = class extends BaseMatch {
|
|
1293
|
+
constructor(pattern) {
|
|
1294
|
+
super(pattern);
|
|
1295
|
+
}
|
|
1296
|
+
static get type() {
|
|
1297
|
+
return "inverse-prefix-exact";
|
|
1298
|
+
}
|
|
1299
|
+
static get multiRegex() {
|
|
1300
|
+
return /^!\^"(.*)"$/;
|
|
1301
|
+
}
|
|
1302
|
+
static get singleRegex() {
|
|
1303
|
+
return /^!\^(.*)$/;
|
|
1304
|
+
}
|
|
1305
|
+
search(text) {
|
|
1306
|
+
const isMatch = !text.startsWith(this.pattern);
|
|
1307
|
+
return {
|
|
1308
|
+
isMatch,
|
|
1309
|
+
score: isMatch ? 0 : 1,
|
|
1310
|
+
indices: [0, text.length - 1]
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
var SuffixExactMatch = class extends BaseMatch {
|
|
1315
|
+
constructor(pattern) {
|
|
1316
|
+
super(pattern);
|
|
1317
|
+
}
|
|
1318
|
+
static get type() {
|
|
1319
|
+
return "suffix-exact";
|
|
1320
|
+
}
|
|
1321
|
+
static get multiRegex() {
|
|
1322
|
+
return /^"(.*)"\$$/;
|
|
1323
|
+
}
|
|
1324
|
+
static get singleRegex() {
|
|
1325
|
+
return /^(.*)\$$/;
|
|
1326
|
+
}
|
|
1327
|
+
search(text) {
|
|
1328
|
+
const isMatch = text.endsWith(this.pattern);
|
|
1329
|
+
return {
|
|
1330
|
+
isMatch,
|
|
1331
|
+
score: isMatch ? 0 : 1,
|
|
1332
|
+
indices: [text.length - this.pattern.length, text.length - 1]
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
var InverseSuffixExactMatch = class extends BaseMatch {
|
|
1337
|
+
constructor(pattern) {
|
|
1338
|
+
super(pattern);
|
|
1339
|
+
}
|
|
1340
|
+
static get type() {
|
|
1341
|
+
return "inverse-suffix-exact";
|
|
1342
|
+
}
|
|
1343
|
+
static get multiRegex() {
|
|
1344
|
+
return /^!"(.*)"\$$/;
|
|
1345
|
+
}
|
|
1346
|
+
static get singleRegex() {
|
|
1347
|
+
return /^!(.*)\$$/;
|
|
1348
|
+
}
|
|
1349
|
+
search(text) {
|
|
1350
|
+
const isMatch = !text.endsWith(this.pattern);
|
|
1351
|
+
return {
|
|
1352
|
+
isMatch,
|
|
1353
|
+
score: isMatch ? 0 : 1,
|
|
1354
|
+
indices: [0, text.length - 1]
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
var FuzzyMatch = class extends BaseMatch {
|
|
1359
|
+
constructor(pattern, {
|
|
1360
|
+
location = Config.location,
|
|
1361
|
+
threshold = Config.threshold,
|
|
1362
|
+
distance = Config.distance,
|
|
1363
|
+
includeMatches = Config.includeMatches,
|
|
1364
|
+
findAllMatches = Config.findAllMatches,
|
|
1365
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1366
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1367
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1368
|
+
ignoreLocation = Config.ignoreLocation
|
|
1369
|
+
} = {}) {
|
|
1370
|
+
super(pattern);
|
|
1371
|
+
this._bitapSearch = new BitapSearch(pattern, {
|
|
1372
|
+
location,
|
|
1373
|
+
threshold,
|
|
1374
|
+
distance,
|
|
1375
|
+
includeMatches,
|
|
1376
|
+
findAllMatches,
|
|
1377
|
+
minMatchCharLength,
|
|
1378
|
+
isCaseSensitive,
|
|
1379
|
+
ignoreDiacritics,
|
|
1380
|
+
ignoreLocation
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
static get type() {
|
|
1384
|
+
return "fuzzy";
|
|
1385
|
+
}
|
|
1386
|
+
static get multiRegex() {
|
|
1387
|
+
return /^"(.*)"$/;
|
|
1388
|
+
}
|
|
1389
|
+
static get singleRegex() {
|
|
1390
|
+
return /^(.*)$/;
|
|
1391
|
+
}
|
|
1392
|
+
search(text) {
|
|
1393
|
+
return this._bitapSearch.searchIn(text);
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
var IncludeMatch = class extends BaseMatch {
|
|
1397
|
+
constructor(pattern) {
|
|
1398
|
+
super(pattern);
|
|
1399
|
+
}
|
|
1400
|
+
static get type() {
|
|
1401
|
+
return "include";
|
|
1402
|
+
}
|
|
1403
|
+
static get multiRegex() {
|
|
1404
|
+
return /^'"(.*)"$/;
|
|
1405
|
+
}
|
|
1406
|
+
static get singleRegex() {
|
|
1407
|
+
return /^'(.*)$/;
|
|
1408
|
+
}
|
|
1409
|
+
search(text) {
|
|
1410
|
+
let location = 0;
|
|
1411
|
+
let index;
|
|
1412
|
+
const indices = [];
|
|
1413
|
+
const patternLen = this.pattern.length;
|
|
1414
|
+
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
1415
|
+
location = index + patternLen;
|
|
1416
|
+
indices.push([index, location - 1]);
|
|
1417
|
+
}
|
|
1418
|
+
const isMatch = !!indices.length;
|
|
1419
|
+
return {
|
|
1420
|
+
isMatch,
|
|
1421
|
+
score: isMatch ? 0 : 1,
|
|
1422
|
+
indices
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
var searchers = [
|
|
1427
|
+
ExactMatch,
|
|
1428
|
+
IncludeMatch,
|
|
1429
|
+
PrefixExactMatch,
|
|
1430
|
+
InversePrefixExactMatch,
|
|
1431
|
+
InverseSuffixExactMatch,
|
|
1432
|
+
SuffixExactMatch,
|
|
1433
|
+
InverseExactMatch,
|
|
1434
|
+
FuzzyMatch
|
|
1435
|
+
];
|
|
1436
|
+
var searchersLen = searchers.length;
|
|
1437
|
+
var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
1438
|
+
var OR_TOKEN = "|";
|
|
1439
|
+
function parseQuery(pattern, options = {}) {
|
|
1440
|
+
return pattern.split(OR_TOKEN).map((item) => {
|
|
1441
|
+
let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
|
|
1442
|
+
let results = [];
|
|
1443
|
+
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1444
|
+
const queryItem = query[i];
|
|
1445
|
+
let found = false;
|
|
1446
|
+
let idx = -1;
|
|
1447
|
+
while (!found && ++idx < searchersLen) {
|
|
1448
|
+
const searcher = searchers[idx];
|
|
1449
|
+
let token = searcher.isMultiMatch(queryItem);
|
|
1450
|
+
if (token) {
|
|
1451
|
+
results.push(new searcher(token, options));
|
|
1452
|
+
found = true;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
if (found) {
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
idx = -1;
|
|
1459
|
+
while (++idx < searchersLen) {
|
|
1460
|
+
const searcher = searchers[idx];
|
|
1461
|
+
let token = searcher.isSingleMatch(queryItem);
|
|
1462
|
+
if (token) {
|
|
1463
|
+
results.push(new searcher(token, options));
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return results;
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
var MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1472
|
+
var ExtendedSearch = class {
|
|
1473
|
+
constructor(pattern, {
|
|
1474
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1475
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1476
|
+
includeMatches = Config.includeMatches,
|
|
1477
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1478
|
+
ignoreLocation = Config.ignoreLocation,
|
|
1479
|
+
findAllMatches = Config.findAllMatches,
|
|
1480
|
+
location = Config.location,
|
|
1481
|
+
threshold = Config.threshold,
|
|
1482
|
+
distance = Config.distance
|
|
1483
|
+
} = {}) {
|
|
1484
|
+
this.query = null;
|
|
1485
|
+
this.options = {
|
|
1486
|
+
isCaseSensitive,
|
|
1487
|
+
ignoreDiacritics,
|
|
1488
|
+
includeMatches,
|
|
1489
|
+
minMatchCharLength,
|
|
1490
|
+
findAllMatches,
|
|
1491
|
+
ignoreLocation,
|
|
1492
|
+
location,
|
|
1493
|
+
threshold,
|
|
1494
|
+
distance
|
|
1495
|
+
};
|
|
1496
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1497
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1498
|
+
this.pattern = pattern;
|
|
1499
|
+
this.query = parseQuery(this.pattern, this.options);
|
|
1500
|
+
}
|
|
1501
|
+
static condition(_6, options) {
|
|
1502
|
+
return options.useExtendedSearch;
|
|
1503
|
+
}
|
|
1504
|
+
searchIn(text) {
|
|
1505
|
+
const query = this.query;
|
|
1506
|
+
if (!query) {
|
|
1507
|
+
return {
|
|
1508
|
+
isMatch: false,
|
|
1509
|
+
score: 1
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
|
|
1513
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1514
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1515
|
+
let numMatches = 0;
|
|
1516
|
+
let allIndices = [];
|
|
1517
|
+
let totalScore = 0;
|
|
1518
|
+
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1519
|
+
const searchers2 = query[i];
|
|
1520
|
+
allIndices.length = 0;
|
|
1521
|
+
numMatches = 0;
|
|
1522
|
+
for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
|
|
1523
|
+
const searcher = searchers2[j];
|
|
1524
|
+
const { isMatch, indices, score } = searcher.search(text);
|
|
1525
|
+
if (isMatch) {
|
|
1526
|
+
numMatches += 1;
|
|
1527
|
+
totalScore += score;
|
|
1528
|
+
if (includeMatches) {
|
|
1529
|
+
const type = searcher.constructor.type;
|
|
1530
|
+
if (MultiMatchSet.has(type)) {
|
|
1531
|
+
allIndices = [...allIndices, ...indices];
|
|
1532
|
+
} else {
|
|
1533
|
+
allIndices.push(indices);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
} else {
|
|
1537
|
+
totalScore = 0;
|
|
1538
|
+
numMatches = 0;
|
|
1539
|
+
allIndices.length = 0;
|
|
1540
|
+
break;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
if (numMatches) {
|
|
1544
|
+
let result = {
|
|
1545
|
+
isMatch: true,
|
|
1546
|
+
score: totalScore / numMatches
|
|
1547
|
+
};
|
|
1548
|
+
if (includeMatches) {
|
|
1549
|
+
result.indices = allIndices;
|
|
1550
|
+
}
|
|
1551
|
+
return result;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return {
|
|
1555
|
+
isMatch: false,
|
|
1556
|
+
score: 1
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
var registeredSearchers = [];
|
|
1561
|
+
function register(...args) {
|
|
1562
|
+
registeredSearchers.push(...args);
|
|
1563
|
+
}
|
|
1564
|
+
function createSearcher(pattern, options) {
|
|
1565
|
+
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
1566
|
+
let searcherClass = registeredSearchers[i];
|
|
1567
|
+
if (searcherClass.condition(pattern, options)) {
|
|
1568
|
+
return new searcherClass(pattern, options);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
return new BitapSearch(pattern, options);
|
|
1572
|
+
}
|
|
1573
|
+
var LogicalOperator = {
|
|
1574
|
+
AND: "$and",
|
|
1575
|
+
OR: "$or"
|
|
1576
|
+
};
|
|
1577
|
+
var KeyType = {
|
|
1578
|
+
PATH: "$path",
|
|
1579
|
+
PATTERN: "$val"
|
|
1580
|
+
};
|
|
1581
|
+
var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1582
|
+
var isPath = (query) => !!query[KeyType.PATH];
|
|
1583
|
+
var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1584
|
+
var convertToExplicit = (query) => ({
|
|
1585
|
+
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1586
|
+
[key]: query[key]
|
|
1587
|
+
}))
|
|
1588
|
+
});
|
|
1589
|
+
function parse(query, options, { auto = true } = {}) {
|
|
1590
|
+
const next = (query2) => {
|
|
1591
|
+
let keys = Object.keys(query2);
|
|
1592
|
+
const isQueryPath = isPath(query2);
|
|
1593
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
|
|
1594
|
+
return next(convertToExplicit(query2));
|
|
1595
|
+
}
|
|
1596
|
+
if (isLeaf(query2)) {
|
|
1597
|
+
const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
|
|
1598
|
+
const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
|
|
1599
|
+
if (!isString(pattern)) {
|
|
1600
|
+
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1601
|
+
}
|
|
1602
|
+
const obj = {
|
|
1603
|
+
keyId: createKeyId(key),
|
|
1604
|
+
pattern
|
|
1605
|
+
};
|
|
1606
|
+
if (auto) {
|
|
1607
|
+
obj.searcher = createSearcher(pattern, options);
|
|
1608
|
+
}
|
|
1609
|
+
return obj;
|
|
1610
|
+
}
|
|
1611
|
+
let node = {
|
|
1612
|
+
children: [],
|
|
1613
|
+
operator: keys[0]
|
|
1614
|
+
};
|
|
1615
|
+
keys.forEach((key) => {
|
|
1616
|
+
const value = query2[key];
|
|
1617
|
+
if (isArray(value)) {
|
|
1618
|
+
value.forEach((item) => {
|
|
1619
|
+
node.children.push(next(item));
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
return node;
|
|
1624
|
+
};
|
|
1625
|
+
if (!isExpression(query)) {
|
|
1626
|
+
query = convertToExplicit(query);
|
|
1627
|
+
}
|
|
1628
|
+
return next(query);
|
|
1629
|
+
}
|
|
1630
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1631
|
+
results.forEach((result) => {
|
|
1632
|
+
let totalScore = 1;
|
|
1633
|
+
result.matches.forEach(({ key, norm: norm2, score }) => {
|
|
1634
|
+
const weight = key ? key.weight : null;
|
|
1635
|
+
totalScore *= Math.pow(
|
|
1636
|
+
score === 0 && weight ? Number.EPSILON : score,
|
|
1637
|
+
(weight || 1) * (ignoreFieldNorm ? 1 : norm2)
|
|
1638
|
+
);
|
|
1639
|
+
});
|
|
1640
|
+
result.score = totalScore;
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
function transformMatches(result, data) {
|
|
1644
|
+
const matches = result.matches;
|
|
1645
|
+
data.matches = [];
|
|
1646
|
+
if (!isDefined(matches)) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
matches.forEach((match) => {
|
|
1650
|
+
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
const { indices, value } = match;
|
|
1654
|
+
let obj = {
|
|
1655
|
+
indices,
|
|
1656
|
+
value
|
|
1657
|
+
};
|
|
1658
|
+
if (match.key) {
|
|
1659
|
+
obj.key = match.key.src;
|
|
1660
|
+
}
|
|
1661
|
+
if (match.idx > -1) {
|
|
1662
|
+
obj.refIndex = match.idx;
|
|
1663
|
+
}
|
|
1664
|
+
data.matches.push(obj);
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
function transformScore(result, data) {
|
|
1668
|
+
data.score = result.score;
|
|
1669
|
+
}
|
|
1670
|
+
function format(results, docs, {
|
|
1671
|
+
includeMatches = Config.includeMatches,
|
|
1672
|
+
includeScore = Config.includeScore
|
|
1673
|
+
} = {}) {
|
|
1674
|
+
const transformers = [];
|
|
1675
|
+
if (includeMatches) transformers.push(transformMatches);
|
|
1676
|
+
if (includeScore) transformers.push(transformScore);
|
|
1677
|
+
return results.map((result) => {
|
|
1678
|
+
const { idx } = result;
|
|
1679
|
+
const data = {
|
|
1680
|
+
item: docs[idx],
|
|
1681
|
+
refIndex: idx
|
|
1682
|
+
};
|
|
1683
|
+
if (transformers.length) {
|
|
1684
|
+
transformers.forEach((transformer) => {
|
|
1685
|
+
transformer(result, data);
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
return data;
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
var Fuse = class {
|
|
1692
|
+
constructor(docs, options = {}, index) {
|
|
1693
|
+
this.options = { ...Config, ...options };
|
|
1694
|
+
if (this.options.useExtendedSearch && false) {
|
|
1695
|
+
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1696
|
+
}
|
|
1697
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
1698
|
+
this.setCollection(docs, index);
|
|
1699
|
+
}
|
|
1700
|
+
setCollection(docs, index) {
|
|
1701
|
+
this._docs = docs;
|
|
1702
|
+
if (index && !(index instanceof FuseIndex)) {
|
|
1703
|
+
throw new Error(INCORRECT_INDEX_TYPE);
|
|
1704
|
+
}
|
|
1705
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1706
|
+
getFn: this.options.getFn,
|
|
1707
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
add(doc) {
|
|
1711
|
+
if (!isDefined(doc)) {
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
this._docs.push(doc);
|
|
1715
|
+
this._myIndex.add(doc);
|
|
1716
|
+
}
|
|
1717
|
+
remove(predicate = () => false) {
|
|
1718
|
+
const results = [];
|
|
1719
|
+
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1720
|
+
const doc = this._docs[i];
|
|
1721
|
+
if (predicate(doc, i)) {
|
|
1722
|
+
this.removeAt(i);
|
|
1723
|
+
i -= 1;
|
|
1724
|
+
len -= 1;
|
|
1725
|
+
results.push(doc);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return results;
|
|
1729
|
+
}
|
|
1730
|
+
removeAt(idx) {
|
|
1731
|
+
this._docs.splice(idx, 1);
|
|
1732
|
+
this._myIndex.removeAt(idx);
|
|
1733
|
+
}
|
|
1734
|
+
getIndex() {
|
|
1735
|
+
return this._myIndex;
|
|
1736
|
+
}
|
|
1737
|
+
search(query, { limit = -1 } = {}) {
|
|
1738
|
+
const {
|
|
1739
|
+
includeMatches,
|
|
1740
|
+
includeScore,
|
|
1741
|
+
shouldSort,
|
|
1742
|
+
sortFn,
|
|
1743
|
+
ignoreFieldNorm
|
|
1744
|
+
} = this.options;
|
|
1745
|
+
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1746
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1747
|
+
if (shouldSort) {
|
|
1748
|
+
results.sort(sortFn);
|
|
1749
|
+
}
|
|
1750
|
+
if (isNumber(limit) && limit > -1) {
|
|
1751
|
+
results = results.slice(0, limit);
|
|
1752
|
+
}
|
|
1753
|
+
return format(results, this._docs, {
|
|
1754
|
+
includeMatches,
|
|
1755
|
+
includeScore
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
_searchStringList(query) {
|
|
1759
|
+
const searcher = createSearcher(query, this.options);
|
|
1760
|
+
const { records } = this._myIndex;
|
|
1761
|
+
const results = [];
|
|
1762
|
+
records.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1763
|
+
if (!isDefined(text)) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1767
|
+
if (isMatch) {
|
|
1768
|
+
results.push({
|
|
1769
|
+
item: text,
|
|
1770
|
+
idx,
|
|
1771
|
+
matches: [{ score, value: text, norm: norm2, indices }]
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
return results;
|
|
1776
|
+
}
|
|
1777
|
+
_searchLogical(query) {
|
|
1778
|
+
const expression = parse(query, this.options);
|
|
1779
|
+
const evaluate = (node, item, idx) => {
|
|
1780
|
+
if (!node.children) {
|
|
1781
|
+
const { keyId, searcher } = node;
|
|
1782
|
+
const matches = this._findMatches({
|
|
1783
|
+
key: this._keyStore.get(keyId),
|
|
1784
|
+
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1785
|
+
searcher
|
|
1786
|
+
});
|
|
1787
|
+
if (matches && matches.length) {
|
|
1788
|
+
return [
|
|
1789
|
+
{
|
|
1790
|
+
idx,
|
|
1791
|
+
item,
|
|
1792
|
+
matches
|
|
1793
|
+
}
|
|
1794
|
+
];
|
|
1795
|
+
}
|
|
1796
|
+
return [];
|
|
1797
|
+
}
|
|
1798
|
+
const res = [];
|
|
1799
|
+
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1800
|
+
const child = node.children[i];
|
|
1801
|
+
const result = evaluate(child, item, idx);
|
|
1802
|
+
if (result.length) {
|
|
1803
|
+
res.push(...result);
|
|
1804
|
+
} else if (node.operator === LogicalOperator.AND) {
|
|
1805
|
+
return [];
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return res;
|
|
1809
|
+
};
|
|
1810
|
+
const records = this._myIndex.records;
|
|
1811
|
+
const resultMap = {};
|
|
1812
|
+
const results = [];
|
|
1813
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1814
|
+
if (isDefined(item)) {
|
|
1815
|
+
let expResults = evaluate(expression, item, idx);
|
|
1816
|
+
if (expResults.length) {
|
|
1817
|
+
if (!resultMap[idx]) {
|
|
1818
|
+
resultMap[idx] = { idx, item, matches: [] };
|
|
1819
|
+
results.push(resultMap[idx]);
|
|
1820
|
+
}
|
|
1821
|
+
expResults.forEach(({ matches }) => {
|
|
1822
|
+
resultMap[idx].matches.push(...matches);
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
return results;
|
|
1828
|
+
}
|
|
1829
|
+
_searchObjectList(query) {
|
|
1830
|
+
const searcher = createSearcher(query, this.options);
|
|
1831
|
+
const { keys, records } = this._myIndex;
|
|
1832
|
+
const results = [];
|
|
1833
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1834
|
+
if (!isDefined(item)) {
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
let matches = [];
|
|
1838
|
+
keys.forEach((key, keyIndex) => {
|
|
1839
|
+
matches.push(
|
|
1840
|
+
...this._findMatches({
|
|
1841
|
+
key,
|
|
1842
|
+
value: item[keyIndex],
|
|
1843
|
+
searcher
|
|
1844
|
+
})
|
|
1845
|
+
);
|
|
1846
|
+
});
|
|
1847
|
+
if (matches.length) {
|
|
1848
|
+
results.push({
|
|
1849
|
+
idx,
|
|
1850
|
+
item,
|
|
1851
|
+
matches
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
});
|
|
1855
|
+
return results;
|
|
1856
|
+
}
|
|
1857
|
+
_findMatches({ key, value, searcher }) {
|
|
1858
|
+
if (!isDefined(value)) {
|
|
1859
|
+
return [];
|
|
1860
|
+
}
|
|
1861
|
+
let matches = [];
|
|
1862
|
+
if (isArray(value)) {
|
|
1863
|
+
value.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1864
|
+
if (!isDefined(text)) {
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1868
|
+
if (isMatch) {
|
|
1869
|
+
matches.push({
|
|
1870
|
+
score,
|
|
1871
|
+
key,
|
|
1872
|
+
value: text,
|
|
1873
|
+
idx,
|
|
1874
|
+
norm: norm2,
|
|
1875
|
+
indices
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
});
|
|
1879
|
+
} else {
|
|
1880
|
+
const { v: text, n: norm2 } = value;
|
|
1881
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1882
|
+
if (isMatch) {
|
|
1883
|
+
matches.push({ score, key, value: text, norm: norm2, indices });
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
return matches;
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
Fuse.version = "7.1.0";
|
|
1890
|
+
Fuse.createIndex = createIndex;
|
|
1891
|
+
Fuse.parseIndex = parseIndex;
|
|
1892
|
+
Fuse.config = Config;
|
|
1893
|
+
{
|
|
1894
|
+
Fuse.parseQuery = parse;
|
|
1895
|
+
}
|
|
1896
|
+
{
|
|
1897
|
+
register(ExtendedSearch);
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// src/data/search/utils/sanitizeInput.ts
|
|
1901
|
+
var sanitizeInput = (str) => str.replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "").replace(/[\-–—_./()]+/g, "").normalize("NFC").trim();
|
|
1902
|
+
|
|
1903
|
+
// src/data/search/getSearchClient.ts
|
|
1904
|
+
var getSearchClient = ({ occupants, amenities }) => {
|
|
1905
|
+
const fuseAmenities = new Fuse(amenities, { threshold: 0.2 });
|
|
1906
|
+
const fuseOccupants = new Fuse(occupants, {
|
|
1907
|
+
threshold: 0.3,
|
|
1908
|
+
// 0.2 is too strict (can't find Mo-Mo Paradise with "momo" search string)
|
|
1909
|
+
includeScore: true,
|
|
1910
|
+
keys: [
|
|
1911
|
+
{ name: "properties.name", "weight": 4, getFn: (obj) => Object.values(obj.properties.name) },
|
|
1912
|
+
{ name: "properties.category", "weight": 0.25 },
|
|
1913
|
+
{
|
|
1914
|
+
name: "properties.local_categories",
|
|
1915
|
+
"weight": 0.25,
|
|
1916
|
+
getFn: (occ) => occ.properties.local_categories.map((cat3) => Object.values(cat3.properties.name)).flat()
|
|
1917
|
+
},
|
|
1918
|
+
{ name: "properties.keywords", "weight": 0.25 },
|
|
1919
|
+
{ name: "properties.description", "weight": 0.25, getFn: (occ) => Object.values(occ.properties.description || {}) },
|
|
1920
|
+
{ name: "properties.unit.properties.name", "weight": 0.25, getFn: (obj) => Object.values(obj.properties.unit?.properties.name || {}) },
|
|
1921
|
+
{ name: "properties.kiosk.properties.name", "weight": 0.25, getFn: (obj) => Object.values(obj.properties.kiosk?.properties.name || {}) }
|
|
1922
|
+
]
|
|
1923
|
+
});
|
|
1924
|
+
const fuseFuzzyAmenities = new Fuse(amenities, {
|
|
1925
|
+
threshold: 0.2,
|
|
1926
|
+
keys: [
|
|
1927
|
+
{ name: "properties.category", weight: 4 }
|
|
1928
|
+
]
|
|
1929
|
+
});
|
|
1930
|
+
const search2 = (value) => {
|
|
1931
|
+
const sanitizedValue = sanitizeInput(value);
|
|
1932
|
+
const matchedAmenities = fuseAmenities.search(sanitizedValue);
|
|
1933
|
+
if (matchedAmenities.length > 0) return matchedAmenities;
|
|
1934
|
+
const matchedOccupants = fuseOccupants.search(sanitizedValue);
|
|
1935
|
+
if (matchedOccupants.length > 0) return matchedOccupants;
|
|
1936
|
+
const matchedFuzzyAmenities = fuseFuzzyAmenities.search(sanitizedValue);
|
|
1937
|
+
if (matchedFuzzyAmenities.length > 0) return matchedFuzzyAmenities;
|
|
1938
|
+
return [];
|
|
1939
|
+
};
|
|
1940
|
+
return {
|
|
1941
|
+
search: search2
|
|
1942
|
+
};
|
|
1943
|
+
};
|
|
1944
|
+
|
|
581
1945
|
// src/data/getDataClient.ts
|
|
582
1946
|
var getDataClient = (options) => {
|
|
1947
|
+
let searchClient;
|
|
583
1948
|
const observers = /* @__PURE__ */ new Map();
|
|
584
1949
|
const queryClient = options.queryClient ?? new QueryClient();
|
|
585
1950
|
const { mode = "delivery", projectId, apiKey, baseUrl, previewToken } = options;
|
|
@@ -608,7 +1973,7 @@ var getDataClient = (options) => {
|
|
|
608
1973
|
}
|
|
609
1974
|
};
|
|
610
1975
|
const internalFindById = async (id) => {
|
|
611
|
-
if (id === null) return null;
|
|
1976
|
+
if (id === null || id === void 0) return null;
|
|
612
1977
|
const featureType = id.slice(0, id.lastIndexOf("-"));
|
|
613
1978
|
const feature2 = await queryClient.ensureQueryData({
|
|
614
1979
|
queryKey: ["_deliveryapi", featureType, id],
|
|
@@ -691,6 +2056,17 @@ var getDataClient = (options) => {
|
|
|
691
2056
|
const feature2 = await queryClient.ensureQueryData(findQueryOptions);
|
|
692
2057
|
return feature2;
|
|
693
2058
|
}
|
|
2059
|
+
const searchFn = async (txt) => {
|
|
2060
|
+
if (!searchClient) {
|
|
2061
|
+
const [occupants, amenities] = await Promise.all([
|
|
2062
|
+
filterByType("occupant", { populate: true }),
|
|
2063
|
+
filterByType("amenity")
|
|
2064
|
+
]);
|
|
2065
|
+
const haystack = { occupants, amenities };
|
|
2066
|
+
searchClient = getSearchClient(haystack);
|
|
2067
|
+
}
|
|
2068
|
+
return searchClient.search(txt);
|
|
2069
|
+
};
|
|
694
2070
|
return {
|
|
695
2071
|
projectId,
|
|
696
2072
|
queryClient,
|
|
@@ -700,7 +2076,8 @@ var getDataClient = (options) => {
|
|
|
700
2076
|
createFilterByTypeQueryOptions,
|
|
701
2077
|
createFindByIdQueryOptions,
|
|
702
2078
|
filterByType,
|
|
703
|
-
findById
|
|
2079
|
+
findById,
|
|
2080
|
+
search: searchFn
|
|
704
2081
|
};
|
|
705
2082
|
};
|
|
706
2083
|
|
|
@@ -758,7 +2135,7 @@ function point(coordinates, properties, options = {}) {
|
|
|
758
2135
|
if (coordinates.length < 2) {
|
|
759
2136
|
throw new Error("coordinates must be at least 2 numbers long");
|
|
760
2137
|
}
|
|
761
|
-
if (!
|
|
2138
|
+
if (!isNumber2(coordinates[0]) || !isNumber2(coordinates[1])) {
|
|
762
2139
|
throw new Error("coordinates must contain numbers");
|
|
763
2140
|
}
|
|
764
2141
|
const geom = {
|
|
@@ -817,7 +2194,7 @@ function multiPoint(coordinates, properties, options = {}) {
|
|
|
817
2194
|
};
|
|
818
2195
|
return feature(geom, properties, options);
|
|
819
2196
|
}
|
|
820
|
-
function
|
|
2197
|
+
function isNumber2(num) {
|
|
821
2198
|
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
822
2199
|
}
|
|
823
2200
|
|
|
@@ -2710,7 +4087,7 @@ import {
|
|
|
2710
4087
|
PlaneGeometry
|
|
2711
4088
|
} from "three";
|
|
2712
4089
|
import { largestRect } from "d3plus-shape";
|
|
2713
|
-
import { max, merge, isNumber as
|
|
4090
|
+
import { max, merge, isNumber as isNumber3, isArray as isArray2, range } from "lodash-es";
|
|
2714
4091
|
var OPTIONS3 = {
|
|
2715
4092
|
// Allowing click through and prevent interaction
|
|
2716
4093
|
interactive: false,
|
|
@@ -2856,7 +4233,7 @@ var GroundLabel = class extends BaseObject4 {
|
|
|
2856
4233
|
strokeStyle,
|
|
2857
4234
|
lineWidth
|
|
2858
4235
|
});
|
|
2859
|
-
const rectAngles =
|
|
4236
|
+
const rectAngles = isArray2(angle) ? angle : [angle];
|
|
2860
4237
|
material.needsUpdate = true;
|
|
2861
4238
|
const rect = largestRect(bound, {
|
|
2862
4239
|
cache: true,
|
|
@@ -2929,32 +4306,32 @@ var GroundLabel = class extends BaseObject4 {
|
|
|
2929
4306
|
return { x: this.#offsetX, y: this.#offsetY };
|
|
2930
4307
|
}
|
|
2931
4308
|
set offsetX(value) {
|
|
2932
|
-
if (
|
|
4309
|
+
if (isNumber3(value)) {
|
|
2933
4310
|
this.#offsetX = value;
|
|
2934
4311
|
this.#updatePosition();
|
|
2935
4312
|
}
|
|
2936
4313
|
}
|
|
2937
4314
|
set offsetY(value) {
|
|
2938
|
-
if (
|
|
4315
|
+
if (isNumber3(value)) {
|
|
2939
4316
|
this.#offsetY = value;
|
|
2940
4317
|
this.#updatePosition();
|
|
2941
4318
|
}
|
|
2942
4319
|
}
|
|
2943
4320
|
set angle(newAngle) {
|
|
2944
|
-
if (
|
|
4321
|
+
if (isNumber3(newAngle)) {
|
|
2945
4322
|
this.#angle = newAngle;
|
|
2946
4323
|
this.getObject3d().rotation.z = Math.PI / 180 * this.#angle;
|
|
2947
4324
|
}
|
|
2948
4325
|
}
|
|
2949
4326
|
setOffset(offsetX, offsetY) {
|
|
2950
|
-
if (
|
|
4327
|
+
if (isNumber3(offsetX) && isNumber3(offsetY)) {
|
|
2951
4328
|
this.#offsetX = offsetX;
|
|
2952
4329
|
this.#offsetY = offsetY;
|
|
2953
4330
|
this.#updatePosition();
|
|
2954
4331
|
}
|
|
2955
4332
|
}
|
|
2956
4333
|
addOffset(deltaX, deltaY) {
|
|
2957
|
-
if (
|
|
4334
|
+
if (isNumber3(deltaX) && isNumber3(deltaY)) {
|
|
2958
4335
|
this.#offsetX += deltaX;
|
|
2959
4336
|
this.#offsetY += deltaY;
|
|
2960
4337
|
this.#updatePosition();
|