cafe-utility 13.3.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +19 -11
- package/index.js +125 -110
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -334,14 +334,20 @@ declare function transformToArray(objectOfArrays: CafeObject<unknown[]>): CafeOb
|
|
|
334
334
|
declare function incrementMulti<T>(objects: T[], key: keyof T, step?: number): void;
|
|
335
335
|
declare function setMulti<T, K extends keyof T>(objects: T[], key: K, value: T[K]): void;
|
|
336
336
|
declare function group<T>(array: T[], groupFn: (current: T, previous: T) => boolean): T[][];
|
|
337
|
-
interface
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
interface TemporalData<T> {
|
|
338
|
+
validUntil: number;
|
|
339
|
+
data: T;
|
|
340
|
+
}
|
|
341
|
+
interface BidirectionalMap<K, T> {
|
|
342
|
+
map: Map<K, T>;
|
|
343
|
+
keys: K[];
|
|
340
344
|
}
|
|
341
|
-
declare function
|
|
342
|
-
declare function
|
|
343
|
-
declare function
|
|
344
|
-
declare function
|
|
345
|
+
declare function createBidirectionalMap<K, T>(): BidirectionalMap<K, T>;
|
|
346
|
+
declare function createTemporalBidirectionalMap<K, T>(): BidirectionalMap<K, TemporalData<T>>;
|
|
347
|
+
declare function pushToBidirectionalMap<K, T>(object: BidirectionalMap<K, T>, key: K, item: T, limit?: number): void;
|
|
348
|
+
declare function unshiftToBidirectionalMap<K, T>(object: BidirectionalMap<K, T>, key: K, item: T, limit?: number): void;
|
|
349
|
+
declare function addToTemporalBidirectionalMap<K, T>(object: BidirectionalMap<K, TemporalData<T>>, key: K, item: T, expiration: number, limit?: number): void;
|
|
350
|
+
declare function getFromTemporalBidirectionalMap<K, T>(object: BidirectionalMap<K, TemporalData<T>>, key: K): T | null;
|
|
345
351
|
declare function makeAsyncQueue(concurrency?: number): {
|
|
346
352
|
enqueue(fn: () => Promise<void>): void;
|
|
347
353
|
drain: () => Promise<void>;
|
|
@@ -535,10 +541,12 @@ export declare const Objects: {
|
|
|
535
541
|
transformToArray: typeof transformToArray;
|
|
536
542
|
setMulti: typeof setMulti;
|
|
537
543
|
incrementMulti: typeof incrementMulti;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
544
|
+
createBidirectionalMap: typeof createBidirectionalMap;
|
|
545
|
+
createTemporalBidirectionalMap: typeof createTemporalBidirectionalMap;
|
|
546
|
+
pushToBidirectionalMap: typeof pushToBidirectionalMap;
|
|
547
|
+
unshiftToBidirectionalMap: typeof unshiftToBidirectionalMap;
|
|
548
|
+
addToTemporalBidirectionalMap: typeof addToTemporalBidirectionalMap;
|
|
549
|
+
getFromTemporalBidirectionalMap: typeof getFromTemporalBidirectionalMap;
|
|
542
550
|
createStatefulToggle: typeof createStatefulToggle;
|
|
543
551
|
diffKeys: typeof diffKeys;
|
|
544
552
|
pickRandomKey: typeof pickRandomKey;
|
package/index.js
CHANGED
|
@@ -126,13 +126,13 @@ function pickManyUnique(n, e, t, r = Math.random) {
|
|
|
126
126
|
return o
|
|
127
127
|
}
|
|
128
128
|
function pickGuaranteed(n, e, t, r, o, i = Math.random) {
|
|
129
|
-
const u = n.filter(
|
|
130
|
-
|
|
131
|
-
for (e !== null &&
|
|
132
|
-
const
|
|
133
|
-
o(u[
|
|
129
|
+
const u = n.filter(s => s !== e && s !== t),
|
|
130
|
+
c = []
|
|
131
|
+
for (e !== null && c.push(e); u.length && c.length < r; ) {
|
|
132
|
+
const s = exports.Random.intBetween(0, u.length - 1, i)
|
|
133
|
+
o(u[s], c) && c.push(u[s]), u.splice(s, 1)
|
|
134
134
|
}
|
|
135
|
-
return shuffle(
|
|
135
|
+
return shuffle(c, i), { values: c, indexOfGuaranteed: e !== null ? c.indexOf(e) : -1 }
|
|
136
136
|
}
|
|
137
137
|
function last(n) {
|
|
138
138
|
return n[n.length - 1]
|
|
@@ -167,10 +167,10 @@ function setDeep(n, e, t) {
|
|
|
167
167
|
let o = n
|
|
168
168
|
for (let i = 0; i < r.length; i++) {
|
|
169
169
|
const u = r[i],
|
|
170
|
-
|
|
170
|
+
c = i < r.length - 1 && r[i + 1].includes(']'),
|
|
171
171
|
f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
172
172
|
if (i === r.length - 1) return (o[f] = t), t
|
|
173
|
-
isObject(o[f]) || (
|
|
173
|
+
isObject(o[f]) || (c ? (o[f] = []) : (o[f] = {})), (o = o[f])
|
|
174
174
|
}
|
|
175
175
|
return t
|
|
176
176
|
}
|
|
@@ -678,9 +678,9 @@ function expand(n) {
|
|
|
678
678
|
o = n.slice(0, t.index),
|
|
679
679
|
i = n.slice(t.index + t[0].length)
|
|
680
680
|
let u = []
|
|
681
|
-
for (const
|
|
682
|
-
const
|
|
683
|
-
u = u.concat(
|
|
681
|
+
for (const c of r) {
|
|
682
|
+
const s = expand(o + c + i)
|
|
683
|
+
u = u.concat(s)
|
|
684
684
|
}
|
|
685
685
|
return u
|
|
686
686
|
}
|
|
@@ -860,12 +860,12 @@ function base64ToUint8Array(n) {
|
|
|
860
860
|
i = 0
|
|
861
861
|
for (; o < n.length; ) {
|
|
862
862
|
const u = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
863
|
-
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
864
863
|
c = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
864
|
+
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
865
865
|
f = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
866
|
-
l = (u << 2) | (
|
|
867
|
-
a = ((
|
|
868
|
-
h = ((
|
|
866
|
+
l = (u << 2) | (c >> 4),
|
|
867
|
+
a = ((c & 15) << 4) | (s >> 2),
|
|
868
|
+
h = ((s & 3) << 6) | f
|
|
869
869
|
;(r[i++] = l), i < t && (r[i++] = a), i < t && (r[i++] = h)
|
|
870
870
|
}
|
|
871
871
|
return r
|
|
@@ -877,11 +877,11 @@ function uint8ArrayToBase64(n) {
|
|
|
877
877
|
const o = n[r],
|
|
878
878
|
i = n[r + 1],
|
|
879
879
|
u = n[r + 2],
|
|
880
|
-
|
|
881
|
-
|
|
880
|
+
c = o >> 2,
|
|
881
|
+
s = ((o & 3) << 4) | (i >> 4),
|
|
882
882
|
f = ((i & 15) << 2) | (u >> 6),
|
|
883
883
|
l = u & 63
|
|
884
|
-
;(e += BASE64_CHARS[
|
|
884
|
+
;(e += BASE64_CHARS[c] + BASE64_CHARS[s]),
|
|
885
885
|
r + 1 < n.length ? (e += BASE64_CHARS[f]) : t++,
|
|
886
886
|
r + 2 < n.length ? (e += BASE64_CHARS[l]) : t++
|
|
887
887
|
}
|
|
@@ -923,7 +923,7 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
923
923
|
const o = exports.Arrays.shuffle(
|
|
924
924
|
e.map(u => ({
|
|
925
925
|
variants: exports.Arrays.shuffle(
|
|
926
|
-
u.variants.map(
|
|
926
|
+
u.variants.map(c => c),
|
|
927
927
|
r
|
|
928
928
|
),
|
|
929
929
|
avoid: u.avoid
|
|
@@ -932,14 +932,14 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
932
932
|
),
|
|
933
933
|
i = []
|
|
934
934
|
for (const u of o) {
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
if (
|
|
935
|
+
const c = u.variants.filter(f => f !== u.avoid),
|
|
936
|
+
s = c.find(f => n.includes(f))
|
|
937
|
+
if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= t)) break
|
|
938
938
|
}
|
|
939
939
|
if (i.length < t)
|
|
940
940
|
for (const u of o) {
|
|
941
|
-
const
|
|
942
|
-
if (
|
|
941
|
+
const c = u.variants.find(s => n.includes(s))
|
|
942
|
+
if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= t)) break
|
|
943
943
|
}
|
|
944
944
|
return i.slice(0, t)
|
|
945
945
|
}
|
|
@@ -991,8 +991,8 @@ function resolveVariableWithDefaultSyntax(n, e, t, r = '$', o = ':') {
|
|
|
991
991
|
if (n[i + e.length + 1] === o)
|
|
992
992
|
if (n[i + e.length + 2] === o) n = n.replace(`${r}${e}${o}${o}`, t)
|
|
993
993
|
else {
|
|
994
|
-
const
|
|
995
|
-
n = n.replace(`${r}${e}${o}${
|
|
994
|
+
const c = readNextWord(n, i + e.length + 2, ['_'])
|
|
995
|
+
n = n.replace(`${r}${e}${o}${c}`, t)
|
|
996
996
|
}
|
|
997
997
|
else n = n.replace(`${r}${e}`, t)
|
|
998
998
|
i = n.indexOf(`${r}${e}`, i + t.length)
|
|
@@ -1020,8 +1020,8 @@ function resolveMarkdownLinks(n, e) {
|
|
|
1020
1020
|
o = n.indexOf(')', t)
|
|
1021
1021
|
if (r !== -1 && o !== -1) {
|
|
1022
1022
|
const [i, u] = n.slice(r + 1, o).split(']('),
|
|
1023
|
-
|
|
1024
|
-
n = n.slice(0, r) +
|
|
1023
|
+
c = e(i, u)
|
|
1024
|
+
n = n.slice(0, r) + c + n.slice(o + 1)
|
|
1025
1025
|
}
|
|
1026
1026
|
t = n.indexOf('](', t + 1)
|
|
1027
1027
|
}
|
|
@@ -1054,7 +1054,7 @@ function parseCsv(n, e = ',', t = '"') {
|
|
|
1054
1054
|
let o = '',
|
|
1055
1055
|
i = !1
|
|
1056
1056
|
const u = n.split('')
|
|
1057
|
-
for (const
|
|
1057
|
+
for (const c of u) c === e && !i ? (r.push(o), (o = '')) : c === t && ((!o && !i) || i) ? (i = !i) : (o += c)
|
|
1058
1058
|
return r.push(o), r
|
|
1059
1059
|
}
|
|
1060
1060
|
function humanizeProgress(n) {
|
|
@@ -1135,12 +1135,12 @@ function getAgoStructured(n, e) {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
function countCycles(n, e, t) {
|
|
1137
1137
|
var r, o, i
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1138
|
+
const c = ((r = t?.now) !== null && r !== void 0 ? r : Date.now()) - n,
|
|
1139
|
+
s = Math.floor(c / e),
|
|
1140
1140
|
f =
|
|
1141
1141
|
e / ((o = t?.precision) !== null && o !== void 0 ? o : 1) -
|
|
1142
|
-
Math.ceil((
|
|
1143
|
-
return { cycles:
|
|
1142
|
+
Math.ceil((c % e) / ((i = t?.precision) !== null && i !== void 0 ? i : 1))
|
|
1143
|
+
return { cycles: s, remaining: f }
|
|
1144
1144
|
}
|
|
1145
1145
|
const throttleTimers = {}
|
|
1146
1146
|
function throttle(n, e) {
|
|
@@ -1157,9 +1157,9 @@ function getProgress(n, e, t, r) {
|
|
|
1157
1157
|
const o = e / t,
|
|
1158
1158
|
i = r - n,
|
|
1159
1159
|
u = i / e,
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs:
|
|
1160
|
+
c = u * t,
|
|
1161
|
+
s = c - i
|
|
1162
|
+
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
|
|
1163
1163
|
}
|
|
1164
1164
|
const dayNumberIndex = {
|
|
1165
1165
|
0: 'sunday',
|
|
@@ -1324,9 +1324,9 @@ function organiseWithLimits(n, e, t, r, o) {
|
|
|
1324
1324
|
for (const u of Object.keys(e)) i[u] = []
|
|
1325
1325
|
;(i[r] = []), o && (n = n.sort(o))
|
|
1326
1326
|
for (const u of n) {
|
|
1327
|
-
const
|
|
1328
|
-
|
|
1329
|
-
i[
|
|
1327
|
+
const c = u[t],
|
|
1328
|
+
s = e[c] ? c : r
|
|
1329
|
+
i[s].length >= e[s] ? i[r].push(u) : i[s].push(u)
|
|
1330
1330
|
}
|
|
1331
1331
|
return i
|
|
1332
1332
|
}
|
|
@@ -1390,11 +1390,11 @@ function formatNumber(n, e) {
|
|
|
1390
1390
|
const o = (t = e?.longForm) !== null && t !== void 0 ? t : !1,
|
|
1391
1391
|
i = e?.unit ? ` ${e.unit}` : '',
|
|
1392
1392
|
u = o ? longNumberUnits : shortNumberUnits,
|
|
1393
|
-
|
|
1393
|
+
c = (r = e?.precision) !== null && r !== void 0 ? r : 1
|
|
1394
1394
|
if (n < thresholds[0]) return `${n}${i}`
|
|
1395
|
-
for (let
|
|
1396
|
-
if (n < thresholds[
|
|
1397
|
-
return `${(n / thresholds[thresholds.length - 1]).toFixed(
|
|
1395
|
+
for (let s = 0; s < thresholds.length - 1; s++)
|
|
1396
|
+
if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
|
|
1397
|
+
return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
|
|
1398
1398
|
}
|
|
1399
1399
|
function makeNumber(n) {
|
|
1400
1400
|
const e = parseFloat(n)
|
|
@@ -1473,20 +1473,20 @@ function flip(n) {
|
|
|
1473
1473
|
}
|
|
1474
1474
|
function getAllPermutations(n) {
|
|
1475
1475
|
const e = Object.keys(n),
|
|
1476
|
-
t = e.map(
|
|
1477
|
-
r = t.reduce((
|
|
1476
|
+
t = e.map(c => n[c].length),
|
|
1477
|
+
r = t.reduce((c, s) => (c *= s))
|
|
1478
1478
|
let o = 1
|
|
1479
1479
|
const i = [1]
|
|
1480
|
-
for (let
|
|
1480
|
+
for (let c = 0; c < t.length - 1; c++) (o *= t[c]), i.push(o)
|
|
1481
1481
|
const u = []
|
|
1482
|
-
for (let
|
|
1483
|
-
const
|
|
1482
|
+
for (let c = 0; c < r; c++) {
|
|
1483
|
+
const s = {}
|
|
1484
1484
|
for (let f = 0; f < e.length; f++) {
|
|
1485
1485
|
const l = n[e[f]],
|
|
1486
|
-
a = Math.floor(
|
|
1487
|
-
|
|
1486
|
+
a = Math.floor(c / i[f]) % l.length
|
|
1487
|
+
s[e[f]] = l[a]
|
|
1488
1488
|
}
|
|
1489
|
-
u.push(
|
|
1489
|
+
u.push(s)
|
|
1490
1490
|
}
|
|
1491
1491
|
return u
|
|
1492
1492
|
}
|
|
@@ -1499,14 +1499,14 @@ function getFlatNotation(n, e, t) {
|
|
|
1499
1499
|
function flattenInner(n, e, t, r, o) {
|
|
1500
1500
|
if (!isObject(e)) return e
|
|
1501
1501
|
for (const [i, u] of Object.entries(e)) {
|
|
1502
|
-
const
|
|
1502
|
+
const c = getFlatNotation(t, i, r)
|
|
1503
1503
|
Array.isArray(u)
|
|
1504
1504
|
? o
|
|
1505
|
-
? flattenInner(n, u,
|
|
1506
|
-
: (n[
|
|
1505
|
+
? flattenInner(n, u, c, !0, o)
|
|
1506
|
+
: (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
|
|
1507
1507
|
: isObject(u)
|
|
1508
|
-
? flattenInner(n, u,
|
|
1509
|
-
: (n[
|
|
1508
|
+
? flattenInner(n, u, c, !1, o)
|
|
1509
|
+
: (n[c] = u)
|
|
1510
1510
|
}
|
|
1511
1511
|
return n
|
|
1512
1512
|
}
|
|
@@ -1572,9 +1572,9 @@ function makeUnique(n, e) {
|
|
|
1572
1572
|
function countUnique(n, e, t, r, o) {
|
|
1573
1573
|
const i = e ? n.map(e) : n,
|
|
1574
1574
|
u = {}
|
|
1575
|
-
for (const
|
|
1576
|
-
const
|
|
1577
|
-
return t ? Object.keys(
|
|
1575
|
+
for (const s of i) u[s] = (u[s] || 0) + 1
|
|
1576
|
+
const c = r ? sortObjectValues(u, o ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : u
|
|
1577
|
+
return t ? Object.keys(c) : c
|
|
1578
1578
|
}
|
|
1579
1579
|
function sortObjectValues(n, e) {
|
|
1580
1580
|
return Object.fromEntries(Object.entries(n).sort(e))
|
|
@@ -1603,24 +1603,37 @@ function group(n, e) {
|
|
|
1603
1603
|
for (let o = 1; o < n.length; o++) e(n[o], n[o - 1]) || ((r = []), t.push(r)), r.push(n[o])
|
|
1604
1604
|
return t
|
|
1605
1605
|
}
|
|
1606
|
-
function
|
|
1607
|
-
return {
|
|
1606
|
+
function createBidirectionalMap() {
|
|
1607
|
+
return { map: new Map(), keys: [] }
|
|
1608
|
+
}
|
|
1609
|
+
function createTemporalBidirectionalMap() {
|
|
1610
|
+
return { map: new Map(), keys: [] }
|
|
1611
|
+
}
|
|
1612
|
+
function pushToBidirectionalMap(n, e, t, r = 100) {
|
|
1613
|
+
if (n.map.has(e)) {
|
|
1614
|
+
const o = n.keys.indexOf(e)
|
|
1615
|
+
n.keys.splice(o, 1)
|
|
1616
|
+
}
|
|
1617
|
+
if ((n.map.set(e, t), n.keys.push(e), n.keys.length > r)) {
|
|
1618
|
+
const o = n.keys.shift()
|
|
1619
|
+
o && n.map.delete(o)
|
|
1620
|
+
}
|
|
1608
1621
|
}
|
|
1609
|
-
function
|
|
1610
|
-
if (n.
|
|
1622
|
+
function unshiftToBidirectionalMap(n, e, t, r = 100) {
|
|
1623
|
+
if (n.map.has(e)) {
|
|
1611
1624
|
const o = n.keys.indexOf(e)
|
|
1612
1625
|
n.keys.splice(o, 1)
|
|
1613
1626
|
}
|
|
1614
|
-
if ((
|
|
1627
|
+
if ((n.map.set(e, t), n.keys.unshift(e), n.keys.length > r)) {
|
|
1615
1628
|
const o = n.keys.shift()
|
|
1616
|
-
o &&
|
|
1629
|
+
o && n.map.delete(o)
|
|
1617
1630
|
}
|
|
1618
1631
|
}
|
|
1619
|
-
function
|
|
1620
|
-
|
|
1632
|
+
function addToTemporalBidirectionalMap(n, e, t, r, o = 100) {
|
|
1633
|
+
pushToBidirectionalMap(n, e, { validUntil: Date.now() + r, data: t }, o)
|
|
1621
1634
|
}
|
|
1622
|
-
function
|
|
1623
|
-
const t = n.
|
|
1635
|
+
function getFromTemporalBidirectionalMap(n, e) {
|
|
1636
|
+
const t = n.map.get(e)
|
|
1624
1637
|
return t && t.validUntil > Date.now() ? t.data : null
|
|
1625
1638
|
}
|
|
1626
1639
|
function makeAsyncQueue(n = 1) {
|
|
@@ -1685,7 +1698,7 @@ function tickPlaybook(n) {
|
|
|
1685
1698
|
)
|
|
1686
1699
|
}
|
|
1687
1700
|
function getArgument(n, e, t, r) {
|
|
1688
|
-
const o = n.findIndex(
|
|
1701
|
+
const o = n.findIndex(c => c.endsWith('-' + e) || c.includes('-' + e + '=')),
|
|
1689
1702
|
i = n[o]
|
|
1690
1703
|
if (!i) return (t || {})[r || e || ''] || null
|
|
1691
1704
|
if (i.includes('=')) return i.split('=')[1]
|
|
@@ -1702,14 +1715,14 @@ function getNumberArgument(n, e, t, r) {
|
|
|
1702
1715
|
}
|
|
1703
1716
|
}
|
|
1704
1717
|
function getBooleanArgument(n, e, t, r) {
|
|
1705
|
-
const o = n.some(
|
|
1718
|
+
const o = n.some(s => s.endsWith('-' + e)),
|
|
1706
1719
|
i = getArgument(n, e, t, r)
|
|
1707
1720
|
if (!i && o) return !0
|
|
1708
1721
|
if (!i && !o) return null
|
|
1709
1722
|
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
1710
|
-
|
|
1723
|
+
c = ['false', '0', 'no', 'n', 'off']
|
|
1711
1724
|
if (u.includes(i.toLowerCase())) return !0
|
|
1712
|
-
if (
|
|
1725
|
+
if (c.includes(i.toLowerCase())) return !1
|
|
1713
1726
|
throw Error(`Invalid boolean argument ${e}: ${i}`)
|
|
1714
1727
|
}
|
|
1715
1728
|
function requireStringArgument(n, e, t, r) {
|
|
@@ -1792,16 +1805,16 @@ function isBottommost(n, e, t) {
|
|
|
1792
1805
|
return !n[e][t + 1]
|
|
1793
1806
|
}
|
|
1794
1807
|
function getCorners(n, e, t) {
|
|
1795
|
-
var r, o, i, u,
|
|
1808
|
+
var r, o, i, u, c, s, f, l
|
|
1796
1809
|
const a = []
|
|
1797
1810
|
return n[e][t]
|
|
1798
1811
|
? isHorizontalLine(n, e, t) || isVerticalLine(n, e, t)
|
|
1799
1812
|
? []
|
|
1800
|
-
: (!(!((
|
|
1813
|
+
: (!(!((c = n[e - 1]) === null || c === void 0) && c[t - 1]) &&
|
|
1801
1814
|
isLeftmost(n, e, t) &&
|
|
1802
1815
|
isTopmost(n, e, t) &&
|
|
1803
1816
|
a.push({ x: e, y: t }),
|
|
1804
|
-
!(!((
|
|
1817
|
+
!(!((s = n[e + 1]) === null || s === void 0) && s[t - 1]) &&
|
|
1805
1818
|
isRightmost(n, e, t) &&
|
|
1806
1819
|
isTopmost(n, e, t) &&
|
|
1807
1820
|
a.push({ x: e + 1, y: t }),
|
|
@@ -1829,42 +1842,42 @@ function findCorners(n, e, t, r) {
|
|
|
1829
1842
|
]
|
|
1830
1843
|
for (let i = 0; i < n.length; i++)
|
|
1831
1844
|
for (let u = 0; u < n[0].length; u++) {
|
|
1832
|
-
const
|
|
1833
|
-
for (const
|
|
1845
|
+
const c = getCorners(n, i, u)
|
|
1846
|
+
for (const s of c) o.some(f => f.x === s.x && f.y === s.y) || o.push(s)
|
|
1834
1847
|
}
|
|
1835
1848
|
return o.map(i => ({ x: i.x * e, y: i.y * e }))
|
|
1836
1849
|
}
|
|
1837
1850
|
function findLines(n, e) {
|
|
1838
|
-
const t = filterCoordinates(n, (
|
|
1839
|
-
Object.assign(Object.assign({},
|
|
1851
|
+
const t = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s =>
|
|
1852
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
1840
1853
|
),
|
|
1841
|
-
r = filterCoordinates(n, (
|
|
1842
|
-
Object.assign(Object.assign({},
|
|
1854
|
+
r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s =>
|
|
1855
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
1843
1856
|
),
|
|
1844
1857
|
o = filterCoordinates(
|
|
1845
1858
|
n,
|
|
1846
|
-
(
|
|
1859
|
+
(s, f) => {
|
|
1847
1860
|
var l
|
|
1848
|
-
return n[
|
|
1861
|
+
return n[s][f] === 0 && ((l = n[s - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
1849
1862
|
},
|
|
1850
1863
|
'column-first'
|
|
1851
|
-
).map(
|
|
1864
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
|
|
1852
1865
|
i = filterCoordinates(
|
|
1853
1866
|
n,
|
|
1854
|
-
(
|
|
1867
|
+
(s, f) => {
|
|
1855
1868
|
var l
|
|
1856
|
-
return n[
|
|
1869
|
+
return n[s][f] === 0 && ((l = n[s + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
1857
1870
|
},
|
|
1858
1871
|
'column-first'
|
|
1859
|
-
).map(
|
|
1860
|
-
t.forEach(
|
|
1861
|
-
const u = group([...o, ...i], (
|
|
1862
|
-
|
|
1863
|
-
return [...u, ...
|
|
1864
|
-
.map(
|
|
1865
|
-
.map(
|
|
1866
|
-
start: multiplyPoint(
|
|
1867
|
-
end: multiplyPoint(addPoint(
|
|
1872
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
|
|
1873
|
+
t.forEach(s => s.y++), i.forEach(s => s.x++)
|
|
1874
|
+
const u = group([...o, ...i], (s, f) => s.x === f.x && s.y - 1 === f.y),
|
|
1875
|
+
c = group([...r, ...t], (s, f) => s.y === f.y && s.x - 1 === f.x)
|
|
1876
|
+
return [...u, ...c]
|
|
1877
|
+
.map(s => ({ start: s[0], end: last(s) }))
|
|
1878
|
+
.map(s => ({
|
|
1879
|
+
start: multiplyPoint(s.start, e),
|
|
1880
|
+
end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), e)
|
|
1868
1881
|
}))
|
|
1869
1882
|
}
|
|
1870
1883
|
function getAngleInRadians(n, e) {
|
|
@@ -1878,11 +1891,11 @@ function getLineIntersectionPoint(n, e, t, r) {
|
|
|
1878
1891
|
if (o === 0) return null
|
|
1879
1892
|
let i = n.y - t.y,
|
|
1880
1893
|
u = n.x - t.x
|
|
1881
|
-
const
|
|
1882
|
-
|
|
1894
|
+
const c = (r.x - t.x) * i - (r.y - t.y) * u,
|
|
1895
|
+
s = (e.x - n.x) * i - (e.y - n.y) * u
|
|
1883
1896
|
return (
|
|
1884
|
-
(i =
|
|
1885
|
-
(u =
|
|
1897
|
+
(i = c / o),
|
|
1898
|
+
(u = s / o),
|
|
1886
1899
|
i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (e.x - n.x), y: n.y + i * (e.y - n.y) } : null
|
|
1887
1900
|
)
|
|
1888
1901
|
}
|
|
@@ -1895,9 +1908,9 @@ function raycast(n, e, t) {
|
|
|
1895
1908
|
}
|
|
1896
1909
|
return r.length
|
|
1897
1910
|
? r.reduce((i, u) => {
|
|
1898
|
-
const
|
|
1899
|
-
|
|
1900
|
-
return
|
|
1911
|
+
const c = getDistanceBetweenPoints(n, u),
|
|
1912
|
+
s = getDistanceBetweenPoints(n, i)
|
|
1913
|
+
return c < s ? u : i
|
|
1901
1914
|
})
|
|
1902
1915
|
: null
|
|
1903
1916
|
}
|
|
@@ -1905,9 +1918,9 @@ function raycastCircle(n, e, t) {
|
|
|
1905
1918
|
const o = getSortedRayAngles(n, t),
|
|
1906
1919
|
i = []
|
|
1907
1920
|
for (const u of o) {
|
|
1908
|
-
const
|
|
1909
|
-
|
|
1910
|
-
|
|
1921
|
+
const c = raycast(n, e, u - 0.001),
|
|
1922
|
+
s = raycast(n, e, u + 0.001)
|
|
1923
|
+
c && i.push(c), s && i.push(s)
|
|
1911
1924
|
}
|
|
1912
1925
|
return i
|
|
1913
1926
|
}
|
|
@@ -2041,10 +2054,12 @@ function raycastCircle(n, e, t) {
|
|
|
2041
2054
|
transformToArray,
|
|
2042
2055
|
setMulti,
|
|
2043
2056
|
incrementMulti,
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2057
|
+
createBidirectionalMap,
|
|
2058
|
+
createTemporalBidirectionalMap,
|
|
2059
|
+
pushToBidirectionalMap,
|
|
2060
|
+
unshiftToBidirectionalMap,
|
|
2061
|
+
addToTemporalBidirectionalMap,
|
|
2062
|
+
getFromTemporalBidirectionalMap,
|
|
2048
2063
|
createStatefulToggle,
|
|
2049
2064
|
diffKeys,
|
|
2050
2065
|
pickRandomKey,
|