@baleada/logic 0.22.5 → 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 CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  UI logic for the Baleada toolkit.
4
4
 
5
- [See the Baleada docs](https://baleada/netlify.com) for more guidance.
5
+ [See the Baleada docs](https://baleada.dev) for more guidance.
package/lib/index.cjs CHANGED
@@ -220,6 +220,15 @@ function createToEntries() {
220
220
  return entries;
221
221
  };
222
222
  }
223
+ function createToKeys() {
224
+ return (object) => {
225
+ const keys = [];
226
+ for (const key in object) {
227
+ keys.push(key);
228
+ }
229
+ return keys;
230
+ };
231
+ }
223
232
  function createMatchesKeycombo(keycombo) {
224
233
  return (event) => eventMatchesKeycombo(event, narrowKeycombo(keycombo));
225
234
  }
@@ -500,7 +509,10 @@ class Recognizeable {
500
509
  getMetadata: () => this.metadata,
501
510
  setMetadata: (metadata) => this.computedMetadata = metadata,
502
511
  recognized: () => this.recognized(),
503
- denied: () => this.denied()
512
+ denied: () => this.denied(),
513
+ recognizedUntilReady: () => this.recognizedUntilReady(),
514
+ deniedUntilReady: () => this.deniedUntilReady(),
515
+ ready: () => this.ready()
504
516
  };
505
517
  this.ready();
506
518
  }
@@ -514,6 +526,12 @@ class Recognizeable {
514
526
  denied() {
515
527
  this.computedStatus = "denied";
516
528
  }
529
+ recognizedUntilReady() {
530
+ this.computedStatus = "recognized until ready";
531
+ }
532
+ deniedUntilReady() {
533
+ this.computedStatus = "denied until ready";
534
+ }
517
535
  computedStatus;
518
536
  ready() {
519
537
  this.computedStatus = "ready";
@@ -536,7 +554,8 @@ class Recognizeable {
536
554
  return this;
537
555
  }
538
556
  recognize(sequenceItem, { onRecognized } = {}) {
539
- this.recognizing();
557
+ if (!this.status.includes("until ready"))
558
+ this.recognizing();
540
559
  const type = this.toType(sequenceItem), excess = predicateNumber(this.maxSequenceLength) ? Math.max(0, this.sequence.length - this.maxSequenceLength) : 0, newSequence = createConcat(
541
560
  createSlice(excess)(this.sequence),
542
561
  [sequenceItem]
@@ -546,7 +565,9 @@ class Recognizeable {
546
565
  });
547
566
  this.effects.get(type)?.(sequenceItem, { ...this.effectApi });
548
567
  switch (this.status) {
568
+ case "ready":
549
569
  case "denied":
570
+ case "denied until ready":
550
571
  this.resetComputedMetadata();
551
572
  this.setSequence([]);
552
573
  break;
@@ -690,10 +711,23 @@ class Listenable {
690
711
  this.active.add({ target, id: [this.type, effect] });
691
712
  }
692
713
  recognizeableListen(effect, options) {
714
+ let effectStatus = "ready";
693
715
  const guardedEffect = (sequenceItem) => {
694
716
  this.recognizeable.recognize(sequenceItem, { onRecognized: (sequenceItem2) => effect(sequenceItem2) });
695
- if (this.recognizeable.status === "recognized") {
696
- effect(sequenceItem);
717
+ switch (this.recognizeable.status) {
718
+ case "recognized until ready":
719
+ if (effectStatus === "ready") {
720
+ effect(sequenceItem);
721
+ effectStatus = "performed";
722
+ }
723
+ break;
724
+ case "recognized":
725
+ effect(sequenceItem);
726
+ effectStatus = "ready";
727
+ break;
728
+ default:
729
+ effectStatus = "ready";
730
+ break;
697
731
  }
698
732
  };
699
733
  for (const type of this.recognizeableEffectsKeys) {
@@ -834,9 +868,8 @@ function eventMatchesKeycombo(event, keycombo) {
834
868
  return lazyCollections.every(({ name, type }, index) => {
835
869
  switch (type) {
836
870
  case "singleCharacter":
837
- if (name === "!") {
871
+ if (name === "!")
838
872
  return event.key === "!";
839
- }
840
873
  const keyToTest = event.altKey && fromComboItemNameToType(event.key) === "custom" ? fromCodeToSingleCharacter(event.code) : event.key.toLowerCase();
841
874
  return name.startsWith("!") ? keyToTest !== toKey(name.slice(1)).toLowerCase() : keyToTest === toKey(name).toLowerCase();
842
875
  case "other":
@@ -3289,6 +3322,7 @@ exports.createSort = createSort;
3289
3322
  exports.createSwap = createSwap;
3290
3323
  exports.createToEntries = createToEntries;
3291
3324
  exports.createToFocusable = createToFocusable;
3325
+ exports.createToKeys = createToKeys;
3292
3326
  exports.createUnique = createUnique;
3293
3327
  exports.easingsNetInBack = easingsNetInBack;
3294
3328
  exports.easingsNetInCirc = easingsNetInCirc;
package/lib/index.d.ts CHANGED
@@ -156,10 +156,13 @@ type RecognizeableEffectApi<Type extends ListenableSupportedType, Metadata exten
156
156
  setMetadata: (metadata: Metadata) => void;
157
157
  recognized: () => void;
158
158
  denied: () => void;
159
+ recognizedUntilReady: () => void;
160
+ deniedUntilReady: () => void;
161
+ ready: () => void;
159
162
  getSequence: () => ListenEffectParam<Type>[];
160
163
  onRecognized: (sequenceItem: ListenEffectParam<Type>) => any;
161
164
  };
162
- type RecognizeableStatus = 'recognized' | 'recognizing' | 'denied' | 'ready';
165
+ type RecognizeableStatus = 'recognized' | 'recognizing' | 'denied' | 'ready' | 'recognized until ready' | 'denied until ready';
163
166
  type RecognizeOptions<Type extends ListenableSupportedType, Metadata extends Record<any, any>> = {
164
167
  onRecognized?: (sequenceItem: ListenEffectParam<Type>) => any;
165
168
  };
@@ -172,6 +175,8 @@ declare class Recognizeable<Type extends ListenableSupportedType, Metadata exten
172
175
  private resetComputedMetadata;
173
176
  private recognized;
174
177
  private denied;
178
+ private recognizedUntilReady;
179
+ private deniedUntilReady;
175
180
  private computedStatus;
176
181
  private ready;
177
182
  get sequence(): ListenEffectParam<Type>[];
@@ -788,6 +793,7 @@ type MapFunction<Key, Value, Returned> = (transform: Map<Key, Value>) => Returne
788
793
  declare function createRename<Key, Value>(from: Key, to: Key): MapFunction<Key, Value, Map<Key, Value>>;
789
794
  type ObjectFunction<Key extends string | number | symbol, Value, Returned> = (transform: Record<Key, Value>) => Returned;
790
795
  declare function createToEntries<Key extends string | number | symbol, Value>(): ObjectFunction<Key, Value, [Key, Value][]>;
796
+ declare function createToKeys<Key extends string | number | symbol>(): ObjectFunction<Key, any, [Key, any][]>;
791
797
  type EventFunction<Evt extends Event, Returned> = (event: Evt) => Returned;
792
798
  declare function createMatchesKeycombo(keycombo: string): EventFunction<KeyboardEvent, boolean>;
793
799
  declare function createMatchesMousecombo(mousecombo: string): EventFunction<MouseEvent, boolean>;
@@ -801,4 +807,4 @@ declare class Pipeable {
801
807
  pipeAsync(...fns: ((...args: any[]) => Promise<any>)[]): Promise<any>;
802
808
  }
803
809
 
804
- export { AnimateFrame, AnimateFrameEffect, AnimateOptions, Animateable, AnimateableKeyframe, AnimateableOptions, AnimateableStatus, ArrayFunction, ArrayFunctionAsync, Broadcastable, BroadcastableOptions, BroadcastableStatus, CompleteOptions, Completeable, CompleteableOptions, CompleteableStatus, Copyable, CopyableOptions, CopyableStatus, Delayable, DelayableEffect, DelayableOptions, DelayableStatus, Drawable, DrawableOptions, DrawableState, DrawableStatus, ElementFunction, EventFunction, FetchOptions, FetchOptionsApi, Fetchable, FetchableOptions, FetchableStatus, Fullscreenable, FullscreenableGetElement, FullscreenableOptions, FullscreenableStatus, Grantable, GrantableOptions, GrantableStatus, ListenEffect, ListenEffectParam, ListenOptions, Listenable, ListenableActive, ListenableKeycombo, ListenableMousecombo, ListenableOptions, ListenablePointercombo, ListenableStatus, ListenableSupportedEventType, ListenableSupportedType, MapFunction, Navigateable, NavigateableOptions, NavigateableStatus, NumberFunction, ObjectFunction, Pickable, PickableOptions, PickableStatus, Pipeable, RecognizeOptions, Recognizeable, RecognizeableEffect, RecognizeableOptions, RecognizeableStatus, Resolveable, ResolveableGetPromise, ResolveableOptions, ResolveableStatus, Sanitizeable, SanitizeableOptions, SanitizeableStatus, Searchable, SearchableOptions, SearchableStatus, Shareable, ShareableOptions, ShareableStatus, Storeable, StoreableOptions, StoreableStatus, StringFunction, 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, 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 };
810
+ export { AnimateFrame, AnimateFrameEffect, AnimateOptions, Animateable, AnimateableKeyframe, AnimateableOptions, AnimateableStatus, ArrayFunction, ArrayFunctionAsync, Broadcastable, BroadcastableOptions, BroadcastableStatus, CompleteOptions, Completeable, CompleteableOptions, CompleteableStatus, Copyable, CopyableOptions, CopyableStatus, Delayable, DelayableEffect, DelayableOptions, DelayableStatus, Drawable, DrawableOptions, DrawableState, DrawableStatus, ElementFunction, EventFunction, FetchOptions, FetchOptionsApi, Fetchable, FetchableOptions, FetchableStatus, Fullscreenable, FullscreenableGetElement, FullscreenableOptions, FullscreenableStatus, Grantable, GrantableOptions, GrantableStatus, ListenEffect, ListenEffectParam, ListenOptions, Listenable, ListenableActive, ListenableKeycombo, ListenableMousecombo, ListenableOptions, ListenablePointercombo, ListenableStatus, ListenableSupportedEventType, ListenableSupportedType, MapFunction, Navigateable, NavigateableOptions, NavigateableStatus, NumberFunction, ObjectFunction, Pickable, PickableOptions, PickableStatus, Pipeable, RecognizeOptions, Recognizeable, RecognizeableEffect, RecognizeableOptions, RecognizeableStatus, Resolveable, ResolveableGetPromise, ResolveableOptions, ResolveableStatus, Sanitizeable, SanitizeableOptions, SanitizeableStatus, Searchable, SearchableOptions, SearchableStatus, Shareable, ShareableOptions, ShareableStatus, Storeable, StoreableOptions, StoreableStatus, StringFunction, 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 };
package/lib/index.js CHANGED
@@ -218,6 +218,15 @@ 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
+ }
221
230
  function createMatchesKeycombo(keycombo) {
222
231
  return (event) => eventMatchesKeycombo(event, narrowKeycombo(keycombo));
223
232
  }
@@ -498,7 +507,10 @@ class Recognizeable {
498
507
  getMetadata: () => this.metadata,
499
508
  setMetadata: (metadata) => this.computedMetadata = metadata,
500
509
  recognized: () => this.recognized(),
501
- denied: () => this.denied()
510
+ denied: () => this.denied(),
511
+ recognizedUntilReady: () => this.recognizedUntilReady(),
512
+ deniedUntilReady: () => this.deniedUntilReady(),
513
+ ready: () => this.ready()
502
514
  };
503
515
  this.ready();
504
516
  }
@@ -512,6 +524,12 @@ class Recognizeable {
512
524
  denied() {
513
525
  this.computedStatus = "denied";
514
526
  }
527
+ recognizedUntilReady() {
528
+ this.computedStatus = "recognized until ready";
529
+ }
530
+ deniedUntilReady() {
531
+ this.computedStatus = "denied until ready";
532
+ }
515
533
  computedStatus;
516
534
  ready() {
517
535
  this.computedStatus = "ready";
@@ -534,7 +552,8 @@ class Recognizeable {
534
552
  return this;
535
553
  }
536
554
  recognize(sequenceItem, { onRecognized } = {}) {
537
- this.recognizing();
555
+ if (!this.status.includes("until ready"))
556
+ this.recognizing();
538
557
  const type = this.toType(sequenceItem), excess = predicateNumber(this.maxSequenceLength) ? Math.max(0, this.sequence.length - this.maxSequenceLength) : 0, newSequence = createConcat(
539
558
  createSlice(excess)(this.sequence),
540
559
  [sequenceItem]
@@ -544,7 +563,9 @@ class Recognizeable {
544
563
  });
545
564
  this.effects.get(type)?.(sequenceItem, { ...this.effectApi });
546
565
  switch (this.status) {
566
+ case "ready":
547
567
  case "denied":
568
+ case "denied until ready":
548
569
  this.resetComputedMetadata();
549
570
  this.setSequence([]);
550
571
  break;
@@ -688,10 +709,23 @@ class Listenable {
688
709
  this.active.add({ target, id: [this.type, effect] });
689
710
  }
690
711
  recognizeableListen(effect, options) {
712
+ let effectStatus = "ready";
691
713
  const guardedEffect = (sequenceItem) => {
692
714
  this.recognizeable.recognize(sequenceItem, { onRecognized: (sequenceItem2) => effect(sequenceItem2) });
693
- if (this.recognizeable.status === "recognized") {
694
- effect(sequenceItem);
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;
695
729
  }
696
730
  };
697
731
  for (const type of this.recognizeableEffectsKeys) {
@@ -832,9 +866,8 @@ function eventMatchesKeycombo(event, keycombo) {
832
866
  return every(({ name, type }, index) => {
833
867
  switch (type) {
834
868
  case "singleCharacter":
835
- if (name === "!") {
869
+ if (name === "!")
836
870
  return event.key === "!";
837
- }
838
871
  const keyToTest = event.altKey && fromComboItemNameToType(event.key) === "custom" ? fromCodeToSingleCharacter(event.code) : event.key.toLowerCase();
839
872
  return name.startsWith("!") ? keyToTest !== toKey(name.slice(1)).toLowerCase() : keyToTest === toKey(name).toLowerCase();
840
873
  case "other":
@@ -3242,4 +3275,4 @@ class Storeable {
3242
3275
  }
3243
3276
  }
3244
3277
 
3245
- 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, 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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.22.5",
3
+ "version": "0.22.6",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -41,9 +41,9 @@
41
41
  "bugs": {
42
42
  "url": "https://github.com/baleada/logic/issues"
43
43
  },
44
- "homepage": "https://baleada.netlify.com",
44
+ "homepage": "https://baleada.dev",
45
45
  "devDependencies": {
46
- "@baleada/prepare": "^0.5.29",
46
+ "@baleada/prepare": "^0.5.30",
47
47
  "@types/node": "^14.14.41",
48
48
  "@vitejs/plugin-vue": "^3.2.0",
49
49
  "esbuild": "^0.15.13",
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@babel/runtime": "^7.20.6",
61
- "@sindresorhus/slugify": "^2.1.1",
61
+ "@sindresorhus/slugify": "^2.2.0",
62
62
  "@snigo.dev/color": "^0.0.6",
63
63
  "@types/dompurify": "^2.4.0",
64
64
  "@types/requestidlecallback": "^0.3.5",