@baleada/logic 0.20.23 → 0.20.27
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/lib/index.cjs +88 -48
- package/lib/index.d.ts +20 -17
- package/lib/index.js +90 -50
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -18,16 +18,16 @@ var BezierEasing__default = /*#__PURE__*/_interopDefaultLegacy(BezierEasing);
|
|
|
18
18
|
var polygonClipping__default = /*#__PURE__*/_interopDefaultLegacy(polygonClipping);
|
|
19
19
|
var createDOMPurify__default = /*#__PURE__*/_interopDefaultLegacy(createDOMPurify);
|
|
20
20
|
|
|
21
|
-
function createReduceAsync(
|
|
21
|
+
function createReduceAsync(accumulate, initialValue) {
|
|
22
22
|
return async (array) => {
|
|
23
23
|
return await lazyCollections.reduce(async (accumulatorPromise, item, index) => {
|
|
24
24
|
const accumulator = await accumulatorPromise;
|
|
25
|
-
return
|
|
25
|
+
return accumulate(accumulator, item, index);
|
|
26
26
|
}, Promise.resolve(initialValue))(array);
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
function createReduce(
|
|
30
|
-
return (array) => lazyCollections.reduce(
|
|
29
|
+
function createReduce(accumulate, initialValue) {
|
|
30
|
+
return (array) => lazyCollections.reduce(accumulate, initialValue)(array);
|
|
31
31
|
}
|
|
32
32
|
function createForEachAsync(forEach) {
|
|
33
33
|
return async (array) => {
|
|
@@ -35,19 +35,19 @@ function createForEachAsync(forEach) {
|
|
|
35
35
|
return array;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function createMapAsync(
|
|
38
|
+
function createMapAsync(transform) {
|
|
39
39
|
return async (array) => {
|
|
40
40
|
return await createReduceAsync(async (resolvedMaps, item, index) => {
|
|
41
|
-
const
|
|
42
|
-
resolvedMaps.push(
|
|
41
|
+
const transformed = await transform(item, index);
|
|
42
|
+
resolvedMaps.push(transformed);
|
|
43
43
|
return resolvedMaps;
|
|
44
44
|
}, [])(array);
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
function createFilterAsync(
|
|
47
|
+
function createFilterAsync(condition) {
|
|
48
48
|
return async (array) => {
|
|
49
|
-
const
|
|
50
|
-
return createFilter((_, index) =>
|
|
49
|
+
const transformedAsync = await createMapAsync(condition)(array);
|
|
50
|
+
return createFilter((_, index) => transformedAsync[index])(array);
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
function createDelete(required) {
|
|
@@ -122,11 +122,11 @@ function createSlice({ from, to }) {
|
|
|
122
122
|
return from === to ? [] : lazyCollections.pipe(lazyCollections.slice(from, to - 1), lazyCollections.toArray())(array);
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
function createFilter(
|
|
126
|
-
return (array) => lazyCollections.pipe(lazyCollections.filter(
|
|
125
|
+
function createFilter(condition) {
|
|
126
|
+
return (array) => lazyCollections.pipe(lazyCollections.filter(condition), lazyCollections.toArray())(array);
|
|
127
127
|
}
|
|
128
|
-
function createMap(
|
|
129
|
-
return (array) => lazyCollections.pipe(lazyCollections.map(
|
|
128
|
+
function createMap(transform) {
|
|
129
|
+
return (array) => lazyCollections.pipe(lazyCollections.map(transform), lazyCollections.toArray())(array);
|
|
130
130
|
}
|
|
131
131
|
function createConcat(...arrays) {
|
|
132
132
|
return (array) => lazyCollections.pipe(lazyCollections.concat(array, ...arrays), lazyCollections.toArray())();
|
|
@@ -167,8 +167,8 @@ function createDetermine(potentialities) {
|
|
|
167
167
|
return (determinant) => lazyCollections.find(({ predicate }) => predicate(determinant))(predicates).outcome;
|
|
168
168
|
}
|
|
169
169
|
function createRename({ from, to }) {
|
|
170
|
-
return (
|
|
171
|
-
const keys = [...
|
|
170
|
+
return (map2) => {
|
|
171
|
+
const keys = [...map2.keys()], keyToRenameIndex = lazyCollections.findIndex((k) => k === from)(keys), newKeys = createReplace({ index: keyToRenameIndex, item: to })(keys), values = [...map2.values()];
|
|
172
172
|
return createReduce((renamed, key, index) => renamed.set(key, values[index]), new Map())(newKeys);
|
|
173
173
|
};
|
|
174
174
|
}
|
|
@@ -482,11 +482,11 @@ function ensureClickcombo(type) {
|
|
|
482
482
|
function ensurePointercombo(type) {
|
|
483
483
|
return toCombo(type);
|
|
484
484
|
}
|
|
485
|
-
const
|
|
485
|
+
const toUnique$1 = lazyCollections.unique();
|
|
486
486
|
const toComboItems = lazyCollections.map((name) => name === "" ? delimiter : name);
|
|
487
487
|
const delimiter = "+";
|
|
488
488
|
function toCombo(type) {
|
|
489
|
-
return lazyCollections.pipe(
|
|
489
|
+
return lazyCollections.pipe(toUnique$1, toComboItems, lazyCollections.toArray())(type.split(delimiter));
|
|
490
490
|
}
|
|
491
491
|
function fromComboItemNameToType(name) {
|
|
492
492
|
return lazyCollections.find((type) => predicatesByType[type](name))(listenableComboItemTypes) ?? "custom";
|
|
@@ -737,7 +737,7 @@ function createToType({
|
|
|
737
737
|
}
|
|
738
738
|
};
|
|
739
739
|
}
|
|
740
|
-
const leftclickcomboEventTypes = new Set(["click", "mousedown", "mouseup", "dblclick"]), rightclickComboEventTypes = new Set(["contextmenu"]), keycomboEventTypes = new Set(["keydown", "keyup"]), toJoinedClickcombo = lazyCollections.join("+"), toJoinedKeycombo = lazyCollections.pipe(lazyCollections.map(({ name }) => name),
|
|
740
|
+
const leftclickcomboEventTypes = new Set(["click", "mousedown", "mouseup", "dblclick"]), rightclickComboEventTypes = new Set(["contextmenu"]), keycomboEventTypes = new Set(["keydown", "keyup"]), toJoinedClickcombo = lazyCollections.join("+"), toJoinedKeycombo = lazyCollections.pipe(lazyCollections.map(({ name }) => name), toJoinedClickcombo);
|
|
741
741
|
|
|
742
742
|
class Listenable {
|
|
743
743
|
constructor(type, options) {
|
|
@@ -2109,13 +2109,13 @@ class Completeable {
|
|
|
2109
2109
|
this.computedStatus = "completed";
|
|
2110
2110
|
}
|
|
2111
2111
|
}
|
|
2112
|
-
const
|
|
2112
|
+
const toString = lazyCollections.join(""), reverse = createReverse();
|
|
2113
2113
|
function toPreviousMatch({ string, re, from }) {
|
|
2114
2114
|
let indexOf;
|
|
2115
2115
|
if (!re.test(string.slice(0, from)) || from === 0) {
|
|
2116
2116
|
indexOf = -1;
|
|
2117
2117
|
} else {
|
|
2118
|
-
const reversedStringBeforeFrom = new Pipeable(string).pipe((string2) => string2.slice(0, from), (sliced) => sliced.split(""), reverse,
|
|
2118
|
+
const reversedStringBeforeFrom = new Pipeable(string).pipe((string2) => string2.slice(0, from), (sliced) => sliced.split(""), reverse, toString), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
|
|
2119
2119
|
indexOf = toNextMatchIndex === -1 ? -1 : reversedStringBeforeFrom.length - 1 - toNextMatchIndex;
|
|
2120
2120
|
}
|
|
2121
2121
|
return indexOf;
|
|
@@ -2719,6 +2719,7 @@ class Grantable {
|
|
|
2719
2719
|
const defaultOptions$2 = {
|
|
2720
2720
|
initialLocation: 0
|
|
2721
2721
|
};
|
|
2722
|
+
const defaultNavigateOptions = { allows: "possible" };
|
|
2722
2723
|
const defaultNextAndPreviousOptions = {
|
|
2723
2724
|
distance: 1,
|
|
2724
2725
|
loops: true
|
|
@@ -2758,28 +2759,36 @@ class Navigateable {
|
|
|
2758
2759
|
this.navigate(location);
|
|
2759
2760
|
return this;
|
|
2760
2761
|
}
|
|
2761
|
-
navigate(location) {
|
|
2762
|
-
|
|
2762
|
+
navigate(location, options = {}) {
|
|
2763
|
+
const { allows } = { ...defaultNavigateOptions, ...options };
|
|
2764
|
+
this._navigate(location, { allows });
|
|
2763
2765
|
this.navigated();
|
|
2764
2766
|
return this;
|
|
2765
2767
|
}
|
|
2766
2768
|
navigated() {
|
|
2767
2769
|
this.computedStatus = "navigated";
|
|
2768
2770
|
}
|
|
2769
|
-
_navigate(location) {
|
|
2771
|
+
_navigate(location, options = {}) {
|
|
2772
|
+
const { allows } = { ...defaultNavigateOptions, ...options };
|
|
2770
2773
|
const ensuredLocation = (() => {
|
|
2771
|
-
if (
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2774
|
+
if (allows === "possible") {
|
|
2775
|
+
if (location < 0 && allows === "possible") {
|
|
2776
|
+
return 0;
|
|
2777
|
+
}
|
|
2778
|
+
if (location > this.array.length - 1) {
|
|
2779
|
+
return Math.max(this.array.length - 1, 0);
|
|
2780
|
+
}
|
|
2776
2781
|
}
|
|
2777
2782
|
return location;
|
|
2778
2783
|
})();
|
|
2779
2784
|
this.computedLocation = ensuredLocation;
|
|
2780
2785
|
}
|
|
2781
2786
|
next(options = {}) {
|
|
2782
|
-
const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options },
|
|
2787
|
+
const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2788
|
+
if (allows === "any") {
|
|
2789
|
+
return this.location + distance;
|
|
2790
|
+
}
|
|
2791
|
+
const lastLocation = this.array.length - 1;
|
|
2783
2792
|
if (this.location + distance <= lastLocation) {
|
|
2784
2793
|
return this.location + distance;
|
|
2785
2794
|
}
|
|
@@ -2794,7 +2803,7 @@ class Navigateable {
|
|
|
2794
2803
|
return newLocation2;
|
|
2795
2804
|
})();
|
|
2796
2805
|
})();
|
|
2797
|
-
this._navigate(newLocation);
|
|
2806
|
+
this._navigate(newLocation, { allows });
|
|
2798
2807
|
this.nexted();
|
|
2799
2808
|
return this;
|
|
2800
2809
|
}
|
|
@@ -2802,7 +2811,10 @@ class Navigateable {
|
|
|
2802
2811
|
this.computedStatus = "navigated to next";
|
|
2803
2812
|
}
|
|
2804
2813
|
previous(options = {}) {
|
|
2805
|
-
const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
|
|
2814
|
+
const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2815
|
+
if (allows === "any") {
|
|
2816
|
+
return this.location - distance;
|
|
2817
|
+
}
|
|
2806
2818
|
if (this.location - distance >= 0) {
|
|
2807
2819
|
return this.location - distance;
|
|
2808
2820
|
}
|
|
@@ -2817,7 +2829,7 @@ class Navigateable {
|
|
|
2817
2829
|
return newLocation2;
|
|
2818
2830
|
})();
|
|
2819
2831
|
})();
|
|
2820
|
-
this._navigate(newLocation);
|
|
2832
|
+
this._navigate(newLocation, { allows });
|
|
2821
2833
|
this.previoused();
|
|
2822
2834
|
return this;
|
|
2823
2835
|
}
|
|
@@ -2877,10 +2889,10 @@ class Pickable {
|
|
|
2877
2889
|
this.pick(indices);
|
|
2878
2890
|
}
|
|
2879
2891
|
get first() {
|
|
2880
|
-
return
|
|
2892
|
+
return this.computedFirst;
|
|
2881
2893
|
}
|
|
2882
2894
|
get last() {
|
|
2883
|
-
return
|
|
2895
|
+
return this.computedLast;
|
|
2884
2896
|
}
|
|
2885
2897
|
get oldest() {
|
|
2886
2898
|
return this.picks[0];
|
|
@@ -2906,18 +2918,41 @@ class Pickable {
|
|
|
2906
2918
|
return this.pick(indexOrIndices);
|
|
2907
2919
|
}
|
|
2908
2920
|
pick(indexOrIndices, options = {}) {
|
|
2909
|
-
const {
|
|
2910
|
-
|
|
2911
|
-
if (
|
|
2912
|
-
return possiblePicks;
|
|
2913
|
-
|
|
2921
|
+
const { replace = "none" } = options;
|
|
2922
|
+
this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
|
|
2923
|
+
if (replace === "all") {
|
|
2924
|
+
return toUnique(possiblePicks);
|
|
2925
|
+
}
|
|
2926
|
+
const possibleWithoutDuplicates = createFilter((possiblePick) => !lazyCollections.find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
|
|
2927
|
+
switch (replace) {
|
|
2928
|
+
case "none":
|
|
2929
|
+
return createConcat(this.picks || [], possibleWithoutDuplicates)([]);
|
|
2930
|
+
case "fifo":
|
|
2931
|
+
if (possibleWithoutDuplicates.length === 0) {
|
|
2932
|
+
return this.picks;
|
|
2933
|
+
}
|
|
2934
|
+
if (possibleWithoutDuplicates.length === this.picks.length) {
|
|
2935
|
+
return possibleWithoutDuplicates;
|
|
2936
|
+
}
|
|
2937
|
+
if (possibleWithoutDuplicates.length > this.picks.length) {
|
|
2938
|
+
return createSlice({ from: possibleWithoutDuplicates.length - this.picks.length })(possibleWithoutDuplicates);
|
|
2939
|
+
}
|
|
2940
|
+
return new Pipeable(this.picks).pipe(createSlice({ from: possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2941
|
+
case "lifo":
|
|
2942
|
+
if (possibleWithoutDuplicates.length === 0) {
|
|
2943
|
+
return this.picks;
|
|
2944
|
+
}
|
|
2945
|
+
if (possibleWithoutDuplicates.length === this.picks.length) {
|
|
2946
|
+
return possibleWithoutDuplicates;
|
|
2947
|
+
}
|
|
2948
|
+
if (possibleWithoutDuplicates.length > this.picks.length) {
|
|
2949
|
+
return createSlice({ from: 0, to: possibleWithoutDuplicates.length - this.picks.length + 1 })(possibleWithoutDuplicates);
|
|
2950
|
+
}
|
|
2951
|
+
return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2952
|
+
}
|
|
2914
2953
|
});
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
this.picked();
|
|
2918
|
-
return this;
|
|
2919
|
-
}
|
|
2920
|
-
this.computedPicks = createConcat(newPicks)(this.picks || []);
|
|
2954
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2955
|
+
this.computedLast = Math.max(...this.picks);
|
|
2921
2956
|
this.picked();
|
|
2922
2957
|
return this;
|
|
2923
2958
|
}
|
|
@@ -2927,11 +2962,15 @@ class Pickable {
|
|
|
2927
2962
|
omit(indexOrIndices) {
|
|
2928
2963
|
if (isUndefined(indexOrIndices)) {
|
|
2929
2964
|
this.computedPicks = [];
|
|
2965
|
+
this.computedFirst = void 0;
|
|
2966
|
+
this.computedLast = void 0;
|
|
2930
2967
|
this.omitted();
|
|
2931
2968
|
return this;
|
|
2932
2969
|
}
|
|
2933
|
-
const omits = ensureIndices(indexOrIndices)
|
|
2934
|
-
this.computedPicks =
|
|
2970
|
+
const omits = ensureIndices(indexOrIndices);
|
|
2971
|
+
this.computedPicks = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)))(this.computedPicks);
|
|
2972
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2973
|
+
this.computedLast = Math.max(...this.picks);
|
|
2935
2974
|
this.omitted();
|
|
2936
2975
|
return this;
|
|
2937
2976
|
}
|
|
@@ -2942,6 +2981,7 @@ class Pickable {
|
|
|
2942
2981
|
function ensureIndices(indexOrIndices) {
|
|
2943
2982
|
return Array.isArray(indexOrIndices) ? indexOrIndices : [indexOrIndices];
|
|
2944
2983
|
}
|
|
2984
|
+
const toUnique = createUnique();
|
|
2945
2985
|
|
|
2946
2986
|
class Sanitizeable {
|
|
2947
2987
|
constructor(html, options) {
|
package/lib/index.d.ts
CHANGED
|
@@ -704,6 +704,13 @@ declare type NavigateableOptions = {
|
|
|
704
704
|
initialLocation?: number;
|
|
705
705
|
};
|
|
706
706
|
declare type NavigateableStatus = 'ready' | 'navigated' | 'navigated to next' | 'navigated to previous' | 'navigated to random' | 'navigated to first' | 'navigated to last';
|
|
707
|
+
declare type NavigateOptions = {
|
|
708
|
+
allows?: 'possible' | 'any';
|
|
709
|
+
};
|
|
710
|
+
declare type NextAndPreviousOptions = {
|
|
711
|
+
distance?: number;
|
|
712
|
+
loops?: boolean;
|
|
713
|
+
};
|
|
707
714
|
declare class Navigateable<Item> {
|
|
708
715
|
constructor(array: Item[], options?: NavigateableOptions);
|
|
709
716
|
private computedStatus;
|
|
@@ -718,18 +725,12 @@ declare class Navigateable<Item> {
|
|
|
718
725
|
get item(): Item;
|
|
719
726
|
setArray(array: Item[]): this;
|
|
720
727
|
setLocation(location: number): this;
|
|
721
|
-
navigate(location: number): this;
|
|
728
|
+
navigate(location: number, options?: NavigateOptions): this;
|
|
722
729
|
private navigated;
|
|
723
730
|
private _navigate;
|
|
724
|
-
next(options?:
|
|
725
|
-
distance?: number;
|
|
726
|
-
loops?: boolean;
|
|
727
|
-
}): this;
|
|
731
|
+
next(options?: NextAndPreviousOptions & NavigateOptions): this;
|
|
728
732
|
private nexted;
|
|
729
|
-
previous(options?:
|
|
730
|
-
distance?: number;
|
|
731
|
-
loops?: boolean;
|
|
732
|
-
}): this;
|
|
733
|
+
previous(options?: NextAndPreviousOptions & NavigateOptions): this;
|
|
733
734
|
private previoused;
|
|
734
735
|
random(): this;
|
|
735
736
|
private randomed;
|
|
@@ -753,7 +754,9 @@ declare class Pickable<Item> {
|
|
|
753
754
|
private computedPicks;
|
|
754
755
|
get picks(): number[];
|
|
755
756
|
set picks(indices: number[]);
|
|
757
|
+
computedFirst: number;
|
|
756
758
|
get first(): number;
|
|
759
|
+
computedLast: number;
|
|
757
760
|
get last(): number;
|
|
758
761
|
get oldest(): number;
|
|
759
762
|
get newest(): number;
|
|
@@ -765,7 +768,7 @@ declare class Pickable<Item> {
|
|
|
765
768
|
setArray(array: Item[]): this;
|
|
766
769
|
setPicks(indexOrIndices: number | number[]): this;
|
|
767
770
|
pick(indexOrIndices: number | number[], options?: {
|
|
768
|
-
|
|
771
|
+
replace?: 'none' | 'all' | 'fifo' | 'lifo';
|
|
769
772
|
}): this;
|
|
770
773
|
private picked;
|
|
771
774
|
omit(indexOrIndices?: number | number[]): this;
|
|
@@ -842,12 +845,12 @@ declare class Storeable {
|
|
|
842
845
|
removeStatus(): this;
|
|
843
846
|
}
|
|
844
847
|
|
|
845
|
-
declare function createReduceAsync<Item, Accumulator>(
|
|
846
|
-
declare function createReduce<Item, Accumulator>(
|
|
848
|
+
declare function createReduceAsync<Item, Accumulator>(accumulate: (accumulator?: Accumulator, item?: Item, index?: number) => Promise<Accumulator>, initialValue?: Accumulator): (array: Item[]) => Promise<Accumulator>;
|
|
849
|
+
declare function createReduce<Item, Accumulator>(accumulate: (accumulator?: Accumulator, item?: Item, index?: number) => Accumulator, initialValue?: Accumulator): (array: Item[]) => Accumulator;
|
|
847
850
|
declare type ArrayFunctionAsync<Item, Returned> = (array: Item[]) => Promise<Returned>;
|
|
848
851
|
declare function createForEachAsync<Item>(forEach: (item?: Item, index?: number) => any): ArrayFunctionAsync<Item, any>;
|
|
849
|
-
declare function createMapAsync<Item, Mapped>(
|
|
850
|
-
declare function createFilterAsync<Item>(
|
|
852
|
+
declare function createMapAsync<Item, Mapped>(transform: (item?: Item, index?: number) => Promise<Mapped>): ArrayFunctionAsync<Item, Mapped[]>;
|
|
853
|
+
declare function createFilterAsync<Item>(condition: (item?: Item, index?: number) => Promise<boolean>): ArrayFunctionAsync<Item, Item[]>;
|
|
851
854
|
declare type ArrayFunction<Item, Returned> = (array: Item[]) => Returned;
|
|
852
855
|
declare function createDelete<Item>(required: {
|
|
853
856
|
index: number;
|
|
@@ -880,8 +883,8 @@ declare function createSlice<Item>({ from, to }: {
|
|
|
880
883
|
from: number;
|
|
881
884
|
to?: number;
|
|
882
885
|
}): ArrayFunction<Item, Item[]>;
|
|
883
|
-
declare function createFilter<Item>(
|
|
884
|
-
declare function createMap<Item,
|
|
886
|
+
declare function createFilter<Item>(condition: (item?: Item, index?: number) => boolean): ArrayFunction<Item, Item[]>;
|
|
887
|
+
declare function createMap<Item, Transformed = Item>(transform: (item?: Item, index?: number) => Transformed): ArrayFunction<Item, Transformed[]>;
|
|
885
888
|
declare function createConcat<Item>(...arrays: Item[][]): ArrayFunction<Item, Item[]>;
|
|
886
889
|
declare function createReverse<Item>(): ArrayFunction<Item, Item[]>;
|
|
887
890
|
declare type StringFunction<Returned> = (string: string) => Returned;
|
|
@@ -897,7 +900,7 @@ declare type Potentiality<Outcome> = {
|
|
|
897
900
|
probability: number;
|
|
898
901
|
};
|
|
899
902
|
declare function createDetermine<Outcome>(potentialities: Potentiality<Outcome>[]): NumberFunction<Outcome>;
|
|
900
|
-
declare type MapFunction<Key, Value, Returned> = (
|
|
903
|
+
declare type MapFunction<Key, Value, Returned> = (transform: Map<Key, Value>) => Returned;
|
|
901
904
|
declare function createRename<Key, Value>({ from, to }: {
|
|
902
905
|
from: Key;
|
|
903
906
|
to: Key;
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { reduce, pipe, filter, toArray, findIndex, slice, concat, unique
|
|
1
|
+
import { reduce, pipe, filter, toArray, findIndex, slice, concat, unique, map, find, some, join, every } from 'lazy-collections';
|
|
2
2
|
import slugify from '@sindresorhus/slugify';
|
|
3
3
|
import BezierEasing from 'bezier-easing';
|
|
4
4
|
import { mix } from '@snigo.dev/color';
|
|
@@ -7,16 +7,16 @@ import polygonClipping from 'polygon-clipping';
|
|
|
7
7
|
import createDOMPurify from 'dompurify';
|
|
8
8
|
import { Searcher } from 'fast-fuzzy';
|
|
9
9
|
|
|
10
|
-
function createReduceAsync(
|
|
10
|
+
function createReduceAsync(accumulate, initialValue) {
|
|
11
11
|
return async (array) => {
|
|
12
12
|
return await reduce(async (accumulatorPromise, item, index) => {
|
|
13
13
|
const accumulator = await accumulatorPromise;
|
|
14
|
-
return
|
|
14
|
+
return accumulate(accumulator, item, index);
|
|
15
15
|
}, Promise.resolve(initialValue))(array);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
function createReduce(
|
|
19
|
-
return (array) => reduce(
|
|
18
|
+
function createReduce(accumulate, initialValue) {
|
|
19
|
+
return (array) => reduce(accumulate, initialValue)(array);
|
|
20
20
|
}
|
|
21
21
|
function createForEachAsync(forEach) {
|
|
22
22
|
return async (array) => {
|
|
@@ -24,19 +24,19 @@ function createForEachAsync(forEach) {
|
|
|
24
24
|
return array;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function createMapAsync(
|
|
27
|
+
function createMapAsync(transform) {
|
|
28
28
|
return async (array) => {
|
|
29
29
|
return await createReduceAsync(async (resolvedMaps, item, index) => {
|
|
30
|
-
const
|
|
31
|
-
resolvedMaps.push(
|
|
30
|
+
const transformed = await transform(item, index);
|
|
31
|
+
resolvedMaps.push(transformed);
|
|
32
32
|
return resolvedMaps;
|
|
33
33
|
}, [])(array);
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
function createFilterAsync(
|
|
36
|
+
function createFilterAsync(condition) {
|
|
37
37
|
return async (array) => {
|
|
38
|
-
const
|
|
39
|
-
return createFilter((_, index) =>
|
|
38
|
+
const transformedAsync = await createMapAsync(condition)(array);
|
|
39
|
+
return createFilter((_, index) => transformedAsync[index])(array);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
function createDelete(required) {
|
|
@@ -104,18 +104,18 @@ function createReplace({ index, item }) {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
function createUnique() {
|
|
107
|
-
return (array) => pipe(unique
|
|
107
|
+
return (array) => pipe(unique(), toArray())(array);
|
|
108
108
|
}
|
|
109
109
|
function createSlice({ from, to }) {
|
|
110
110
|
return (array) => {
|
|
111
111
|
return from === to ? [] : pipe(slice(from, to - 1), toArray())(array);
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
function createFilter(
|
|
115
|
-
return (array) => pipe(filter(
|
|
114
|
+
function createFilter(condition) {
|
|
115
|
+
return (array) => pipe(filter(condition), toArray())(array);
|
|
116
116
|
}
|
|
117
|
-
function createMap(
|
|
118
|
-
return (array) => pipe(map(
|
|
117
|
+
function createMap(transform) {
|
|
118
|
+
return (array) => pipe(map(transform), toArray())(array);
|
|
119
119
|
}
|
|
120
120
|
function createConcat(...arrays) {
|
|
121
121
|
return (array) => pipe(concat(array, ...arrays), toArray())();
|
|
@@ -156,8 +156,8 @@ function createDetermine(potentialities) {
|
|
|
156
156
|
return (determinant) => find(({ predicate }) => predicate(determinant))(predicates).outcome;
|
|
157
157
|
}
|
|
158
158
|
function createRename({ from, to }) {
|
|
159
|
-
return (
|
|
160
|
-
const keys = [...
|
|
159
|
+
return (map2) => {
|
|
160
|
+
const keys = [...map2.keys()], keyToRenameIndex = findIndex((k) => k === from)(keys), newKeys = createReplace({ index: keyToRenameIndex, item: to })(keys), values = [...map2.values()];
|
|
161
161
|
return createReduce((renamed, key, index) => renamed.set(key, values[index]), new Map())(newKeys);
|
|
162
162
|
};
|
|
163
163
|
}
|
|
@@ -471,11 +471,11 @@ function ensureClickcombo(type) {
|
|
|
471
471
|
function ensurePointercombo(type) {
|
|
472
472
|
return toCombo(type);
|
|
473
473
|
}
|
|
474
|
-
const
|
|
474
|
+
const toUnique$1 = unique();
|
|
475
475
|
const toComboItems = map((name) => name === "" ? delimiter : name);
|
|
476
476
|
const delimiter = "+";
|
|
477
477
|
function toCombo(type) {
|
|
478
|
-
return pipe(
|
|
478
|
+
return pipe(toUnique$1, toComboItems, toArray())(type.split(delimiter));
|
|
479
479
|
}
|
|
480
480
|
function fromComboItemNameToType(name) {
|
|
481
481
|
return find((type) => predicatesByType[type](name))(listenableComboItemTypes) ?? "custom";
|
|
@@ -726,7 +726,7 @@ function createToType({
|
|
|
726
726
|
}
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
|
-
const leftclickcomboEventTypes = new Set(["click", "mousedown", "mouseup", "dblclick"]), rightclickComboEventTypes = new Set(["contextmenu"]), keycomboEventTypes = new Set(["keydown", "keyup"]), toJoinedClickcombo = join
|
|
729
|
+
const leftclickcomboEventTypes = new Set(["click", "mousedown", "mouseup", "dblclick"]), rightclickComboEventTypes = new Set(["contextmenu"]), keycomboEventTypes = new Set(["keydown", "keyup"]), toJoinedClickcombo = join("+"), toJoinedKeycombo = pipe(map(({ name }) => name), toJoinedClickcombo);
|
|
730
730
|
|
|
731
731
|
class Listenable {
|
|
732
732
|
constructor(type, options) {
|
|
@@ -2098,13 +2098,13 @@ class Completeable {
|
|
|
2098
2098
|
this.computedStatus = "completed";
|
|
2099
2099
|
}
|
|
2100
2100
|
}
|
|
2101
|
-
const
|
|
2101
|
+
const toString = join(""), reverse = createReverse();
|
|
2102
2102
|
function toPreviousMatch({ string, re, from }) {
|
|
2103
2103
|
let indexOf;
|
|
2104
2104
|
if (!re.test(string.slice(0, from)) || from === 0) {
|
|
2105
2105
|
indexOf = -1;
|
|
2106
2106
|
} else {
|
|
2107
|
-
const reversedStringBeforeFrom = new Pipeable(string).pipe((string2) => string2.slice(0, from), (sliced) => sliced.split(""), reverse,
|
|
2107
|
+
const reversedStringBeforeFrom = new Pipeable(string).pipe((string2) => string2.slice(0, from), (sliced) => sliced.split(""), reverse, toString), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
|
|
2108
2108
|
indexOf = toNextMatchIndex === -1 ? -1 : reversedStringBeforeFrom.length - 1 - toNextMatchIndex;
|
|
2109
2109
|
}
|
|
2110
2110
|
return indexOf;
|
|
@@ -2708,6 +2708,7 @@ class Grantable {
|
|
|
2708
2708
|
const defaultOptions$2 = {
|
|
2709
2709
|
initialLocation: 0
|
|
2710
2710
|
};
|
|
2711
|
+
const defaultNavigateOptions = { allows: "possible" };
|
|
2711
2712
|
const defaultNextAndPreviousOptions = {
|
|
2712
2713
|
distance: 1,
|
|
2713
2714
|
loops: true
|
|
@@ -2747,28 +2748,36 @@ class Navigateable {
|
|
|
2747
2748
|
this.navigate(location);
|
|
2748
2749
|
return this;
|
|
2749
2750
|
}
|
|
2750
|
-
navigate(location) {
|
|
2751
|
-
|
|
2751
|
+
navigate(location, options = {}) {
|
|
2752
|
+
const { allows } = { ...defaultNavigateOptions, ...options };
|
|
2753
|
+
this._navigate(location, { allows });
|
|
2752
2754
|
this.navigated();
|
|
2753
2755
|
return this;
|
|
2754
2756
|
}
|
|
2755
2757
|
navigated() {
|
|
2756
2758
|
this.computedStatus = "navigated";
|
|
2757
2759
|
}
|
|
2758
|
-
_navigate(location) {
|
|
2760
|
+
_navigate(location, options = {}) {
|
|
2761
|
+
const { allows } = { ...defaultNavigateOptions, ...options };
|
|
2759
2762
|
const ensuredLocation = (() => {
|
|
2760
|
-
if (
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2763
|
+
if (allows === "possible") {
|
|
2764
|
+
if (location < 0 && allows === "possible") {
|
|
2765
|
+
return 0;
|
|
2766
|
+
}
|
|
2767
|
+
if (location > this.array.length - 1) {
|
|
2768
|
+
return Math.max(this.array.length - 1, 0);
|
|
2769
|
+
}
|
|
2765
2770
|
}
|
|
2766
2771
|
return location;
|
|
2767
2772
|
})();
|
|
2768
2773
|
this.computedLocation = ensuredLocation;
|
|
2769
2774
|
}
|
|
2770
2775
|
next(options = {}) {
|
|
2771
|
-
const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options },
|
|
2776
|
+
const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2777
|
+
if (allows === "any") {
|
|
2778
|
+
return this.location + distance;
|
|
2779
|
+
}
|
|
2780
|
+
const lastLocation = this.array.length - 1;
|
|
2772
2781
|
if (this.location + distance <= lastLocation) {
|
|
2773
2782
|
return this.location + distance;
|
|
2774
2783
|
}
|
|
@@ -2783,7 +2792,7 @@ class Navigateable {
|
|
|
2783
2792
|
return newLocation2;
|
|
2784
2793
|
})();
|
|
2785
2794
|
})();
|
|
2786
|
-
this._navigate(newLocation);
|
|
2795
|
+
this._navigate(newLocation, { allows });
|
|
2787
2796
|
this.nexted();
|
|
2788
2797
|
return this;
|
|
2789
2798
|
}
|
|
@@ -2791,7 +2800,10 @@ class Navigateable {
|
|
|
2791
2800
|
this.computedStatus = "navigated to next";
|
|
2792
2801
|
}
|
|
2793
2802
|
previous(options = {}) {
|
|
2794
|
-
const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
|
|
2803
|
+
const { distance, loops, allows } = { ...defaultNextAndPreviousOptions, ...defaultNavigateOptions, ...options }, newLocation = (() => {
|
|
2804
|
+
if (allows === "any") {
|
|
2805
|
+
return this.location - distance;
|
|
2806
|
+
}
|
|
2795
2807
|
if (this.location - distance >= 0) {
|
|
2796
2808
|
return this.location - distance;
|
|
2797
2809
|
}
|
|
@@ -2806,7 +2818,7 @@ class Navigateable {
|
|
|
2806
2818
|
return newLocation2;
|
|
2807
2819
|
})();
|
|
2808
2820
|
})();
|
|
2809
|
-
this._navigate(newLocation);
|
|
2821
|
+
this._navigate(newLocation, { allows });
|
|
2810
2822
|
this.previoused();
|
|
2811
2823
|
return this;
|
|
2812
2824
|
}
|
|
@@ -2866,10 +2878,10 @@ class Pickable {
|
|
|
2866
2878
|
this.pick(indices);
|
|
2867
2879
|
}
|
|
2868
2880
|
get first() {
|
|
2869
|
-
return
|
|
2881
|
+
return this.computedFirst;
|
|
2870
2882
|
}
|
|
2871
2883
|
get last() {
|
|
2872
|
-
return
|
|
2884
|
+
return this.computedLast;
|
|
2873
2885
|
}
|
|
2874
2886
|
get oldest() {
|
|
2875
2887
|
return this.picks[0];
|
|
@@ -2895,18 +2907,41 @@ class Pickable {
|
|
|
2895
2907
|
return this.pick(indexOrIndices);
|
|
2896
2908
|
}
|
|
2897
2909
|
pick(indexOrIndices, options = {}) {
|
|
2898
|
-
const {
|
|
2899
|
-
|
|
2900
|
-
if (
|
|
2901
|
-
return possiblePicks;
|
|
2902
|
-
|
|
2910
|
+
const { replace = "none" } = options;
|
|
2911
|
+
this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
|
|
2912
|
+
if (replace === "all") {
|
|
2913
|
+
return toUnique(possiblePicks);
|
|
2914
|
+
}
|
|
2915
|
+
const possibleWithoutDuplicates = createFilter((possiblePick) => !find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
|
|
2916
|
+
switch (replace) {
|
|
2917
|
+
case "none":
|
|
2918
|
+
return createConcat(this.picks || [], possibleWithoutDuplicates)([]);
|
|
2919
|
+
case "fifo":
|
|
2920
|
+
if (possibleWithoutDuplicates.length === 0) {
|
|
2921
|
+
return this.picks;
|
|
2922
|
+
}
|
|
2923
|
+
if (possibleWithoutDuplicates.length === this.picks.length) {
|
|
2924
|
+
return possibleWithoutDuplicates;
|
|
2925
|
+
}
|
|
2926
|
+
if (possibleWithoutDuplicates.length > this.picks.length) {
|
|
2927
|
+
return createSlice({ from: possibleWithoutDuplicates.length - this.picks.length })(possibleWithoutDuplicates);
|
|
2928
|
+
}
|
|
2929
|
+
return new Pipeable(this.picks).pipe(createSlice({ from: possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2930
|
+
case "lifo":
|
|
2931
|
+
if (possibleWithoutDuplicates.length === 0) {
|
|
2932
|
+
return this.picks;
|
|
2933
|
+
}
|
|
2934
|
+
if (possibleWithoutDuplicates.length === this.picks.length) {
|
|
2935
|
+
return possibleWithoutDuplicates;
|
|
2936
|
+
}
|
|
2937
|
+
if (possibleWithoutDuplicates.length > this.picks.length) {
|
|
2938
|
+
return createSlice({ from: 0, to: possibleWithoutDuplicates.length - this.picks.length + 1 })(possibleWithoutDuplicates);
|
|
2939
|
+
}
|
|
2940
|
+
return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
|
|
2941
|
+
}
|
|
2903
2942
|
});
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
this.picked();
|
|
2907
|
-
return this;
|
|
2908
|
-
}
|
|
2909
|
-
this.computedPicks = createConcat(newPicks)(this.picks || []);
|
|
2943
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2944
|
+
this.computedLast = Math.max(...this.picks);
|
|
2910
2945
|
this.picked();
|
|
2911
2946
|
return this;
|
|
2912
2947
|
}
|
|
@@ -2916,11 +2951,15 @@ class Pickable {
|
|
|
2916
2951
|
omit(indexOrIndices) {
|
|
2917
2952
|
if (isUndefined(indexOrIndices)) {
|
|
2918
2953
|
this.computedPicks = [];
|
|
2954
|
+
this.computedFirst = void 0;
|
|
2955
|
+
this.computedLast = void 0;
|
|
2919
2956
|
this.omitted();
|
|
2920
2957
|
return this;
|
|
2921
2958
|
}
|
|
2922
|
-
const omits = ensureIndices(indexOrIndices)
|
|
2923
|
-
this.computedPicks =
|
|
2959
|
+
const omits = ensureIndices(indexOrIndices);
|
|
2960
|
+
this.computedPicks = createFilter((pick) => isUndefined(find((omit) => pick === omit)(omits)))(this.computedPicks);
|
|
2961
|
+
this.computedFirst = Math.min(...this.picks);
|
|
2962
|
+
this.computedLast = Math.max(...this.picks);
|
|
2924
2963
|
this.omitted();
|
|
2925
2964
|
return this;
|
|
2926
2965
|
}
|
|
@@ -2931,6 +2970,7 @@ class Pickable {
|
|
|
2931
2970
|
function ensureIndices(indexOrIndices) {
|
|
2932
2971
|
return Array.isArray(indexOrIndices) ? indexOrIndices : [indexOrIndices];
|
|
2933
2972
|
}
|
|
2973
|
+
const toUnique = createUnique();
|
|
2934
2974
|
|
|
2935
2975
|
class Sanitizeable {
|
|
2936
2976
|
constructor(html, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baleada/logic",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.27",
|
|
4
4
|
"description": "UI logic for the Baleada toolkit",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/resize-observer-browser": "^0.1.5",
|
|
67
67
|
"bezier-easing": "^2.1.0",
|
|
68
68
|
"dompurify": "^2.2.6",
|
|
69
|
-
"fast-fuzzy": "^1.
|
|
69
|
+
"fast-fuzzy": "^1.11.1",
|
|
70
70
|
"lazy-collections": "^0.8.0",
|
|
71
71
|
"perfect-freehand": "^1.0.4",
|
|
72
72
|
"polygon-clipping": "^0.15.3"
|