@baleada/logic 0.22.7 → 0.23.0

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.
Files changed (4) hide show
  1. package/lib/index.cjs +2224 -508
  2. package/lib/index.d.ts +507 -73
  3. package/lib/index.js +2168 -500
  4. package/package.json +28 -16
package/lib/index.cjs CHANGED
@@ -1,52 +1,57 @@
1
1
  'use strict';
2
2
 
3
- var lazyCollections = require('lazy-collections');
4
- var slugify = require('@sindresorhus/slugify');
5
3
  var BezierEasing = require('bezier-easing');
6
4
  var color = require('@snigo.dev/color');
5
+ var lazyCollections = require('lazy-collections');
7
6
  var perfectFreehand = require('perfect-freehand');
8
7
  var polygonClipping = require('polygon-clipping');
8
+ var ky = require('ky');
9
9
  var createDOMPurify = require('dompurify');
10
10
  var fastFuzzy = require('fast-fuzzy');
11
+ var klona = require('klona');
12
+ var dequal = require('dequal');
13
+ var slugify = require('@sindresorhus/slugify');
14
+ var clsx = require('clsx');
11
15
 
12
- function createReduceAsync(accumulate, initialValue) {
13
- return async (array) => {
14
- return await lazyCollections.reduce(
15
- async (accumulatorPromise, item, index) => {
16
- const accumulator = await accumulatorPromise;
17
- return accumulate(accumulator, item, index);
18
- },
19
- Promise.resolve(initialValue)
20
- )(array);
16
+ function createClone() {
17
+ return (any) => {
18
+ return klona.klona(any);
21
19
  };
22
20
  }
23
- function createReduce(accumulate, initialValue) {
24
- return (array) => lazyCollections.reduce(accumulate, initialValue)(array);
21
+ function createEqual(compared) {
22
+ return (any) => dequal.dequal(any, compared);
25
23
  }
26
- function createForEachAsync(forEach) {
27
- return async (array) => {
28
- await createReduceAsync(async (_, item, index) => await forEach(item, index))(array);
29
- return array;
30
- };
24
+
25
+ function createConcat(...arrays) {
26
+ return (array) => lazyCollections.pipe(
27
+ lazyCollections.concat(array, ...arrays),
28
+ lazyCollections.toArray()
29
+ )();
31
30
  }
32
- function createMapAsync(transform) {
33
- return async (array) => {
34
- return await createReduceAsync(
35
- async (resolvedMaps, item, index) => {
36
- const transformed = await transform(item, index);
37
- resolvedMaps.push(transformed);
38
- return resolvedMaps;
39
- },
40
- []
41
- )(array);
42
- };
31
+ function createFilter(predicate) {
32
+ return (array) => lazyCollections.pipe(
33
+ lazyCollections.filter(predicate),
34
+ lazyCollections.toArray()
35
+ )(array);
43
36
  }
44
- function createFilterAsync(predicate) {
45
- return async (array) => {
46
- const transformedAsync = await createMapAsync(predicate)(array);
47
- return createFilter((_, index) => transformedAsync[index])(array);
37
+ function createInsert(item, index) {
38
+ return (array) => {
39
+ const withItems = createConcat(array, [item])([]);
40
+ return createReorder(
41
+ { start: array.length, itemCount: 1 },
42
+ index
43
+ )(withItems);
48
44
  };
49
45
  }
46
+ function createMap(transform) {
47
+ return (array) => lazyCollections.pipe(
48
+ lazyCollections.map(transform),
49
+ lazyCollections.toArray()
50
+ )(array);
51
+ }
52
+ function createReduce(accumulate, initialValue) {
53
+ return (array) => lazyCollections.reduce(accumulate, initialValue)(array);
54
+ }
50
55
  function createRemove(index) {
51
56
  return (array) => {
52
57
  return createConcat(
@@ -55,15 +60,6 @@ function createRemove(index) {
55
60
  )([]);
56
61
  };
57
62
  }
58
- function createInsert(item, index) {
59
- return (array) => {
60
- const withItems = createConcat(array, [item])([]);
61
- return createReorder(
62
- { start: array.length, itemCount: 1 },
63
- index
64
- )(withItems);
65
- };
66
- }
67
63
  function createReorder(from, to) {
68
64
  return (array) => {
69
65
  const [itemsToMoveStartIndex, itemsToMoveCount] = predicateObject(from) ? [from.start, from.itemCount] : [from, 1], insertIndex = to;
@@ -92,8 +88,34 @@ function createReorder(from, to) {
92
88
  return array;
93
89
  };
94
90
  }
95
- function predicateObject(value) {
96
- return typeof value === "object";
91
+ function createReplace(index, replacement) {
92
+ return createMap((item, i) => i === index ? replacement : item);
93
+ }
94
+ function createReverse() {
95
+ return (array) => {
96
+ const reversed = [];
97
+ for (let i = array.length - 1; i > -1; i--) {
98
+ reversed.push(array[i]);
99
+ }
100
+ return reversed;
101
+ };
102
+ }
103
+ function createSlice(from, to) {
104
+ const toSliced = to ? lazyCollections.slice(from, to - 1) : lazyCollections.slice(from);
105
+ return (array) => {
106
+ return from === to ? [] : lazyCollections.pipe(
107
+ toSliced,
108
+ lazyCollections.toArray()
109
+ )(array);
110
+ };
111
+ }
112
+ function createSort(compare) {
113
+ return (array) => {
114
+ return lazyCollections.pipe(
115
+ lazyCollections.sort(compare),
116
+ lazyCollections.toArray()
117
+ )(array);
118
+ };
97
119
  }
98
120
  function createSwap(indices) {
99
121
  return (array) => {
@@ -115,16 +137,7 @@ function createSwap(indices) {
115
137
  reorderTo: (array2) => array2
116
138
  };
117
139
  })();
118
- return new Pipeable(array).pipe(reorderFrom, reorderTo);
119
- };
120
- }
121
- function createReplace(index, item) {
122
- return (array) => {
123
- return createConcat(
124
- createSlice(0, index)(array),
125
- [item],
126
- createSlice(index + 1)(array)
127
- )([]);
140
+ return lazyCollections.pipe(reorderFrom, reorderTo)(array);
128
141
  };
129
142
  }
130
143
  function createUnique() {
@@ -133,277 +146,1986 @@ function createUnique() {
133
146
  lazyCollections.toArray()
134
147
  )(array);
135
148
  }
136
- function createSlice(from, to) {
137
- return (array) => {
138
- return from === to ? [] : lazyCollections.pipe(
139
- lazyCollections.slice(from, to - 1),
140
- lazyCollections.toArray()
149
+
150
+ function createFilterAsync(predicate) {
151
+ return async (array) => {
152
+ const transformedAsync = await createMapAsync(predicate)(array);
153
+ return createFilter((_, index) => transformedAsync[index])(array);
154
+ };
155
+ }
156
+ function createFindAsync(predicate) {
157
+ return async (array) => {
158
+ for (let i = 0; i < array.length; i++) {
159
+ const item = array[i], is = await predicate(item, i);
160
+ if (is)
161
+ return item;
162
+ }
163
+ };
164
+ }
165
+ function createFindIndexAsync(predicate) {
166
+ return async (array) => {
167
+ for (let i = 0; i < array.length; i++) {
168
+ const item = array[i], is = await predicate(item, i);
169
+ if (is)
170
+ return i;
171
+ }
172
+ };
173
+ }
174
+ function createForEachAsync(forEach) {
175
+ return async (array) => {
176
+ for (let i = 0; i < array.length; i++) {
177
+ const item = array[i];
178
+ await forEach(item, i);
179
+ }
180
+ return array;
181
+ };
182
+ }
183
+ function createMapAsync(transform) {
184
+ return async (array) => {
185
+ return await createReduceAsync(
186
+ async (resolvedMaps, item, index) => {
187
+ const transformed = await transform(item, index);
188
+ resolvedMaps.push(transformed);
189
+ return resolvedMaps;
190
+ },
191
+ []
141
192
  )(array);
142
193
  };
143
194
  }
144
- function createFilter(predicate) {
145
- return (array) => lazyCollections.pipe(
146
- lazyCollections.filter(predicate),
147
- lazyCollections.toArray()
148
- )(array);
195
+ function createReduceAsync(accumulate, initialValue) {
196
+ return async (array) => {
197
+ return await lazyCollections.reduce(
198
+ async (accumulatorPromise, item, index) => {
199
+ const accumulator = await accumulatorPromise;
200
+ return accumulate(accumulator, item, index);
201
+ },
202
+ Promise.resolve(initialValue)
203
+ )(array);
204
+ };
149
205
  }
150
- function createMap(transform) {
151
- return (array) => lazyCollections.pipe(
152
- lazyCollections.map(transform),
153
- lazyCollections.toArray()
154
- )(array);
206
+
207
+ function createClip(required) {
208
+ return (string) => {
209
+ return string.replace(required, "");
210
+ };
155
211
  }
156
- function createConcat(...arrays) {
157
- return (array) => lazyCollections.pipe(
158
- lazyCollections.concat(array, ...arrays),
159
- lazyCollections.toArray()
160
- )();
212
+ function createSlug(options) {
213
+ return (string) => {
214
+ return slugify(string, options);
215
+ };
161
216
  }
162
- function createReverse() {
163
- return (array) => {
164
- const reversed = [];
165
- for (let i = array.length - 1; i > -1; i--) {
166
- reversed.push(array[i]);
217
+
218
+ function createClamp(min, max) {
219
+ return (number) => {
220
+ const maxed = Math.max(number, min);
221
+ return Math.min(maxed, max);
222
+ };
223
+ }
224
+ function createDetermine(potentialities) {
225
+ const predicates = createMap(({ outcome, probability }, index) => {
226
+ const lowerBound = index === 0 ? 0 : lazyCollections.pipe(
227
+ lazyCollections.slice(0, index - 1),
228
+ lazyCollections.reduce((lowerBound2, { probability: probability2 }) => lowerBound2 + probability2, 0)
229
+ )(potentialities), upperBound = lowerBound + probability;
230
+ return {
231
+ outcome,
232
+ predicate: (determinant) => determinant >= lowerBound && determinant < upperBound || determinant < 0 && index === 0 || index === predicates.length - 1
233
+ };
234
+ })(potentialities);
235
+ return (determinant) => lazyCollections.find(({ predicate }) => predicate(determinant))(predicates).outcome;
236
+ }
237
+
238
+ function createEntries() {
239
+ return (object) => {
240
+ const entries = [];
241
+ for (const key in object) {
242
+ entries.push([key, object[key]]);
243
+ }
244
+ return entries;
245
+ };
246
+ }
247
+ function createKeys() {
248
+ return (object) => {
249
+ const keys = [];
250
+ for (const key in object) {
251
+ keys.push(key);
252
+ }
253
+ return keys;
254
+ };
255
+ }
256
+ function createEvery(predicate) {
257
+ return (object) => {
258
+ for (const key in object) {
259
+ if (!predicate(key, object[key])) {
260
+ return false;
261
+ }
262
+ }
263
+ return true;
264
+ };
265
+ }
266
+ function createSome(predicate) {
267
+ return (object) => {
268
+ for (const key in object) {
269
+ if (predicate(key, object[key]))
270
+ return true;
271
+ }
272
+ return false;
273
+ };
274
+ }
275
+
276
+ function createRename(from, to) {
277
+ return (map) => {
278
+ const keys = [...map.keys()], keyToRenameIndex = lazyCollections.findIndex((k) => k === from)(keys), newKeys = createReplace(keyToRenameIndex, to)(keys), values = [...map.values()];
279
+ return createReduce((renamed, key, index) => renamed.set(key, values[index]), /* @__PURE__ */ new Map())(newKeys);
280
+ };
281
+ }
282
+
283
+ const defaultOptions$m = {
284
+ elementIsCandidate: false,
285
+ // Adapted from React Aria https://github.com/adobe/react-spectrum/blob/b6786da906973130a1746b2bee63215bba013ca4/packages/%40react-aria/focus/src/FocusScope.tsx#L256
286
+ tabbableSelector: lazyCollections.join(':not([hidden]):not([tabindex="-1"]),')([
287
+ "input:not([disabled]):not([type=hidden])",
288
+ "select:not([disabled])",
289
+ "textarea:not([disabled])",
290
+ "button:not([disabled])",
291
+ "a[href]",
292
+ "area[href]",
293
+ "summary",
294
+ "iframe",
295
+ "object",
296
+ "embed",
297
+ "audio[controls]",
298
+ "video[controls]",
299
+ "[contenteditable]",
300
+ "[tabindex]:not([disabled])"
301
+ ])
302
+ };
303
+ function createFocusable(order, options = {}) {
304
+ const { elementIsCandidate, tabbableSelector } = { ...defaultOptions$m, ...options }, predicateFocusable = (element) => element.matches(tabbableSelector);
305
+ return (element) => {
306
+ if (elementIsCandidate && predicateFocusable(element))
307
+ return element;
308
+ switch (order) {
309
+ case "first":
310
+ for (let i = 0; i < element.children.length; i++) {
311
+ const focusable = createFocusable(order, { elementIsCandidate: true })(element.children[i]);
312
+ if (focusable)
313
+ return focusable;
314
+ }
315
+ break;
316
+ case "last":
317
+ for (let i = element.children.length - 1; i > -1; i--) {
318
+ const focusable = createFocusable(order, { elementIsCandidate: true })(element.children[i]);
319
+ if (focusable)
320
+ return focusable;
321
+ }
322
+ break;
323
+ }
324
+ };
325
+ }
326
+
327
+ function createToIndegree(graph) {
328
+ const toIncoming = createToIncoming(graph);
329
+ return (node) => lazyCollections.pipe(
330
+ toIncoming,
331
+ toLength()
332
+ )(node);
333
+ }
334
+ function createToOutdegree(graph) {
335
+ const toOutgoing = createToOutgoing(graph);
336
+ return (node) => lazyCollections.pipe(
337
+ toOutgoing,
338
+ toLength()
339
+ )(node);
340
+ }
341
+ function createToIncoming(graph) {
342
+ const { edges } = graph;
343
+ return function* (node) {
344
+ yield* lazyCollections.filter(
345
+ ({ to }) => to === node
346
+ )(edges);
347
+ };
348
+ }
349
+ function createToOutgoing(graph) {
350
+ const { edges } = graph;
351
+ return function* (node) {
352
+ yield* lazyCollections.filter(
353
+ ({ from }) => from === node
354
+ )(edges);
355
+ };
356
+ }
357
+ function createPredicateRoot(graph) {
358
+ const toIndegree = createToIndegree(graph);
359
+ return (node) => toIndegree(node) === 0;
360
+ }
361
+
362
+ function createFind(node) {
363
+ return (tree) => {
364
+ for (const treeNode of tree) {
365
+ if (treeNode.node === node)
366
+ return treeNode;
367
+ const found = createFind(node)(treeNode.children);
368
+ if (found)
369
+ return found;
370
+ }
371
+ };
372
+ }
373
+
374
+ function createToLayers$1(options = {}) {
375
+ const toSteps = createToSteps$2(options.createToSteps);
376
+ return function toLayers(directedAcyclic) {
377
+ const layers = [];
378
+ for (const { path } of toSteps(directedAcyclic)) {
379
+ const node = path.at(-1), depth = path.length - 1;
380
+ (layers[depth] || (layers[depth] = [])).push(node);
381
+ }
382
+ return layers;
383
+ };
384
+ }
385
+ function createToTree$2(options = {}) {
386
+ const toSteps = createToSteps$2(options.createToSteps);
387
+ return function toTree(directedAcyclic) {
388
+ const firstRoot = lazyCollections.pipe(
389
+ createToRoots(),
390
+ lazyCollections.at(0)
391
+ )(directedAcyclic), tree = [];
392
+ tree.push({
393
+ node: firstRoot,
394
+ children: []
395
+ });
396
+ for (const { path } of toSteps(directedAcyclic)) {
397
+ const node = path.at(-1), parent = path.at(-2);
398
+ if (parent) {
399
+ const parentTreeNode = createFind(parent)(tree);
400
+ if (parentTreeNode) {
401
+ parentTreeNode.children.push({
402
+ node,
403
+ children: []
404
+ });
405
+ }
406
+ }
407
+ }
408
+ return tree;
409
+ };
410
+ }
411
+ function createToCommonAncestors$2(directedAcyclic) {
412
+ const toNodeSteps = createToNodeSteps$2(directedAcyclic);
413
+ return function* (a, b) {
414
+ for (const { path: aPath } of toNodeSteps(a)) {
415
+ for (const { path: bPath } of toNodeSteps(b)) {
416
+ for (let aPathIndex = aPath.length - 1; aPathIndex >= 0; aPathIndex--) {
417
+ for (let bPathIndex = bPath.length - 1; bPathIndex >= 0; bPathIndex--) {
418
+ if (aPath[aPathIndex] === bPath[bPathIndex] && !lazyCollections.includes(aPath[aPathIndex])([a, b])) {
419
+ yield {
420
+ node: aPath[aPathIndex],
421
+ distances: {
422
+ [a]: aPath.length - aPathIndex - 1,
423
+ [b]: bPath.length - bPathIndex - 1
424
+ }
425
+ };
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+ };
432
+ }
433
+ function createPredicateAncestor$2(directedAcyclic) {
434
+ const toNodeSteps = createToNodeSteps$2(directedAcyclic);
435
+ return function(descendant, ancestor) {
436
+ return lazyCollections.pipe(
437
+ toNodeSteps,
438
+ lazyCollections.some(({ path }) => lazyCollections.includes(ancestor)(path))
439
+ )(descendant);
440
+ };
441
+ }
442
+ function createToNodeSteps$2(directedAcyclic, options = {}) {
443
+ const toSteps = createToSteps$2(options.createToSteps);
444
+ return function* (node) {
445
+ yield* lazyCollections.pipe(
446
+ toSteps,
447
+ lazyCollections.filter(({ path }) => path.at(-1) === node)
448
+ )(directedAcyclic);
449
+ };
450
+ }
451
+ const defaultCreateToStepsOptions$1 = {
452
+ toUnsetMetadata: () => 0,
453
+ toMockMetadata: (node, totalConnectionsFollowed) => totalConnectionsFollowed,
454
+ kind: "directed acyclic"
455
+ };
456
+ function createToSteps$2(options = {}) {
457
+ const { toUnsetMetadata, toMockMetadata, root, kind } = { ...defaultCreateToStepsOptions$1, ...options };
458
+ return function* (directedAcyclic) {
459
+ const { nodes } = directedAcyclic, toOutdegree = createToOutdegree(directedAcyclic), toPath = createToPath$2(directedAcyclic), roots = lazyCollections.pipe(
460
+ createToRoots({ kind }),
461
+ lazyCollections.toArray()
462
+ )(directedAcyclic), state = {}, totalConnectionsFollowedByNode = {}, predicateExhausted = (node) => {
463
+ return totalConnectionsFollowedByNode[node] === toOutdegree(node);
464
+ };
465
+ for (const node of nodes) {
466
+ state[node] = {
467
+ status: "unset",
468
+ metadata: toUnsetMetadata(node)
469
+ };
470
+ }
471
+ let location = root || lazyCollections.at(0)(roots);
472
+ const path = toPath(state);
473
+ yield { path, state: JSON.parse(JSON.stringify(state)) };
474
+ function* toStep() {
475
+ if (predicateExhausted(location)) {
476
+ if (lazyCollections.includes(location)(roots))
477
+ return;
478
+ state[location].status = "unset";
479
+ state[location].metadata = toUnsetMetadata(location);
480
+ const path3 = toPath(state);
481
+ location = path3.at(-2);
482
+ yield* toStep();
483
+ return;
484
+ }
485
+ if (!(location in totalConnectionsFollowedByNode))
486
+ totalConnectionsFollowedByNode[location] = 0;
487
+ state[location].status = "set";
488
+ state[location].metadata = toMockMetadata(location, totalConnectionsFollowedByNode[location]);
489
+ const path2 = toPath(state);
490
+ yield { path: path2, state: JSON.parse(JSON.stringify(state)) };
491
+ totalConnectionsFollowedByNode[location]++;
492
+ const newLocation = path2.at(-1);
493
+ if (toOutdegree(newLocation) > 0)
494
+ location = newLocation;
495
+ yield* toStep();
496
+ }
497
+ yield* toStep();
498
+ };
499
+ }
500
+ function createToPath$2(directedAcyclic) {
501
+ const toOutdegree = createToOutdegree(directedAcyclic), toOutgoing = createToOutgoing(directedAcyclic), firstRoot = lazyCollections.pipe(
502
+ createToRoots(),
503
+ lazyCollections.at(0)
504
+ )(directedAcyclic);
505
+ return (state) => {
506
+ const path = [firstRoot], getLastOutdegree = () => toOutdegree(path.at(-1)), getLastStatus = () => state[path.at(-1)].status;
507
+ while (getLastOutdegree() > 0 && getLastStatus() === "set") {
508
+ const edge = lazyCollections.pipe(
509
+ toOutgoing,
510
+ lazyCollections.find(
511
+ ({ predicateTraversable }) => predicateTraversable(state)
512
+ )
513
+ )(path.at(-1));
514
+ path.push(edge.to);
515
+ }
516
+ return path;
517
+ };
518
+ }
519
+ function createToRoots(options = {}) {
520
+ return function* (directedAcyclic) {
521
+ const { nodes } = directedAcyclic;
522
+ for (const node of nodes) {
523
+ if (createPredicateRoot(directedAcyclic)(node))
524
+ yield node;
525
+ if (options.kind === "arborescence")
526
+ break;
527
+ }
528
+ };
529
+ }
530
+
531
+ function createToLayers(options = {}) {
532
+ const toSteps = createToSteps$1(options.createToSteps);
533
+ return async function toLayers(directedAcyclic) {
534
+ const layers = [];
535
+ for await (const { path } of toSteps(directedAcyclic)) {
536
+ const node = path.at(-1), depth = path.length - 1;
537
+ (layers[depth] || (layers[depth] = [])).push(node);
538
+ }
539
+ return layers;
540
+ };
541
+ }
542
+ function createToTree$1(options = {}) {
543
+ const toSteps = createToSteps$1(options.createToSteps);
544
+ return async function toTree(directedAcyclic) {
545
+ const firstRoot = lazyCollections.pipe(
546
+ createToRoots(),
547
+ lazyCollections.at(0)
548
+ )(directedAcyclic), tree = [];
549
+ tree.push({
550
+ node: firstRoot,
551
+ children: []
552
+ });
553
+ for await (const { path } of toSteps(directedAcyclic)) {
554
+ const node = path.at(-1), parent = path.at(-2);
555
+ if (parent) {
556
+ const parentTreeNode = createFind(parent)(tree);
557
+ if (parentTreeNode) {
558
+ parentTreeNode.children.push({
559
+ node,
560
+ children: []
561
+ });
562
+ }
563
+ }
564
+ }
565
+ return tree;
566
+ };
567
+ }
568
+ function createToCommonAncestors$1(directedAcyclic) {
569
+ const toNodeSteps = createToNodeSteps$1(directedAcyclic);
570
+ return async function* (a, b) {
571
+ for await (const { path: aPath } of toNodeSteps(a)) {
572
+ for await (const { path: bPath } of toNodeSteps(b)) {
573
+ for (let aPathIndex = aPath.length - 1; aPathIndex >= 0; aPathIndex--) {
574
+ for (let bPathIndex = bPath.length - 1; bPathIndex >= 0; bPathIndex--) {
575
+ if (aPath[aPathIndex] === bPath[bPathIndex] && !lazyCollections.includes(aPath[aPathIndex])([a, b])) {
576
+ yield {
577
+ node: aPath[aPathIndex],
578
+ distances: {
579
+ [a]: aPath.length - aPathIndex - 1,
580
+ [b]: bPath.length - bPathIndex - 1
581
+ }
582
+ };
583
+ }
584
+ }
585
+ }
586
+ }
587
+ }
588
+ };
589
+ }
590
+ function createPredicateAncestor$1(directedAcyclic) {
591
+ const toNodeSteps = createToNodeSteps$1(directedAcyclic);
592
+ return async function(descendant, ancestor) {
593
+ return await lazyCollections.pipe(
594
+ toNodeSteps,
595
+ lazyCollections.some(({ path }) => lazyCollections.includes(ancestor)(path))
596
+ )(descendant);
597
+ };
598
+ }
599
+ function createToNodeSteps$1(directedAcyclic, options = {}) {
600
+ const toSteps = createToSteps$1(options.createToSteps);
601
+ return async function* (node) {
602
+ yield* await lazyCollections.pipe(
603
+ toSteps,
604
+ lazyCollections.filter(({ path }) => path.at(-1) === node)
605
+ )(directedAcyclic);
606
+ };
607
+ }
608
+ function createToSteps$1(options = {}) {
609
+ const { toUnsetMetadata, toMockMetadata, root, kind } = { ...defaultCreateToStepsOptions$1, ...options };
610
+ return async function* (directedAcyclic) {
611
+ const { nodes } = directedAcyclic, toOutdegree = createToOutdegree(directedAcyclic), toPath = createToPath$1(directedAcyclic), roots = lazyCollections.pipe(
612
+ createToRoots({ kind }),
613
+ lazyCollections.toArray()
614
+ )(directedAcyclic), state = {}, totalConnectionsFollowedByNode = {}, predicateExhausted = (node) => {
615
+ return totalConnectionsFollowedByNode[node] === toOutdegree(node);
616
+ };
617
+ for (const node of nodes) {
618
+ state[node] = {
619
+ status: "unset",
620
+ metadata: toUnsetMetadata(node)
621
+ };
622
+ }
623
+ let location = root || lazyCollections.at(0)(roots);
624
+ const path = await toPath(state);
625
+ yield { path, state: JSON.parse(JSON.stringify(state)) };
626
+ async function* toStep() {
627
+ if (predicateExhausted(location)) {
628
+ if (lazyCollections.includes(location)(roots))
629
+ return;
630
+ state[location].status = "unset";
631
+ state[location].metadata = toUnsetMetadata(location);
632
+ const path3 = await toPath(state);
633
+ location = path3.at(-2);
634
+ yield* await toStep();
635
+ return;
636
+ }
637
+ if (!(location in totalConnectionsFollowedByNode))
638
+ totalConnectionsFollowedByNode[location] = 0;
639
+ state[location].status = "set";
640
+ state[location].metadata = toMockMetadata(location, totalConnectionsFollowedByNode[location]);
641
+ const path2 = await toPath(state);
642
+ yield { path: path2, state: JSON.parse(JSON.stringify(state)) };
643
+ totalConnectionsFollowedByNode[location]++;
644
+ const newLocation = path2.at(-1);
645
+ if (toOutdegree(newLocation) > 0)
646
+ location = newLocation;
647
+ yield* await toStep();
648
+ }
649
+ yield* await toStep();
650
+ };
651
+ }
652
+ function createToPath$1(directedAcyclic) {
653
+ const toOutdegree = createToOutdegree(directedAcyclic), toOutgoing = createToOutgoing(directedAcyclic), firstRoot = lazyCollections.pipe(
654
+ createToRoots(),
655
+ lazyCollections.at(0)
656
+ )(directedAcyclic);
657
+ return async (state) => {
658
+ const path = [firstRoot], getLastOutdegree = () => toOutdegree(path.at(-1)), getLastStatus = () => state[path.at(-1)].status;
659
+ while (getLastOutdegree() > 0 && getLastStatus() === "set") {
660
+ const edge = await lazyCollections.pipe(
661
+ toOutgoing,
662
+ lazyCollections.toArray(),
663
+ createFindAsync(
664
+ async ({ predicateTraversable }) => await predicateTraversable(state)
665
+ )
666
+ )(path.at(-1));
667
+ path.push(edge.to);
668
+ }
669
+ return path;
670
+ };
671
+ }
672
+
673
+ const defaultCreateToStepsOptions = {
674
+ priorityBranch: false,
675
+ kind: "directed acyclic"
676
+ };
677
+ function createToTree(options = {}) {
678
+ const withDefaults = {
679
+ ...options,
680
+ createToSteps: {
681
+ ...defaultCreateToStepsOptions,
682
+ ...options.createToSteps
683
+ }
684
+ };
685
+ return createToTree$2({
686
+ ...withDefaults,
687
+ createToSteps: toCreateDirectedAcyclicToStepsOptions(withDefaults.createToSteps)
688
+ });
689
+ }
690
+ function createToCommonAncestors(...params) {
691
+ return createToCommonAncestors$2(...params);
692
+ }
693
+ function createPredicateAncestor(...params) {
694
+ return createPredicateAncestor$2(...params);
695
+ }
696
+ function createToNodeSteps(decisionTree, options = {}) {
697
+ const withDefaults = {
698
+ ...options,
699
+ createToSteps: {
700
+ ...defaultCreateToStepsOptions,
701
+ ...options.createToSteps
702
+ }
703
+ };
704
+ return createToNodeSteps$2(
705
+ decisionTree,
706
+ {
707
+ ...withDefaults,
708
+ createToSteps: toCreateDirectedAcyclicToStepsOptions(withDefaults.createToSteps)
709
+ }
710
+ );
711
+ }
712
+ function createToSteps(options = {}) {
713
+ const withDefaults = {
714
+ ...defaultCreateToStepsOptions,
715
+ ...options
716
+ };
717
+ return createToSteps$2(
718
+ toCreateDirectedAcyclicToStepsOptions(withDefaults)
719
+ );
720
+ }
721
+ function createToPath(...params) {
722
+ return createToPath$2(...params);
723
+ }
724
+ function toCreateDirectedAcyclicToStepsOptions(options) {
725
+ return {
726
+ ...defaultCreateToStepsOptions,
727
+ ...options,
728
+ ...{
729
+ toUnsetMetadata: () => false,
730
+ toMockMetadata: (node, totalConnectionsFollowed) => options.priorityBranch ? !totalConnectionsFollowed : !!totalConnectionsFollowed
731
+ }
732
+ };
733
+ }
734
+
735
+ function createList() {
736
+ return (...classValues) => clsx(...classValues);
737
+ }
738
+
739
+ const defaultOptions$l = {
740
+ toId: (node) => node.id,
741
+ toChildren: (node) => node.children
742
+ };
743
+ function createToGraph(options = {}) {
744
+ const { toId, toChildren } = { ...defaultOptions$l, ...options };
745
+ return function* (tree) {
746
+ const root = tree[0], rootId = toId(root);
747
+ function* toPair(node, id) {
748
+ const children = toChildren(node) || [];
749
+ for (const child of children) {
750
+ const childId = toId(child);
751
+ yield {
752
+ node: childId,
753
+ edge: { from: id, to: childId }
754
+ };
755
+ yield* toPair(child, childId);
756
+ }
757
+ }
758
+ yield { node: rootId };
759
+ yield* toPair(root, rootId);
760
+ };
761
+ }
762
+
763
+ const defaultOptions$k = {
764
+ toKey: (alias) => fromAliasToKeyStatusKey(alias)
765
+ };
766
+ const createPredicateKeycomboMatch$1 = (keycombo, options = {}) => {
767
+ const { toKey } = { ...defaultOptions$k, ...options }, keys = lazyCollections.pipe(
768
+ fromComboToAliases,
769
+ lazyCollections.map(toKey)
770
+ )(keycombo);
771
+ return (event) => {
772
+ const { toValue, set } = createKeyStatuses();
773
+ set(fromEventToKeyStatusKey(event), "down");
774
+ for (const modifier of modifiers) {
775
+ if (event[`${modifier.toLowerCase()}Key`])
776
+ set({ key: modifier }, "down");
777
+ }
778
+ return lazyCollections.every(lazyCollections.pipe(
779
+ toValue,
780
+ predicateDown
781
+ ))(keys);
782
+ };
783
+ };
784
+
785
+ const defaultOptions$j = {
786
+ initial: [],
787
+ createPredicateKey: (query) => (candidate) => query === candidate
788
+ };
789
+ function createAssociativeArray(options = {}) {
790
+ const { initial, createPredicateKey } = { ...defaultOptions$j, ...options }, entries = [...initial];
791
+ const toValue = (key) => {
792
+ const predicateKey = createPredicateKey(key);
793
+ return lazyCollections.find(
794
+ ([candidate]) => predicateKey(candidate)
795
+ )(entries)?.[1];
796
+ };
797
+ const set = (key, value) => {
798
+ const predicateKey = createPredicateKey(key), index = lazyCollections.findIndex(
799
+ ([candidate]) => predicateKey(candidate)
800
+ )(entries);
801
+ if (index === -1) {
802
+ entries.push([key, value]);
803
+ return;
804
+ }
805
+ entries[index][1] = value;
806
+ };
807
+ const predicateHas = (key) => {
808
+ const predicateKey = createPredicateKey(key);
809
+ return lazyCollections.findIndex(
810
+ ([candidate]) => predicateKey(candidate)
811
+ )(entries) !== -1;
812
+ };
813
+ const clear = () => {
814
+ entries.length = 0;
815
+ };
816
+ const del = (key) => {
817
+ const predicateKey = createPredicateKey(key), index = lazyCollections.findIndex(
818
+ ([candidate]) => predicateKey(candidate)
819
+ )(entries);
820
+ if (index === -1) {
821
+ return false;
822
+ }
823
+ entries.splice(index, 1);
824
+ return true;
825
+ };
826
+ const toKeys = () => {
827
+ return createMap(([key]) => key)(entries);
828
+ };
829
+ const toValues = () => {
830
+ return createMap(([, value]) => value)(entries);
831
+ };
832
+ const toEntries = () => {
833
+ return entries;
834
+ };
835
+ return {
836
+ toValue,
837
+ set,
838
+ predicateHas,
839
+ clear,
840
+ delete: del,
841
+ toKeys,
842
+ toValues,
843
+ toEntries
844
+ // get: toValue,
845
+ // has: predicateHas,
846
+ // keys: toKeys,
847
+ // values: toValues,
848
+ };
849
+ }
850
+
851
+ const defaultOptions$i = {
852
+ minDuration: 0,
853
+ preventsDefaultUnlessDenied: true,
854
+ toKey: (alias) => fromAliasToKeyStatusKey(alias),
855
+ toAliases: (event) => fromEventToAliases(event)
856
+ };
857
+ function createKeypress(keycomboOrKeycombos, options = {}) {
858
+ const {
859
+ minDuration,
860
+ preventsDefaultUnlessDenied,
861
+ toKey,
862
+ toAliases,
863
+ onDown,
864
+ onUp,
865
+ onVisibilitychange
866
+ } = { ...defaultOptions$i, ...options }, {
867
+ matchPredicatesByKeycombo,
868
+ getDownCombos,
869
+ predicateValid,
870
+ cleanup,
871
+ statuses
872
+ } = createKeyState({
873
+ keycomboOrKeycombos,
874
+ unsupportedAliases: unsupportedAliases$2,
875
+ toKey,
876
+ toAliases,
877
+ getRequest: () => request
878
+ });
879
+ let request;
880
+ let localStatus;
881
+ const keydown = (event, api) => {
882
+ const { denied, getStatus } = api, key = fromEventToKeyStatusKey(event);
883
+ if (statuses.toValue(key) === "down") {
884
+ onDown?.(toHookApi(api));
885
+ return;
886
+ }
887
+ statuses.set(key, "down");
888
+ if (localStatus === "denied") {
889
+ denied();
890
+ onDown?.(toHookApi(api));
891
+ return;
892
+ }
893
+ const downCombos = getDownCombos();
894
+ if (
895
+ // NOT BUILDING VALID COMBO
896
+ !predicateValid(event) || downCombos.length > 1 && fromComboToAliasesLength(downCombos[0]) === fromComboToAliasesLength(downCombos[1])
897
+ ) {
898
+ denied();
899
+ localStatus = getStatus();
900
+ if (lazyCollections.includes(event.key)(unsupportedKeys$2))
901
+ statuses.clear();
902
+ onDown?.(toHookApi(api));
903
+ return;
904
+ }
905
+ if (preventsDefaultUnlessDenied)
906
+ event.preventDefault();
907
+ const { getMetadata } = api, metadata = getMetadata();
908
+ metadata.pressed = downCombos[0];
909
+ localStatus = "recognizing";
910
+ cleanup();
911
+ storeKeyboardTimeMetadata({
912
+ event,
913
+ api,
914
+ getTimeMetadata: getMetadata,
915
+ getShouldStore: () => downCombos.length && getDownCombos()[0] === downCombos[0],
916
+ setRequest: (newRequest) => request = newRequest,
917
+ recognize
918
+ });
919
+ onDown?.(toHookApi(api));
920
+ };
921
+ const recognize = (event, api) => {
922
+ const { getMetadata, recognized } = api, metadata = getMetadata();
923
+ if (metadata.duration >= minDuration) {
924
+ recognized();
925
+ localStatus = "recognized";
926
+ return;
927
+ }
928
+ };
929
+ const keyup = (event, api) => {
930
+ const { denied } = api, key = fromEventToKeyStatusKey(event);
931
+ if (localStatus === "denied") {
932
+ denied();
933
+ if (lazyCollections.includes(event.key)(unsupportedKeys$2))
934
+ statuses.clear();
935
+ else
936
+ statuses.delete(key);
937
+ if (!predicateSomeKeyDown(statuses))
938
+ localStatus = "recognizing";
939
+ onUp?.(toHookApi(api));
940
+ return;
941
+ }
942
+ statuses.delete(key);
943
+ const downCombos = getDownCombos(), matches = matchPredicatesByKeycombo[downCombos[0]]?.(statuses);
944
+ if (downCombos.length && matches) {
945
+ const { getMetadata } = api, metadata = getMetadata();
946
+ metadata.pressed = downCombos[0];
947
+ if (preventsDefaultUnlessDenied)
948
+ event.preventDefault();
949
+ localStatus = "recognizing";
950
+ onUp?.(toHookApi(api));
951
+ return;
952
+ }
953
+ denied();
954
+ cleanup();
955
+ onUp?.(toHookApi(api));
956
+ };
957
+ const visibilitychange = (event, api) => {
958
+ if (document.visibilityState === "hidden") {
959
+ statuses.clear();
960
+ localStatus = "recognizing";
961
+ cleanup();
962
+ }
963
+ onVisibilitychange?.(toHookApi(api));
964
+ };
965
+ return {
966
+ keydown,
967
+ keyup,
968
+ visibilitychange
969
+ };
970
+ }
971
+ const unsupportedAliases$2 = ["meta", "command", "cmd"];
972
+ const unsupportedKeys$2 = ["Meta"];
973
+
974
+ const defaultOptions$h = {
975
+ minDuration: 0,
976
+ preventsDefaultUnlessDenied: true,
977
+ toKey: (alias) => fromAliasToKeyStatusKey(alias),
978
+ toAliases: (event) => fromEventToAliases(event)
979
+ };
980
+ function createKeyrelease(keycomboOrKeycombos, options = {}) {
981
+ const {
982
+ minDuration,
983
+ preventsDefaultUnlessDenied,
984
+ toKey,
985
+ toAliases,
986
+ onDown,
987
+ onUp,
988
+ onVisibilitychange
989
+ } = { ...defaultOptions$h, ...options }, {
990
+ matchPredicatesByKeycombo,
991
+ getDownCombos,
992
+ predicateValid,
993
+ cleanup,
994
+ statuses
995
+ } = createKeyState({
996
+ keycomboOrKeycombos,
997
+ unsupportedAliases: unsupportedAliases$1,
998
+ toKey,
999
+ toAliases,
1000
+ getRequest: () => request
1001
+ });
1002
+ let request, localStatus;
1003
+ const keydown = (event, api) => {
1004
+ const { denied, getStatus } = api, key = fromEventToKeyStatusKey(event);
1005
+ if (statuses.toValue(key) === "down") {
1006
+ onDown?.(toHookApi(api));
1007
+ return;
1008
+ }
1009
+ statuses.set(key, "down");
1010
+ if (localStatus === "denied") {
1011
+ denied();
1012
+ onDown?.(toHookApi(api));
1013
+ return;
1014
+ }
1015
+ const downCombos = getDownCombos();
1016
+ if (
1017
+ // NOT BUILDING VALID COMBO
1018
+ !predicateValid(event) || downCombos.length > 1 && fromComboToAliasesLength(downCombos[0]) === fromComboToAliasesLength(downCombos[1])
1019
+ ) {
1020
+ denied();
1021
+ localStatus = getStatus();
1022
+ if (lazyCollections.includes(event.key)(unsupportedKeys$1))
1023
+ statuses.clear();
1024
+ onDown?.(toHookApi(api));
1025
+ return;
1026
+ }
1027
+ if (preventsDefaultUnlessDenied)
1028
+ event.preventDefault();
1029
+ const { getMetadata } = api;
1030
+ localStatus = "recognizing";
1031
+ cleanup();
1032
+ storeKeyboardTimeMetadata({
1033
+ event,
1034
+ api,
1035
+ getTimeMetadata: getMetadata,
1036
+ getShouldStore: () => downCombos.length && getDownCombos()[0] === downCombos[0],
1037
+ setRequest: (newRequest) => request = newRequest
1038
+ });
1039
+ onDown?.(toHookApi(api));
1040
+ };
1041
+ const keyup = (event, api) => {
1042
+ const {
1043
+ getStatus,
1044
+ getMetadata,
1045
+ denied
1046
+ } = api, metadata = getMetadata(), key = fromEventToKeyStatusKey(event);
1047
+ if (["denied", "recognized"].includes(localStatus)) {
1048
+ if (localStatus === "denied")
1049
+ denied();
1050
+ if (lazyCollections.includes(event.key)(unsupportedKeys$1))
1051
+ statuses.clear();
1052
+ else
1053
+ statuses.delete(key);
1054
+ if (!predicateSomeKeyDown(statuses))
1055
+ localStatus = "recognizing";
1056
+ onUp?.(toHookApi(api));
1057
+ return;
1058
+ }
1059
+ const downCombos = getDownCombos(), matches = matchPredicatesByKeycombo[downCombos[0]]?.(statuses);
1060
+ statuses.delete(key);
1061
+ if (!downCombos.length || !matches) {
1062
+ onUp?.(toHookApi(api));
1063
+ return;
1064
+ }
1065
+ recognize(event, api);
1066
+ const status = getStatus();
1067
+ if (status === "recognized") {
1068
+ localStatus = status;
1069
+ metadata.released = downCombos[0];
1070
+ }
1071
+ if (preventsDefaultUnlessDenied)
1072
+ event.preventDefault();
1073
+ onUp?.(toHookApi(api));
1074
+ };
1075
+ const recognize = (event, api) => {
1076
+ const { getMetadata, recognized, denied } = api, metadata = getMetadata();
1077
+ if (metadata.duration < minDuration) {
1078
+ denied();
1079
+ return;
1080
+ }
1081
+ recognized();
1082
+ };
1083
+ const visibilitychange = (event, api) => {
1084
+ if (document.visibilityState === "hidden") {
1085
+ statuses.clear();
1086
+ localStatus = "recognizing";
1087
+ cleanup();
1088
+ }
1089
+ onVisibilitychange?.(toHookApi(api));
1090
+ };
1091
+ return {
1092
+ keydown,
1093
+ keyup,
1094
+ visibilitychange
1095
+ };
1096
+ }
1097
+ const unsupportedAliases$1 = ["meta", "command", "cmd"];
1098
+ const unsupportedKeys$1 = ["Meta"];
1099
+
1100
+ const defaultOptions$g = {
1101
+ minDuration: 0,
1102
+ maxInterval: 5e3,
1103
+ // VS Code default
1104
+ preventsDefaultUnlessDenied: true,
1105
+ toKey: (alias) => fromAliasToKeyStatusKey(alias),
1106
+ toAliases: (event) => fromEventToAliases(event)
1107
+ };
1108
+ function createKeychord(keychord, options = {}) {
1109
+ const {
1110
+ minDuration,
1111
+ maxInterval,
1112
+ preventsDefaultUnlessDenied,
1113
+ toKey,
1114
+ toAliases,
1115
+ onDown,
1116
+ onUp,
1117
+ onVisibilitychange
1118
+ } = { ...defaultOptions$g, ...options }, narrowedKeychord = keychord.split(" "), keyStates = createMap((keycombo) => createKeyState({
1119
+ keycomboOrKeycombos: keycombo,
1120
+ unsupportedAliases,
1121
+ toKey,
1122
+ toAliases,
1123
+ getRequest: () => request
1124
+ }))(narrowedKeychord), localStatuses = createMap(
1125
+ () => "recognizing"
1126
+ )(keyStates);
1127
+ let request, playedIndex = 0;
1128
+ const keydown = (event, api) => {
1129
+ const { denied, getStatus } = api, key = fromEventToKeyStatusKey(event);
1130
+ if (keyStates[playedIndex].statuses.toValue(key) === "down") {
1131
+ onDown?.(toHookApi(api));
1132
+ return;
1133
+ }
1134
+ if (localStatuses[playedIndex] === "recognized") {
1135
+ playedIndex++;
1136
+ for (const [key2, status] of keyStates[playedIndex - 1].statuses.toEntries()) {
1137
+ keyStates[playedIndex].statuses.set(key2, status);
1138
+ }
1139
+ }
1140
+ keyStates[playedIndex].statuses.set(key, "down");
1141
+ if (localStatuses[playedIndex] === "denied") {
1142
+ denied();
1143
+ onDown?.(toHookApi(api));
1144
+ return;
1145
+ }
1146
+ const { getMetadata } = api, metadata = getMetadata(), downCombos = keyStates[playedIndex].getDownCombos();
1147
+ if (playedIndex === 0)
1148
+ metadata.played = [];
1149
+ if (
1150
+ // NOT BUILDING VALID COMBO
1151
+ !keyStates[playedIndex].predicateValid(event) || downCombos.length > 1 && fromComboToAliasesLength(downCombos[0]) === fromComboToAliasesLength(downCombos[1]) || playedIndex > 0 && event.timeStamp - metadata.played[playedIndex - 1].times.end > maxInterval
1152
+ ) {
1153
+ denied();
1154
+ localStatuses[playedIndex] = getStatus();
1155
+ if (lazyCollections.includes(event.key)(unsupportedKeys)) {
1156
+ for (const { statuses } of keyStates)
1157
+ statuses.clear();
1158
+ }
1159
+ onDown?.(toHookApi(api));
1160
+ return;
1161
+ }
1162
+ if (preventsDefaultUnlessDenied)
1163
+ event.preventDefault();
1164
+ localStatuses[playedIndex] = "recognizing";
1165
+ keyStates[playedIndex].cleanup();
1166
+ storeKeyboardTimeMetadata({
1167
+ event,
1168
+ api,
1169
+ getTimeMetadata: () => {
1170
+ const metadata2 = getMetadata();
1171
+ return metadata2.played[playedIndex] || (metadata2.played[playedIndex] = {});
1172
+ },
1173
+ getShouldStore: () => downCombos.length && keyStates[playedIndex].getDownCombos()[0] === downCombos[0],
1174
+ setRequest: (newRequest) => request = newRequest
1175
+ });
1176
+ onDown?.(toHookApi(api));
1177
+ };
1178
+ const keyup = (event, api) => {
1179
+ const {
1180
+ getStatus,
1181
+ getMetadata,
1182
+ denied
1183
+ } = api, metadata = getMetadata(), key = fromEventToKeyStatusKey(event);
1184
+ if (["denied", "recognized"].includes(localStatuses[playedIndex])) {
1185
+ if (localStatuses[playedIndex] === "denied")
1186
+ denied();
1187
+ for (const { statuses } of keyStates) {
1188
+ if (lazyCollections.includes(event.key)(unsupportedKeys))
1189
+ statuses.clear();
1190
+ else
1191
+ statuses.delete(key);
1192
+ }
1193
+ if (!predicateSomeKeyDown(keyStates[playedIndex].statuses)) {
1194
+ if (localStatuses[playedIndex] === "denied" || playedIndex === narrowedKeychord.length - 1 && localStatuses[playedIndex] === "recognized") {
1195
+ playedIndex = 0;
1196
+ for (let i = 0; i < localStatuses.length; i++)
1197
+ localStatuses[i] = "recognizing";
1198
+ for (const { statuses } of keyStates)
1199
+ statuses.clear();
1200
+ }
1201
+ }
1202
+ onUp?.(toHookApi(api));
1203
+ return;
1204
+ }
1205
+ const downCombos = keyStates[playedIndex].getDownCombos(), matches = keyStates[playedIndex].matchPredicatesByKeycombo[downCombos[0]]?.(keyStates[playedIndex].statuses);
1206
+ keyStates[playedIndex].statuses.delete(key);
1207
+ if (!downCombos.length || !matches) {
1208
+ onUp?.(toHookApi(api));
1209
+ return;
1210
+ }
1211
+ recognize(event, api);
1212
+ const status = getStatus();
1213
+ if (status === "recognizing" && localStatuses[playedIndex] === "recognized" || status === "recognized") {
1214
+ metadata.played[playedIndex] = {
1215
+ ...metadata.played[playedIndex],
1216
+ released: downCombos[0]
1217
+ };
1218
+ }
1219
+ if (preventsDefaultUnlessDenied)
1220
+ event.preventDefault();
1221
+ if (playedIndex === narrowedKeychord.length - 1 && !predicateSomeKeyDown(keyStates[playedIndex].statuses)) {
1222
+ playedIndex = 0;
1223
+ for (let i = 0; i < localStatuses.length; i++)
1224
+ localStatuses[i] = "recognizing";
1225
+ for (const { statuses } of keyStates)
1226
+ statuses.clear();
1227
+ }
1228
+ onUp?.(toHookApi(api));
1229
+ };
1230
+ const recognize = (event, api) => {
1231
+ const { getMetadata, recognized, denied } = api, metadata = getMetadata();
1232
+ if (metadata.played[playedIndex].duration < minDuration) {
1233
+ denied();
1234
+ return;
1235
+ }
1236
+ if (playedIndex === narrowedKeychord.length - 1) {
1237
+ recognized();
1238
+ localStatuses[playedIndex] = "recognized";
1239
+ return;
1240
+ }
1241
+ localStatuses[playedIndex] = "recognized";
1242
+ };
1243
+ const visibilitychange = (event, api) => {
1244
+ if (document.visibilityState === "hidden") {
1245
+ for (const { statuses } of keyStates)
1246
+ statuses.clear();
1247
+ localStatuses[playedIndex] = "recognizing";
1248
+ keyStates[playedIndex].cleanup();
1249
+ playedIndex = 0;
1250
+ }
1251
+ onVisibilitychange?.(toHookApi(api));
1252
+ };
1253
+ return {
1254
+ keydown,
1255
+ keyup,
1256
+ visibilitychange
1257
+ };
1258
+ }
1259
+ const unsupportedAliases = ["meta", "command", "cmd"];
1260
+ const unsupportedKeys = ["Meta"];
1261
+
1262
+ const defaultOptions$f = {
1263
+ minDuration: 0,
1264
+ minDistance: 0,
1265
+ getMousemoveTarget: (event) => event.target
1266
+ };
1267
+ function createMousepress(options = {}) {
1268
+ const {
1269
+ minDuration,
1270
+ minDistance,
1271
+ getMousemoveTarget,
1272
+ onDown,
1273
+ onLeave,
1274
+ onMove,
1275
+ onUp
1276
+ } = { ...defaultOptions$f, ...options }, cleanup = (event) => {
1277
+ window.cancelAnimationFrame(request);
1278
+ getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1279
+ };
1280
+ let request;
1281
+ let mousemoveEffect;
1282
+ let mouseStatus;
1283
+ const mousedown = (event, api) => {
1284
+ mouseStatus = "down";
1285
+ mousemoveEffect = (event2) => mousemove(event2, api);
1286
+ storePointerStartMetadata(event, api);
1287
+ storePointerMoveMetadata(event, api);
1288
+ storePointerTimeMetadata(
1289
+ event,
1290
+ api,
1291
+ () => mouseStatus === "down",
1292
+ (newRequest) => request = newRequest,
1293
+ recognize
1294
+ );
1295
+ getMousemoveTarget(event).addEventListener("mousemove", mousemoveEffect);
1296
+ onDown?.(toHookApi(api));
1297
+ };
1298
+ const mousemove = (event, api) => {
1299
+ storePointerMoveMetadata(event, api);
1300
+ recognize(event, api);
1301
+ onMove?.(toHookApi(api));
1302
+ };
1303
+ const recognize = (event, api) => {
1304
+ const { getMetadata, recognized } = api, metadata = getMetadata();
1305
+ if (metadata.duration >= minDuration && metadata.distance.straight.fromStart >= minDistance) {
1306
+ recognized();
1307
+ }
1308
+ };
1309
+ const mouseleave = (event, api) => {
1310
+ const { denied } = api;
1311
+ if (mouseStatus === "down") {
1312
+ denied();
1313
+ cleanup(event);
1314
+ mouseStatus = "leave";
1315
+ }
1316
+ onLeave?.(toHookApi(api));
1317
+ };
1318
+ const mouseup = (event, api) => {
1319
+ const { denied } = api;
1320
+ if (mouseStatus !== "down")
1321
+ return;
1322
+ denied();
1323
+ cleanup(event);
1324
+ mouseStatus = "up";
1325
+ onUp?.(toHookApi(api));
1326
+ };
1327
+ return {
1328
+ mousedown,
1329
+ mouseleave,
1330
+ mouseup
1331
+ };
1332
+ }
1333
+
1334
+ const defaultOptions$e = {
1335
+ minDuration: 0,
1336
+ minDistance: 0,
1337
+ minVelocity: 0,
1338
+ getMousemoveTarget: (event) => event.target
1339
+ };
1340
+ function createMouserelease(options = {}) {
1341
+ const {
1342
+ minDuration,
1343
+ minDistance,
1344
+ minVelocity,
1345
+ getMousemoveTarget,
1346
+ onDown,
1347
+ onLeave,
1348
+ onMove,
1349
+ onUp
1350
+ } = { ...defaultOptions$e, ...options }, cleanup = (event) => {
1351
+ window.cancelAnimationFrame(request);
1352
+ getMousemoveTarget(event).removeEventListener("mousemove", mousemoveEffect);
1353
+ };
1354
+ let request;
1355
+ let mousemoveEffect;
1356
+ let mouseStatus;
1357
+ const mousedown = (event, api) => {
1358
+ mouseStatus = "down";
1359
+ mousemoveEffect = (event2) => mousemove(event2, api);
1360
+ storePointerStartMetadata(event, api);
1361
+ storePointerMoveMetadata(event, api);
1362
+ storePointerTimeMetadata(
1363
+ event,
1364
+ api,
1365
+ () => mouseStatus === "down",
1366
+ (newRequest) => request = newRequest
1367
+ );
1368
+ getMousemoveTarget(event).addEventListener("mousemove", mousemoveEffect);
1369
+ onDown?.(toHookApi(api));
1370
+ };
1371
+ const mousemove = (event, api) => {
1372
+ storePointerMoveMetadata(event, api);
1373
+ onMove?.(toHookApi(api));
1374
+ };
1375
+ const mouseleave = (event, api) => {
1376
+ const { denied } = api;
1377
+ if (mouseStatus === "down") {
1378
+ denied();
1379
+ cleanup(event);
1380
+ mouseStatus = "leave";
1381
+ }
1382
+ onLeave?.(toHookApi(api));
1383
+ };
1384
+ const mouseup = (event, api) => {
1385
+ if (mouseStatus !== "down")
1386
+ return;
1387
+ storePointerMoveMetadata(event, api);
1388
+ cleanup(event);
1389
+ mouseStatus = "up";
1390
+ recognize(event, api);
1391
+ onUp?.(toHookApi(api));
1392
+ };
1393
+ const recognize = (event, api) => {
1394
+ const { getMetadata, recognized, denied } = api, metadata = getMetadata();
1395
+ if (metadata.duration >= minDuration && metadata.distance.straight.fromStart >= minDistance && metadata.velocity >= minVelocity) {
1396
+ recognized();
1397
+ } else {
1398
+ denied();
1399
+ }
1400
+ };
1401
+ return {
1402
+ mousedown,
1403
+ mouseleave,
1404
+ mouseup
1405
+ };
1406
+ }
1407
+
1408
+ const defaultOptions$d = {
1409
+ minDuration: 0,
1410
+ minDistance: 0
1411
+ };
1412
+ function createTouchpress(options = {}) {
1413
+ const {
1414
+ minDuration,
1415
+ minDistance,
1416
+ onStart,
1417
+ onCancel,
1418
+ onMove,
1419
+ onEnd
1420
+ } = { ...defaultOptions$d, ...options }, cleanup = () => {
1421
+ window.cancelAnimationFrame(request);
1422
+ };
1423
+ let request;
1424
+ let totalTouches = 0;
1425
+ const touchstart = (event, api) => {
1426
+ const { denied } = api;
1427
+ totalTouches++;
1428
+ if (totalTouches > 1) {
1429
+ cleanup();
1430
+ denied();
1431
+ onStart?.(toHookApi(api));
1432
+ return;
1433
+ }
1434
+ storePointerStartMetadata(event, api);
1435
+ storePointerMoveMetadata(event, api);
1436
+ storePointerTimeMetadata(
1437
+ event,
1438
+ api,
1439
+ () => totalTouches === 1,
1440
+ (newRequest) => request = newRequest,
1441
+ recognize
1442
+ );
1443
+ onStart?.(toHookApi(api));
1444
+ };
1445
+ const touchmove = (event, api) => {
1446
+ const { getStatus } = api;
1447
+ if (getStatus() !== "denied") {
1448
+ storePointerMoveMetadata(event, api);
1449
+ recognize(event, api);
1450
+ }
1451
+ onMove?.(toHookApi(api));
1452
+ };
1453
+ const recognize = (event, api) => {
1454
+ const { getMetadata, recognized } = api, metadata = getMetadata();
1455
+ if (metadata.duration >= minDuration && metadata.distance.straight.fromStart >= minDistance) {
1456
+ recognized();
1457
+ }
1458
+ };
1459
+ const touchcancel = (event, api) => {
1460
+ const { denied } = api;
1461
+ cleanup();
1462
+ denied();
1463
+ totalTouches--;
1464
+ onCancel?.(toHookApi(api));
1465
+ };
1466
+ const touchend = (event, api) => {
1467
+ const { denied } = api;
1468
+ cleanup();
1469
+ denied();
1470
+ totalTouches--;
1471
+ onEnd?.(toHookApi(api));
1472
+ };
1473
+ return {
1474
+ touchstart,
1475
+ touchmove,
1476
+ touchcancel,
1477
+ touchend
1478
+ };
1479
+ }
1480
+
1481
+ const defaultOptions$c = {
1482
+ minDuration: 0,
1483
+ minDistance: 0,
1484
+ minVelocity: 0
1485
+ };
1486
+ function createTouchrelease(options = {}) {
1487
+ const {
1488
+ minDuration,
1489
+ minDistance,
1490
+ minVelocity,
1491
+ onStart,
1492
+ onCancel,
1493
+ onMove,
1494
+ onEnd
1495
+ } = { ...defaultOptions$c, ...options }, cleanup = () => {
1496
+ window.cancelAnimationFrame(request);
1497
+ };
1498
+ let request;
1499
+ let totalTouches = 0;
1500
+ const touchstart = (event, api) => {
1501
+ const { denied } = api;
1502
+ totalTouches++;
1503
+ if (totalTouches > 1) {
1504
+ cleanup();
1505
+ denied();
1506
+ onStart?.(toHookApi(api));
1507
+ return;
1508
+ }
1509
+ storePointerStartMetadata(event, api);
1510
+ storePointerMoveMetadata(event, api);
1511
+ storePointerTimeMetadata(
1512
+ event,
1513
+ api,
1514
+ () => totalTouches === 1,
1515
+ (newRequest) => request = newRequest
1516
+ );
1517
+ onStart?.(toHookApi(api));
1518
+ };
1519
+ const touchmove = (event, api) => {
1520
+ const { getStatus } = api;
1521
+ if (getStatus() !== "denied")
1522
+ storePointerMoveMetadata(event, api);
1523
+ onMove?.(toHookApi(api));
1524
+ };
1525
+ const touchcancel = (event, api) => {
1526
+ const { denied } = api;
1527
+ cleanup();
1528
+ denied();
1529
+ totalTouches--;
1530
+ onCancel?.(toHookApi(api));
1531
+ };
1532
+ const touchend = (event, api) => {
1533
+ const { denied } = api;
1534
+ if (totalTouches !== 1) {
1535
+ cleanup();
1536
+ denied();
1537
+ onEnd?.(toHookApi(api));
1538
+ return;
1539
+ }
1540
+ storePointerMoveMetadata(event, api);
1541
+ cleanup();
1542
+ totalTouches--;
1543
+ recognize(event, api);
1544
+ onEnd?.(toHookApi(api));
1545
+ };
1546
+ const recognize = (event, api) => {
1547
+ const { getMetadata, recognized, denied } = api, metadata = getMetadata();
1548
+ if (metadata.duration >= minDuration && metadata.distance.straight.fromStart >= minDistance && metadata.velocity >= minVelocity) {
1549
+ recognized();
1550
+ } else {
1551
+ denied();
1552
+ }
1553
+ };
1554
+ return {
1555
+ touchstart,
1556
+ touchmove,
1557
+ touchcancel,
1558
+ touchend
1559
+ };
1560
+ }
1561
+
1562
+ const defaultOptions$b = {
1563
+ initial: []
1564
+ };
1565
+ function createKeyStatuses(options = {}) {
1566
+ return createAssociativeArray({
1567
+ ...defaultOptions$b,
1568
+ ...options,
1569
+ createPredicateKey: (query) => (key) => {
1570
+ for (const prop in query) {
1571
+ if (query[prop] !== key[prop]) {
1572
+ return false;
1573
+ }
1574
+ }
1575
+ return true;
1576
+ }
1577
+ });
1578
+ }
1579
+ function predicateDown(status) {
1580
+ return status === "down";
1581
+ }
1582
+ function predicateSomeKeyDown(statuses) {
1583
+ return lazyCollections.includes("down")(statuses.toValues());
1584
+ }
1585
+
1586
+ function fromComboToAliases(combo) {
1587
+ const delimiter = "+";
1588
+ return lazyCollections.pipe(
1589
+ lazyCollections.unique(),
1590
+ lazyCollections.map((name) => name === "" ? delimiter : name.toLowerCase()),
1591
+ lazyCollections.toArray()
1592
+ )(combo.split(delimiter));
1593
+ }
1594
+
1595
+ function fromAliasToKeyStatusKey(alias) {
1596
+ if (alias in keysByAlias) {
1597
+ return { key: keysByAlias[alias] };
1598
+ }
1599
+ return {
1600
+ code: (() => {
1601
+ if (alias in codesByAlias)
1602
+ return codesByAlias[alias];
1603
+ if (letterRE.test(alias))
1604
+ return `Key${alias.toUpperCase()}`;
1605
+ if (digitRE.test(alias))
1606
+ return `Digit${alias}`;
1607
+ if (functionRE.test(alias))
1608
+ return alias.toUpperCase();
1609
+ return "unsupported";
1610
+ })()
1611
+ };
1612
+ }
1613
+ const digitRE = /^[0-9]$/;
1614
+ const letterRE = /^[a-zA-Z]$/;
1615
+ const functionRE = /^[fF][0-9]{1,2}$/;
1616
+ const codesByAlias = {
1617
+ "`": "Backquote",
1618
+ "~": "Backquote",
1619
+ "-": "Minus",
1620
+ _: "Minus",
1621
+ "=": "Equal",
1622
+ "+": "Equal",
1623
+ "[": "BracketLeft",
1624
+ "{": "BracketLeft",
1625
+ "]": "BracketRight",
1626
+ "}": "BracketRight",
1627
+ "\\": "Backslash",
1628
+ "|": "Backslash",
1629
+ ";": "Semicolon",
1630
+ ":": "Semicolon",
1631
+ "'": "Quote",
1632
+ '"': "Quote",
1633
+ ",": "Comma",
1634
+ "<": "Comma",
1635
+ ".": "Period",
1636
+ ">": "Period",
1637
+ "/": "Slash",
1638
+ "?": "Slash",
1639
+ "!": "Digit1",
1640
+ "@": "Digit2",
1641
+ "#": "Digit3",
1642
+ $: "Digit4",
1643
+ "%": "Digit5",
1644
+ "^": "Digit6",
1645
+ "&": "Digit7",
1646
+ "*": "Digit8",
1647
+ "(": "Digit9",
1648
+ ")": "Digit0",
1649
+ up: "ArrowUp",
1650
+ down: "ArrowDown",
1651
+ left: "ArrowLeft",
1652
+ right: "ArrowRight",
1653
+ enter: "Enter",
1654
+ space: "Space",
1655
+ tab: "Tab",
1656
+ esc: "Escape",
1657
+ backspace: "Backspace",
1658
+ delete: "Delete",
1659
+ home: "Home",
1660
+ end: "End",
1661
+ pagedown: "PageDown",
1662
+ pageup: "PageUp",
1663
+ capslock: "CapsLock",
1664
+ camera: "Camera"
1665
+ };
1666
+ const keysByAlias = {
1667
+ alt: "Alt",
1668
+ opt: "Alt",
1669
+ option: "Alt",
1670
+ ctrl: "Control",
1671
+ control: "Control",
1672
+ meta: "Meta",
1673
+ cmd: "Meta",
1674
+ command: "Meta",
1675
+ shift: "Shift"
1676
+ };
1677
+
1678
+ const defaultOptions$a = {
1679
+ toKey: (alias) => fromAliasToKeyStatusKey(alias)
1680
+ };
1681
+ const createPredicateKeycomboDown = (keycombo, options = {}) => {
1682
+ const { toKey } = { ...defaultOptions$a, ...options }, keys = lazyCollections.pipe(
1683
+ fromComboToAliases,
1684
+ lazyCollections.map(toKey)
1685
+ )(keycombo);
1686
+ return (statuses) => {
1687
+ const { toValue } = statuses;
1688
+ return lazyCollections.every(lazyCollections.pipe(
1689
+ toValue,
1690
+ predicateDown
1691
+ ))(keys);
1692
+ };
1693
+ };
1694
+
1695
+ function fromEventToAliases(event) {
1696
+ if (event.shiftKey && event.code in aliasesByShiftCode) {
1697
+ return [aliasesByShiftCode[event.code]];
1698
+ }
1699
+ if (event.key in aliasListsByModifier) {
1700
+ return aliasListsByModifier[event.key];
1701
+ }
1702
+ return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
1703
+ }
1704
+ const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
1705
+ const aliasesByCode = {
1706
+ Backquote: "`",
1707
+ Minus: "-",
1708
+ Equal: "=",
1709
+ BracketLeft: "[",
1710
+ BracketRight: "]",
1711
+ Backslash: "\\",
1712
+ Semicolon: ";",
1713
+ Quote: "'",
1714
+ Comma: ",",
1715
+ Period: ".",
1716
+ Slash: "/",
1717
+ ArrowUp: "up",
1718
+ ArrowDown: "down",
1719
+ ArrowLeft: "left",
1720
+ ArrowRight: "right",
1721
+ Enter: "enter",
1722
+ Space: "space",
1723
+ Tab: "tab",
1724
+ Escape: "esc",
1725
+ Backspace: "backspace",
1726
+ Delete: "delete",
1727
+ Home: "home",
1728
+ End: "end",
1729
+ PageDown: "pagedown",
1730
+ PageUp: "pageup",
1731
+ CapsLock: "capslock",
1732
+ Camera: "camera"
1733
+ };
1734
+ const aliasesByShiftCode = {
1735
+ Backquote: "~",
1736
+ Minus: "_",
1737
+ Equal: "+",
1738
+ BracketLeft: "{",
1739
+ BracketRight: "}",
1740
+ Backslash: "|",
1741
+ Semicolon: ":",
1742
+ Quote: '"',
1743
+ Comma: "<",
1744
+ Period: ">",
1745
+ Slash: "?",
1746
+ Digit1: "!",
1747
+ Digit2: "@",
1748
+ Digit3: "#",
1749
+ Digit4: "$",
1750
+ Digit5: "%",
1751
+ Digit6: "^",
1752
+ Digit7: "&",
1753
+ Digit8: "*",
1754
+ Digit9: "(",
1755
+ Digit0: ")"
1756
+ };
1757
+ const aliasListsByModifier = {
1758
+ Alt: ["alt", "option", "opt"],
1759
+ Control: ["control", "ctrl"],
1760
+ Meta: ["meta", "command", "cmd"],
1761
+ Shift: ["shift"]
1762
+ };
1763
+
1764
+ const defaultOptions$9 = {
1765
+ toKey: (alias) => fromAliasToKeyStatusKey(alias),
1766
+ toAliases: (event) => fromEventToAliases(event)
1767
+ };
1768
+ const createPredicateKeycomboMatch = (keycombo, options = {}) => {
1769
+ const { toKey, toAliases } = { ...defaultOptions$9, ...options }, aliases = fromComboToAliases(keycombo), keys = lazyCollections.map(toKey)(aliases);
1770
+ return (statuses) => {
1771
+ const { toValue } = statuses;
1772
+ return lazyCollections.every(lazyCollections.pipe(
1773
+ toValue,
1774
+ predicateDown
1775
+ ))(keys) && lazyCollections.every(
1776
+ ([key, value]) => value === "up" || lazyCollections.some(
1777
+ (alias) => lazyCollections.includes(alias)(aliases)
1778
+ )(toAliases(key))
1779
+ )(statuses.toEntries());
1780
+ };
1781
+ };
1782
+
1783
+ function createKeyState({
1784
+ keycomboOrKeycombos,
1785
+ unsupportedAliases,
1786
+ toKey,
1787
+ toAliases,
1788
+ getRequest
1789
+ }) {
1790
+ const narrowedKeycombos = createFilter(
1791
+ (keycombo) => !lazyCollections.some(
1792
+ (alias) => lazyCollections.includes(alias)(unsupportedAliases)
1793
+ )(fromComboToAliases(keycombo))
1794
+ )(Array.isArray(keycomboOrKeycombos) ? keycomboOrKeycombos : [keycomboOrKeycombos]), createPredicateKeycomboDownOptions = { toKey }, downPredicatesByKeycombo = (() => {
1795
+ const predicates = [];
1796
+ for (const keycombo of narrowedKeycombos) {
1797
+ predicates.push([
1798
+ keycombo,
1799
+ createPredicateKeycomboDown(
1800
+ keycombo,
1801
+ createPredicateKeycomboDownOptions
1802
+ )
1803
+ ]);
167
1804
  }
168
- return reversed;
1805
+ return predicates;
1806
+ })(), createPredicateKeycomboMatchOptions = { ...createPredicateKeycomboDownOptions, toAliases }, matchPredicatesByKeycombo = (() => {
1807
+ const predicates = {};
1808
+ for (const keycombo of narrowedKeycombos) {
1809
+ predicates[keycombo] = createPredicateKeycomboMatch(
1810
+ keycombo,
1811
+ createPredicateKeycomboMatchOptions
1812
+ );
1813
+ }
1814
+ return predicates;
1815
+ })(), validAliases = lazyCollections.pipe(
1816
+ lazyCollections.flatMap(fromComboToAliases),
1817
+ lazyCollections.unique(),
1818
+ lazyCollections.toArray()
1819
+ )(narrowedKeycombos), getDownCombos = () => lazyCollections.pipe(
1820
+ lazyCollections.filter(([, predicate]) => predicate(statuses)),
1821
+ lazyCollections.map(([keycombo]) => [keycombo, fromComboToAliases(keycombo)]),
1822
+ lazyCollections.sort(([, aliasesA], [, aliasesB]) => aliasesB.length - aliasesA.length),
1823
+ lazyCollections.map(([keycombo]) => keycombo),
1824
+ lazyCollections.toArray()
1825
+ )(downPredicatesByKeycombo), predicateValid = (event) => {
1826
+ const aliases = toAliases(event);
1827
+ return lazyCollections.some(
1828
+ (validAlias) => lazyCollections.includes(validAlias)(aliases)
1829
+ )(validAliases);
1830
+ }, cleanup = () => {
1831
+ window.cancelAnimationFrame(getRequest());
1832
+ }, statuses = createKeyStatuses();
1833
+ return {
1834
+ narrowedKeycombos,
1835
+ createPredicateKeycomboDownOptions,
1836
+ downPredicatesByKeycombo,
1837
+ createPredicateKeycomboMatchOptions,
1838
+ matchPredicatesByKeycombo,
1839
+ validAliases,
1840
+ getDownCombos,
1841
+ predicateValid,
1842
+ cleanup,
1843
+ statuses
169
1844
  };
170
1845
  }
171
- function createSort(compare) {
172
- return (array) => {
173
- return new Pipeable(array).pipe(
174
- createSlice(0),
175
- (sliced) => compare ? sliced.sort(compare) : sliced.sort()
176
- );
1846
+
1847
+ function toLength() {
1848
+ return function toLengthFn(data) {
1849
+ return [...data].length;
177
1850
  };
178
1851
  }
179
- function createSlug(options) {
180
- return (string) => {
181
- return slugify(string, options);
182
- };
1852
+
1853
+ const fromComboToAliasesLength = lazyCollections.pipe(
1854
+ fromComboToAliases,
1855
+ toLength()
1856
+ );
1857
+
1858
+ function fromEventToKeyStatusKey({ key, code }) {
1859
+ return lazyCollections.includes(key)(modifiers) ? { key } : { code };
183
1860
  }
184
- function createClip(required) {
185
- return (string) => {
186
- return string.replace(required, "");
187
- };
1861
+ const modifiers = ["Alt", "Control", "Meta", "Shift"];
1862
+
1863
+ function toDirection(angle, unit = "degrees") {
1864
+ return Object.keys(directions).find((direction) => directions[direction][unit](angle));
188
1865
  }
189
- function createClamp(min, max) {
190
- return (number) => {
191
- const maxed = Math.max(number, min);
192
- return Math.min(maxed, max);
1866
+ const directions = {
1867
+ up: {
1868
+ degrees: (degrees) => degrees >= 67.5 && degrees <= 112.5,
1869
+ radians: (radians) => radians >= 0.375 * Math.PI && radians <= 0.625 * Math.PI
1870
+ },
1871
+ upRight: {
1872
+ degrees: (degrees) => degrees >= 22.5 && degrees < 67.5,
1873
+ radians: (radians) => radians >= 0.125 * Math.PI && radians < 0.375 * Math.PI
1874
+ },
1875
+ right: {
1876
+ degrees: (degrees) => degrees > 337.5 && degrees <= 360 || degrees < 22.5 && degrees >= 0,
1877
+ radians: (radians) => radians > 1.875 * Math.PI && radians <= 2 * Math.PI || radians < 0.125 * Math.PI && radians >= 0
1878
+ },
1879
+ downRight: {
1880
+ degrees: (degrees) => degrees > 292.5 && degrees <= 337.5,
1881
+ radians: (radians) => radians > 1.625 * Math.PI && radians <= 1.875 * Math.PI
1882
+ },
1883
+ down: {
1884
+ degrees: (degrees) => degrees >= 247.5 && degrees <= 292.5,
1885
+ radians: (radians) => radians >= 1.375 * Math.PI && radians <= 1.625 * Math.PI
1886
+ },
1887
+ downLeft: {
1888
+ degrees: (degrees) => degrees >= 202.5 && degrees < 247.5,
1889
+ radians: (radians) => radians >= 1.125 * Math.PI && radians < 1.375 * Math.PI
1890
+ },
1891
+ left: {
1892
+ degrees: (degrees) => degrees > 157.5 && degrees < 202.5,
1893
+ radians: (radians) => radians > 0.875 * Math.PI && radians < 1.125 * Math.PI
1894
+ },
1895
+ upLeft: {
1896
+ degrees: (degrees) => degrees > 112.5 && degrees <= 157.5,
1897
+ radians: (radians) => radians > 0.625 * Math.PI && radians <= 0.875 * Math.PI
1898
+ }
1899
+ };
1900
+
1901
+ function toHookApi({
1902
+ getSequence,
1903
+ getStatus,
1904
+ getMetadata
1905
+ }) {
1906
+ return {
1907
+ sequence: getSequence(),
1908
+ status: getStatus(),
1909
+ metadata: getMetadata()
193
1910
  };
194
1911
  }
195
- function createDetermine(potentialities) {
196
- const predicates = createMap(({ outcome, probability }, index) => {
197
- const lowerBound = index === 0 ? 0 : lazyCollections.pipe(
198
- lazyCollections.slice(0, index - 1),
199
- lazyCollections.reduce((lowerBound2, { probability: probability2 }) => lowerBound2 + probability2, 0)
200
- )(potentialities), upperBound = lowerBound + probability;
201
- return {
202
- outcome,
203
- predicate: (determinant) => determinant >= lowerBound && determinant < upperBound || determinant < 0 && index === 0 || index === predicates.length - 1
204
- };
205
- })(potentialities);
206
- return (determinant) => lazyCollections.find(({ predicate }) => predicate(determinant))(predicates).outcome;
1912
+
1913
+ function toMousePoint(event) {
1914
+ return {
1915
+ x: event.clientX,
1916
+ y: event.clientY
1917
+ };
207
1918
  }
208
- function createRename(from, to) {
209
- return (map2) => {
210
- const keys = [...map2.keys()], keyToRenameIndex = lazyCollections.findIndex((k) => k === from)(keys), newKeys = createReplace(keyToRenameIndex, to)(keys), values = [...map2.values()];
211
- return createReduce((renamed, key, index) => renamed.set(key, values[index]), /* @__PURE__ */ new Map())(newKeys);
1919
+ function toTouchMovePoint(event) {
1920
+ return {
1921
+ x: event.touches.item(0).clientX,
1922
+ y: event.touches.item(0).clientY
212
1923
  };
213
1924
  }
214
- function createToEntries() {
215
- return (object) => {
216
- const entries = [];
217
- for (const key in object) {
218
- entries.push([key, object[key]]);
219
- }
220
- return entries;
1925
+ function toTouchEndPoint(event) {
1926
+ return {
1927
+ x: event.changedTouches.item(0).clientX,
1928
+ y: event.changedTouches.item(0).clientY
221
1929
  };
222
1930
  }
223
- function createToKeys() {
224
- return (object) => {
225
- const keys = [];
226
- for (const key in object) {
227
- keys.push(key);
228
- }
229
- return keys;
1931
+
1932
+ function toPolarCoordinates({ xA, xB, yA, yB }) {
1933
+ const distance = Math.hypot(xB - xA, yB - yA), angle = Math.atan2(yA - yB, xB - xA), radians = angle >= 0 ? angle : 2 * Math.PI + angle, degrees = radians * 180 / Math.PI;
1934
+ return {
1935
+ distance,
1936
+ angle: { radians, degrees }
230
1937
  };
231
1938
  }
232
- function createToSome(predicate) {
233
- return (object) => {
234
- for (const key in object) {
235
- if (predicate(key, object[key])) {
236
- return true;
1939
+
1940
+ const initialMetadata$3 = {
1941
+ times: {
1942
+ start: 0,
1943
+ end: 0
1944
+ },
1945
+ duration: 0
1946
+ };
1947
+ function storeKeyboardTimeMetadata({
1948
+ event,
1949
+ api,
1950
+ getTimeMetadata,
1951
+ getShouldStore,
1952
+ setRequest,
1953
+ recognize
1954
+ }) {
1955
+ if (!getShouldStore())
1956
+ return;
1957
+ const { getStatus, onRecognized } = api, timeMetadata = getTimeMetadata();
1958
+ if (!timeMetadata.times)
1959
+ timeMetadata.times = createClone()(initialMetadata$3.times);
1960
+ timeMetadata.times.start = Math.round(event.timeStamp);
1961
+ timeMetadata.times.end = Math.round(event.timeStamp);
1962
+ const storeDuration = () => {
1963
+ const request = requestAnimationFrame((timestamp) => {
1964
+ if (!getShouldStore())
1965
+ return;
1966
+ timeMetadata.times.end = Math.round(timestamp);
1967
+ timeMetadata.duration = Math.max(0, timeMetadata.times.end - timeMetadata.times.start);
1968
+ if (recognize) {
1969
+ recognize(event, api);
1970
+ if (getStatus() === "recognized")
1971
+ onRecognized(event);
237
1972
  }
238
- }
239
- return false;
1973
+ storeDuration();
1974
+ });
1975
+ setRequest(request);
240
1976
  };
1977
+ storeDuration();
241
1978
  }
242
- function createToEvery(predicate) {
243
- return (object) => {
244
- for (const key in object) {
245
- if (!predicate(key, object[key])) {
246
- return false;
1979
+
1980
+ const initialMetadata$2 = {
1981
+ points: {
1982
+ start: { x: 0, y: 0 },
1983
+ end: { x: 0, y: 0 }
1984
+ }
1985
+ };
1986
+ function storePointerStartMetadata(event, api) {
1987
+ const { getMetadata } = api, metadata = getMetadata();
1988
+ const point = event instanceof MouseEvent ? toMousePoint(event) : toTouchMovePoint(event);
1989
+ if (!metadata.points)
1990
+ metadata.points = createClone()(initialMetadata$2.points);
1991
+ metadata.points.start = point;
1992
+ metadata.points.end = point;
1993
+ }
1994
+
1995
+ const initialMetadata$1 = {
1996
+ distance: {
1997
+ straight: {
1998
+ fromStart: 0,
1999
+ fromPrevious: 0
2000
+ },
2001
+ horizontal: {
2002
+ fromStart: 0,
2003
+ fromPrevious: 0
2004
+ },
2005
+ vertical: {
2006
+ fromStart: 0,
2007
+ fromPrevious: 0
2008
+ }
2009
+ },
2010
+ angle: {
2011
+ fromPrevious: { radians: 0, degrees: 0 },
2012
+ fromStart: { radians: 0, degrees: 0 }
2013
+ },
2014
+ direction: {
2015
+ fromPrevious: "up",
2016
+ fromStart: "up"
2017
+ }
2018
+ };
2019
+ function storePointerMoveMetadata(event, api) {
2020
+ const { getMetadata } = api, metadata = getMetadata();
2021
+ if (!metadata.distance) {
2022
+ metadata.distance = createClone()(initialMetadata$1.distance);
2023
+ metadata.angle = createClone()(initialMetadata$1.angle);
2024
+ metadata.direction = createClone()(initialMetadata$1.direction);
2025
+ }
2026
+ const { x: previousX, y: previousY } = metadata.points.end, { x: startX, y: startY } = metadata.points.start, { x: newX, y: newY } = (() => {
2027
+ if (event instanceof MouseEvent) {
2028
+ return toMousePoint(event);
2029
+ }
2030
+ if (event instanceof TouchEvent) {
2031
+ if (event.type === "touchmove") {
2032
+ return toTouchMovePoint(event);
247
2033
  }
2034
+ return toTouchEndPoint(event);
248
2035
  }
249
- return true;
2036
+ })(), { distance: distanceFromPrevious, angle: angleFromPrevious } = toPolarCoordinates({
2037
+ xA: previousX,
2038
+ xB: newX,
2039
+ yA: previousY,
2040
+ yB: newY
2041
+ }), { distance: distanceFromStart, angle: angleFromStart } = toPolarCoordinates({
2042
+ xA: startX,
2043
+ xB: newX,
2044
+ yA: startY,
2045
+ yB: newY
2046
+ });
2047
+ metadata.distance.straight.fromPrevious = distanceFromPrevious;
2048
+ metadata.distance.horizontal.fromPrevious = newX - previousX;
2049
+ metadata.distance.vertical.fromPrevious = newY - previousY;
2050
+ metadata.angle.fromPrevious = angleFromPrevious;
2051
+ metadata.direction.fromPrevious = toDirection(angleFromPrevious.degrees);
2052
+ metadata.distance.straight.fromStart = distanceFromStart;
2053
+ metadata.distance.horizontal.fromStart = newX - startX;
2054
+ metadata.distance.vertical.fromStart = newY - startY;
2055
+ metadata.angle.fromStart = angleFromStart;
2056
+ metadata.direction.fromStart = toDirection(angleFromStart.degrees);
2057
+ metadata.points.end = { x: newX, y: newY };
2058
+ }
2059
+
2060
+ const initialMetadata = {
2061
+ times: {
2062
+ start: 0,
2063
+ end: 0
2064
+ },
2065
+ duration: 0,
2066
+ velocity: 0
2067
+ };
2068
+ function storePointerTimeMetadata(event, api, getShouldStore, setRequest, recognize) {
2069
+ const { getMetadata, getStatus, onRecognized } = api, metadata = getMetadata();
2070
+ if (!metadata.times) {
2071
+ metadata.times = createClone()(initialMetadata.times);
2072
+ }
2073
+ metadata.times.start = Math.round(event.timeStamp);
2074
+ metadata.times.end = Math.round(event.timeStamp);
2075
+ let previousTime = metadata.times.start;
2076
+ const storeDuration = () => {
2077
+ const request = requestAnimationFrame((timestamp) => {
2078
+ if (getShouldStore()) {
2079
+ previousTime = metadata.times.end;
2080
+ metadata.times.end = Math.round(timestamp);
2081
+ metadata.duration = Math.max(0, metadata.times.end - metadata.times.start);
2082
+ const durationFromPrevious = Math.max(0, metadata.times.end - previousTime);
2083
+ metadata.velocity = metadata.distance.straight.fromPrevious / durationFromPrevious;
2084
+ recognize?.(event, api);
2085
+ if (getStatus() === "recognized")
2086
+ onRecognized(event);
2087
+ storeDuration();
2088
+ }
2089
+ });
2090
+ setRequest(request);
250
2091
  };
2092
+ storeDuration();
251
2093
  }
252
- function createMatchesKeycombo(keycombo) {
253
- return (event) => eventMatchesKeycombo(event, narrowKeycombo(keycombo));
2094
+
2095
+ function defineGraph(nodes, edges) {
2096
+ return { nodes, edges };
254
2097
  }
255
- function createMatchesMousecombo(mousecombo) {
256
- return (event) => eventMatchesMousecombo(event, narrowMousecombo(mousecombo));
2098
+ function defineGraphNodes(nodes) {
2099
+ return nodes;
257
2100
  }
258
- function createMatchesPointercombo(pointercombo) {
259
- return (event) => eventMatchesPointercombo(event, narrowPointercombo(pointercombo));
2101
+ function defineGraphEdges(edges) {
2102
+ return edges;
260
2103
  }
261
- function createToFocusable(order, elementIsCandidate) {
262
- return (element) => {
263
- if (elementIsCandidate && predicateFocusable(element))
264
- return element;
265
- switch (order) {
266
- case "first":
267
- for (let i = 0; i < element.children.length; i++) {
268
- const focusable = createToFocusable(order, true)(element.children[i]);
269
- if (focusable)
270
- return focusable;
271
- }
272
- break;
273
- case "last":
274
- for (let i = element.children.length - 1; i > -1; i--) {
275
- const focusable = createToFocusable(order, true)(element.children[i]);
276
- if (focusable)
277
- return focusable;
278
- }
279
- break;
280
- }
281
- };
2104
+ function defineGraphNode(node) {
2105
+ return node;
282
2106
  }
283
- class Pipeable {
284
- constructor(state) {
285
- this.state = state;
286
- }
287
- pipe(...fns) {
288
- return createReduce((piped, fn, index) => fn(piped, index), this.state)(fns);
289
- }
290
- async pipeAsync(...fns) {
291
- return await createReduceAsync(
292
- async (piped, fn, index) => await fn(piped, index),
293
- this.state
294
- )(fns);
295
- }
2107
+ function defineGraphEdge(from, to, predicateTraversable) {
2108
+ return { from, to, predicateTraversable };
296
2109
  }
297
-
298
- function toKey(name) {
299
- return name in keysByName ? keysByName[name] : name;
2110
+ function defineAsyncGraph(nodes, edges) {
2111
+ return { nodes, edges };
300
2112
  }
301
- const keysByName = {
302
- up: "ArrowUp",
303
- right: "ArrowRight",
304
- down: "ArrowDown",
305
- left: "ArrowLeft",
306
- enter: "Enter",
307
- backspace: "Backspace",
308
- tab: "Tab",
309
- space: " ",
310
- shift: "Shift",
311
- meta: "Meta",
312
- command: "Meta",
313
- cmd: "Meta",
314
- control: "Control",
315
- ctrl: "Control",
316
- alt: "Alt",
317
- opt: "Alt",
318
- option: "Alt",
319
- fn: "Fn",
320
- capslock: "CapsLock",
321
- end: "End",
322
- home: "Home",
323
- pagedown: "PageDown",
324
- pageup: "PageUp",
325
- esc: "Escape",
326
- camera: "Camera",
327
- delete: "Delete",
328
- f1: "F1",
329
- f2: "F2",
330
- f3: "F3",
331
- f4: "F4",
332
- f5: "F5",
333
- f6: "F6",
334
- f7: "F7",
335
- f8: "F8",
336
- f9: "F9",
337
- f10: "F10",
338
- f11: "F11",
339
- f12: "F12",
340
- f13: "F13",
341
- f14: "F14",
342
- f15: "F15",
343
- f16: "F16",
344
- f17: "F17",
345
- f18: "F18",
346
- f19: "F19",
347
- f20: "F20"
348
- };
349
- const toListenableKeycomboItems = createMap((name) => ({ name, type: fromComboItemNameToType(name) }));
350
- function narrowKeycombo(type) {
351
- return new Pipeable(type).pipe(
352
- toCombo,
353
- toListenableKeycomboItems
354
- );
2113
+ function defineAsyncGraphEdges(edges) {
2114
+ return edges;
355
2115
  }
356
- function narrowMousecombo(type) {
357
- return toCombo(type);
2116
+ function defineAsyncGraphEdge(from, to, predicateTraversable) {
2117
+ return { from, to, predicateTraversable };
358
2118
  }
359
- function narrowPointercombo(type) {
360
- return toCombo(type);
2119
+
2120
+ function defineAssociativeArrayEntries(entries) {
2121
+ return entries;
361
2122
  }
362
- const toUnique$1 = lazyCollections.unique();
363
- const toComboItems = lazyCollections.map((name) => name === "" ? delimiter : name);
364
- const delimiter = "+";
365
- function toCombo(type) {
366
- return lazyCollections.pipe(
367
- toUnique$1,
368
- toComboItems,
369
- lazyCollections.toArray()
370
- )(type.split(delimiter));
371
- }
372
- function fromComboItemNameToType(name) {
373
- return lazyCollections.find((type) => predicatesByType[type](name))(listenableComboItemTypes) ?? "custom";
374
- }
375
- const listenableComboItemTypes = /* @__PURE__ */ new Set(["singleCharacter", "arrow", "other", "modifier", "click", "pointer"]);
376
- const predicatesByType = {
377
- singleCharacter: (name) => typeREs["singleCharacter"].test(name),
378
- arrow: (name) => typeREs["arrow"].test(name),
379
- other: (name) => typeREs["other"].test(name),
380
- modifier: (name) => typeREs["modifier"].test(name),
381
- click: (name) => typeREs["click"].test(name),
382
- pointer: (name) => typeREs["pointer"].test(name)
383
- };
384
- const typeREs = {
385
- singleCharacter: /^!?[a-zA-Z0-9,<.>/?;:'"[{\]}\\|`~!@#$%^&*()-_=+]$/,
386
- arrow: /^!?(arrow|vertical|horizontal|up|down|right|left)$/,
387
- other: /^!?(enter|backspace|space|tab|esc|home|end|pagedown|pageup|capslock|f[0-9]{1,2}|camera|delete)$/,
388
- modifier: /^!?(cmd|command|meta|shift|ctrl|control|alt|opt|option)$/,
389
- click: /^!?(rightclick|contextmenu|click|mousedown|mouseup|dblclick)$/,
390
- pointer: /^!?(pointerdown|pointerup|pointermove|pointerover|pointerout|pointerenter|pointerleave|pointercancel|gotpointercapture|lostpointercapture)$/
391
- };
392
- function toModifier(modifierOrAlias) {
393
- return modifierOrAlias in modifiersByAlias ? modifiersByAlias[modifierOrAlias] : modifierOrAlias;
394
- }
395
- const modifiersByAlias = {
396
- cmd: "meta",
397
- command: "meta",
398
- ctrl: "control",
399
- opt: "alt",
400
- option: "alt"
401
- };
2123
+
402
2124
  function createExceptAndOnlyEffect(type, effect, options) {
403
2125
  const { except = [], only = [] } = options;
404
2126
  if (type === "keydown" || type === "keyup") {
405
2127
  return (event) => {
406
- const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
2128
+ const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, false];
407
2129
  if (matchesOnly) {
408
2130
  effect(event);
409
2131
  return;
@@ -416,7 +2138,7 @@ function createExceptAndOnlyEffect(type, effect, options) {
416
2138
  }
417
2139
  if (type === "click" || type === "dblclick" || type === "contextmenu" || type.startsWith("mouse")) {
418
2140
  return (event) => {
419
- const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
2141
+ const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, false];
420
2142
  if (matchesOnly) {
421
2143
  effect(event);
422
2144
  return;
@@ -429,7 +2151,7 @@ function createExceptAndOnlyEffect(type, effect, options) {
429
2151
  }
430
2152
  if (type.startsWith("pointer")) {
431
2153
  return (event) => {
432
- const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
2154
+ const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, false];
433
2155
  if (matchesOnly) {
434
2156
  effect(event);
435
2157
  return;
@@ -441,7 +2163,7 @@ function createExceptAndOnlyEffect(type, effect, options) {
441
2163
  };
442
2164
  }
443
2165
  return (event) => {
444
- const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, true];
2166
+ const { target } = event, [matchesOnly, matchesExcept] = target instanceof Element ? createMap((selectors) => lazyCollections.some((selector) => target.matches(selector))(selectors))([only, except]) : [false, false];
445
2167
  if (matchesOnly) {
446
2168
  effect(event, {});
447
2169
  return;
@@ -452,27 +2174,15 @@ function createExceptAndOnlyEffect(type, effect, options) {
452
2174
  }
453
2175
  };
454
2176
  }
455
- function predicateModified({ event, alias }) {
456
- return predicatesByModifier[alias]?.(event);
457
- }
458
- const predicatesByModifier = {
459
- shift: (event) => event.shiftKey,
460
- cmd: (event) => event.metaKey,
461
- command: (event) => event.metaKey,
462
- meta: (event) => event.metaKey,
463
- ctrl: (event) => event.ctrlKey,
464
- control: (event) => event.ctrlKey,
465
- alt: (event) => event.altKey,
466
- opt: (event) => event.altKey,
467
- option: (event) => event.altKey
468
- };
469
- function domIsAvailable() {
2177
+
2178
+ function getDomAvailability() {
470
2179
  try {
471
- return !!window;
2180
+ return !!window ? "available" : "unavailable";
472
2181
  } catch (error) {
473
- return false;
2182
+ return "unavailable";
474
2183
  }
475
2184
  }
2185
+
476
2186
  function predicateArray(value) {
477
2187
  return Array.isArray(value);
478
2188
  }
@@ -491,24 +2201,8 @@ function predicateNumber(value) {
491
2201
  function predicateString(value) {
492
2202
  return typeof value === "string";
493
2203
  }
494
- const tabbableSelector = lazyCollections.join(':not([hidden]):not([tabindex="-1"]),')([
495
- "input:not([disabled]):not([type=hidden])",
496
- "select:not([disabled])",
497
- "textarea:not([disabled])",
498
- "button:not([disabled])",
499
- "a[href]",
500
- "area[href]",
501
- "summary",
502
- "iframe",
503
- "object",
504
- "embed",
505
- "audio[controls]",
506
- "video[controls]",
507
- "[contenteditable]",
508
- "[tabindex]:not([disabled])"
509
- ]);
510
- function predicateFocusable(element) {
511
- return element.matches(tabbableSelector);
2204
+ function predicateObject(value) {
2205
+ return typeof value === "object";
512
2206
  }
513
2207
 
514
2208
  class Recognizeable {
@@ -521,7 +2215,7 @@ class Recognizeable {
521
2215
  effects: {}
522
2216
  };
523
2217
  this.maxSequenceLength = options?.maxSequenceLength || defaultOptions.maxSequenceLength;
524
- this.effects = new Map(Object.entries(options?.effects || defaultOptions.effects));
2218
+ this.effects = options?.effects || defaultOptions.effects;
525
2219
  this.resetComputedMetadata();
526
2220
  this.setSequence(sequence);
527
2221
  this.effectApi = {
@@ -530,8 +2224,6 @@ class Recognizeable {
530
2224
  setMetadata: (metadata) => this.computedMetadata = metadata,
531
2225
  recognized: () => this.recognized(),
532
2226
  denied: () => this.denied(),
533
- recognizedUntilReady: () => this.recognizedUntilReady(),
534
- deniedUntilReady: () => this.deniedUntilReady(),
535
2227
  ready: () => this.ready()
536
2228
  };
537
2229
  this.ready();
@@ -546,12 +2238,6 @@ class Recognizeable {
546
2238
  denied() {
547
2239
  this.computedStatus = "denied";
548
2240
  }
549
- recognizedUntilReady() {
550
- this.computedStatus = "recognized until ready";
551
- }
552
- deniedUntilReady() {
553
- this.computedStatus = "denied until ready";
554
- }
555
2241
  computedStatus;
556
2242
  ready() {
557
2243
  this.computedStatus = "ready";
@@ -574,8 +2260,7 @@ class Recognizeable {
574
2260
  return this;
575
2261
  }
576
2262
  recognize(sequenceItem, { onRecognized } = {}) {
577
- if (!this.status.includes("until ready"))
578
- this.recognizing();
2263
+ this.recognizing();
579
2264
  const type = this.toType(sequenceItem), excess = predicateNumber(this.maxSequenceLength) ? Math.max(0, this.sequence.length - this.maxSequenceLength) : 0, newSequence = createConcat(
580
2265
  createSlice(excess)(this.sequence),
581
2266
  [sequenceItem]
@@ -583,11 +2268,10 @@ class Recognizeable {
583
2268
  this.effectApi.getSequence = () => newSequence;
584
2269
  this.effectApi.onRecognized = onRecognized || (() => {
585
2270
  });
586
- this.effects.get(type)?.(sequenceItem, { ...this.effectApi });
2271
+ this.effects[type]?.(sequenceItem, { ...this.effectApi });
587
2272
  switch (this.status) {
588
2273
  case "ready":
589
2274
  case "denied":
590
- case "denied until ready":
591
2275
  this.resetComputedMetadata();
592
2276
  this.setSequence([]);
593
2277
  break;
@@ -630,8 +2314,8 @@ class Listenable {
630
2314
  computedActive;
631
2315
  constructor(type, options) {
632
2316
  if (type === "recognizeable") {
633
- this.computedRecognizeable = new Recognizeable([], options?.recognizeable || {});
634
- this.recognizeableEffectsKeys = Object.keys(options?.recognizeable?.effects || {});
2317
+ this.computedRecognizeable = new Recognizeable([], options?.recognizeable);
2318
+ this.recognizeableEffectsKeys = Object.keys(options?.recognizeable?.effects);
635
2319
  }
636
2320
  this.computedActive = /* @__PURE__ */ new Set();
637
2321
  this.setType(type);
@@ -731,24 +2415,10 @@ class Listenable {
731
2415
  this.active.add({ target, id: [this.type, effect] });
732
2416
  }
733
2417
  recognizeableListen(effect, options) {
734
- let effectStatus = "ready";
735
2418
  const guardedEffect = (sequenceItem) => {
736
2419
  this.recognizeable.recognize(sequenceItem, { onRecognized: (sequenceItem2) => effect(sequenceItem2) });
737
- switch (this.recognizeable.status) {
738
- case "recognized until ready":
739
- if (effectStatus === "ready") {
740
- effect(sequenceItem);
741
- effectStatus = "performed";
742
- }
743
- break;
744
- case "recognized":
745
- effect(sequenceItem);
746
- effectStatus = "ready";
747
- break;
748
- default:
749
- effectStatus = "ready";
750
- break;
751
- }
2420
+ if (this.recognizeable.status === "recognized")
2421
+ effect(sequenceItem);
752
2422
  };
753
2423
  for (const type of this.recognizeableEffectsKeys) {
754
2424
  const listenable = new Listenable(type);
@@ -769,10 +2439,10 @@ class Listenable {
769
2439
  }
770
2440
  addEventListeners(eventListeners, options) {
771
2441
  const { target = document } = options;
772
- eventListeners.forEach((eventListener) => {
2442
+ for (const eventListener of eventListeners) {
773
2443
  target.addEventListener(eventListener[0], eventListener[1], eventListener[2]);
774
2444
  this.active.add({ target, id: eventListener });
775
- });
2445
+ }
776
2446
  }
777
2447
  listening() {
778
2448
  this.computedStatus = "listening";
@@ -884,109 +2554,22 @@ function toAddEventListenerParams(type, effect, options) {
884
2554
  const { addEventListener, useCapture } = options, exceptAndOnlyEffect = createExceptAndOnlyEffect(type, effect, options), effectOptions = [addEventListener || useCapture];
885
2555
  return { exceptAndOnlyEffect, effectOptions };
886
2556
  }
887
- function eventMatchesKeycombo(event, keycombo) {
888
- return lazyCollections.every(({ name, type }, index) => {
889
- switch (type) {
890
- case "singleCharacter":
891
- if (name === "!")
892
- return event.key === "!";
893
- const keyToTest = event.altKey && fromComboItemNameToType(event.key) === "custom" ? fromCodeToSingleCharacter(event.code) : event.key.toLowerCase();
894
- return name.startsWith("!") ? keyToTest !== toKey(name.slice(1)).toLowerCase() : keyToTest === toKey(name).toLowerCase();
895
- case "other":
896
- if (name === "!") {
897
- return event.key === "!";
898
- }
899
- return name.startsWith("!") ? event.key.toLowerCase() !== toKey(name.slice(1)).toLowerCase() : event.key.toLowerCase() === toKey(name).toLowerCase();
900
- case "arrow":
901
- return predicatesByArrow.get(name)?.({ event, name }) ?? predicatesByArrow.get("default")({ event, name });
902
- case "modifier":
903
- if (index === keycombo.length - 1) {
904
- return name.startsWith("!") ? event.key.toLowerCase() !== toModifier(name.slice(1)).toLowerCase() : event.key.toLowerCase() === toModifier(name).toLowerCase();
905
- }
906
- return name.startsWith("!") ? !predicateModified({ event, alias: name.slice(1) }) : predicateModified({ event, alias: name });
907
- }
908
- })(keycombo);
909
- }
910
- function fromCodeToSingleCharacter(code) {
911
- for (const c in aliasesByCode) {
912
- if (c === code) {
913
- return aliasesByCode[c];
914
- }
915
- }
916
- for (const prefix of ["Key", "Digit"]) {
917
- const re = new RegExp(`^${prefix}`);
918
- if (re.test(code)) {
919
- return createClip(re)(code).toLowerCase();
920
- }
921
- }
922
- return code;
923
- }
924
- const aliasesByCode = {
925
- "Backquote": "`",
926
- "Minus": "-",
927
- "Equal": "=",
928
- "BracketLeft": "[",
929
- "BracketRight": "]",
930
- "Backslash": "\\",
931
- "Semicolon": ";",
932
- "Quote": "'",
933
- "Comma": ",",
934
- "Period": ".",
935
- "Slash": "/"
936
- };
937
- const predicatesByArrow = /* @__PURE__ */ new Map([
938
- [
939
- "arrow",
940
- ({ event }) => arrows.has(event.key.toLowerCase())
941
- ],
942
- [
943
- "!arrow",
944
- ({ event }) => !arrows.has(event.key.toLowerCase())
945
- ],
946
- [
947
- "vertical",
948
- ({ event }) => verticalArrows.has(event.key.toLowerCase())
949
- ],
950
- [
951
- "!vertical",
952
- ({ event }) => !verticalArrows.has(event.key.toLowerCase())
953
- ],
954
- [
955
- "horizontal",
956
- ({ event }) => horizontalArrows.has(event.key.toLowerCase())
957
- ],
958
- [
959
- "!horizontal",
960
- ({ event }) => !horizontalArrows.has(event.key.toLowerCase())
961
- ],
962
- [
963
- "default",
964
- ({ event, name }) => name.startsWith("!") ? event.key.toLowerCase() !== `arrow${name.toLowerCase()}` : event.key.toLowerCase() === `arrow${name.toLowerCase()}`
965
- ]
966
- ]);
967
- const arrows = /* @__PURE__ */ new Set(["arrowup", "arrowright", "arrowdown", "arrowleft"]);
968
- const verticalArrows = /* @__PURE__ */ new Set(["arrowup", "arrowdown"]);
969
- const horizontalArrows = /* @__PURE__ */ new Set(["arrowright", "arrowleft"]);
970
- function eventMatchesMousecombo(event, Mousecombo) {
971
- return lazyCollections.every((name) => fromComboItemNameToType(name) === "click" || name.startsWith("!") && !predicateModified({ alias: name.slice(1), event }) || !name.startsWith("!") && predicateModified({ alias: name, event }))(Mousecombo);
972
- }
973
- function eventMatchesPointercombo(event, pointercombo) {
974
- return lazyCollections.every((name) => fromComboItemNameToType(name) === "pointer" || name.startsWith("!") && !predicateModified({ alias: name.slice(1), event }) || !name.startsWith("!") && predicateModified({ alias: name, event }))(pointercombo);
975
- }
976
2557
  const observerAssertionsByType = {
977
2558
  intersect: (observer) => observer instanceof IntersectionObserver,
978
2559
  mutate: (observer) => observer instanceof MutationObserver,
979
2560
  resize: (observer) => observer instanceof ResizeObserver
980
2561
  };
981
2562
 
982
- const defaultOptions$7 = {
2563
+ const defaultOptions$8 = {
983
2564
  duration: 0,
2565
+ // delay not supported, because it can be effectd by delayable
984
2566
  timing: [
985
2567
  0,
986
2568
  0,
987
2569
  1,
988
2570
  1
989
2571
  ],
2572
+ // linear by default
990
2573
  iterations: 1,
991
2574
  alternates: false
992
2575
  };
@@ -1007,10 +2590,10 @@ class Animateable {
1007
2590
  getEaseables;
1008
2591
  getReversedEaseables;
1009
2592
  constructor(keyframes, options = {}) {
1010
- this.initialDuration = options?.duration || defaultOptions$7.duration;
1011
- this.controlPoints = fromTimingToControlPoints(options?.timing || defaultOptions$7.timing);
1012
- this.iterationLimit = options?.iterations || defaultOptions$7.iterations;
1013
- this.alternates = options?.alternates || defaultOptions$7.alternates;
2593
+ this.initialDuration = options?.duration || defaultOptions$8.duration;
2594
+ this.controlPoints = fromTimingToControlPoints(options?.timing || defaultOptions$8.timing);
2595
+ this.iterationLimit = options?.iterations || defaultOptions$8.iterations;
2596
+ this.alternates = options?.alternates || defaultOptions$8.alternates;
1014
2597
  this.reversedControlPoints = fromControlPointsToReversedControlPoints(this.controlPoints);
1015
2598
  this.toAnimationProgress = createToAnimationProgress(this.controlPoints);
1016
2599
  this.reversedToAnimationProgress = createToAnimationProgress(this.reversedControlPoints);
@@ -1086,10 +2669,11 @@ class Animateable {
1086
2669
  setKeyframes(keyframes) {
1087
2670
  this.stop();
1088
2671
  this.computedKeyframes = Array.from(keyframes).sort(({ progress: progressA }, { progress: progressB }) => progressA - progressB);
1089
- this.reversedKeyframes = new Pipeable(this.keyframes).pipe(
1090
- createReverse(),
1091
- createMap(({ progress, properties }) => ({ progress: 1 - progress, properties }))
1092
- );
2672
+ this.reversedKeyframes = lazyCollections.pipe(
2673
+ lazyCollections.reverse(),
2674
+ lazyCollections.map(({ progress, properties }) => ({ progress: 1 - progress, properties })),
2675
+ lazyCollections.toArray()
2676
+ )(this.keyframes);
1093
2677
  this.properties = toProperties(this.keyframes);
1094
2678
  this.easeables = this.getEaseables({ keyframes: this.keyframes, properties: this.properties });
1095
2679
  this.reversedEaseables = this.getReversedEaseables({ keyframes: this.reversedKeyframes, properties: this.properties });
@@ -1387,7 +2971,7 @@ class Animateable {
1387
2971
  break;
1388
2972
  case "reversing":
1389
2973
  this.computedIterations += 1;
1390
- if (this.iterations < this.iterationLimit || this.iterationLimit === true) {
2974
+ if (this.iterationLimit === true || this.iterations < this.iterationLimit) {
1391
2975
  this.createAnimate("reverse")(effect, options);
1392
2976
  } else {
1393
2977
  this.alternateCache.status = "ready";
@@ -1396,7 +2980,7 @@ class Animateable {
1396
2980
  }
1397
2981
  } else {
1398
2982
  this.computedIterations += 1;
1399
- if (this.iterations < this.iterationLimit || this.iterationLimit === true) {
2983
+ if (this.iterationLimit === true || this.iterations < this.iterationLimit) {
1400
2984
  this.createAnimate("play")(effect, options);
1401
2985
  }
1402
2986
  }
@@ -1412,7 +2996,7 @@ class Animateable {
1412
2996
  switch (this.alternateCache.status) {
1413
2997
  case "playing":
1414
2998
  this.computedIterations += 1;
1415
- if (this.iterations < this.iterationLimit || this.iterationLimit === true) {
2999
+ if (this.iterationLimit === true || this.iterations < this.iterationLimit) {
1416
3000
  this.createAnimate("play")(effect, options);
1417
3001
  } else {
1418
3002
  this.alternateCache.status = "ready";
@@ -1424,7 +3008,7 @@ class Animateable {
1424
3008
  }
1425
3009
  } else {
1426
3010
  this.computedIterations += 1;
1427
- if (this.iterations < this.iterationLimit) {
3011
+ if (this.iterationLimit === true || this.iterations < this.iterationLimit) {
1428
3012
  this.createAnimate("reverse")(effect, options);
1429
3013
  }
1430
3014
  }
@@ -1633,7 +3217,7 @@ function createGetEaseables(fromKeyframeToControlPoints) {
1633
3217
  (easeables, property) => {
1634
3218
  const propertyKeyframes = createFilter(({ properties: properties2 }) => properties2.hasOwnProperty(property))(keyframes), fromKeyframesToEaseables = createReduce(
1635
3219
  (propertyEaseables2, keyframe, index) => {
1636
- const previous = keyframe.properties[property], next = index === propertyKeyframes.length - 1 ? previous : propertyKeyframes[index + 1].properties[property], start = keyframe.progress, end = index === propertyKeyframes.length - 1 ? 2 : propertyKeyframes[index + 1].progress, hasCustomTiming = !!keyframe.timing, toAnimationProgress = index === propertyKeyframes.length - 1 ? (timeProgress) => 1 : createToAnimationProgress(fromKeyframeToControlPoints({ keyframe, index, propertyKeyframes }));
3220
+ const previous = keyframe.properties[property], next = index === propertyKeyframes.length - 1 ? previous : propertyKeyframes[index + 1].properties[property], start = keyframe.progress, end = index === propertyKeyframes.length - 1 ? 2 : propertyKeyframes[index + 1].progress, hasCustomTiming = !!keyframe.timing, toAnimationProgress = index === propertyKeyframes.length - 1 ? () => 1 : createToAnimationProgress(fromKeyframeToControlPoints({ keyframe, index, propertyKeyframes }));
1637
3221
  propertyEaseables2.push({
1638
3222
  property,
1639
3223
  value: { previous, next },
@@ -1648,7 +3232,7 @@ function createGetEaseables(fromKeyframeToControlPoints) {
1648
3232
  property,
1649
3233
  value: { previous: propertyEaseables[0].value.previous, next: propertyEaseables[0].value.previous },
1650
3234
  progress: { start: -1, end: propertyEaseables[0].progress.start },
1651
- toAnimationProgress: (timeProgress) => 1,
3235
+ toAnimationProgress: () => 1,
1652
3236
  hasCustomTiming: false
1653
3237
  };
1654
3238
  return createConcat(
@@ -1893,14 +3477,14 @@ const easingsNetInOutBack = [
1893
3477
  1.6
1894
3478
  ];
1895
3479
 
1896
- const defaultOptions$6 = {
3480
+ const defaultOptions$7 = {
1897
3481
  name: "baleada"
1898
3482
  };
1899
3483
  class Broadcastable {
1900
3484
  name;
1901
3485
  constructor(state, options = {}) {
1902
3486
  this.setState(state);
1903
- this.name = options.name ?? defaultOptions$6.name;
3487
+ this.name = options.name ?? defaultOptions$7.name;
1904
3488
  this.ready();
1905
3489
  }
1906
3490
  computedStatus;
@@ -1965,12 +3549,69 @@ function toMessageListenParams(instance, effect) {
1965
3549
  ];
1966
3550
  }
1967
3551
 
3552
+ const defaultOptions$6 = {
3553
+ locales: "en",
3554
+ collator: { sensitivity: "base" }
3555
+ };
3556
+ class Compareable {
3557
+ constructor(string, options = {}) {
3558
+ const locales = options.locales || defaultOptions$6.locales, collatorOptions = { ...defaultOptions$6.collator, ...options.collator }, key = locales + lazyCollections.pipe(
3559
+ createEntries(),
3560
+ lazyCollections.sort((a, b) => a[0] < b[0] ? -1 : 1),
3561
+ lazyCollections.join()
3562
+ )(collatorOptions);
3563
+ this.computedCollator = cache[key] || (cache[key] = new Intl.Collator(locales, collatorOptions));
3564
+ this.setString(string);
3565
+ this.ready();
3566
+ }
3567
+ computedStatus;
3568
+ ready() {
3569
+ this.computedStatus = "ready";
3570
+ }
3571
+ get string() {
3572
+ return this.computedString;
3573
+ }
3574
+ set string(string) {
3575
+ this.setString(string);
3576
+ }
3577
+ get status() {
3578
+ return this.computedStatus;
3579
+ }
3580
+ computedCollator;
3581
+ get collator() {
3582
+ return this.computedCollator;
3583
+ }
3584
+ computedComparison;
3585
+ get comparison() {
3586
+ return this.computedComparison;
3587
+ }
3588
+ computedString;
3589
+ setString(string) {
3590
+ this.computedString = string;
3591
+ return this;
3592
+ }
3593
+ compare(compared) {
3594
+ this.comparing();
3595
+ this.computedComparison = this.computedCollator.compare(this.string, compared);
3596
+ this.compared();
3597
+ return this;
3598
+ }
3599
+ comparing() {
3600
+ this.computedStatus = "comparing";
3601
+ }
3602
+ compared() {
3603
+ this.computedStatus = "compared";
3604
+ }
3605
+ }
3606
+ const cache = {};
3607
+
1968
3608
  const defaultOptions$5 = {
1969
3609
  segment: {
1970
3610
  from: "start",
1971
3611
  to: "end"
1972
3612
  },
1973
3613
  divider: /\s/
3614
+ // Keep an eye out for use cases where a { before, after } object would be needed, or where multi-character dividers need to be used
1974
3615
  };
1975
3616
  const defaultCompleteOptions = {
1976
3617
  select: "completionEnd"
@@ -2053,6 +3694,7 @@ class Completeable {
2053
3694
  }
2054
3695
  return this;
2055
3696
  }
3697
+ // TODO: Support array of selections for multi cursor editing
2056
3698
  computedSelection;
2057
3699
  setSelection(selection) {
2058
3700
  this.computedSelection = selection;
@@ -2129,12 +3771,12 @@ function toPreviousMatch({ string, re, from }) {
2129
3771
  if (!re.test(string.slice(0, from)) || from === 0) {
2130
3772
  indexOf = -1;
2131
3773
  } else {
2132
- const reversedStringBeforeFrom = new Pipeable(string).pipe(
3774
+ const reversedStringBeforeFrom = lazyCollections.pipe(
2133
3775
  (string2) => string2.slice(0, from),
2134
3776
  (sliced) => sliced.split(""),
2135
3777
  reverse,
2136
3778
  toString
2137
- ), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
3779
+ )(string), toNextMatchIndex = toNextMatch({ string: reversedStringBeforeFrom, re, from: 0 });
2138
3780
  indexOf = toNextMatchIndex === -1 ? -1 : reversedStringBeforeFrom.length - 1 - toNextMatchIndex;
2139
3781
  }
2140
3782
  return indexOf;
@@ -2505,11 +4147,12 @@ class Fetchable {
2505
4147
  computedText;
2506
4148
  constructor(resource, options = {}) {
2507
4149
  this.setResource(resource);
2508
- this.computedArrayBuffer = new Resolveable(async () => "arrayBuffer" in this.response ? await this.response.arrayBuffer() : await void 0);
2509
- this.computedBlob = new Resolveable(async () => "blob" in this.response ? await this.response.blob() : await void 0);
2510
- this.computedFormData = new Resolveable(async () => "formData" in this.response ? await this.response.formData() : await void 0);
2511
- this.computedJson = new Resolveable(async () => "json" in this.response ? await this.response.json() : await void 0);
2512
- this.computedText = new Resolveable(async () => "text" in this.response ? await this.response.text() : await void 0);
4150
+ this.computedKy = ky.create(narrowOptions(options.ky));
4151
+ this.computedArrayBuffer = new Resolveable(async () => "arrayBuffer" in this.response ? await this.response.arrayBuffer() : void 0);
4152
+ this.computedBlob = new Resolveable(async () => "blob" in this.response ? await this.response.blob() : void 0);
4153
+ this.computedFormData = new Resolveable(async () => "formData" in this.response ? await this.response.formData() : void 0);
4154
+ this.computedJson = new Resolveable(async () => "json" in this.response ? await this.response.json() : void 0);
4155
+ this.computedText = new Resolveable(async () => "text" in this.response ? await this.response.text() : void 0);
2513
4156
  this.ready();
2514
4157
  }
2515
4158
  computedStatus;
@@ -2522,6 +4165,10 @@ class Fetchable {
2522
4165
  set resource(resource) {
2523
4166
  this.setResource(resource);
2524
4167
  }
4168
+ computedKy;
4169
+ get ky() {
4170
+ return this.computedKy;
4171
+ }
2525
4172
  computedAbortController;
2526
4173
  get abortController() {
2527
4174
  if (!this.computedAbortController) {
@@ -2535,6 +4182,10 @@ class Fetchable {
2535
4182
  get response() {
2536
4183
  return this.computedResponse;
2537
4184
  }
4185
+ computedRetryCount = 0;
4186
+ get retryCount() {
4187
+ return this.computedRetryCount;
4188
+ }
2538
4189
  get error() {
2539
4190
  return this.computedError;
2540
4191
  }
@@ -2563,7 +4214,23 @@ class Fetchable {
2563
4214
  async fetch(options = {}) {
2564
4215
  this.fetching();
2565
4216
  try {
2566
- this.computedResponse = await fetch(this.resource, { signal: this.abortController.signal, ...narrowOptions(options) });
4217
+ this.computedResponse = await this.ky(
4218
+ this.resource,
4219
+ {
4220
+ ...options,
4221
+ signal: this.abortController.signal,
4222
+ hooks: {
4223
+ ...options.hooks,
4224
+ beforeRetry: [
4225
+ ...options.hooks?.beforeRetry || [],
4226
+ ({ retryCount }) => {
4227
+ this.retrying();
4228
+ this.computedRetryCount = retryCount;
4229
+ }
4230
+ ]
4231
+ }
4232
+ }
4233
+ );
2567
4234
  this.fetched();
2568
4235
  } catch (error) {
2569
4236
  this.computedError = error;
@@ -2577,6 +4244,9 @@ class Fetchable {
2577
4244
  fetching() {
2578
4245
  this.computedStatus = "fetching";
2579
4246
  }
4247
+ retrying() {
4248
+ this.computedStatus = "retrying";
4249
+ }
2580
4250
  fetched() {
2581
4251
  this.computedStatus = "fetched";
2582
4252
  }
@@ -2587,23 +4257,27 @@ class Fetchable {
2587
4257
  this.computedStatus = "errored";
2588
4258
  }
2589
4259
  async get(options = {}) {
2590
- await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "get" });
4260
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "get" });
2591
4261
  return this;
2592
4262
  }
2593
4263
  async patch(options = {}) {
2594
- await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "patch" });
4264
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "patch" });
2595
4265
  return this;
2596
4266
  }
2597
4267
  async post(options = {}) {
2598
- await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "post" });
4268
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "post" });
2599
4269
  return this;
2600
4270
  }
2601
4271
  async put(options = {}) {
2602
- await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "put" });
4272
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "put" });
2603
4273
  return this;
2604
4274
  }
2605
4275
  async delete(options = {}) {
2606
- await this.fetch({ signal: this.abortController.signal, ...narrowOptions(options), method: "delete" });
4276
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "delete" });
4277
+ return this;
4278
+ }
4279
+ async head(options = {}) {
4280
+ await this.fetch({ signal: this.abortController.signal, ...options, method: "head" });
2607
4281
  return this;
2608
4282
  }
2609
4283
  abort() {
@@ -2612,16 +4286,9 @@ class Fetchable {
2612
4286
  }
2613
4287
  }
2614
4288
  function narrowOptions(options) {
2615
- return predicateFunction(options) ? options({ withJson }) : options;
2616
- }
2617
- function withJson(data) {
2618
- return {
2619
- body: JSON.stringify(data),
2620
- headers: {
2621
- "Accept": "application/json",
2622
- "Content-Type": "application/json"
2623
- }
2624
- };
4289
+ if (!options)
4290
+ return {};
4291
+ return predicateFunction(options) ? options({ stop: ky.stop }) : options;
2625
4292
  }
2626
4293
 
2627
4294
  class Fullscreenable {
@@ -2949,13 +4616,12 @@ class Pickable {
2949
4616
  }
2950
4617
  pick(indexOrIndices, options = {}) {
2951
4618
  const { replace, allowsDuplicates } = { ...defaultPickOptions, ...options };
2952
- this.computedPicks = new Pipeable(indexOrIndices).pipe(
4619
+ this.computedPicks = lazyCollections.pipe(
2953
4620
  narrowIndices,
2954
4621
  this.toPossiblePicks,
2955
4622
  (possiblePicks) => {
2956
- if (replace === "all") {
4623
+ if (replace === "all")
2957
4624
  return allowsDuplicates ? possiblePicks : toUnique(possiblePicks);
2958
- }
2959
4625
  const maybeWithoutDuplicates = allowsDuplicates ? possiblePicks : createFilter(
2960
4626
  (possiblePick) => typeof lazyCollections.find((pick) => pick === possiblePick)(this.picks || []) !== "number"
2961
4627
  )(possiblePicks);
@@ -2972,10 +4638,11 @@ class Pickable {
2972
4638
  if (maybeWithoutDuplicates.length > this.picks.length) {
2973
4639
  return createSlice(maybeWithoutDuplicates.length - this.picks.length)(maybeWithoutDuplicates);
2974
4640
  }
2975
- return new Pipeable(this.picks).pipe(
2976
- createSlice(maybeWithoutDuplicates.length),
2977
- createConcat(maybeWithoutDuplicates)
2978
- );
4641
+ return lazyCollections.pipe(
4642
+ lazyCollections.slice(maybeWithoutDuplicates.length),
4643
+ (array) => lazyCollections.concat(array, maybeWithoutDuplicates),
4644
+ lazyCollections.toArray()
4645
+ )(this.picks);
2979
4646
  case "lifo":
2980
4647
  if (maybeWithoutDuplicates.length === 0) {
2981
4648
  return this.picks;
@@ -2986,13 +4653,14 @@ class Pickable {
2986
4653
  if (maybeWithoutDuplicates.length > this.picks.length) {
2987
4654
  return createSlice(0, maybeWithoutDuplicates.length - this.picks.length + 1)(maybeWithoutDuplicates);
2988
4655
  }
2989
- return new Pipeable(this.picks).pipe(
2990
- createSlice(0, this.picks.length - maybeWithoutDuplicates.length),
2991
- createConcat(maybeWithoutDuplicates)
2992
- );
4656
+ return lazyCollections.pipe(
4657
+ lazyCollections.slice(0, this.picks.length - maybeWithoutDuplicates.length - 1),
4658
+ (array) => lazyCollections.concat(array, maybeWithoutDuplicates),
4659
+ lazyCollections.toArray()
4660
+ )(this.picks);
2993
4661
  }
2994
4662
  }
2995
- );
4663
+ )(indexOrIndices);
2996
4664
  this.computedFirst = Math.min(...this.picks);
2997
4665
  this.computedLast = Math.max(...this.picks);
2998
4666
  this.computedMultiple = toUnique(this.picks).length > 1;
@@ -3040,7 +4708,7 @@ class Sanitizeable {
3040
4708
  computedDompurify;
3041
4709
  computedStatus;
3042
4710
  ready() {
3043
- if (domIsAvailable()) {
4711
+ if (getDomAvailability() === "available") {
3044
4712
  this.computedDompurify = createDOMPurify();
3045
4713
  this.computedDompurify.setConfig(this.domPurifyConfig);
3046
4714
  }
@@ -3053,7 +4721,7 @@ class Sanitizeable {
3053
4721
  this.setHtml(html);
3054
4722
  }
3055
4723
  get dompurify() {
3056
- if (!this.computedDompurify && domIsAvailable()) {
4724
+ if (!this.computedDompurify && getDomAvailability() === "available") {
3057
4725
  this.computedDompurify = createDOMPurify();
3058
4726
  this.computedDompurify.setConfig(this.domPurifyConfig);
3059
4727
  }
@@ -3196,7 +4864,7 @@ class Storeable {
3196
4864
  computedStatus;
3197
4865
  ready() {
3198
4866
  this.computedStatus = "ready";
3199
- if (domIsAvailable()) {
4867
+ if (getDomAvailability() === "available") {
3200
4868
  if (predicateNull(this.storage.getItem(this.computedStatusKey))) {
3201
4869
  this.storeStatus();
3202
4870
  }
@@ -3209,7 +4877,7 @@ class Storeable {
3209
4877
  this.setKey(key);
3210
4878
  }
3211
4879
  get status() {
3212
- if (domIsAvailable()) {
4880
+ if (getDomAvailability() === "available") {
3213
4881
  const storedStatus = this.storage.getItem(this.computedStatusKey);
3214
4882
  if (this.computedStatus !== storedStatus && predicateString(storedStatus)) {
3215
4883
  this.computedStatus = storedStatus;
@@ -3299,6 +4967,7 @@ class Storeable {
3299
4967
 
3300
4968
  exports.Animateable = Animateable;
3301
4969
  exports.Broadcastable = Broadcastable;
4970
+ exports.Compareable = Compareable;
3302
4971
  exports.Completeable = Completeable;
3303
4972
  exports.Copyable = Copyable;
3304
4973
  exports.Delayable = Delayable;
@@ -3309,26 +4978,60 @@ exports.Grantable = Grantable;
3309
4978
  exports.Listenable = Listenable;
3310
4979
  exports.Navigateable = Navigateable;
3311
4980
  exports.Pickable = Pickable;
3312
- exports.Pipeable = Pipeable;
3313
4981
  exports.Recognizeable = Recognizeable;
3314
4982
  exports.Resolveable = Resolveable;
3315
4983
  exports.Sanitizeable = Sanitizeable;
3316
4984
  exports.Searchable = Searchable;
3317
4985
  exports.Shareable = Shareable;
3318
4986
  exports.Storeable = Storeable;
4987
+ exports.createAssociativeArray = createAssociativeArray;
4988
+ exports.createAsyncDirectedAcyclicPredicateAncestor = createPredicateAncestor$1;
4989
+ exports.createAsyncDirectedAcyclicToCommonAncestors = createToCommonAncestors$1;
4990
+ exports.createAsyncDirectedAcyclicToLayers = createToLayers;
4991
+ exports.createAsyncDirectedAcyclicToNodeSteps = createToNodeSteps$1;
4992
+ exports.createAsyncDirectedAcyclicToPath = createToPath$1;
4993
+ exports.createAsyncDirectedAcyclicToSteps = createToSteps$1;
4994
+ exports.createAsyncDirectedAcyclicToTree = createToTree$1;
3319
4995
  exports.createClamp = createClamp;
3320
4996
  exports.createClip = createClip;
4997
+ exports.createClone = createClone;
3321
4998
  exports.createConcat = createConcat;
4999
+ exports.createDecisionTreePredicateAncestor = createPredicateAncestor;
5000
+ exports.createDecisionTreeToCommonAncestors = createToCommonAncestors;
5001
+ exports.createDecisionTreeToNodeSteps = createToNodeSteps;
5002
+ exports.createDecisionTreeToPath = createToPath;
5003
+ exports.createDecisionTreeToSteps = createToSteps;
5004
+ exports.createDecisionTreeToTree = createToTree;
3322
5005
  exports.createDetermine = createDetermine;
5006
+ exports.createDirectedAcyclicPredicateAncestor = createPredicateAncestor$2;
5007
+ exports.createDirectedAcyclicToCommonAncestors = createToCommonAncestors$2;
5008
+ exports.createDirectedAcyclicToLayers = createToLayers$1;
5009
+ exports.createDirectedAcyclicToNodeSteps = createToNodeSteps$2;
5010
+ exports.createDirectedAcyclicToPath = createToPath$2;
5011
+ exports.createDirectedAcyclicToRoots = createToRoots;
5012
+ exports.createDirectedAcyclicToSteps = createToSteps$2;
5013
+ exports.createDirectedAcyclicToTree = createToTree$2;
5014
+ exports.createEntries = createEntries;
5015
+ exports.createEqual = createEqual;
5016
+ exports.createEvery = createEvery;
3323
5017
  exports.createFilter = createFilter;
3324
5018
  exports.createFilterAsync = createFilterAsync;
5019
+ exports.createFindAsync = createFindAsync;
5020
+ exports.createFindIndexAsync = createFindIndexAsync;
5021
+ exports.createFocusable = createFocusable;
3325
5022
  exports.createForEachAsync = createForEachAsync;
3326
5023
  exports.createInsert = createInsert;
5024
+ exports.createKeychord = createKeychord;
5025
+ exports.createKeypress = createKeypress;
5026
+ exports.createKeyrelease = createKeyrelease;
5027
+ exports.createKeys = createKeys;
5028
+ exports.createList = createList;
3327
5029
  exports.createMap = createMap;
3328
5030
  exports.createMapAsync = createMapAsync;
3329
- exports.createMatchesKeycombo = createMatchesKeycombo;
3330
- exports.createMatchesMousecombo = createMatchesMousecombo;
3331
- exports.createMatchesPointercombo = createMatchesPointercombo;
5031
+ exports.createMousepress = createMousepress;
5032
+ exports.createMouserelease = createMouserelease;
5033
+ exports.createPredicateKeycomboMatch = createPredicateKeycomboMatch$1;
5034
+ exports.createPredicateRoot = createPredicateRoot;
3332
5035
  exports.createReduce = createReduce;
3333
5036
  exports.createReduceAsync = createReduceAsync;
3334
5037
  exports.createRemove = createRemove;
@@ -3338,14 +5041,27 @@ exports.createReplace = createReplace;
3338
5041
  exports.createReverse = createReverse;
3339
5042
  exports.createSlice = createSlice;
3340
5043
  exports.createSlug = createSlug;
5044
+ exports.createSome = createSome;
3341
5045
  exports.createSort = createSort;
3342
5046
  exports.createSwap = createSwap;
3343
- exports.createToEntries = createToEntries;
3344
- exports.createToEvery = createToEvery;
3345
- exports.createToFocusable = createToFocusable;
3346
- exports.createToKeys = createToKeys;
3347
- exports.createToSome = createToSome;
5047
+ exports.createToGraph = createToGraph;
5048
+ exports.createToIncoming = createToIncoming;
5049
+ exports.createToIndegree = createToIndegree;
5050
+ exports.createToOutdegree = createToOutdegree;
5051
+ exports.createToOutgoing = createToOutgoing;
5052
+ exports.createTouchpress = createTouchpress;
5053
+ exports.createTouchrelease = createTouchrelease;
5054
+ exports.createTreeFind = createFind;
3348
5055
  exports.createUnique = createUnique;
5056
+ exports.defineAssociativeArrayEntries = defineAssociativeArrayEntries;
5057
+ exports.defineAsyncGraph = defineAsyncGraph;
5058
+ exports.defineAsyncGraphEdge = defineAsyncGraphEdge;
5059
+ exports.defineAsyncGraphEdges = defineAsyncGraphEdges;
5060
+ exports.defineGraph = defineGraph;
5061
+ exports.defineGraphEdge = defineGraphEdge;
5062
+ exports.defineGraphEdges = defineGraphEdges;
5063
+ exports.defineGraphNode = defineGraphNode;
5064
+ exports.defineGraphNodes = defineGraphNodes;
3349
5065
  exports.easingsNetInBack = easingsNetInBack;
3350
5066
  exports.easingsNetInCirc = easingsNetInCirc;
3351
5067
  exports.easingsNetInCubic = easingsNetInCubic;