@baleada/logic 0.20.22 → 0.20.26

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 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(reduce, initialValue) {
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 reduce(accumulator, item, index);
25
+ return accumulate(accumulator, item, index);
26
26
  }, Promise.resolve(initialValue))(array);
27
27
  };
28
28
  }
29
- function createReduce(reduce, initialValue) {
30
- return (array) => lazyCollections.reduce(reduce, initialValue)(array);
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(map) {
38
+ function createMapAsync(transform) {
39
39
  return async (array) => {
40
40
  return await createReduceAsync(async (resolvedMaps, item, index) => {
41
- const mapped = await map(item, index);
42
- resolvedMaps.push(mapped);
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(filter) {
47
+ function createFilterAsync(condition) {
48
48
  return async (array) => {
49
- const mappedAsync = await createMapAsync(filter)(array);
50
- return createFilter((_, index) => mappedAsync[index])(array);
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(filter) {
126
- return (array) => lazyCollections.pipe(lazyCollections.filter(filter), lazyCollections.toArray())(array);
125
+ function createFilter(condition) {
126
+ return (array) => lazyCollections.pipe(lazyCollections.filter(condition), lazyCollections.toArray())(array);
127
127
  }
128
- function createMap(map) {
129
- return (array) => lazyCollections.pipe(lazyCollections.map(map), lazyCollections.toArray())(array);
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 (map) => {
171
- const keys = [...map.keys()], keyToRenameIndex = lazyCollections.findIndex((k) => k === from)(keys), newKeys = createReplace({ index: keyToRenameIndex, item: to })(keys), values = [...map.values()];
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 unique = lazyCollections.unique();
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(unique, toComboItems, lazyCollections.toArray())(type.split(delimiter));
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), lazyCollections.join("+"));
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 join = lazyCollections.join(""), reverse = createReverse();
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, join), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
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;
@@ -2877,10 +2877,16 @@ class Pickable {
2877
2877
  this.pick(indices);
2878
2878
  }
2879
2879
  get first() {
2880
- return Math.min(...this.picks);
2880
+ return this.computedFirst;
2881
2881
  }
2882
2882
  get last() {
2883
- return Math.max(...this.picks);
2883
+ return this.computedLast;
2884
+ }
2885
+ get oldest() {
2886
+ return this.picks[0];
2887
+ }
2888
+ get newest() {
2889
+ return this.picks[this.picks.length - 1];
2884
2890
  }
2885
2891
  get status() {
2886
2892
  return this.computedStatus;
@@ -2900,18 +2906,41 @@ class Pickable {
2900
2906
  return this.pick(indexOrIndices);
2901
2907
  }
2902
2908
  pick(indexOrIndices, options = {}) {
2903
- const { replaces } = options;
2904
- const newPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
2905
- if (replaces)
2906
- return possiblePicks;
2907
- return createFilter((possiblePick) => !lazyCollections.find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
2909
+ const { replace = "none" } = options;
2910
+ this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
2911
+ if (replace === "all") {
2912
+ return toUnique(possiblePicks);
2913
+ }
2914
+ const possibleWithoutDuplicates = createFilter((possiblePick) => !lazyCollections.find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
2915
+ switch (replace) {
2916
+ case "none":
2917
+ return createConcat(this.picks || [], possibleWithoutDuplicates)([]);
2918
+ case "fifo":
2919
+ if (possibleWithoutDuplicates.length === 0) {
2920
+ return this.picks;
2921
+ }
2922
+ if (possibleWithoutDuplicates.length === this.picks.length) {
2923
+ return possibleWithoutDuplicates;
2924
+ }
2925
+ if (possibleWithoutDuplicates.length > this.picks.length) {
2926
+ return createSlice({ from: possibleWithoutDuplicates.length - this.picks.length })(possibleWithoutDuplicates);
2927
+ }
2928
+ return new Pipeable(this.picks).pipe(createSlice({ from: possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
2929
+ case "lifo":
2930
+ if (possibleWithoutDuplicates.length === 0) {
2931
+ return this.picks;
2932
+ }
2933
+ if (possibleWithoutDuplicates.length === this.picks.length) {
2934
+ return possibleWithoutDuplicates;
2935
+ }
2936
+ if (possibleWithoutDuplicates.length > this.picks.length) {
2937
+ return createSlice({ from: 0, to: possibleWithoutDuplicates.length - this.picks.length + 1 })(possibleWithoutDuplicates);
2938
+ }
2939
+ return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
2940
+ }
2908
2941
  });
2909
- if (replaces) {
2910
- this.computedPicks = newPicks;
2911
- this.picked();
2912
- return this;
2913
- }
2914
- this.computedPicks = createConcat(newPicks)(this.picks || []);
2942
+ this.computedFirst = Math.min(...this.picks);
2943
+ this.computedLast = Math.max(...this.picks);
2915
2944
  this.picked();
2916
2945
  return this;
2917
2946
  }
@@ -2921,11 +2950,15 @@ class Pickable {
2921
2950
  omit(indexOrIndices) {
2922
2951
  if (isUndefined(indexOrIndices)) {
2923
2952
  this.computedPicks = [];
2953
+ this.computedFirst = void 0;
2954
+ this.computedLast = void 0;
2924
2955
  this.omitted();
2925
2956
  return this;
2926
2957
  }
2927
- const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)));
2928
- this.computedPicks = filter(this.computedPicks);
2958
+ const omits = ensureIndices(indexOrIndices);
2959
+ this.computedPicks = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)))(this.computedPicks);
2960
+ this.computedFirst = Math.min(...this.picks);
2961
+ this.computedLast = Math.max(...this.picks);
2929
2962
  this.omitted();
2930
2963
  return this;
2931
2964
  }
@@ -2936,6 +2969,7 @@ class Pickable {
2936
2969
  function ensureIndices(indexOrIndices) {
2937
2970
  return Array.isArray(indexOrIndices) ? indexOrIndices : [indexOrIndices];
2938
2971
  }
2972
+ const toUnique = createUnique();
2939
2973
 
2940
2974
  class Sanitizeable {
2941
2975
  constructor(html, options) {
package/lib/index.d.ts CHANGED
@@ -753,8 +753,12 @@ declare class Pickable<Item> {
753
753
  private computedPicks;
754
754
  get picks(): number[];
755
755
  set picks(indices: number[]);
756
+ computedFirst: number;
756
757
  get first(): number;
758
+ computedLast: number;
757
759
  get last(): number;
760
+ get oldest(): number;
761
+ get newest(): number;
758
762
  get status(): PickableStatus;
759
763
  get items(): Item[];
760
764
  private toItems;
@@ -763,7 +767,7 @@ declare class Pickable<Item> {
763
767
  setArray(array: Item[]): this;
764
768
  setPicks(indexOrIndices: number | number[]): this;
765
769
  pick(indexOrIndices: number | number[], options?: {
766
- replaces?: boolean;
770
+ replace?: 'none' | 'all' | 'fifo' | 'lifo';
767
771
  }): this;
768
772
  private picked;
769
773
  omit(indexOrIndices?: number | number[]): this;
@@ -840,12 +844,12 @@ declare class Storeable {
840
844
  removeStatus(): this;
841
845
  }
842
846
 
843
- declare function createReduceAsync<Item, Accumulator>(reduce: (accumulator?: Accumulator, item?: Item, index?: number) => Promise<Accumulator>, initialValue?: Accumulator): (array: Item[]) => Promise<Accumulator>;
844
- declare function createReduce<Item, Accumulator>(reduce: (accumulator?: Accumulator, item?: Item, index?: number) => Accumulator, initialValue?: Accumulator): (array: Item[]) => Accumulator;
847
+ declare function createReduceAsync<Item, Accumulator>(accumulate: (accumulator?: Accumulator, item?: Item, index?: number) => Promise<Accumulator>, initialValue?: Accumulator): (array: Item[]) => Promise<Accumulator>;
848
+ declare function createReduce<Item, Accumulator>(accumulate: (accumulator?: Accumulator, item?: Item, index?: number) => Accumulator, initialValue?: Accumulator): (array: Item[]) => Accumulator;
845
849
  declare type ArrayFunctionAsync<Item, Returned> = (array: Item[]) => Promise<Returned>;
846
850
  declare function createForEachAsync<Item>(forEach: (item?: Item, index?: number) => any): ArrayFunctionAsync<Item, any>;
847
- declare function createMapAsync<Item, Mapped>(map: (item?: Item, index?: number) => Promise<Mapped>): ArrayFunctionAsync<Item, Mapped[]>;
848
- declare function createFilterAsync<Item>(filter: (item?: Item, index?: number) => Promise<boolean>): ArrayFunctionAsync<Item, Item[]>;
851
+ declare function createMapAsync<Item, Mapped>(transform: (item?: Item, index?: number) => Promise<Mapped>): ArrayFunctionAsync<Item, Mapped[]>;
852
+ declare function createFilterAsync<Item>(condition: (item?: Item, index?: number) => Promise<boolean>): ArrayFunctionAsync<Item, Item[]>;
849
853
  declare type ArrayFunction<Item, Returned> = (array: Item[]) => Returned;
850
854
  declare function createDelete<Item>(required: {
851
855
  index: number;
@@ -878,8 +882,8 @@ declare function createSlice<Item>({ from, to }: {
878
882
  from: number;
879
883
  to?: number;
880
884
  }): ArrayFunction<Item, Item[]>;
881
- declare function createFilter<Item>(filter: (item?: Item, index?: number) => boolean): ArrayFunction<Item, Item[]>;
882
- declare function createMap<Item, Mapped = Item>(map: (item?: Item, index?: number) => Mapped): ArrayFunction<Item, Mapped[]>;
885
+ declare function createFilter<Item>(condition: (item?: Item, index?: number) => boolean): ArrayFunction<Item, Item[]>;
886
+ declare function createMap<Item, Transformed = Item>(transform: (item?: Item, index?: number) => Transformed): ArrayFunction<Item, Transformed[]>;
883
887
  declare function createConcat<Item>(...arrays: Item[][]): ArrayFunction<Item, Item[]>;
884
888
  declare function createReverse<Item>(): ArrayFunction<Item, Item[]>;
885
889
  declare type StringFunction<Returned> = (string: string) => Returned;
@@ -895,7 +899,7 @@ declare type Potentiality<Outcome> = {
895
899
  probability: number;
896
900
  };
897
901
  declare function createDetermine<Outcome>(potentialities: Potentiality<Outcome>[]): NumberFunction<Outcome>;
898
- declare type MapFunction<Key, Value, Returned> = (map: Map<Key, Value>) => Returned;
902
+ declare type MapFunction<Key, Value, Returned> = (transform: Map<Key, Value>) => Returned;
899
903
  declare function createRename<Key, Value>({ from, to }: {
900
904
  from: Key;
901
905
  to: Key;
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { reduce, pipe, filter, toArray, findIndex, slice, concat, unique as unique$1, map, find, some, join as join$1, every } from 'lazy-collections';
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(reduce$1, initialValue) {
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 reduce$1(accumulator, item, index);
14
+ return accumulate(accumulator, item, index);
15
15
  }, Promise.resolve(initialValue))(array);
16
16
  };
17
17
  }
18
- function createReduce(reduce$1, initialValue) {
19
- return (array) => reduce(reduce$1, initialValue)(array);
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(map) {
27
+ function createMapAsync(transform) {
28
28
  return async (array) => {
29
29
  return await createReduceAsync(async (resolvedMaps, item, index) => {
30
- const mapped = await map(item, index);
31
- resolvedMaps.push(mapped);
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(filter) {
36
+ function createFilterAsync(condition) {
37
37
  return async (array) => {
38
- const mappedAsync = await createMapAsync(filter)(array);
39
- return createFilter((_, index) => mappedAsync[index])(array);
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$1(), toArray())(array);
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(filter$1) {
115
- return (array) => pipe(filter(filter$1), toArray())(array);
114
+ function createFilter(condition) {
115
+ return (array) => pipe(filter(condition), toArray())(array);
116
116
  }
117
- function createMap(map$1) {
118
- return (array) => pipe(map(map$1), toArray())(array);
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 (map) => {
160
- const keys = [...map.keys()], keyToRenameIndex = findIndex((k) => k === from)(keys), newKeys = createReplace({ index: keyToRenameIndex, item: to })(keys), values = [...map.values()];
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 unique = unique$1();
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(unique, toComboItems, toArray())(type.split(delimiter));
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$1("+"), toJoinedKeycombo = pipe(map(({ name }) => name), join$1("+"));
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 join = join$1(""), reverse = createReverse();
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, join), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
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;
@@ -2866,10 +2866,16 @@ class Pickable {
2866
2866
  this.pick(indices);
2867
2867
  }
2868
2868
  get first() {
2869
- return Math.min(...this.picks);
2869
+ return this.computedFirst;
2870
2870
  }
2871
2871
  get last() {
2872
- return Math.max(...this.picks);
2872
+ return this.computedLast;
2873
+ }
2874
+ get oldest() {
2875
+ return this.picks[0];
2876
+ }
2877
+ get newest() {
2878
+ return this.picks[this.picks.length - 1];
2873
2879
  }
2874
2880
  get status() {
2875
2881
  return this.computedStatus;
@@ -2889,18 +2895,41 @@ class Pickable {
2889
2895
  return this.pick(indexOrIndices);
2890
2896
  }
2891
2897
  pick(indexOrIndices, options = {}) {
2892
- const { replaces } = options;
2893
- const newPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
2894
- if (replaces)
2895
- return possiblePicks;
2896
- return createFilter((possiblePick) => !find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
2898
+ const { replace = "none" } = options;
2899
+ this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
2900
+ if (replace === "all") {
2901
+ return toUnique(possiblePicks);
2902
+ }
2903
+ const possibleWithoutDuplicates = createFilter((possiblePick) => !find((pick) => pick === possiblePick)(this.picks || []))(possiblePicks);
2904
+ switch (replace) {
2905
+ case "none":
2906
+ return createConcat(this.picks || [], possibleWithoutDuplicates)([]);
2907
+ case "fifo":
2908
+ if (possibleWithoutDuplicates.length === 0) {
2909
+ return this.picks;
2910
+ }
2911
+ if (possibleWithoutDuplicates.length === this.picks.length) {
2912
+ return possibleWithoutDuplicates;
2913
+ }
2914
+ if (possibleWithoutDuplicates.length > this.picks.length) {
2915
+ return createSlice({ from: possibleWithoutDuplicates.length - this.picks.length })(possibleWithoutDuplicates);
2916
+ }
2917
+ return new Pipeable(this.picks).pipe(createSlice({ from: possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
2918
+ case "lifo":
2919
+ if (possibleWithoutDuplicates.length === 0) {
2920
+ return this.picks;
2921
+ }
2922
+ if (possibleWithoutDuplicates.length === this.picks.length) {
2923
+ return possibleWithoutDuplicates;
2924
+ }
2925
+ if (possibleWithoutDuplicates.length > this.picks.length) {
2926
+ return createSlice({ from: 0, to: possibleWithoutDuplicates.length - this.picks.length + 1 })(possibleWithoutDuplicates);
2927
+ }
2928
+ return new Pipeable(this.picks).pipe(createSlice({ from: 0, to: this.picks.length - possibleWithoutDuplicates.length }), createConcat(possibleWithoutDuplicates));
2929
+ }
2897
2930
  });
2898
- if (replaces) {
2899
- this.computedPicks = newPicks;
2900
- this.picked();
2901
- return this;
2902
- }
2903
- this.computedPicks = createConcat(newPicks)(this.picks || []);
2931
+ this.computedFirst = Math.min(...this.picks);
2932
+ this.computedLast = Math.max(...this.picks);
2904
2933
  this.picked();
2905
2934
  return this;
2906
2935
  }
@@ -2910,11 +2939,15 @@ class Pickable {
2910
2939
  omit(indexOrIndices) {
2911
2940
  if (isUndefined(indexOrIndices)) {
2912
2941
  this.computedPicks = [];
2942
+ this.computedFirst = void 0;
2943
+ this.computedLast = void 0;
2913
2944
  this.omitted();
2914
2945
  return this;
2915
2946
  }
2916
- const omits = ensureIndices(indexOrIndices), filter = createFilter((pick) => isUndefined(find((omit) => pick === omit)(omits)));
2917
- this.computedPicks = filter(this.computedPicks);
2947
+ const omits = ensureIndices(indexOrIndices);
2948
+ this.computedPicks = createFilter((pick) => isUndefined(find((omit) => pick === omit)(omits)))(this.computedPicks);
2949
+ this.computedFirst = Math.min(...this.picks);
2950
+ this.computedLast = Math.max(...this.picks);
2918
2951
  this.omitted();
2919
2952
  return this;
2920
2953
  }
@@ -2925,6 +2958,7 @@ class Pickable {
2925
2958
  function ensureIndices(indexOrIndices) {
2926
2959
  return Array.isArray(indexOrIndices) ? indexOrIndices : [indexOrIndices];
2927
2960
  }
2961
+ const toUnique = createUnique();
2928
2962
 
2929
2963
  class Sanitizeable {
2930
2964
  constructor(html, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.20.22",
3
+ "version": "0.20.26",
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.10.8",
69
+ "fast-fuzzy": "^1.11.0",
70
70
  "lazy-collections": "^0.8.0",
71
71
  "perfect-freehand": "^1.0.4",
72
72
  "polygon-clipping": "^0.15.3"