cafe-utility 22.5.0 → 23.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 CHANGED
@@ -538,10 +538,10 @@ declare function findLines(grid: Truthy[][], tileSize: number): Line[];
538
538
  declare function getLineIntersectionPoint(line1Start: Point, line1End: Point, line2Start: Point, line2End: Point): Point | null;
539
539
  declare function raycast(origin: Point, lines: Line[], angle: number): Point | null;
540
540
  declare function raycastCircle(origin: Point, lines: Line[], corners: Point[]): Point[];
541
- export declare class PubSubSystem {
541
+ export declare class PubSubChannel<T> {
542
542
  private subscribers;
543
- subscribe(event: string, callback: (data: unknown) => void): () => void;
544
- publish(event: string, data: unknown): void;
543
+ subscribe(callback: (data: T) => void): () => void;
544
+ publish(data: T): void;
545
545
  }
546
546
  export declare const Binary: {
547
547
  hexToUint8Array: typeof hexToUint8Array;
package/index.js CHANGED
@@ -13,7 +13,7 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
13
13
  exports.Arrays =
14
14
  exports.Random =
15
15
  exports.Binary =
16
- exports.PubSubSystem =
16
+ exports.PubSubChannel =
17
17
  exports.Optional =
18
18
  void 0)
19
19
  async function invertPromise(n) {
@@ -143,13 +143,13 @@ function pickManyUnique(n, t, e, r = Math.random) {
143
143
  return o
144
144
  }
145
145
  function pickGuaranteed(n, t, e, r, o, i = Math.random) {
146
- const u = n.filter(s => s !== t && s !== e),
147
- c = []
148
- for (t !== null && c.push(t); u.length && c.length < r; ) {
149
- const s = exports.Random.intBetween(0, u.length - 1, i)
150
- o(u[s], c) && c.push(u[s]), u.splice(s, 1)
146
+ const u = n.filter(c => c !== t && c !== e),
147
+ s = []
148
+ for (t !== null && s.push(t); u.length && s.length < r; ) {
149
+ const c = exports.Random.intBetween(0, u.length - 1, i)
150
+ o(u[c], s) && s.push(u[c]), u.splice(c, 1)
151
151
  }
152
- return shuffle(c, i), { values: c, indexOfGuaranteed: t !== null ? c.indexOf(t) : -1 }
152
+ return shuffle(s, i), { values: s, indexOfGuaranteed: t !== null ? s.indexOf(t) : -1 }
153
153
  }
154
154
  function last(n) {
155
155
  if (!n.length) throw Error('Received empty array')
@@ -189,10 +189,10 @@ function setDeep(n, t, e) {
189
189
  let o = n
190
190
  for (let i = 0; i < r.length; i++) {
191
191
  const u = r[i],
192
- c = i < r.length - 1 && r[i + 1].includes(']'),
192
+ s = i < r.length - 1 && r[i + 1].includes(']'),
193
193
  f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
194
194
  if (i === r.length - 1) return (o[f] = e), e
195
- isObject(o[f]) || (c ? (o[f] = []) : (o[f] = {})), (o = o[f])
195
+ isObject(o[f]) || (s ? (o[f] = []) : (o[f] = {})), (o = o[f])
196
196
  }
197
197
  return e
198
198
  }
@@ -259,9 +259,9 @@ function rgbToHex(n) {
259
259
  function haversineDistanceToMeters(n, t, e, r) {
260
260
  const i = (n * Math.PI) / 180,
261
261
  u = (e * Math.PI) / 180,
262
- c = ((e - n) * Math.PI) / 180,
263
- s = ((r - t) * Math.PI) / 180,
264
- f = Math.sin(c / 2) * Math.sin(c / 2) + Math.cos(i) * Math.cos(u) * Math.sin(s / 2) * Math.sin(s / 2)
262
+ s = ((e - n) * Math.PI) / 180,
263
+ c = ((r - t) * Math.PI) / 180,
264
+ f = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(i) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 2)
265
265
  return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
266
266
  }
267
267
  function roundToNearest(n, t) {
@@ -780,9 +780,9 @@ function expand(n) {
780
780
  o = n.slice(0, e.index),
781
781
  i = n.slice(e.index + e[0].length)
782
782
  let u = []
783
- for (const c of r) {
784
- const s = expand(o + c + i)
785
- u = u.concat(s)
783
+ for (const s of r) {
784
+ const c = expand(o + s + i)
785
+ u = u.concat(c)
786
786
  }
787
787
  return u
788
788
  }
@@ -1016,12 +1016,12 @@ function base64ToUint8Array(n) {
1016
1016
  i = 0
1017
1017
  for (; o < n.length; ) {
1018
1018
  const u = BASE64_CHARS.indexOf(n.charAt(o++)),
1019
- c = BASE64_CHARS.indexOf(n.charAt(o++)),
1020
1019
  s = BASE64_CHARS.indexOf(n.charAt(o++)),
1020
+ c = BASE64_CHARS.indexOf(n.charAt(o++)),
1021
1021
  f = BASE64_CHARS.indexOf(n.charAt(o++)),
1022
- l = (u << 2) | (c >> 4),
1023
- a = ((c & 15) << 4) | (s >> 2),
1024
- h = ((s & 3) << 6) | f
1022
+ l = (u << 2) | (s >> 4),
1023
+ a = ((s & 15) << 4) | (c >> 2),
1024
+ h = ((c & 3) << 6) | f
1025
1025
  ;(r[i++] = l), i < e && (r[i++] = a), i < e && (r[i++] = h)
1026
1026
  }
1027
1027
  return r
@@ -1033,11 +1033,11 @@ function uint8ArrayToBase64(n) {
1033
1033
  const o = n[r],
1034
1034
  i = n[r + 1],
1035
1035
  u = n[r + 2],
1036
- c = o >> 2,
1037
- s = ((o & 3) << 4) | (i >> 4),
1036
+ s = o >> 2,
1037
+ c = ((o & 3) << 4) | (i >> 4),
1038
1038
  f = ((i & 15) << 2) | (u >> 6),
1039
1039
  l = u & 63
1040
- ;(t += BASE64_CHARS[c] + BASE64_CHARS[s]),
1040
+ ;(t += BASE64_CHARS[s] + BASE64_CHARS[c]),
1041
1041
  r + 1 < n.length ? (t += BASE64_CHARS[f]) : e++,
1042
1042
  r + 2 < n.length ? (t += BASE64_CHARS[l]) : e++
1043
1043
  }
@@ -1079,7 +1079,7 @@ function generateVariants(n, t, e, r = Math.random) {
1079
1079
  const o = exports.Arrays.shuffle(
1080
1080
  t.map(u => ({
1081
1081
  variants: exports.Arrays.shuffle(
1082
- u.variants.map(c => c),
1082
+ u.variants.map(s => s),
1083
1083
  r
1084
1084
  ),
1085
1085
  avoid: u.avoid
@@ -1088,14 +1088,14 @@ function generateVariants(n, t, e, r = Math.random) {
1088
1088
  ),
1089
1089
  i = []
1090
1090
  for (const u of o) {
1091
- const c = u.variants.filter(f => f !== u.avoid),
1092
- s = c.find(f => n.includes(f))
1093
- if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= e)) break
1091
+ const s = u.variants.filter(f => f !== u.avoid),
1092
+ c = s.find(f => n.includes(f))
1093
+ if (c && (pushAll(i, explodeReplace(n, c, s)), i.length >= e)) break
1094
1094
  }
1095
1095
  if (i.length < e)
1096
1096
  for (const u of o) {
1097
- const c = u.variants.find(s => n.includes(s))
1098
- if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= e)) break
1097
+ const s = u.variants.find(c => n.includes(c))
1098
+ if (s && (pushAll(i, explodeReplace(n, s, u.variants)), i.length >= e)) break
1099
1099
  }
1100
1100
  return i.slice(0, e)
1101
1101
  }
@@ -1130,9 +1130,9 @@ function toLines(n, t, e = {}) {
1130
1130
  let o = '',
1131
1131
  i = 0
1132
1132
  for (let u = 0; u < n.length; u++) {
1133
- const c = n[u],
1134
- s = e[c] || 1
1135
- if (((o += c), (i += s), i > t)) {
1133
+ const s = n[u],
1134
+ c = e[s] || 1
1135
+ if (((o += s), (i += c), i > t)) {
1136
1136
  const { line: f, rest: l } = breakLine(o)
1137
1137
  r.push(f),
1138
1138
  (o = l),
@@ -1187,8 +1187,8 @@ function resolveVariableWithDefaultSyntax(n, t, e, r = '$', o = ':') {
1187
1187
  if (n[i + t.length + 1] === o)
1188
1188
  if (n[i + t.length + 2] === o) n = n.replace(`${r}${t}${o}${o}`, e)
1189
1189
  else {
1190
- const c = readNextWord(n, i + t.length + 2, ['_'])
1191
- n = n.replace(`${r}${t}${o}${c}`, e)
1190
+ const s = readNextWord(n, i + t.length + 2, ['_'])
1191
+ n = n.replace(`${r}${t}${o}${s}`, e)
1192
1192
  }
1193
1193
  else n = n.replace(`${r}${t}`, e)
1194
1194
  i = n.indexOf(`${r}${t}`, i + e.length)
@@ -1216,8 +1216,8 @@ function resolveMarkdownLinks(n, t) {
1216
1216
  o = n.indexOf(')', e)
1217
1217
  if (r !== -1 && o !== -1) {
1218
1218
  const [i, u] = n.slice(r + 1, o).split(']('),
1219
- c = t(i, u)
1220
- n = n.slice(0, r) + c + n.slice(o + 1)
1219
+ s = t(i, u)
1220
+ n = n.slice(0, r) + s + n.slice(o + 1)
1221
1221
  }
1222
1222
  e = n.indexOf('](', e + 1)
1223
1223
  }
@@ -1255,8 +1255,8 @@ function reposition(n, t, e, r) {
1255
1255
  const o = n.find(u => u[t] === e),
1256
1256
  i = n.find(u => u[t] === e + r)
1257
1257
  o && i ? ((o[t] = e + r), (i[t] = e)) : o && (o[t] = e + r),
1258
- n.sort((u, c) => asNumber(u[t]) - asNumber(c[t])),
1259
- n.forEach((u, c) => (u[t] = c + 1))
1258
+ n.sort((u, s) => asNumber(u[t]) - asNumber(s[t])),
1259
+ n.forEach((u, s) => (u[t] = s + 1))
1260
1260
  }
1261
1261
  function unwrapSingleKey(n) {
1262
1262
  const t = Object.keys(n)
@@ -1271,7 +1271,7 @@ function parseCsv(n, t = ',', e = '"') {
1271
1271
  let o = '',
1272
1272
  i = !1
1273
1273
  const u = n.split('')
1274
- for (const c of u) c === t && !i ? (r.push(o), (o = '')) : c === e && ((!o && !i) || i) ? (i = !i) : (o += c)
1274
+ for (const s of u) s === t && !i ? (r.push(o), (o = '')) : s === e && ((!o && !i) || i) ? (i = !i) : (o += s)
1275
1275
  return r.push(o), r
1276
1276
  }
1277
1277
  function humanizeProgress(n) {
@@ -1389,12 +1389,12 @@ function secondsToHumanTime(n, t = DefaultTimeDeltaLabels) {
1389
1389
  }
1390
1390
  function countCycles(n, t, e) {
1391
1391
  var r, o, i
1392
- const c = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
1393
- s = Math.floor(c / t),
1392
+ const s = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
1393
+ c = Math.floor(s / t),
1394
1394
  f =
1395
1395
  t / ((o = e?.precision) !== null && o !== void 0 ? o : 1) -
1396
- Math.ceil((c % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
1397
- return { cycles: s, remaining: f }
1396
+ Math.ceil((s % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
1397
+ return { cycles: c, remaining: f }
1398
1398
  }
1399
1399
  const throttleTimers = {}
1400
1400
  function throttle(n, t) {
@@ -1411,9 +1411,9 @@ function getProgress(n, t, e, r) {
1411
1411
  const o = t / e,
1412
1412
  i = r - n,
1413
1413
  u = i / t,
1414
- c = u * e,
1415
- s = c - i
1416
- return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
1414
+ s = u * e,
1415
+ c = s - i
1416
+ return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: s, remainingTimeMs: c }
1417
1417
  }
1418
1418
  const dayNumberIndex = {
1419
1419
  0: 'sunday',
@@ -1578,9 +1578,9 @@ function organiseWithLimits(n, t, e, r, o) {
1578
1578
  for (const u of Object.keys(t)) i[u] = []
1579
1579
  ;(i[r] = []), o && (n = n.sort(o))
1580
1580
  for (const u of n) {
1581
- const c = u[e],
1582
- s = t[c] ? c : r
1583
- i[s].length >= t[s] ? i[r].push(u) : i[s].push(u)
1581
+ const s = u[e],
1582
+ c = t[s] ? s : r
1583
+ i[c].length >= t[c] ? i[r].push(u) : i[c].push(u)
1584
1584
  }
1585
1585
  return i
1586
1586
  }
@@ -1649,11 +1649,11 @@ function formatNumber(n, t) {
1649
1649
  const o = (e = t?.longForm) !== null && e !== void 0 ? e : !1,
1650
1650
  i = t?.unit ? ` ${t.unit}` : '',
1651
1651
  u = o ? longNumberUnits : shortNumberUnits,
1652
- c = (r = t?.precision) !== null && r !== void 0 ? r : 1
1652
+ s = (r = t?.precision) !== null && r !== void 0 ? r : 1
1653
1653
  if (n < thresholds[0]) return `${n}${i}`
1654
- for (let s = 0; s < thresholds.length - 1; s++)
1655
- if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
1656
- return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
1654
+ for (let c = 0; c < thresholds.length - 1; c++)
1655
+ if (n < thresholds[c + 1]) return `${(n / thresholds[c]).toFixed(s)}${o ? ' ' : ''}${u[c]}${i}`
1656
+ return `${(n / thresholds[thresholds.length - 1]).toFixed(s)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
1657
1657
  }
1658
1658
  function makeNumber(n) {
1659
1659
  const t = parseFloat(n)
@@ -1732,20 +1732,20 @@ function flip(n) {
1732
1732
  }
1733
1733
  function getAllPermutations(n) {
1734
1734
  const t = Object.keys(n),
1735
- e = t.map(c => n[c].length),
1736
- r = e.reduce((c, s) => (c *= s))
1735
+ e = t.map(s => n[s].length),
1736
+ r = e.reduce((s, c) => (s *= c))
1737
1737
  let o = 1
1738
1738
  const i = [1]
1739
- for (let c = 0; c < e.length - 1; c++) (o *= e[c]), i.push(o)
1739
+ for (let s = 0; s < e.length - 1; s++) (o *= e[s]), i.push(o)
1740
1740
  const u = []
1741
- for (let c = 0; c < r; c++) {
1742
- const s = {}
1741
+ for (let s = 0; s < r; s++) {
1742
+ const c = {}
1743
1743
  for (let f = 0; f < t.length; f++) {
1744
1744
  const l = n[t[f]],
1745
- a = Math.floor(c / i[f]) % l.length
1746
- s[t[f]] = l[a]
1745
+ a = Math.floor(s / i[f]) % l.length
1746
+ c[t[f]] = l[a]
1747
1747
  }
1748
- u.push(s)
1748
+ u.push(c)
1749
1749
  }
1750
1750
  return u
1751
1751
  }
@@ -1758,14 +1758,14 @@ function getFlatNotation(n, t, e) {
1758
1758
  function flattenInner(n, t, e, r, o) {
1759
1759
  if (!isObject(t)) return t
1760
1760
  for (const [i, u] of Object.entries(t)) {
1761
- const c = getFlatNotation(e, i, r)
1761
+ const s = getFlatNotation(e, i, r)
1762
1762
  Array.isArray(u)
1763
1763
  ? o
1764
- ? flattenInner(n, u, c, !0, o)
1765
- : (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
1764
+ ? flattenInner(n, u, s, !0, o)
1765
+ : (n[s] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, o)))
1766
1766
  : isObject(u)
1767
- ? flattenInner(n, u, c, !1, o)
1768
- : (n[c] = u)
1767
+ ? flattenInner(n, u, s, !1, o)
1768
+ : (n[s] = u)
1769
1769
  }
1770
1770
  return n
1771
1771
  }
@@ -1831,9 +1831,9 @@ function makeUnique(n, t) {
1831
1831
  function countUnique(n, t, e, r, o) {
1832
1832
  const i = t ? n.map(t) : n,
1833
1833
  u = {}
1834
- for (const s of i) u[s] = (u[s] || 0) + 1
1835
- const c = r ? sortObjectValues(u, o ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : u
1836
- return e ? Object.keys(c) : c
1834
+ for (const c of i) u[c] = (u[c] || 0) + 1
1835
+ const s = r ? sortObjectValues(u, o ? (c, f) => c[1] - f[1] : (c, f) => f[1] - c[1]) : u
1836
+ return e ? Object.keys(s) : s
1837
1837
  }
1838
1838
  function sortObjectValues(n, t) {
1839
1839
  return Object.fromEntries(Object.entries(n).sort(t))
@@ -1974,28 +1974,28 @@ class Node {
1974
1974
  function createHierarchy(n, t, e, r, o = !1) {
1975
1975
  const i = new Map(),
1976
1976
  u = []
1977
- n.forEach(s => {
1978
- const f = new Node(s)
1979
- i.set(s[t], f)
1977
+ n.forEach(c => {
1978
+ const f = new Node(c)
1979
+ i.set(c[t], f)
1980
1980
  }),
1981
- n.forEach(s => {
1982
- const f = i.get(s[t])
1981
+ n.forEach(c => {
1982
+ const f = i.get(c[t])
1983
1983
  if (!f) return
1984
- const l = s[e]
1984
+ const l = c[e]
1985
1985
  if (l) {
1986
1986
  const a = i.get(l)
1987
1987
  a && a.children.push(f)
1988
1988
  } else u.push(f)
1989
1989
  })
1990
- const c = s => {
1991
- s.children.sort((f, l) => {
1990
+ const s = c => {
1991
+ c.children.sort((f, l) => {
1992
1992
  const a = f.value[r],
1993
1993
  h = l.value[r]
1994
1994
  return o ? h - a : a - h
1995
1995
  }),
1996
- s.children.forEach(c)
1996
+ c.children.forEach(s)
1997
1997
  }
1998
- return u.forEach(c), u
1998
+ return u.forEach(s), u
1999
1999
  }
2000
2000
  function log2Reduce(n, t) {
2001
2001
  if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
@@ -2122,7 +2122,7 @@ function tickPlaybook(n) {
2122
2122
  )
2123
2123
  }
2124
2124
  function getArgument(n, t, e, r) {
2125
- const o = n.findIndex(c => c === `--${t}` || c.startsWith(`--${t}=`)),
2125
+ const o = n.findIndex(s => s === `--${t}` || s.startsWith(`--${t}=`)),
2126
2126
  i = n[o]
2127
2127
  if (!i) return (e || {})[r || t || ''] || null
2128
2128
  if (i.includes('=')) return i.split('=')[1]
@@ -2139,14 +2139,14 @@ function getNumberArgument(n, t, e, r) {
2139
2139
  }
2140
2140
  }
2141
2141
  function getBooleanArgument(n, t, e, r) {
2142
- const o = n.some(s => s.endsWith('-' + t)),
2142
+ const o = n.some(c => c.endsWith('-' + t)),
2143
2143
  i = getArgument(n, t, e, r)
2144
2144
  if (!i && o) return !0
2145
2145
  if (!i && !o) return null
2146
2146
  const u = ['true', '1', 'yes', 'y', 'on'],
2147
- c = ['false', '0', 'no', 'n', 'off']
2147
+ s = ['false', '0', 'no', 'n', 'off']
2148
2148
  if (u.includes(i.toLowerCase())) return !0
2149
- if (c.includes(i.toLowerCase())) return !1
2149
+ if (s.includes(i.toLowerCase())) return !1
2150
2150
  throw Error(`Invalid boolean argument ${t}: ${i}`)
2151
2151
  }
2152
2152
  function requireStringArgument(n, t, e, r) {
@@ -2229,16 +2229,16 @@ function isBottommost(n, t, e) {
2229
2229
  return !n[t][e + 1]
2230
2230
  }
2231
2231
  function getCorners(n, t, e) {
2232
- var r, o, i, u, c, s, f, l
2232
+ var r, o, i, u, s, c, f, l
2233
2233
  const a = []
2234
2234
  return n[t][e]
2235
2235
  ? isHorizontalLine(n, t, e) || isVerticalLine(n, t, e)
2236
2236
  ? []
2237
- : (!(!((c = n[t - 1]) === null || c === void 0) && c[e - 1]) &&
2237
+ : (!(!((s = n[t - 1]) === null || s === void 0) && s[e - 1]) &&
2238
2238
  isLeftmost(n, t, e) &&
2239
2239
  isTopmost(n, t, e) &&
2240
2240
  a.push({ x: t, y: e }),
2241
- !(!((s = n[t + 1]) === null || s === void 0) && s[e - 1]) &&
2241
+ !(!((c = n[t + 1]) === null || c === void 0) && c[e - 1]) &&
2242
2242
  isRightmost(n, t, e) &&
2243
2243
  isTopmost(n, t, e) &&
2244
2244
  a.push({ x: t + 1, y: e }),
@@ -2266,42 +2266,42 @@ function findCorners(n, t, e, r) {
2266
2266
  ]
2267
2267
  for (let i = 0; i < n.length; i++)
2268
2268
  for (let u = 0; u < n[0].length; u++) {
2269
- const c = getCorners(n, i, u)
2270
- for (const s of c) o.some(f => f.x === s.x && f.y === s.y) || o.push(s)
2269
+ const s = getCorners(n, i, u)
2270
+ for (const c of s) o.some(f => f.x === c.x && f.y === c.y) || o.push(c)
2271
2271
  }
2272
2272
  return o.map(i => ({ x: i.x * t, y: i.y * t }))
2273
2273
  }
2274
2274
  function findLines(n, t) {
2275
- const e = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s =>
2276
- Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
2275
+ const e = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f + 1] !== 0, 'row-first').map(c =>
2276
+ Object.assign(Object.assign({}, c), { dx: 1, dy: 0 })
2277
2277
  ),
2278
- r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s =>
2279
- Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
2278
+ r = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f - 1] !== 0, 'row-first').map(c =>
2279
+ Object.assign(Object.assign({}, c), { dx: 1, dy: 0 })
2280
2280
  ),
2281
2281
  o = filterCoordinates(
2282
2282
  n,
2283
- (s, f) => {
2283
+ (c, f) => {
2284
2284
  var l
2285
- return n[s][f] === 0 && ((l = n[s - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2285
+ return n[c][f] === 0 && ((l = n[c - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2286
2286
  },
2287
2287
  'column-first'
2288
- ).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
2288
+ ).map(c => Object.assign(Object.assign({}, c), { dx: 0, dy: 1 })),
2289
2289
  i = filterCoordinates(
2290
2290
  n,
2291
- (s, f) => {
2291
+ (c, f) => {
2292
2292
  var l
2293
- return n[s][f] === 0 && ((l = n[s + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2293
+ return n[c][f] === 0 && ((l = n[c + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2294
2294
  },
2295
2295
  'column-first'
2296
- ).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
2297
- e.forEach(s => s.y++), i.forEach(s => s.x++)
2298
- const u = group([...o, ...i], (s, f) => s.x === f.x && s.y - 1 === f.y),
2299
- c = group([...r, ...e], (s, f) => s.y === f.y && s.x - 1 === f.x)
2300
- return [...u, ...c]
2301
- .map(s => ({ start: s[0], end: last(s) }))
2302
- .map(s => ({
2303
- start: multiplyPoint(s.start, t),
2304
- end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), t)
2296
+ ).map(c => Object.assign(Object.assign({}, c), { dx: 0, dy: 1 }))
2297
+ e.forEach(c => c.y++), i.forEach(c => c.x++)
2298
+ const u = group([...o, ...i], (c, f) => c.x === f.x && c.y - 1 === f.y),
2299
+ s = group([...r, ...e], (c, f) => c.y === f.y && c.x - 1 === f.x)
2300
+ return [...u, ...s]
2301
+ .map(c => ({ start: c[0], end: last(c) }))
2302
+ .map(c => ({
2303
+ start: multiplyPoint(c.start, t),
2304
+ end: multiplyPoint(addPoint(c.end, { x: c.start.dx, y: c.start.dy }), t)
2305
2305
  }))
2306
2306
  }
2307
2307
  function getAngleInRadians(n, t) {
@@ -2315,11 +2315,11 @@ function getLineIntersectionPoint(n, t, e, r) {
2315
2315
  if (o === 0) return null
2316
2316
  let i = n.y - e.y,
2317
2317
  u = n.x - e.x
2318
- const c = (r.x - e.x) * i - (r.y - e.y) * u,
2319
- s = (t.x - n.x) * i - (t.y - n.y) * u
2318
+ const s = (r.x - e.x) * i - (r.y - e.y) * u,
2319
+ c = (t.x - n.x) * i - (t.y - n.y) * u
2320
2320
  return (
2321
- (i = c / o),
2322
- (u = s / o),
2321
+ (i = s / o),
2322
+ (u = c / o),
2323
2323
  i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (t.x - n.x), y: n.y + i * (t.y - n.y) } : null
2324
2324
  )
2325
2325
  }
@@ -2332,9 +2332,9 @@ function raycast(n, t, e) {
2332
2332
  }
2333
2333
  return r.length
2334
2334
  ? r.reduce((i, u) => {
2335
- const c = getDistanceBetweenPoints(n, u),
2336
- s = getDistanceBetweenPoints(n, i)
2337
- return c < s ? u : i
2335
+ const s = getDistanceBetweenPoints(n, u),
2336
+ c = getDistanceBetweenPoints(n, i)
2337
+ return s < c ? u : i
2338
2338
  })
2339
2339
  : null
2340
2340
  }
@@ -2342,30 +2342,29 @@ function raycastCircle(n, t, e) {
2342
2342
  const o = getSortedRayAngles(n, e),
2343
2343
  i = []
2344
2344
  for (const u of o) {
2345
- const c = raycast(n, t, u - 0.001),
2346
- s = raycast(n, t, u + 0.001)
2347
- c && i.push(c), s && i.push(s)
2345
+ const s = raycast(n, t, u - 0.001),
2346
+ c = raycast(n, t, u + 0.001)
2347
+ s && i.push(s), c && i.push(c)
2348
2348
  }
2349
2349
  return i
2350
2350
  }
2351
- class PubSubSystem {
2351
+ class PubSubChannel {
2352
2352
  constructor() {
2353
- this.subscribers = {}
2353
+ this.subscribers = []
2354
2354
  }
2355
- subscribe(t, e) {
2355
+ subscribe(t) {
2356
2356
  return (
2357
- this.subscribers[t] || (this.subscribers[t] = []),
2358
- this.subscribers[t].push(e),
2357
+ this.subscribers.push(t),
2359
2358
  () => {
2360
- this.subscribers[t] = this.subscribers[t].filter(r => r !== e)
2359
+ this.subscribers = this.subscribers.filter(e => e !== t)
2361
2360
  }
2362
2361
  )
2363
2362
  }
2364
- publish(t, e) {
2365
- this.subscribers[t] && this.subscribers[t].forEach(r => r(e))
2363
+ publish(t) {
2364
+ this.subscribers.forEach(e => e(t))
2366
2365
  }
2367
2366
  }
2368
- ;(exports.PubSubSystem = PubSubSystem),
2367
+ ;(exports.PubSubChannel = PubSubChannel),
2369
2368
  (exports.Binary = {
2370
2369
  hexToUint8Array,
2371
2370
  uint8ArrayToHex,
package/module.mjs CHANGED
@@ -15,4 +15,4 @@ export const System = utility.System
15
15
  export const Types = utility.Types
16
16
  export const Optional = utility.Optional
17
17
  export const Vector = utility.Vector
18
- export const PubSubSystem = utility.PubSubSystem
18
+ export const PubSubChannel = utility.PubSubChannel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "22.5.0",
3
+ "version": "23.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {