@baleada/logic 0.21.0 → 0.21.3

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
@@ -194,239 +194,6 @@ class Pipeable {
194
194
  }
195
195
  }
196
196
 
197
- function toEvent(eventType, options) {
198
- const implementation = toImplementation(eventType);
199
- switch (implementation) {
200
- case "keycombo": {
201
- const combo = toCombo(eventType), modifiers = createSlice(0, combo.length - 1)(combo), { 0: name } = createSlice(combo.length - 1)(combo);
202
- return new KeyboardEvent("keyDirection" in options ? `key${options.keyDirection}` : "keydown", {
203
- ...options.init || {},
204
- key: toKey(name),
205
- ...createReduce((flags, alias) => {
206
- flags[toModifierFlag(alias)] = true;
207
- return flags;
208
- }, {})(modifiers)
209
- });
210
- }
211
- case "leftclickcombo":
212
- case "rightclickcombo": {
213
- const combo = toCombo(eventType), modifiers = createSlice(0, combo.length - 1)(combo), { 0: name } = createSlice(combo.length - 1)(combo);
214
- return new MouseEvent(name === "rightclick" ? "contextmenu" : name, {
215
- ...options.init || {},
216
- ...createReduce((flags, alias) => {
217
- flags[toModifierFlag(alias)] = true;
218
- return flags;
219
- }, {})(modifiers)
220
- });
221
- }
222
- case "pointercombo": {
223
- const combo = toCombo(eventType), modifiers = createSlice(0, combo.length - 1)(combo), { 0: name } = createSlice(combo.length - 1)(combo);
224
- return new PointerEvent(name === "rightclick" ? "contextmenu" : name, {
225
- ...options.init || {},
226
- ...createReduce((flags, alias) => {
227
- flags[toModifierFlag(alias)] = true;
228
- return flags;
229
- }, {})(modifiers)
230
- });
231
- }
232
- case "documentevent":
233
- case "event":
234
- if (eventType === "abort")
235
- return new UIEvent(eventType, options.init);
236
- if (eventType === "animationcancel")
237
- return new AnimationEvent(eventType, options.init);
238
- if (eventType === "animationend")
239
- return new AnimationEvent(eventType, options.init);
240
- if (eventType === "animationiteration")
241
- return new AnimationEvent(eventType, options.init);
242
- if (eventType === "animationstart")
243
- return new AnimationEvent(eventType, options.init);
244
- if (eventType === "auxclick")
245
- return new MouseEvent(eventType, options.init);
246
- if (eventType === "beforeinput")
247
- return new InputEvent(eventType, options.init);
248
- if (eventType === "blur")
249
- return new FocusEvent(eventType, options.init);
250
- if (eventType === "canplay")
251
- return new Event(eventType, options.init);
252
- if (eventType === "canplaythrough")
253
- return new Event(eventType, options.init);
254
- if (eventType === "change")
255
- return new Event(eventType, options.init);
256
- if (eventType === "click")
257
- return new MouseEvent(eventType, options.init);
258
- if (eventType === "close")
259
- return new Event(eventType, options.init);
260
- if (eventType === "compositionend")
261
- return new CompositionEvent(eventType, options.init);
262
- if (eventType === "compositionstart")
263
- return new CompositionEvent(eventType, options.init);
264
- if (eventType === "compositionupdate")
265
- return new CompositionEvent(eventType, options.init);
266
- if (eventType === "contextmenu")
267
- return new MouseEvent(eventType, options.init);
268
- if (eventType === "cuechange")
269
- return new Event(eventType, options.init);
270
- if (eventType === "dblclick")
271
- return new MouseEvent(eventType, options.init);
272
- if (eventType === "drag")
273
- return new DragEvent(eventType, options.init);
274
- if (eventType === "dragend")
275
- return new DragEvent(eventType, options.init);
276
- if (eventType === "dragenter")
277
- return new DragEvent(eventType, options.init);
278
- if (eventType === "dragleave")
279
- return new DragEvent(eventType, options.init);
280
- if (eventType === "dragover")
281
- return new DragEvent(eventType, options.init);
282
- if (eventType === "dragstart")
283
- return new DragEvent(eventType, options.init);
284
- if (eventType === "drop")
285
- return new DragEvent(eventType, options.init);
286
- if (eventType === "durationchange")
287
- return new Event(eventType, options.init);
288
- if (eventType === "emptied")
289
- return new Event(eventType, options.init);
290
- if (eventType === "ended")
291
- return new Event(eventType, options.init);
292
- if (eventType === "error")
293
- return new ErrorEvent(eventType, options.init);
294
- if (eventType === "focus")
295
- return new FocusEvent(eventType, options.init);
296
- if (eventType === "focusin")
297
- return new FocusEvent(eventType, options.init);
298
- if (eventType === "focusout")
299
- return new FocusEvent(eventType, options.init);
300
- if (eventType === "gotpointercapture")
301
- return new PointerEvent(eventType, options.init);
302
- if (eventType === "input")
303
- return new Event(eventType, options.init);
304
- if (eventType === "invalid")
305
- return new Event(eventType, options.init);
306
- if (eventType === "keydown")
307
- return new KeyboardEvent(eventType, options.init);
308
- if (eventType === "keypress")
309
- return new KeyboardEvent(eventType, options.init);
310
- if (eventType === "keyup")
311
- return new KeyboardEvent(eventType, options.init);
312
- if (eventType === "load")
313
- return new Event(eventType, options.init);
314
- if (eventType === "loadeddata")
315
- return new Event(eventType, options.init);
316
- if (eventType === "loadedmetadata")
317
- return new Event(eventType, options.init);
318
- if (eventType === "loadstart")
319
- return new Event(eventType, options.init);
320
- if (eventType === "lostpointercapture")
321
- return new PointerEvent(eventType, options.init);
322
- if (eventType === "mousedown")
323
- return new MouseEvent(eventType, options.init);
324
- if (eventType === "mouseenter")
325
- return new MouseEvent(eventType, options.init);
326
- if (eventType === "mouseleave")
327
- return new MouseEvent(eventType, options.init);
328
- if (eventType === "mousemove")
329
- return new MouseEvent(eventType, options.init);
330
- if (eventType === "mouseout")
331
- return new MouseEvent(eventType, options.init);
332
- if (eventType === "mouseover")
333
- return new MouseEvent(eventType, options.init);
334
- if (eventType === "mouseup")
335
- return new MouseEvent(eventType, options.init);
336
- if (eventType === "pause")
337
- return new Event(eventType, options.init);
338
- if (eventType === "play")
339
- return new Event(eventType, options.init);
340
- if (eventType === "playing")
341
- return new Event(eventType, options.init);
342
- if (eventType === "pointercancel")
343
- return new PointerEvent(eventType, options.init);
344
- if (eventType === "pointerdown")
345
- return new PointerEvent(eventType, options.init);
346
- if (eventType === "pointerenter")
347
- return new PointerEvent(eventType, options.init);
348
- if (eventType === "pointerleave")
349
- return new PointerEvent(eventType, options.init);
350
- if (eventType === "pointermove")
351
- return new PointerEvent(eventType, options.init);
352
- if (eventType === "pointerout")
353
- return new PointerEvent(eventType, options.init);
354
- if (eventType === "pointerover")
355
- return new PointerEvent(eventType, options.init);
356
- if (eventType === "pointerup")
357
- return new PointerEvent(eventType, options.init);
358
- if (eventType === "progress")
359
- return new ProgressEvent(eventType, options.init);
360
- if (eventType === "ratechange")
361
- return new Event(eventType, options.init);
362
- if (eventType === "reset")
363
- return new Event(eventType, options.init);
364
- if (eventType === "scroll")
365
- return new Event(eventType, options.init);
366
- if (eventType === "securitypolicyviolation")
367
- return new SecurityPolicyViolationEvent(eventType, options.init);
368
- if (eventType === "seeked")
369
- return new Event(eventType, options.init);
370
- if (eventType === "seeking")
371
- return new Event(eventType, options.init);
372
- if (eventType === "select")
373
- return new Event(eventType, options.init);
374
- if (eventType === "selectionchange")
375
- return new Event(eventType, options.init);
376
- if (eventType === "selectstart")
377
- return new Event(eventType, options.init);
378
- if (eventType === "stalled")
379
- return new Event(eventType, options.init);
380
- if (eventType === "submit")
381
- return new Event(eventType, options.init);
382
- if (eventType === "suspend")
383
- return new Event(eventType, options.init);
384
- if (eventType === "timeupdate")
385
- return new Event(eventType, options.init);
386
- if (eventType === "toggle")
387
- return new Event(eventType, options.init);
388
- if (eventType === "touchcancel")
389
- return new TouchEvent(eventType, options.init);
390
- if (eventType === "touchend")
391
- return new TouchEvent(eventType, options.init);
392
- if (eventType === "touchmove")
393
- return new TouchEvent(eventType, options.init);
394
- if (eventType === "touchstart")
395
- return new TouchEvent(eventType, options.init);
396
- if (eventType === "transitioncancel")
397
- return new TransitionEvent(eventType, options.init);
398
- if (eventType === "transitionend")
399
- return new TransitionEvent(eventType, options.init);
400
- if (eventType === "transitionrun")
401
- return new TransitionEvent(eventType, options.init);
402
- if (eventType === "transitionstart")
403
- return new TransitionEvent(eventType, options.init);
404
- if (eventType === "volumechange")
405
- return new Event(eventType, options.init);
406
- if (eventType === "waiting")
407
- return new Event(eventType, options.init);
408
- if (eventType === "wheel")
409
- return new WheelEvent(eventType, options.init);
410
- if (eventType === "copy")
411
- return new ClipboardEvent(eventType, options.init);
412
- if (eventType === "cut")
413
- return new ClipboardEvent(eventType, options.init);
414
- if (eventType === "paste")
415
- return new ClipboardEvent(eventType, options.init);
416
- if (eventType === "fullscreenchange")
417
- return new Event(eventType, options.init);
418
- if (eventType === "fullscreenerror")
419
- return new Event(eventType, options.init);
420
- if (eventType === "pointerlockchange")
421
- return new Event(eventType, options.init);
422
- if (eventType === "pointerlockerror")
423
- return new Event(eventType, options.init);
424
- if (eventType === "readystatechange")
425
- return new Event(eventType, options.init);
426
- if (eventType === "visibilitychange")
427
- return new Event(eventType, options.init);
428
- }
429
- }
430
197
  function toKey(name) {
431
198
  return name in keysByName ? keysByName[name] : name;
432
199
  }
