@baleada/logic 0.22.4 → 0.22.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/README.md +1 -1
- package/lib/index.cjs +180 -98
- package/lib/index.d.ts +27 -25
- package/lib/index.js +176 -99
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { reduce, pipe, unique, toArray, slice, filter, map, concat, find, findIndex, some, every
|
|
1
|
+
import { reduce, pipe, unique, toArray, slice, filter, map, concat, find, findIndex, join, some, 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';
|
|
@@ -45,7 +45,7 @@ function createFilterAsync(condition) {
|
|
|
45
45
|
return createFilter((_, index) => transformedAsync[index])(array);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function createRemove(index) {
|
|
49
49
|
return (array) => {
|
|
50
50
|
return createConcat(
|
|
51
51
|
createSlice(0, index)(array),
|
|
@@ -64,7 +64,7 @@ function createInsert(item, index) {
|
|
|
64
64
|
}
|
|
65
65
|
function createReorder(from, to) {
|
|
66
66
|
return (array) => {
|
|
67
|
-
const [itemsToMoveStartIndex, itemsToMoveCount] =
|
|
67
|
+
const [itemsToMoveStartIndex, itemsToMoveCount] = predicateObject(from) ? [from.start, from.itemCount] : [from, 1], insertIndex = to;
|
|
68
68
|
if (insertIndex > itemsToMoveStartIndex && insertIndex < itemsToMoveStartIndex + itemsToMoveCount) {
|
|
69
69
|
return array;
|
|
70
70
|
}
|
|
@@ -90,7 +90,7 @@ function createReorder(from, to) {
|
|
|
90
90
|
return array;
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function predicateObject(value) {
|
|
94
94
|
return typeof value === "object";
|
|
95
95
|
}
|
|
96
96
|
function createSwap(indices) {
|
|
@@ -218,6 +218,46 @@ function createToEntries() {
|
|
|
218
218
|
return entries;
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
|
+
function createToKeys() {
|
|
222
|
+
return (object) => {
|
|
223
|
+
const keys = [];
|
|
224
|
+
for (const key in object) {
|
|
225
|
+
keys.push(key);
|
|
226
|
+
}
|
|
227
|
+
return keys;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function createMatchesKeycombo(keycombo) {
|
|
231
|
+
return (event) => eventMatchesKeycombo(event, narrowKeycombo(keycombo));
|
|
232
|
+
}
|
|
233
|
+
function createMatchesMousecombo(mousecombo) {
|
|
234
|
+
return (event) => eventMatchesMousecombo(event, narrowMousecombo(mousecombo));
|
|
235
|
+
}
|
|
236
|
+
function createMatchesPointercombo(pointercombo) {
|
|
237
|
+
return (event) => eventMatchesPointercombo(event, narrowPointercombo(pointercombo));
|
|
238
|
+
}
|
|
239
|
+
function createToFocusable(order, elementIsCandidate) {
|
|
240
|
+
return (element) => {
|
|
241
|
+
if (elementIsCandidate && predicateFocusable(element))
|
|
242
|
+
return element;
|
|
243
|
+
switch (order) {
|
|
244
|
+
case "first":
|
|
245
|
+
for (let i = 0; i < element.children.length; i++) {
|
|
246
|
+
const focusable = createToFocusable(order, true)(element.children[i]);
|
|
247
|
+
if (focusable)
|
|
248
|
+
return focusable;
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
case "last":
|
|
252
|
+
for (let i = element.children.length - 1; i > -1; i--) {
|
|
253
|
+
const focusable = createToFocusable(order, true)(element.children[i]);
|
|
254
|
+
if (focusable)
|
|
255
|
+
return focusable;
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
221
261
|
class Pipeable {
|
|
222
262
|
constructor(state) {
|
|
223
263
|
this.state = state;
|
|
@@ -285,16 +325,16 @@ const keysByName = {
|
|
|
285
325
|
f20: "F20"
|
|
286
326
|
};
|
|
287
327
|
const toListenableKeycomboItems = createMap((name) => ({ name, type: fromComboItemNameToType(name) }));
|
|
288
|
-
function
|
|
328
|
+
function narrowKeycombo(type) {
|
|
289
329
|
return new Pipeable(type).pipe(
|
|
290
330
|
toCombo,
|
|
291
331
|
toListenableKeycomboItems
|
|
292
332
|
);
|
|
293
333
|
}
|
|
294
|
-
function
|
|
334
|
+
function narrowMousecombo(type) {
|
|
295
335
|
return toCombo(type);
|
|
296
336
|
}
|
|
297
|
-
function
|
|
337
|
+
function narrowPointercombo(type) {
|
|
298
338
|
return toCombo(type);
|
|
299
339
|
}
|
|
300
340
|
const toUnique$1 = unique();
|
|
@@ -341,45 +381,39 @@ function createExceptAndOnlyEffect(type, effect, options) {
|
|
|
341
381
|
const { except = [], only = [] } = options;
|
|
342
382
|
if (type === "keydown" || type === "keyup") {
|
|
343
383
|
return (event) => {
|
|
344
|
-
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true]
|
|
345
|
-
matches: (keycombo) => eventMatchesKeycombo(event, ensureKeycombo(keycombo))
|
|
346
|
-
};
|
|
384
|
+
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
|
|
347
385
|
if (matchesOnly) {
|
|
348
|
-
effect(event
|
|
386
|
+
effect(event);
|
|
349
387
|
return;
|
|
350
388
|
}
|
|
351
389
|
if (only.length === 0 && !matchesExcept) {
|
|
352
|
-
effect(event
|
|
390
|
+
effect(event);
|
|
353
391
|
return;
|
|
354
392
|
}
|
|
355
393
|
};
|
|
356
394
|
}
|
|
357
395
|
if (type === "click" || type === "dblclick" || type === "contextmenu" || type.startsWith("mouse")) {
|
|
358
396
|
return (event) => {
|
|
359
|
-
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true]
|
|
360
|
-
matches: (clickcombo) => eventMatchesClickcombo(event, ensureClickcombo(clickcombo))
|
|
361
|
-
};
|
|
397
|
+
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
|
|
362
398
|
if (matchesOnly) {
|
|
363
|
-
effect(event
|
|
399
|
+
effect(event);
|
|
364
400
|
return;
|
|
365
401
|
}
|
|
366
402
|
if (only.length === 0 && !matchesExcept) {
|
|
367
|
-
effect(event
|
|
403
|
+
effect(event);
|
|
368
404
|
return;
|
|
369
405
|
}
|
|
370
406
|
};
|
|
371
407
|
}
|
|
372
408
|
if (type.startsWith("pointer")) {
|
|
373
409
|
return (event) => {
|
|
374
|
-
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true]
|
|
375
|
-
matches: (pointercombo) => eventMatchesPointercombo(event, ensurePointercombo(pointercombo))
|
|
376
|
-
};
|
|
410
|
+
const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
|
|
377
411
|
if (matchesOnly) {
|
|
378
|
-
effect(event
|
|
412
|
+
effect(event);
|
|
379
413
|
return;
|
|
380
414
|
}
|
|
381
415
|
if (only.length === 0 && !matchesExcept) {
|
|
382
|
-
effect(event
|
|
416
|
+
effect(event);
|
|
383
417
|
return;
|
|
384
418
|
}
|
|
385
419
|
};
|
|
@@ -396,7 +430,7 @@ function createExceptAndOnlyEffect(type, effect, options) {
|
|
|
396
430
|
}
|
|
397
431
|
};
|
|
398
432
|
}
|
|
399
|
-
function
|
|
433
|
+
function predicateModified({ event, alias }) {
|
|
400
434
|
return predicatesByModifier[alias]?.(event);
|
|
401
435
|
}
|
|
402
436
|
const predicatesByModifier = {
|
|
@@ -417,24 +451,43 @@ function domIsAvailable() {
|
|
|
417
451
|
return false;
|
|
418
452
|
}
|
|
419
453
|
}
|
|
420
|
-
function
|
|
454
|
+
function predicateArray(value) {
|
|
421
455
|
return Array.isArray(value);
|
|
422
456
|
}
|
|
423
|
-
function
|
|
457
|
+
function predicateUndefined(value) {
|
|
424
458
|
return value === void 0;
|
|
425
459
|
}
|
|
426
|
-
function
|
|
460
|
+
function predicateFunction(value) {
|
|
427
461
|
return typeof value === "function";
|
|
428
462
|
}
|
|
429
|
-
function
|
|
463
|
+
function predicateNull(value) {
|
|
430
464
|
return value === null;
|
|
431
465
|
}
|
|
432
|
-
function
|
|
466
|
+
function predicateNumber(value) {
|
|
433
467
|
return typeof value === "number";
|
|
434
468
|
}
|
|
435
|
-
function
|
|
469
|
+
function predicateString(value) {
|
|
436
470
|
return typeof value === "string";
|
|
437
471
|
}
|
|
472
|
+
const tabbableSelector = join(':not([hidden]):not([tabindex="-1"]),')([
|
|
473
|
+
"input:not([disabled]):not([type=hidden])",
|
|
474
|
+
"select:not([disabled])",
|
|
475
|
+
"textarea:not([disabled])",
|
|
476
|
+
"button:not([disabled])",
|
|
477
|
+
"a[href]",
|
|
478
|
+
"area[href]",
|
|
479
|
+
"summary",
|
|
480
|
+
"iframe",
|
|
481
|
+
"object",
|
|
482
|
+
"embed",
|
|
483
|
+
"audio[controls]",
|
|
484
|
+
"video[controls]",
|
|
485
|
+
"[contenteditable]",
|
|
486
|
+
"[tabindex]:not([disabled])"
|
|
487
|
+
]);
|
|
488
|
+
function predicateFocusable(element) {
|
|
489
|
+
return element.matches(tabbableSelector);
|
|
490
|
+
}
|
|
438
491
|
|
|
439
492
|
class Recognizeable {
|
|
440
493
|
maxSequenceLength;
|
|
@@ -454,7 +507,10 @@ class Recognizeable {
|
|
|
454
507
|
getMetadata: () => this.metadata,
|
|
455
508
|
setMetadata: (metadata) => this.computedMetadata = metadata,
|
|
456
509
|
recognized: () => this.recognized(),
|
|
457
|
-
denied: () => this.denied()
|
|
510
|
+
denied: () => this.denied(),
|
|
511
|
+
recognizedUntilReady: () => this.recognizedUntilReady(),
|
|
512
|
+
deniedUntilReady: () => this.deniedUntilReady(),
|
|
513
|
+
ready: () => this.ready()
|
|
458
514
|
};
|
|
459
515
|
this.ready();
|
|
460
516
|
}
|
|
@@ -468,6 +524,12 @@ class Recognizeable {
|
|
|
468
524
|
denied() {
|
|
469
525
|
this.computedStatus = "denied";
|
|
470
526
|
}
|
|
527
|
+
recognizedUntilReady() {
|
|
528
|
+
this.computedStatus = "recognized until ready";
|
|
529
|
+
}
|
|
530
|
+
deniedUntilReady() {
|
|
531
|
+
this.computedStatus = "denied until ready";
|
|
532
|
+
}
|
|
471
533
|
computedStatus;
|
|
472
534
|
ready() {
|
|
473
535
|
this.computedStatus = "ready";
|
|
@@ -489,18 +551,21 @@ class Recognizeable {
|
|
|
489
551
|
this.computedSequence = sequence;
|
|
490
552
|
return this;
|
|
491
553
|
}
|
|
492
|
-
recognize(sequenceItem,
|
|
493
|
-
this.
|
|
494
|
-
|
|
554
|
+
recognize(sequenceItem, { onRecognized } = {}) {
|
|
555
|
+
if (!this.status.includes("until ready"))
|
|
556
|
+
this.recognizing();
|
|
557
|
+
const type = this.toType(sequenceItem), excess = predicateNumber(this.maxSequenceLength) ? Math.max(0, this.sequence.length - this.maxSequenceLength) : 0, newSequence = createConcat(
|
|
495
558
|
createSlice(excess)(this.sequence),
|
|
496
559
|
[sequenceItem]
|
|
497
560
|
)([]);
|
|
498
561
|
this.effectApi.getSequence = () => newSequence;
|
|
499
562
|
this.effectApi.onRecognized = onRecognized || (() => {
|
|
500
563
|
});
|
|
501
|
-
this.effects.get(type)?.(sequenceItem, { ...
|
|
564
|
+
this.effects.get(type)?.(sequenceItem, { ...this.effectApi });
|
|
502
565
|
switch (this.status) {
|
|
566
|
+
case "ready":
|
|
503
567
|
case "denied":
|
|
568
|
+
case "denied until ready":
|
|
504
569
|
this.resetComputedMetadata();
|
|
505
570
|
this.setSequence([]);
|
|
506
571
|
break;
|
|
@@ -515,7 +580,7 @@ class Recognizeable {
|
|
|
515
580
|
this.computedStatus = "recognizing";
|
|
516
581
|
}
|
|
517
582
|
toType(sequenceItem) {
|
|
518
|
-
if (
|
|
583
|
+
if (predicateArray(sequenceItem)) {
|
|
519
584
|
if (sequenceItem[0] instanceof IntersectionObserverEntry) {
|
|
520
585
|
return "intersect";
|
|
521
586
|
}
|
|
@@ -627,27 +692,40 @@ class Listenable {
|
|
|
627
692
|
}
|
|
628
693
|
mediaQueryListen(effect, options) {
|
|
629
694
|
const target = window.matchMedia(this.type);
|
|
630
|
-
if (
|
|
695
|
+
if (predicateFunction(options.instantEffect)) {
|
|
631
696
|
options.instantEffect(target);
|
|
632
697
|
}
|
|
633
|
-
const withApi = (event) => effect(event
|
|
698
|
+
const withApi = (event) => effect(event);
|
|
634
699
|
target.addEventListener("change", withApi);
|
|
635
700
|
this.active.add({ target, id: ["change", withApi] });
|
|
636
701
|
}
|
|
637
702
|
idleListen(effect, options) {
|
|
638
|
-
const { requestIdleCallback } = options, id = window.requestIdleCallback((deadline) => effect(deadline
|
|
703
|
+
const { requestIdleCallback } = options, id = window.requestIdleCallback((deadline) => effect(deadline), requestIdleCallback);
|
|
639
704
|
this.active.add({ target: window, id });
|
|
640
705
|
}
|
|
641
706
|
messageListen(effect, options) {
|
|
642
707
|
const { target = new BroadcastChannel("baleada") } = options;
|
|
643
|
-
target.addEventListener(this.type, (event) => effect(event
|
|
708
|
+
target.addEventListener(this.type, (event) => effect(event));
|
|
644
709
|
this.active.add({ target, id: [this.type, effect] });
|
|
645
710
|
}
|
|
646
711
|
recognizeableListen(effect, options) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
712
|
+
let effectStatus = "ready";
|
|
713
|
+
const guardedEffect = (sequenceItem) => {
|
|
714
|
+
this.recognizeable.recognize(sequenceItem, { onRecognized: (sequenceItem2) => effect(sequenceItem2) });
|
|
715
|
+
switch (this.recognizeable.status) {
|
|
716
|
+
case "recognized until ready":
|
|
717
|
+
if (effectStatus === "ready") {
|
|
718
|
+
effect(sequenceItem);
|
|
719
|
+
effectStatus = "performed";
|
|
720
|
+
}
|
|
721
|
+
break;
|
|
722
|
+
case "recognized":
|
|
723
|
+
effect(sequenceItem);
|
|
724
|
+
effectStatus = "ready";
|
|
725
|
+
break;
|
|
726
|
+
default:
|
|
727
|
+
effectStatus = "ready";
|
|
728
|
+
break;
|
|
651
729
|
}
|
|
652
730
|
};
|
|
653
731
|
for (const type of this.recognizeableEffectsKeys) {
|
|
@@ -657,11 +735,11 @@ class Listenable {
|
|
|
657
735
|
}
|
|
658
736
|
}
|
|
659
737
|
documentEventListen(effect, options) {
|
|
660
|
-
const
|
|
738
|
+
const narrowedOptions = {
|
|
661
739
|
...options,
|
|
662
740
|
target: document
|
|
663
741
|
};
|
|
664
|
-
this.eventListen(effect,
|
|
742
|
+
this.eventListen(effect, narrowedOptions);
|
|
665
743
|
}
|
|
666
744
|
eventListen(effect, options) {
|
|
667
745
|
const { exceptAndOnlyEffect, effectOptions } = toAddEventListenerParams(this.type, effect, options), eventListeners = [[this.type, exceptAndOnlyEffect, ...effectOptions]];
|
|
@@ -715,7 +793,7 @@ function stop(stoppable) {
|
|
|
715
793
|
target2.removeEventListener(id2[0], id2[1]);
|
|
716
794
|
return;
|
|
717
795
|
}
|
|
718
|
-
if (
|
|
796
|
+
if (predicateNumber(stoppable.id)) {
|
|
719
797
|
const { target: target2, id: id2 } = stoppable;
|
|
720
798
|
target2.cancelIdleCallback(id2);
|
|
721
799
|
return;
|
|
@@ -788,9 +866,8 @@ function eventMatchesKeycombo(event, keycombo) {
|
|
|
788
866
|
return every(({ name, type }, index) => {
|
|
789
867
|
switch (type) {
|
|
790
868
|
case "singleCharacter":
|
|
791
|
-
if (name === "!")
|
|
869
|
+
if (name === "!")
|
|
792
870
|
return event.key === "!";
|
|
793
|
-
}
|
|
794
871
|
const keyToTest = event.altKey && fromComboItemNameToType(event.key) === "custom" ? fromCodeToSingleCharacter(event.code) : event.key.toLowerCase();
|
|
795
872
|
return name.startsWith("!") ? keyToTest !== toKey(name.slice(1)).toLowerCase() : keyToTest === toKey(name).toLowerCase();
|
|
796
873
|
case "other":
|
|
@@ -804,7 +881,7 @@ function eventMatchesKeycombo(event, keycombo) {
|
|
|
804
881
|
if (index === keycombo.length - 1) {
|
|
805
882
|
return name.startsWith("!") ? event.key.toLowerCase() !== toModifier(name.slice(1)).toLowerCase() : event.key.toLowerCase() === toModifier(name).toLowerCase();
|
|
806
883
|
}
|
|
807
|
-
return name.startsWith("!") ? !
|
|
884
|
+
return name.startsWith("!") ? !predicateModified({ event, alias: name.slice(1) }) : predicateModified({ event, alias: name });
|
|
808
885
|
}
|
|
809
886
|
})(keycombo);
|
|
810
887
|
}
|
|
@@ -868,11 +945,11 @@ const predicatesByArrow = /* @__PURE__ */ new Map([
|
|
|
868
945
|
const arrows = /* @__PURE__ */ new Set(["arrowup", "arrowright", "arrowdown", "arrowleft"]);
|
|
869
946
|
const verticalArrows = /* @__PURE__ */ new Set(["arrowup", "arrowdown"]);
|
|
870
947
|
const horizontalArrows = /* @__PURE__ */ new Set(["arrowright", "arrowleft"]);
|
|
871
|
-
function
|
|
872
|
-
return every((name) => fromComboItemNameToType(name) === "click" || name.startsWith("!") && !
|
|
948
|
+
function eventMatchesMousecombo(event, Mousecombo) {
|
|
949
|
+
return every((name) => fromComboItemNameToType(name) === "click" || name.startsWith("!") && !predicateModified({ alias: name.slice(1), event }) || !name.startsWith("!") && predicateModified({ alias: name, event }))(Mousecombo);
|
|
873
950
|
}
|
|
874
951
|
function eventMatchesPointercombo(event, pointercombo) {
|
|
875
|
-
return every((name) => fromComboItemNameToType(name) === "pointer" || name.startsWith("!") && !
|
|
952
|
+
return every((name) => fromComboItemNameToType(name) === "pointer" || name.startsWith("!") && !predicateModified({ alias: name.slice(1), event }) || !name.startsWith("!") && predicateModified({ alias: name, event }))(pointercombo);
|
|
876
953
|
}
|
|
877
954
|
const observerAssertionsByType = {
|
|
878
955
|
intersect: (observer) => observer instanceof IntersectionObserver,
|
|
@@ -1000,13 +1077,13 @@ class Animateable {
|
|
|
1000
1077
|
duration;
|
|
1001
1078
|
totalTimeInvisible;
|
|
1002
1079
|
setPlaybackRate(playbackRate) {
|
|
1003
|
-
const
|
|
1004
|
-
this.computedPlaybackRate =
|
|
1005
|
-
this.duration = 1 /
|
|
1080
|
+
const narrowedPlaybackRate = Math.max(0, playbackRate);
|
|
1081
|
+
this.computedPlaybackRate = narrowedPlaybackRate;
|
|
1082
|
+
this.duration = 1 / narrowedPlaybackRate * this.initialDuration;
|
|
1006
1083
|
switch (this.status) {
|
|
1007
1084
|
case "playing":
|
|
1008
1085
|
case "reversing":
|
|
1009
|
-
this.totalTimeInvisible = 1 /
|
|
1086
|
+
this.totalTimeInvisible = 1 / narrowedPlaybackRate * this.totalTimeInvisible;
|
|
1010
1087
|
this.seek(this.progress.time);
|
|
1011
1088
|
break;
|
|
1012
1089
|
}
|
|
@@ -1395,51 +1472,51 @@ class Animateable {
|
|
|
1395
1472
|
seek(timeProgress, options = {}) {
|
|
1396
1473
|
const iterations = Math.floor(timeProgress), naiveIterationProgress = timeProgress - iterations, { effect: naiveEffect } = options;
|
|
1397
1474
|
this.computedIterations = iterations;
|
|
1398
|
-
let
|
|
1475
|
+
let narrowedTimeProgress, effect;
|
|
1399
1476
|
if (this.alternates) {
|
|
1400
1477
|
if (naiveIterationProgress <= 0.5) {
|
|
1401
|
-
|
|
1478
|
+
narrowedTimeProgress = naiveIterationProgress * 2;
|
|
1402
1479
|
switch (this.alternateCache.status) {
|
|
1403
1480
|
case "playing":
|
|
1404
1481
|
this.cancelAnimate();
|
|
1405
|
-
this.seekCache = { timeProgress:
|
|
1482
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1406
1483
|
this.sought();
|
|
1407
|
-
effect =
|
|
1484
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.playCache.effect;
|
|
1408
1485
|
this.play(effect, this.playCache.options);
|
|
1409
1486
|
break;
|
|
1410
1487
|
case "reversing":
|
|
1411
1488
|
this.cancelAnimate();
|
|
1412
|
-
this.seekCache = { timeProgress:
|
|
1489
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1413
1490
|
this.sought();
|
|
1414
|
-
effect =
|
|
1491
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.reverseCache.effect;
|
|
1415
1492
|
this.reverse(effect, this.reverseCache.options);
|
|
1416
1493
|
break;
|
|
1417
1494
|
default:
|
|
1418
|
-
this.seekCache = { timeProgress:
|
|
1495
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1419
1496
|
this.sought();
|
|
1420
1497
|
effect = naiveEffect;
|
|
1421
1498
|
this.createAnimate("seek")(effect, options);
|
|
1422
1499
|
break;
|
|
1423
1500
|
}
|
|
1424
1501
|
} else {
|
|
1425
|
-
|
|
1502
|
+
narrowedTimeProgress = (naiveIterationProgress - 0.5) * 2;
|
|
1426
1503
|
switch (this.alternateCache.status) {
|
|
1427
1504
|
case "playing":
|
|
1428
1505
|
this.cancelAnimate();
|
|
1429
|
-
this.seekCache = { timeProgress:
|
|
1506
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1430
1507
|
this.sought();
|
|
1431
|
-
effect =
|
|
1508
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.reverseCache.effect;
|
|
1432
1509
|
this.reverse(effect, this.reverseCache.options);
|
|
1433
1510
|
break;
|
|
1434
1511
|
case "reversing":
|
|
1435
1512
|
this.cancelAnimate();
|
|
1436
|
-
this.seekCache = { timeProgress:
|
|
1513
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1437
1514
|
this.sought();
|
|
1438
|
-
effect =
|
|
1515
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.playCache.effect;
|
|
1439
1516
|
this.play(effect, this.playCache.options);
|
|
1440
1517
|
break;
|
|
1441
1518
|
default:
|
|
1442
|
-
this.seekCache = { timeProgress:
|
|
1519
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1443
1520
|
this.sought();
|
|
1444
1521
|
effect = naiveEffect;
|
|
1445
1522
|
if (effect) {
|
|
@@ -1449,24 +1526,24 @@ class Animateable {
|
|
|
1449
1526
|
}
|
|
1450
1527
|
}
|
|
1451
1528
|
} else {
|
|
1452
|
-
|
|
1529
|
+
narrowedTimeProgress = naiveIterationProgress;
|
|
1453
1530
|
switch (this.status) {
|
|
1454
1531
|
case "playing":
|
|
1455
1532
|
this.cancelAnimate();
|
|
1456
|
-
this.seekCache = { timeProgress:
|
|
1533
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1457
1534
|
this.sought();
|
|
1458
|
-
effect =
|
|
1535
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.playCache.effect;
|
|
1459
1536
|
this.play(effect, this.playCache.options);
|
|
1460
1537
|
break;
|
|
1461
1538
|
case "reversing":
|
|
1462
1539
|
this.cancelAnimate();
|
|
1463
|
-
this.seekCache = { timeProgress:
|
|
1540
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1464
1541
|
this.sought();
|
|
1465
|
-
effect =
|
|
1542
|
+
effect = predicateFunction(naiveEffect) ? naiveEffect : this.reverseCache.effect;
|
|
1466
1543
|
this.reverse(effect, this.reverseCache.options);
|
|
1467
1544
|
break;
|
|
1468
1545
|
default:
|
|
1469
|
-
this.seekCache = { timeProgress:
|
|
1546
|
+
this.seekCache = { timeProgress: narrowedTimeProgress };
|
|
1470
1547
|
this.sought();
|
|
1471
1548
|
effect = naiveEffect;
|
|
1472
1549
|
if (effect) {
|
|
@@ -1592,13 +1669,13 @@ function createToAnimationProgress(points) {
|
|
|
1592
1669
|
return BezierEasing(point1x, point1y, point2x, point2y);
|
|
1593
1670
|
}
|
|
1594
1671
|
function toInterpolated({ previous, next, progress }, options = {}) {
|
|
1595
|
-
if (
|
|
1672
|
+
if (predicateUndefined(previous)) {
|
|
1596
1673
|
return next;
|
|
1597
1674
|
}
|
|
1598
|
-
if (
|
|
1675
|
+
if (predicateNumber(previous) && predicateNumber(next)) {
|
|
1599
1676
|
return (next - previous) * progress + previous;
|
|
1600
1677
|
}
|
|
1601
|
-
if (
|
|
1678
|
+
if (predicateString(previous) && predicateString(next)) {
|
|
1602
1679
|
return mix(
|
|
1603
1680
|
options.colorModel,
|
|
1604
1681
|
{
|
|
@@ -1608,7 +1685,7 @@ function toInterpolated({ previous, next, progress }, options = {}) {
|
|
|
1608
1685
|
}
|
|
1609
1686
|
).toRgb().toRgbString();
|
|
1610
1687
|
}
|
|
1611
|
-
if (
|
|
1688
|
+
if (predicateArray(previous) && predicateArray(next)) {
|
|
1612
1689
|
const exactSliceEnd = (next.length - previous.length) * progress + previous.length, nextIsLonger = next.length > previous.length, sliceEnd = nextIsLonger ? Math.floor(exactSliceEnd) : Math.ceil(exactSliceEnd), sliceTarget = nextIsLonger ? next : previous;
|
|
1613
1690
|
return createSlice(0, sliceEnd)(sliceTarget);
|
|
1614
1691
|
}
|
|
@@ -1974,7 +2051,7 @@ class Completeable {
|
|
|
1974
2051
|
complete(completion, options = {}) {
|
|
1975
2052
|
this.completing();
|
|
1976
2053
|
const { select } = { ...defaultCompleteOptions, ...options }, before = this.getBefore(), after = this.getAfter(), completedString = before + completion + after, completedSelection = (() => {
|
|
1977
|
-
if (
|
|
2054
|
+
if (predicateFunction(select)) {
|
|
1978
2055
|
return select({ before, completion, after });
|
|
1979
2056
|
}
|
|
1980
2057
|
switch (select) {
|
|
@@ -2379,7 +2456,7 @@ class Resolveable {
|
|
|
2379
2456
|
this.resolving();
|
|
2380
2457
|
try {
|
|
2381
2458
|
const promises = this.getPromise(...args);
|
|
2382
|
-
this.computedValue =
|
|
2459
|
+
this.computedValue = predicateArray(promises) ? await createMapAsync(async (promise) => await promise)(promises) : await promises;
|
|
2383
2460
|
this.resolved();
|
|
2384
2461
|
} catch (error) {
|
|
2385
2462
|
this.computedValue = error;
|
|
@@ -2464,7 +2541,7 @@ class Fetchable {
|
|
|
2464
2541
|
async fetch(options = {}) {
|
|
2465
2542
|
this.fetching();
|
|
2466
2543
|
try {
|
|
2467
|
-
this.computedResponse = await fetch(this.resource, { signal: this.abortController.signal, ...
|
|
2544
|
+
this.computedResponse = await fetch(this.resource, { signal: this.abortController.signal, ...narrowOptions(options) });
|
|
2468
2545
|
this.fetched();
|
|
2469
2546
|
} catch (error) {
|
|
2470
2547
|
this.computedError = error;
|
|
@@ -2488,23 +2565,23 @@ class Fetchable {
|
|
|
2488
2565
|
this.computedStatus = "errored";
|
|
2489
2566
|
}
|
|
2490
2567
|
async get(options = {}) {
|
|
2491
|
-
await this.fetch({ signal: this.abortController.signal, ...
|
|
2568
|
+
await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "get" });
|
|
2492
2569
|
return this;
|
|
2493
2570
|
}
|
|
2494
2571
|
async patch(options = {}) {
|
|
2495
|
-
await this.fetch({ signal: this.abortController.signal, ...
|
|
2572
|
+
await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "patch" });
|
|
2496
2573
|
return this;
|
|
2497
2574
|
}
|
|
2498
2575
|
async post(options = {}) {
|
|
2499
|
-
await this.fetch({ signal: this.abortController.signal, ...
|
|
2576
|
+
await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "post" });
|
|
2500
2577
|
return this;
|
|
2501
2578
|
}
|
|
2502
2579
|
async put(options = {}) {
|
|
2503
|
-
await this.fetch({ signal: this.abortController.signal, ...
|
|
2580
|
+
await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "put" });
|
|
2504
2581
|
return this;
|
|
2505
2582
|
}
|
|
2506
2583
|
async delete(options = {}) {
|
|
2507
|
-
await this.fetch({ signal: this.abortController.signal, ...
|
|
2584
|
+
await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "delete" });
|
|
2508
2585
|
return this;
|
|
2509
2586
|
}
|
|
2510
2587
|
abort() {
|
|
@@ -2512,8 +2589,8 @@ class Fetchable {
|
|
|
2512
2589
|
return this;
|
|
2513
2590
|
}
|
|
2514
2591
|
}
|
|
2515
|
-
function
|
|
2516
|
-
return
|
|
2592
|
+
function narrowOptions(options) {
|
|
2593
|
+
return predicateFunction(options) ? options({ withJson }) : options;
|
|
2517
2594
|
}
|
|
2518
2595
|
function withJson(data) {
|
|
2519
2596
|
return {
|
|
@@ -2696,7 +2773,7 @@ class Navigateable {
|
|
|
2696
2773
|
}
|
|
2697
2774
|
_navigate(location, options = {}) {
|
|
2698
2775
|
const { allow } = { ...defaultNavigateOptions, ...options };
|
|
2699
|
-
const
|
|
2776
|
+
const narrowedLocation = (() => {
|
|
2700
2777
|
if (allow === "possible") {
|
|
2701
2778
|
if (location < 0 && allow === "possible") {
|
|
2702
2779
|
return 0;
|
|
@@ -2707,7 +2784,7 @@ class Navigateable {
|
|
|
2707
2784
|
}
|
|
2708
2785
|
return location;
|
|
2709
2786
|
})();
|
|
2710
|
-
this.computedLocation =
|
|
2787
|
+
this.computedLocation = narrowedLocation;
|
|
2711
2788
|
}
|
|
2712
2789
|
next(options = {}) {
|
|
2713
2790
|
const { distance, loops } = { ...defaultNextAndPreviousOptions, ...options }, newLocation = (() => {
|
|
@@ -2851,7 +2928,7 @@ class Pickable {
|
|
|
2851
2928
|
pick(indexOrIndices, options = {}) {
|
|
2852
2929
|
const { replace, allowsDuplicates } = { ...defaultPickOptions, ...options };
|
|
2853
2930
|
this.computedPicks = new Pipeable(indexOrIndices).pipe(
|
|
2854
|
-
|
|
2931
|
+
narrowIndices,
|
|
2855
2932
|
this.toPossiblePicks,
|
|
2856
2933
|
(possiblePicks) => {
|
|
2857
2934
|
if (replace === "all") {
|
|
@@ -2904,7 +2981,7 @@ class Pickable {
|
|
|
2904
2981
|
this.computedStatus = "picked";
|
|
2905
2982
|
}
|
|
2906
2983
|
omit(indexOrIndices, options = { reference: "array" }) {
|
|
2907
|
-
if (
|
|
2984
|
+
if (predicateUndefined(indexOrIndices)) {
|
|
2908
2985
|
this.computedPicks = [];
|
|
2909
2986
|
this.computedFirst = void 0;
|
|
2910
2987
|
this.computedLast = void 0;
|
|
@@ -2912,9 +2989,9 @@ class Pickable {
|
|
|
2912
2989
|
this.omitted();
|
|
2913
2990
|
return this;
|
|
2914
2991
|
}
|
|
2915
|
-
const omits =
|
|
2992
|
+
const omits = narrowIndices(indexOrIndices);
|
|
2916
2993
|
this.computedPicks = createFilter(
|
|
2917
|
-
(pick, index) => options.reference === "array" ?
|
|
2994
|
+
(pick, index) => options.reference === "array" ? predicateUndefined(find((omit) => pick === omit)(omits)) : predicateUndefined(find((omit) => index === omit)(omits))
|
|
2918
2995
|
)(this.computedPicks);
|
|
2919
2996
|
this.computedFirst = Math.min(...this.picks);
|
|
2920
2997
|
this.computedLast = Math.max(...this.picks);
|
|
@@ -2926,7 +3003,7 @@ class Pickable {
|
|
|
2926
3003
|
this.computedStatus = "omitted";
|
|
2927
3004
|
}
|
|
2928
3005
|
}
|
|
2929
|
-
function
|
|
3006
|
+
function narrowIndices(indexOrIndices) {
|
|
2930
3007
|
return Array.isArray(indexOrIndices) ? indexOrIndices : [indexOrIndices];
|
|
2931
3008
|
}
|
|
2932
3009
|
const toUnique = createUnique();
|
|
@@ -3098,7 +3175,7 @@ class Storeable {
|
|
|
3098
3175
|
ready() {
|
|
3099
3176
|
this.computedStatus = "ready";
|
|
3100
3177
|
if (domIsAvailable()) {
|
|
3101
|
-
if (
|
|
3178
|
+
if (predicateNull(this.storage.getItem(this.computedStatusKey))) {
|
|
3102
3179
|
this.storeStatus();
|
|
3103
3180
|
}
|
|
3104
3181
|
}
|
|
@@ -3112,7 +3189,7 @@ class Storeable {
|
|
|
3112
3189
|
get status() {
|
|
3113
3190
|
if (domIsAvailable()) {
|
|
3114
3191
|
const storedStatus = this.storage.getItem(this.computedStatusKey);
|
|
3115
|
-
if (this.computedStatus !== storedStatus &&
|
|
3192
|
+
if (this.computedStatus !== storedStatus && predicateString(storedStatus)) {
|
|
3116
3193
|
this.computedStatus = storedStatus;
|
|
3117
3194
|
}
|
|
3118
3195
|
}
|
|
@@ -3198,4 +3275,4 @@ class Storeable {
|
|
|
3198
3275
|
}
|
|
3199
3276
|
}
|
|
3200
3277
|
|
|
3201
|
-
export { Animateable, Broadcastable, Completeable, Copyable, Delayable, Drawable, Fetchable, Fullscreenable, Grantable, Listenable, Navigateable, Pickable, Pipeable, Recognizeable, Resolveable, Sanitizeable, Searchable, Shareable, Storeable, createClamp, createClip, createConcat,
|
|
3278
|
+
export { Animateable, Broadcastable, Completeable, Copyable, Delayable, Drawable, Fetchable, Fullscreenable, Grantable, Listenable, Navigateable, Pickable, Pipeable, Recognizeable, Resolveable, Sanitizeable, Searchable, Shareable, Storeable, createClamp, createClip, createConcat, createDetermine, createFilter, createFilterAsync, createForEachAsync, createInsert, createMap, createMapAsync, createMatchesKeycombo, createMatchesMousecombo, createMatchesPointercombo, createReduce, createReduceAsync, createRemove, createRename, createReorder, createReplace, createReverse, createSlice, createSlug, createSort, createSwap, createToEntries, createToFocusable, createToKeys, createUnique, easingsNetInBack, easingsNetInCirc, easingsNetInCubic, easingsNetInExpo, easingsNetInOutBack, easingsNetInOutCirc, easingsNetInOutCubic, easingsNetInOutExpo, easingsNetInOutQuad, easingsNetInOutQuint, easingsNetInOutSine, easingsNetInQuad, easingsNetInQuart, easingsNetInQuint, easingsNetInSine, easingsNetOutBack, easingsNetOutCirc, easingsNetOutCubic, easingsNetOutExpo, easingsNetOutQuad, easingsNetOutQuint, easingsNetOutSine, linear, materialAccelerated, materialDecelerated, materialStandard, toD, toFlattenedD, toMessageListenParams, verouEase, verouEaseIn, verouEaseInOut, verouEaseOut };
|