@@ -524,20 +291,6 @@ const modifiersByAlias = {
524
291
  opt: "alt",
525
292
  option: "alt"
526
293
  };
527
- function toModifierFlag(modifierOrAlias) {
528
- return flagsByModifierOrAlias[modifierOrAlias];
529
- }
530
- const flagsByModifierOrAlias = {
531
- shift: "shiftKey",
532
- cmd: "metaKey",
533
- command: "metaKey",
534
- meta: "metaKey",
535
- ctrl: "ctrlKey",
536
- control: "ctrlKey",
537
- alt: "altKey",
538
- opt: "altKey",
539
- option: "altKey"
540
- };
541
294
  function createExceptAndOnlyEffect(effect, options) {
542
295
  const { except = [], only = [] } = options;
543
296
  return (event) => {
@@ -2258,10 +2011,10 @@ class Copyable {
2258
2011
  }
2259
2012
  computedResponse;
2260
2013
  computedError;
2261
- async copy(options = { type: "clipboard" }) {
2014
+ async copy(options = { kind: "clipboard" }) {
2262
2015
  this.copying();
2263
- const { type } = options;
2264
- switch (type) {
2016
+ const { kind } = options;
2017
+ switch (kind) {
2265
2018
  case "clipboard":
2266
2019
  try {
2267
2020
  this.computedResponse = await navigator.clipboard.writeText(this.string);
@@ -2449,44 +2202,6 @@ class Delayable {
2449
2202
  }
2450
2203
  }
2451
2204
 
2452
- class Dispatchable {
2453
- constructor(type, options = {}) {
2454
- this.setType(type);
2455
- this.ready();
2456
- }
2457
- computedStatus;
2458
- ready() {
2459
- this.computedStatus = "ready";
2460
- }
2461
- get type() {
2462
- return this.computedType;
2463
- }
2464
- set type(type) {
2465
- this.setType(type);
2466
- }
2467
- get cancelled() {
2468
- return this.computedCancelled;
2469
- }
2470
- get status() {
2471
- return this.computedStatus;
2472
- }
2473
- computedType;
2474
- setType(type) {
2475
- this.computedType = type;
2476
- return this;
2477
- }
2478
- computedCancelled;
2479
- dispatch(options = {}) {
2480
- const { target = window, ...rest } = options, event = toEvent(this.type, rest);
2481
- this.computedCancelled = !target.dispatchEvent(event);
2482
- this.dispatched();
2483
- return this;
2484
- }
2485
- dispatched() {
2486
- this.computedStatus = "dispatched";
2487
- }
2488
- }
2489
-
2490
2205
  const defaultOptions$3 = {
2491
2206
  toD: (stroke) => stroke.length === 0 ? "" : toD(stroke)
2492
2207
  };
@@ -2989,6 +2704,10 @@ class Navigateable {
2989
2704
  const defaultOptions$1 = {
2990
2705
  initialPicks: []
2991
2706
  };
2707
+ const defaultPickOptions = {
2708
+ replace: "none",
2709
+ allowsDuplicates: false
2710
+ };
2992
2711
  class Pickable {
2993
2712
  constructor(array, options = {}) {
2994
2713
  this.setArray(array);
@@ -3034,8 +2753,9 @@ class Pickable {
3034
2753
  return this.toItems(this.picks);
3035
2754
  }
3036
2755
  toItems = createMap((index) => this.array[index]);
2756
+ computedMultiple;
3037
2757
  get multiple() {
3038
- return this.picks.length > 1;
2758
+ return this.computedMultiple;
3039
2759
  }
3040
2760
  toPossiblePicks;
3041
2761
  setArray(array) {
@@ -3047,59 +2767,62 @@ class Pickable {
3047
2767
  return this.pick(indexOrIndices);
3048
2768
  }
3049
2769
  pick(indexOrIndices, options = {}) {
3050
- const { replace = "none" } = options;
2770
+ const { replace, allowsDuplicates } = { ...defaultPickOptions, ...options };
3051
2771
  this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
3052
2772
  if (replace === "all") {
3053
- return toUnique(possiblePicks);
2773
+ return allowsDuplicates ? possiblePicks : toUnique(possiblePicks);
3054
2774
  }
3055
- const possibleWithoutDuplicates = createFilter((possiblePick) => typeof lazyCollections.find((pick) => pick === possiblePick)(this.picks || []) !== "number")(possiblePicks);
2775
+ const maybeWithoutDuplicates = allowsDuplicates ? possiblePicks : createFilter((possiblePick) => typeof lazyCollections.find((pick) => pick === possiblePick)(this.picks || []) !== "number")(possiblePicks);
3056
2776
  switch (replace) {
3057
2777
  case "none":
3058
- return createConcat(this.picks || [], possibleWithoutDuplicates)([]);
2778
+ return createConcat(this.picks || [], maybeWithoutDuplicates)([]);
3059
2779
  case "fifo":
3060
- if (possibleWithoutDuplicates.length === 0) {
2780
+ if (maybeWithoutDuplicates.length === 0) {
3061
2781
  return this.picks;
3062
2782
  }
3063
- if (possibleWithoutDuplicates.length === this.picks.length) {
3064
- return possibleWithoutDuplicates;
2783
+ if (maybeWithoutDuplicates.length === this.picks.length) {
2784
+ return maybeWithoutDuplicates;
3065
2785
  }
3066
- if (possibleWithoutDuplicates.length > this.picks.length) {
3067
- return createSlice(possibleWithoutDuplicates.length - this.picks.length)(possibleWithoutDuplicates);
2786
+ if (maybeWithoutDuplicates.length > this.picks.length) {
2787
+ return createSlice(maybeWithoutDuplicates.length - this.picks.length)(maybeWithoutDuplicates);
3068
2788
  }
3069
- return new Pipeable(this.picks).pipe(createSlice(possibleWithoutDuplicates.length), createConcat(possibleWithoutDuplicates));
2789
+ return new Pipeable(this.picks).pipe(createSlice(maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
3070
2790
  case "lifo":
3071
- if (possibleWithoutDuplicates.length === 0) {
2791
+ if (maybeWithoutDuplicates.length === 0) {
3072
2792
  return this.picks;
3073
2793
  }
3074
- if (possibleWithoutDuplicates.length === this.picks.length) {
3075
- return possibleWithoutDuplicates;
2794
+ if (maybeWithoutDuplicates.length === this.picks.length) {
2795
+ return maybeWithoutDuplicates;
3076
2796
  }
3077
- if (possibleWithoutDuplicates.length > this.picks.length) {
3078
- return createSlice(0, possibleWithoutDuplicates.length - this.picks.length + 1)(possibleWithoutDuplicates);
2797
+ if (maybeWithoutDuplicates.length > this.picks.length) {
2798
+ return createSlice(0, maybeWithoutDuplicates.length - this.picks.length + 1)(maybeWithoutDuplicates);
3079
2799
  }
3080
- return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length - possibleWithoutDuplicates.length), createConcat(possibleWithoutDuplicates));
2800
+ return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length - maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
3081
2801
  }
3082
2802
  });
3083
2803
  this.computedFirst = Math.min(...this.picks);
3084
2804
  this.computedLast = Math.max(...this.picks);
2805
+ this.computedMultiple = toUnique(this.picks).length > 1;
3085
2806
  this.picked();
3086
2807
  return this;
3087
2808
  }
3088
2809
  picked() {
3089
2810
  this.computedStatus = "picked";
3090
2811
  }
3091
- omit(indexOrIndices) {
2812
+ omit(indexOrIndices, options = { reference: "array" }) {
3092
2813
  if (isUndefined(indexOrIndices)) {
3093
2814
  this.computedPicks = [];
3094
2815
  this.computedFirst = void 0;
3095
2816
  this.computedLast = void 0;
2817
+ this.computedMultiple = false;
3096
2818
  this.omitted();
3097
2819
  return this;
3098
2820
  }
3099
2821
  const omits = ensureIndices(indexOrIndices);
3100
- this.computedPicks = createFilter((pick) => isUndefined(lazyCollections.find((omit) => pick === omit)(omits)))(this.computedPicks);
2822
+ this.computedPicks = createFilter((pick, index) => options.reference === "array" ? isUndefined(lazyCollections.find((omit) => pick === omit)(omits)) : isUndefined(lazyCollections.find((omit) => index === omit)(omits)))(this.computedPicks);
3101
2823
  this.computedFirst = Math.min(...this.picks);
3102
2824
  this.computedLast = Math.max(...this.picks);
2825
+ this.computedMultiple = toUnique(this.picks).length > 1;
3103
2826
  this.omitted();
3104
2827
  return this;
3105
2828
  }
@@ -3205,15 +2928,15 @@ class Searchable {
3205
2928
  }
3206
2929
 
3207
2930
  const defaultOptions = {
3208
- type: "local",
2931
+ kind: "local",
3209
2932
  statusKeySuffix: " status"
3210
2933
  };
3211
2934
  class Storeable {
3212
- type;
2935
+ kind;
3213
2936
  statusKeySuffix;
3214
2937
  constructor(key, options = {}) {
3215
2938
  this.constructing();
3216
- this.type = options.type ?? defaultOptions.type;
2939
+ this.kind = options.kind ?? defaultOptions.kind;
3217
2940
  this.statusKeySuffix = options.statusKeySuffix ?? defaultOptions.statusKeySuffix;
3218
2941
  this.setKey(key);
3219
2942
  this.ready();
@@ -3246,7 +2969,7 @@ class Storeable {
3246
2969
  return this.computedStatus;
3247
2970
  }
3248
2971
  get storage() {
3249
- switch (this.type) {
2972
+ switch (this.kind) {
3250
2973
  case "local":
3251
2974
  return localStorage;
3252
2975
  case "session":
@@ -3329,7 +3052,6 @@ exports.Animateable = Animateable;
3329
3052
  exports.Completeable = Completeable;
3330
3053
  exports.Copyable = Copyable;
3331
3054
  exports.Delayable = Delayable;
3332
- exports.Dispatchable = Dispatchable;
3333
3055
  exports.Drawable = Drawable;
3334
3056
  exports.Fetchable = Fetchable;
3335
3057
  exports.Fullscreenable = Fullscreenable;