cubing 0.28.1 → 0.29.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 (101) hide show
  1. package/README.md +2 -0
  2. package/dist/esm/alg/index.js +2 -2
  3. package/dist/esm/bluetooth/index.js +222 -86
  4. package/dist/esm/bluetooth/index.js.map +3 -3
  5. package/dist/esm/{chunk-F4WWCPVE.js → chunk-2IZUSAXQ.js} +2 -2
  6. package/dist/esm/{chunk-F4WWCPVE.js.map → chunk-2IZUSAXQ.js.map} +1 -1
  7. package/dist/esm/{chunk-YSVFZVG4.js → chunk-DZGFGBKT.js} +183 -76
  8. package/dist/esm/chunk-DZGFGBKT.js.map +7 -0
  9. package/dist/esm/{chunk-7D7LW3WQ.js → chunk-GW4FGG42.js} +8 -4
  10. package/dist/esm/{chunk-7D7LW3WQ.js.map → chunk-GW4FGG42.js.map} +1 -1
  11. package/dist/esm/{chunk-32FWPPTW.js → chunk-LSCTPPWV.js} +22 -8
  12. package/dist/esm/{chunk-32FWPPTW.js.map → chunk-LSCTPPWV.js.map} +1 -1
  13. package/dist/esm/{chunk-LSVR2HCG.js → chunk-LV7IKG36.js} +389 -363
  14. package/dist/esm/{chunk-LSVR2HCG.js.map → chunk-LV7IKG36.js.map} +1 -1
  15. package/dist/esm/{chunk-CSBUJ64Q.js → chunk-NI7U4XAZ.js} +373 -238
  16. package/dist/esm/chunk-NI7U4XAZ.js.map +7 -0
  17. package/dist/esm/{chunk-GVPTO3OF.js → chunk-OX6O2ZO5.js} +1 -1
  18. package/dist/esm/{chunk-GVPTO3OF.js.map → chunk-OX6O2ZO5.js.map} +1 -1
  19. package/dist/esm/{chunk-67VJZGH2.js → chunk-PYWGREIP.js} +44 -13
  20. package/dist/esm/chunk-PYWGREIP.js.map +7 -0
  21. package/dist/esm/{chunk-WAL36PO3.js → chunk-Q4W5ZR4U.js} +28 -12
  22. package/dist/esm/{chunk-WAL36PO3.js.map → chunk-Q4W5ZR4U.js.map} +1 -1
  23. package/dist/esm/{chunk-MGJA5U5O.js → chunk-SBZRVSPK.js} +1 -12
  24. package/dist/esm/{chunk-MGJA5U5O.js.map → chunk-SBZRVSPK.js.map} +0 -0
  25. package/dist/esm/{chunk-MWKALF6W.js → chunk-TGPS3CXW.js} +22 -13
  26. package/dist/esm/chunk-TGPS3CXW.js.map +7 -0
  27. package/dist/esm/{chunk-V55YSWJY.js → chunk-WXCNEGW3.js} +10 -4
  28. package/dist/esm/{chunk-V55YSWJY.js.map → chunk-WXCNEGW3.js.map} +1 -1
  29. package/dist/esm/{chunk-ZY3RTFFS.js → chunk-XU5ILFX5.js} +137 -66
  30. package/dist/esm/{chunk-ZY3RTFFS.js.map → chunk-XU5ILFX5.js.map} +3 -3
  31. package/dist/esm/{chunk-ALBEW4DJ.js → chunk-ZB3P5AZN.js} +1 -1
  32. package/dist/esm/{chunk-ALBEW4DJ.js.map → chunk-ZB3P5AZN.js.map} +1 -1
  33. package/dist/esm/{chunk-NPHUBFZ6.js → chunk-ZNAYJGVL.js} +2 -2
  34. package/dist/esm/{chunk-NPHUBFZ6.js.map → chunk-ZNAYJGVL.js.map} +1 -1
  35. package/dist/esm/kpuzzle/index.js +3 -3
  36. package/dist/esm/notation/index.js +3 -3
  37. package/dist/esm/protocol/index.js +5 -5
  38. package/dist/esm/puzzle-geometry/index.js +271 -71
  39. package/dist/esm/puzzle-geometry/index.js.map +2 -2
  40. package/dist/esm/puzzles/index.js +5 -5
  41. package/dist/esm/{puzzles-dynamic-3x3x3-NB2PEZTV.js → puzzles-dynamic-3x3x3-KIG5A6QR.js} +2 -2
  42. package/dist/esm/{puzzles-dynamic-3x3x3-NB2PEZTV.js.map → puzzles-dynamic-3x3x3-KIG5A6QR.js.map} +0 -0
  43. package/dist/esm/puzzles-dynamic-4x4x4-PEDAPUZK.js +126 -0
  44. package/dist/esm/puzzles-dynamic-4x4x4-PEDAPUZK.js.map +7 -0
  45. package/dist/esm/{puzzles-dynamic-side-events-WZI4Y3N6.js → puzzles-dynamic-side-events-5C7LMBWX.js} +2 -2
  46. package/dist/esm/{puzzles-dynamic-side-events-WZI4Y3N6.js.map → puzzles-dynamic-side-events-5C7LMBWX.js.map} +0 -0
  47. package/dist/esm/{puzzles-dynamic-unofficial-FUG3JBMH.js → puzzles-dynamic-unofficial-WWJ4NJMX.js} +2 -2
  48. package/dist/esm/{puzzles-dynamic-unofficial-FUG3JBMH.js.map → puzzles-dynamic-unofficial-WWJ4NJMX.js.map} +0 -0
  49. package/dist/esm/scramble/index.js +5 -5
  50. package/dist/esm/search/index.js +10 -10
  51. package/dist/esm/{search-dynamic-sgs-side-events-R3HDJ5XQ.js → search-dynamic-sgs-side-events-AYX7MZO7.js} +35 -17
  52. package/dist/esm/{search-dynamic-sgs-side-events-R3HDJ5XQ.js.map → search-dynamic-sgs-side-events-AYX7MZO7.js.map} +2 -2
  53. package/dist/esm/{search-dynamic-sgs-unofficial-FQNKGHVO.js → search-dynamic-sgs-unofficial-DLJOJFJL.js} +35 -14
  54. package/dist/esm/{search-dynamic-sgs-unofficial-FQNKGHVO.js.map → search-dynamic-sgs-unofficial-DLJOJFJL.js.map} +2 -2
  55. package/dist/esm/{search-dynamic-solve-3x3x3-K42IWMQV.js → search-dynamic-solve-3x3x3-7XZTYQMO.js} +795 -142
  56. package/dist/esm/{search-dynamic-solve-3x3x3-K42IWMQV.js.map → search-dynamic-solve-3x3x3-7XZTYQMO.js.map} +1 -1
  57. package/dist/esm/{search-dynamic-solve-4x4x4-XRV4NBMQ.js → search-dynamic-solve-4x4x4-CWWTFKMR.js} +135 -29
  58. package/dist/esm/{search-dynamic-solve-4x4x4-XRV4NBMQ.js.map → search-dynamic-solve-4x4x4-CWWTFKMR.js.map} +1 -1
  59. package/dist/esm/{search-dynamic-solve-fto-O6UXF7EC.js → search-dynamic-solve-fto-4LI23P6K.js} +253 -69
  60. package/dist/esm/{search-dynamic-solve-fto-O6UXF7EC.js.map → search-dynamic-solve-fto-4LI23P6K.js.map} +2 -2
  61. package/dist/esm/{search-dynamic-solve-kilominx-G4MLGWNS.js → search-dynamic-solve-kilominx-3HEVQ4MC.js} +32 -8
  62. package/dist/esm/{search-dynamic-solve-kilominx-G4MLGWNS.js.map → search-dynamic-solve-kilominx-3HEVQ4MC.js.map} +2 -2
  63. package/dist/esm/{search-dynamic-solve-master_tetraminx-3RKD3IAN.js → search-dynamic-solve-master_tetraminx-UB32C7MM.js} +111 -42
  64. package/dist/esm/{search-dynamic-solve-master_tetraminx-3RKD3IAN.js.map → search-dynamic-solve-master_tetraminx-UB32C7MM.js.map} +2 -2
  65. package/dist/esm/{search-dynamic-solve-sq1-WIJEGVLP.js → search-dynamic-solve-sq1-HA72TYF2.js} +54 -9
  66. package/dist/esm/{search-dynamic-solve-sq1-WIJEGVLP.js.map → search-dynamic-solve-sq1-HA72TYF2.js.map} +2 -2
  67. package/dist/esm/{search-worker-inside-generated-string-IZCKWXUA.js → search-worker-inside-generated-string-AMEXYCKK.js} +146 -28
  68. package/dist/esm/search-worker-inside-generated-string-AMEXYCKK.js.map +7 -0
  69. package/dist/esm/{search-worker-js-entry-WBEKNBB7.js → search-worker-js-entry-TP2T3NUL.js} +147 -53
  70. package/dist/esm/{search-worker-js-entry-WBEKNBB7.js.map → search-worker-js-entry-TP2T3NUL.js.map} +2 -2
  71. package/dist/esm/{search-worker-ts-entry-XQWMEOC4.js → search-worker-ts-entry-NEH77S4I.js} +5 -5
  72. package/dist/esm/{search-worker-ts-entry-XQWMEOC4.js.map → search-worker-ts-entry-NEH77S4I.js.map} +1 -1
  73. package/dist/esm/stream/index.js +12 -8
  74. package/dist/esm/stream/index.js.map +1 -1
  75. package/dist/esm/twisty/index.js +1154 -762
  76. package/dist/esm/twisty/index.js.map +3 -3
  77. package/dist/esm/{twisty-dynamic-3d-QOX7IEXC.js → twisty-dynamic-3d-D3ZDBJUH.js} +352 -175
  78. package/dist/esm/{twisty-dynamic-3d-QOX7IEXC.js.map → twisty-dynamic-3d-D3ZDBJUH.js.map} +2 -2
  79. package/dist/types/{Alg-e2a80975.d.ts → Alg-137fb0d5.d.ts} +19 -16
  80. package/dist/types/{KState-a2f0e651.d.ts → KState-a73111d7.d.ts} +1 -9
  81. package/dist/types/{TwizzleLink-dcf51446.d.ts → TwizzleLink-bef52ecd.d.ts} +46 -10
  82. package/dist/types/alg/index.d.ts +4 -4
  83. package/dist/types/bluetooth/index.d.ts +4 -4
  84. package/dist/types/{bluetooth-puzzle-3670a6a1.d.ts → bluetooth-puzzle-8a678993.d.ts} +9 -9
  85. package/dist/types/kpuzzle/index.d.ts +2 -2
  86. package/dist/types/notation/index.d.ts +1 -1
  87. package/dist/types/{outside-0ce1b145.d.ts → outside-e55f28a0.d.ts} +2 -2
  88. package/dist/types/{parseAlg-db0dec6c.d.ts → parseAlg-a28f7568.d.ts} +1 -1
  89. package/dist/types/protocol/index.d.ts +2 -2
  90. package/dist/types/puzzle-geometry/index.d.ts +3 -3
  91. package/dist/types/puzzles/index.d.ts +5 -5
  92. package/dist/types/scramble/index.d.ts +3 -3
  93. package/dist/types/search/index.d.ts +3 -3
  94. package/dist/types/stream/index.d.ts +5 -5
  95. package/dist/types/twisty/index.d.ts +5 -5
  96. package/package.json +47 -41
  97. package/dist/esm/chunk-67VJZGH2.js.map +0 -7
  98. package/dist/esm/chunk-CSBUJ64Q.js.map +0 -7
  99. package/dist/esm/chunk-MWKALF6W.js.map +0 -7
  100. package/dist/esm/chunk-YSVFZVG4.js.map +0 -7
  101. package/dist/esm/search-worker-inside-generated-string-IZCKWXUA.js.map +0 -7
package/README.md CHANGED
@@ -55,6 +55,8 @@ make dev
55
55
  # Now visit http://localhost:3333
56
56
  ```
57
57
 
58
+ To quickly check any changes for issues, try `make test-fast`. Run `make test` for more thorough testing options.
59
+
58
60
  ## Acknowledgments
59
61
 
60
62
  As of this time, `cubing.js` primarily contains code by [Lucas Garron (@lgarron)](https://github.com/lgarron) and [Tom Rokicki (@rokicki)](https://github.com/rokicki). Significant parts of the cubing code also are from:
@@ -17,8 +17,8 @@ import {
17
17
  experimentalIs,
18
18
  keyToMove,
19
19
  setAlgDebug
20
- } from "../chunk-CSBUJ64Q.js";
21
- import "../chunk-MGJA5U5O.js";
20
+ } from "../chunk-NI7U4XAZ.js";
21
+ import "../chunk-SBZRVSPK.js";
22
22
  export {
23
23
  Alg,
24
24
  AlgBuilder,
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  binaryComponentsToReid3x3x3,
3
3
  twizzleBinaryToBinaryComponents
4
- } from "../chunk-32FWPPTW.js";
4
+ } from "../chunk-LSCTPPWV.js";
5
5
  import {
6
6
  puzzles
7
- } from "../chunk-YSVFZVG4.js";
7
+ } from "../chunk-DZGFGBKT.js";
8
8
  import {
9
9
  experimental3x3x3KPuzzle
10
- } from "../chunk-67VJZGH2.js";
10
+ } from "../chunk-PYWGREIP.js";
11
11
  import {
12
12
  KState
13
- } from "../chunk-ZY3RTFFS.js";
13
+ } from "../chunk-XU5ILFX5.js";
14
14
  import {
15
15
  Alg,
16
16
  Move,
17
17
  experimentalAppendMove,
18
18
  keyToMove
19
- } from "../chunk-CSBUJ64Q.js";
20
- import "../chunk-MGJA5U5O.js";
19
+ } from "../chunk-NI7U4XAZ.js";
20
+ import "../chunk-SBZRVSPK.js";
21
21
 
22
22
  // src/cubing/bluetooth/debug.ts
23
23
  var DEBUG_LOGGING_ENABLED = false;
@@ -64,7 +64,7 @@ var m = {
64
64
  "-x z": new Quaternion(0, 0, s2, s2)
65
65
  };
66
66
  var BasicRotationTransformer = class {
67
- transformMove(_moveEvent) {
67
+ transformAlgLeaf(_algLeafEvent) {
68
68
  }
69
69
  transformOrientation(orientationEvent) {
70
70
  const { x, y, z, w } = orientationEvent.quaternion;
@@ -94,7 +94,7 @@ var BluetoothPuzzle = class extends EventTarget {
94
94
  async getState() {
95
95
  throw new Error("cannot get state");
96
96
  }
97
- addMoveListener(listener) {
97
+ addAlgLeafListener(listener) {
98
98
  this.listeners.push(listener);
99
99
  }
100
100
  addOrientationListener(listener) {
@@ -103,12 +103,12 @@ var BluetoothPuzzle = class extends EventTarget {
103
103
  experimentalAddBasicRotationTransformer() {
104
104
  this.transformers.push(new BasicRotationTransformer());
105
105
  }
106
- dispatchMove(moveEvent) {
106
+ dispatchAlgLeaf(algLeaf) {
107
107
  for (const transformer of this.transformers) {
108
- transformer.transformMove(moveEvent);
108
+ transformer.transformAlgLeaf(algLeaf);
109
109
  }
110
110
  for (const l of this.listeners) {
111
- l(moveEvent);
111
+ l(algLeaf);
112
112
  }
113
113
  }
114
114
  dispatchOrientation(orientationEvent) {
@@ -151,12 +151,12 @@ var KeyboardPuzzle = class extends BluetoothPuzzle {
151
151
  if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
152
152
  return;
153
153
  }
154
- const move = keyToMove(e);
155
- if (move) {
156
- const newState = (await this.state).applyMove(move);
154
+ const algLeaf = keyToMove(e);
155
+ if (algLeaf) {
156
+ const newState = (await this.state).applyAlg(new Alg([algLeaf]));
157
157
  this.state = Promise.resolve(newState);
158
- this.dispatchMove({
159
- latestMove: move,
158
+ this.dispatchAlgLeaf({
159
+ latestAlgLeaf: algLeaf,
160
160
  timeStamp: e.timeStamp,
161
161
  state: newState
162
162
  });
@@ -181,7 +181,9 @@ function requestOptions(configs, acceptAllDevices = false) {
181
181
  if (!acceptAllDevices) {
182
182
  options.filters = options.filters.concat(config.filters);
183
183
  }
184
- options.optionalServices = options.optionalServices.concat(config.optionalServices);
184
+ options.optionalServices = options.optionalServices.concat(
185
+ config.optionalServices
186
+ );
185
187
  }
186
188
  debugLog({ requestOptions: options });
187
189
  return options;
@@ -194,10 +196,14 @@ async function bluetoothConnect(configs, options = {}) {
194
196
  try {
195
197
  let acceptAllDevices = options.acceptAllDevices;
196
198
  if (!acceptAllDevices && consecutiveFailures >= MAX_FAILURES_BEFORE_ACCEPT_ALL_FALLBACK) {
197
- console.info(`The last ${MAX_FAILURES_BEFORE_ACCEPT_ALL_FALLBACK} Bluetooth puzzle connection attempts failed. This time, the Bluetooth prompt will show all possible devices.`);
199
+ console.info(
200
+ `The last ${MAX_FAILURES_BEFORE_ACCEPT_ALL_FALLBACK} Bluetooth puzzle connection attempts failed. This time, the Bluetooth prompt will show all possible devices.`
201
+ );
198
202
  acceptAllDevices = true;
199
203
  }
200
- device = await navigator.bluetooth.requestDevice(requestOptions(configs, acceptAllDevices));
204
+ device = await navigator.bluetooth.requestDevice(
205
+ requestOptions(configs, acceptAllDevices)
206
+ );
201
207
  consecutiveFailures = 0;
202
208
  } catch (e) {
203
209
  consecutiveFailures++;
@@ -226,7 +232,9 @@ import { Quaternion as Quaternion2 } from "three";
226
232
  // src/cubing/vendor/unsafe-raw-aes/unsafe-raw-aes.ts
227
233
  var blockSize = 16;
228
234
  var zeros = new Uint8Array(blockSize);
229
- var paddingBlockPlaintext = new Uint8Array(new Array(blockSize).fill(blockSize));
235
+ var paddingBlockPlaintext = new Uint8Array(
236
+ new Array(blockSize).fill(blockSize)
237
+ );
230
238
  var AES_CBC = "AES-CBC";
231
239
  async function importKey(keyBytes) {
232
240
  return await crypto.subtle.importKey("raw", keyBytes, AES_CBC, true, [
@@ -235,21 +243,33 @@ async function importKey(keyBytes) {
235
243
  ]);
236
244
  }
237
245
  async function unsafeEncryptBlockWithIV(key, plaintextBlock, iv) {
238
- const cryptoResult = await window.crypto.subtle.encrypt({
239
- name: AES_CBC,
240
- iv
241
- }, key, plaintextBlock);
246
+ const cryptoResult = await window.crypto.subtle.encrypt(
247
+ {
248
+ name: AES_CBC,
249
+ iv
250
+ },
251
+ key,
252
+ plaintextBlock
253
+ );
242
254
  return cryptoResult.slice(0, blockSize);
243
255
  }
244
256
  async function unsafeDecryptBlock(key, ciphertextBlock) {
245
- const paddingBlock = await unsafeEncryptBlockWithIV(key, paddingBlockPlaintext, ciphertextBlock);
257
+ const paddingBlock = await unsafeEncryptBlockWithIV(
258
+ key,
259
+ paddingBlockPlaintext,
260
+ ciphertextBlock
261
+ );
246
262
  const cbcCiphertext = new Uint8Array(2 * blockSize);
247
263
  cbcCiphertext.set(new Uint8Array(ciphertextBlock), 0);
248
264
  cbcCiphertext.set(new Uint8Array(paddingBlock), blockSize);
249
- const cryptoResult = await window.crypto.subtle.decrypt({
250
- name: AES_CBC,
251
- iv: zeros
252
- }, key, cbcCiphertext);
265
+ const cryptoResult = await window.crypto.subtle.decrypt(
266
+ {
267
+ name: AES_CBC,
268
+ iv: zeros
269
+ },
270
+ key,
271
+ cbcCiphertext
272
+ );
253
273
  return cryptoResult.slice(0, blockSize);
254
274
  }
255
275
 
@@ -316,7 +336,10 @@ async function decryptState(data, aesKey) {
316
336
  }
317
337
  const copy = new Uint8Array(data);
318
338
  copy.set(new Uint8Array(await unsafeDecryptBlock(aesKey, copy.slice(3))), 3);
319
- copy.set(new Uint8Array(await unsafeDecryptBlock(aesKey, copy.slice(0, 16))), 0);
339
+ copy.set(
340
+ new Uint8Array(await unsafeDecryptBlock(aesKey, copy.slice(0, 16))),
341
+ 0
342
+ );
320
343
  if (probablyDecodedCorrectly(copy)) {
321
344
  return copy;
322
345
  }
@@ -333,7 +356,10 @@ var PhysicalState = class {
333
356
  }
334
357
  }
335
358
  static async read(characteristic, aesKey) {
336
- const value = await decryptState(new Uint8Array((await characteristic.readValue()).buffer), aesKey);
359
+ const value = await decryptState(
360
+ new Uint8Array((await characteristic.readValue()).buffer),
361
+ aesKey
362
+ );
337
363
  const timeStamp = Date.now();
338
364
  return new PhysicalState(new DataView(value.buffer), timeStamp);
339
365
  }
@@ -346,7 +372,7 @@ var PhysicalState = class {
346
372
  const w = wSquared > 0 ? Math.sqrt(wSquared) : 0;
347
373
  const quat = new Quaternion2(x, y, z, w);
348
374
  if (!homeQuatInverse) {
349
- homeQuatInverse = quat.clone().inverse();
375
+ homeQuatInverse = quat.clone().invert();
350
376
  }
351
377
  return quat.clone().multiply(homeQuatInverse.clone());
352
378
  }
@@ -360,7 +386,9 @@ var PhysicalState = class {
360
386
  if (n < 0 || n > MAX_LATEST_MOVES) {
361
387
  throw new Error(`Must ask for 0 to 6 latest moves. (Asked for ${n})`);
362
388
  }
363
- return Array.from(this.arr.slice(19 - n, 19)).map((i) => ganMoveToBlockMove[i]);
389
+ return Array.from(this.arr.slice(19 - n, 19)).map(
390
+ (i) => ganMoveToBlockMove[i]
391
+ );
364
392
  }
365
393
  debugInfo() {
366
394
  return {
@@ -401,7 +429,10 @@ var commands = {
401
429
  ])
402
430
  };
403
431
  function buf2hex(buffer) {
404
- return Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join(" ");
432
+ return Array.prototype.map.call(
433
+ new Uint8Array(buffer),
434
+ (x) => ("00" + x.toString(16)).slice(-2)
435
+ ).join(" ");
405
436
  }
406
437
  var reidEdgeOrder = "UF UR UB UL DF DR DB DL FR FL BR BL".split(" ");
407
438
  var reidCornerOrder = "UFR URB UBL ULF DRF DFL DLB DBR".split(" ");
@@ -446,15 +477,23 @@ var gan356iEdgeMappings = [
446
477
  var faceOrder = "URFDLB";
447
478
  async function getKey(server) {
448
479
  const infoService = await server.getPrimaryService(UUIDs.infoService);
449
- const versionCharacteristic = await infoService.getCharacteristic(UUIDs.versionCharacteristic);
450
- const versionBuffer = new Uint8Array((await versionCharacteristic.readValue()).buffer);
480
+ const versionCharacteristic = await infoService.getCharacteristic(
481
+ UUIDs.versionCharacteristic
482
+ );
483
+ const versionBuffer = new Uint8Array(
484
+ (await versionCharacteristic.readValue()).buffer
485
+ );
451
486
  const versionValue = ((versionBuffer[0] << 8) + versionBuffer[1] << 8) + versionBuffer[2];
452
487
  if (versionValue < 65544) {
453
488
  return null;
454
489
  }
455
490
  const keyXor = versionValue < 65792 ? key10 : key11;
456
- const systemIDCharacteristic = await infoService.getCharacteristic(UUIDs.systemIDCharacteristic);
457
- const systemID = new Uint8Array((await systemIDCharacteristic.readValue()).buffer).reverse();
491
+ const systemIDCharacteristic = await infoService.getCharacteristic(
492
+ UUIDs.systemIDCharacteristic
493
+ );
494
+ const systemID = new Uint8Array(
495
+ (await systemIDCharacteristic.readValue()).buffer
496
+ ).reverse();
458
497
  const key = new Uint8Array(keyXor);
459
498
  for (let i = 0; i < systemID.length; i++) {
460
499
  key[i] = (key[i] + systemID[i]) % 256;
@@ -478,12 +517,21 @@ var GanCube = class extends BluetoothPuzzle {
478
517
  static async connect(server) {
479
518
  const ganCubeService = await server.getPrimaryService(UUIDs.ganCubeService);
480
519
  debugLog("Service:", ganCubeService);
481
- const physicalStateCharacteristic = await ganCubeService.getCharacteristic(UUIDs.physicalStateCharacteristic);
520
+ const physicalStateCharacteristic = await ganCubeService.getCharacteristic(
521
+ UUIDs.physicalStateCharacteristic
522
+ );
482
523
  debugLog("Characteristic:", physicalStateCharacteristic);
483
524
  const aesKey = await getKey(server);
484
525
  const initialMoveCounter = (await PhysicalState.read(physicalStateCharacteristic, aesKey)).moveCounter();
485
526
  debugLog("Initial Move Counter:", initialMoveCounter);
486
- const cube = new GanCube(await puzzles["3x3x3"].kpuzzle(), ganCubeService, server, physicalStateCharacteristic, initialMoveCounter, aesKey);
527
+ const cube = new GanCube(
528
+ await puzzles["3x3x3"].kpuzzle(),
529
+ ganCubeService,
530
+ server,
531
+ physicalStateCharacteristic,
532
+ initialMoveCounter,
533
+ aesKey
534
+ );
487
535
  return cube;
488
536
  }
489
537
  name() {
@@ -493,7 +541,10 @@ var GanCube = class extends BluetoothPuzzle {
493
541
  this.server.disconnect();
494
542
  }
495
543
  startTrackingMoves() {
496
- this.intervalHandle = window.setInterval(this.intervalHandler.bind(this), this.INTERVAL_MS);
544
+ this.intervalHandle = window.setInterval(
545
+ this.intervalHandler.bind(this),
546
+ this.INTERVAL_MS
547
+ );
497
548
  }
498
549
  stopTrackingMoves() {
499
550
  if (!this.intervalHandle) {
@@ -503,16 +554,21 @@ var GanCube = class extends BluetoothPuzzle {
503
554
  this.intervalHandle = null;
504
555
  }
505
556
  async intervalHandler() {
506
- const physicalState = await PhysicalState.read(this.physicalStateCharacteristic, this.aesKey);
557
+ const physicalState = await PhysicalState.read(
558
+ this.physicalStateCharacteristic,
559
+ this.aesKey
560
+ );
507
561
  let numInterveningMoves = physicalState.numMovesSince(this.lastMoveCounter);
508
562
  if (numInterveningMoves > MAX_LATEST_MOVES) {
509
- debugLog(`Too many moves! Dropping ${numInterveningMoves - MAX_LATEST_MOVES} moves`);
563
+ debugLog(
564
+ `Too many moves! Dropping ${numInterveningMoves - MAX_LATEST_MOVES} moves`
565
+ );
510
566
  numInterveningMoves = MAX_LATEST_MOVES;
511
567
  }
512
568
  for (const move of physicalState.latestMoves(numInterveningMoves)) {
513
569
  this.state = this.state.applyMove(move);
514
- this.dispatchMove({
515
- latestMove: move,
570
+ this.dispatchAlgLeaf({
571
+ latestAlgLeaf: move,
516
572
  timeStamp: physicalState.timeStamp,
517
573
  debug: physicalState.debugInfo(),
518
574
  state: this.state
@@ -525,10 +581,15 @@ var GanCube = class extends BluetoothPuzzle {
525
581
  this.lastMoveCounter = physicalState.moveCounter();
526
582
  }
527
583
  async getBattery() {
528
- return new Uint8Array(await this.readActualAngleAndBatteryCharacteristic())[7];
584
+ return new Uint8Array(
585
+ await this.readActualAngleAndBatteryCharacteristic()
586
+ )[7];
529
587
  }
530
588
  async getState() {
531
- const arr = await decryptState(new Uint8Array(await this.readFaceletStatus1Characteristic()), this.aesKey);
589
+ const arr = await decryptState(
590
+ new Uint8Array(await this.readFaceletStatus1Characteristic()),
591
+ this.aesKey
592
+ );
532
593
  const stickers = [];
533
594
  for (let i = 0; i < 18; i += 3) {
534
595
  let v = ((arr[i ^ 1] << 8) + arr[i + 1 ^ 1] << 8) + arr[i + 2 ^ 1];
@@ -716,13 +777,20 @@ var GiiKERCube = class extends BluetoothPuzzle {
716
777
  static async connect(server) {
717
778
  const cubeService = await server.getPrimaryService(UUIDs2.cubeService);
718
779
  debugLog("Service:", cubeService);
719
- const cubeCharacteristic = await cubeService.getCharacteristic(UUIDs2.cubeCharacteristic);
780
+ const cubeCharacteristic = await cubeService.getCharacteristic(
781
+ UUIDs2.cubeCharacteristic
782
+ );
720
783
  debugLog("Characteristic:", cubeCharacteristic);
721
- const originalValue = await decodeState(new Uint8Array((await cubeCharacteristic.readValue()).buffer));
784
+ const originalValue = await decodeState(
785
+ new Uint8Array((await cubeCharacteristic.readValue()).buffer)
786
+ );
722
787
  debugLog("Original value:", originalValue);
723
788
  const cube = new GiiKERCube(server, cubeCharacteristic, originalValue);
724
789
  await cubeCharacteristic.startNotifications();
725
- cubeCharacteristic.addEventListener("characteristicvaluechanged", cube.onCubeCharacteristicChanged.bind(cube));
790
+ cubeCharacteristic.addEventListener(
791
+ "characteristicvaluechanged",
792
+ cube.onCubeCharacteristicChanged.bind(cube)
793
+ );
726
794
  return cube;
727
795
  }
728
796
  name() {
@@ -732,7 +800,9 @@ var GiiKERCube = class extends BluetoothPuzzle {
732
800
  this.server.disconnect();
733
801
  }
734
802
  async getState() {
735
- return this.toReid333(new Uint8Array((await this.cubeCharacteristic.readValue()).buffer));
803
+ return this.toReid333(
804
+ new Uint8Array((await this.cubeCharacteristic.readValue()).buffer)
805
+ );
736
806
  }
737
807
  getBit(val, i) {
738
808
  const n = i / 8 | 0;
@@ -779,8 +849,8 @@ var GiiKERCube = class extends BluetoothPuzzle {
779
849
  debugLog(giikerState);
780
850
  const str = giikerStateStr(giikerState);
781
851
  debugLog(str);
782
- this.dispatchMove({
783
- latestMove: giikerMoveToAlgMove(giikerState[32], giikerState[33]),
852
+ this.dispatchAlgLeaf({
853
+ latestAlgLeaf: giikerMoveToAlgMove(giikerState[32], giikerState[33]),
784
854
  timeStamp: event.timeStamp,
785
855
  debug: {
786
856
  stateStr: str
@@ -828,7 +898,10 @@ var UUIDs3 = {
828
898
  goCubeStateCharacteristic: "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
829
899
  };
830
900
  function buf2hex2(buffer) {
831
- return Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join(" ");
901
+ return Array.prototype.map.call(
902
+ new Uint8Array(buffer),
903
+ (x) => ("00" + x.toString(16)).slice(-2)
904
+ ).join(" ");
832
905
  }
833
906
  function bufferToString(buffer) {
834
907
  const byteView = new Uint8Array(buffer);
@@ -867,11 +940,16 @@ var GoCube = class extends BluetoothPuzzle {
867
940
  static async connect(server) {
868
941
  const service = await server.getPrimaryService(UUIDs3.goCubeService);
869
942
  debugLog({ service });
870
- const goCubeStateCharacteristic = await service.getCharacteristic(UUIDs3.goCubeStateCharacteristic);
943
+ const goCubeStateCharacteristic = await service.getCharacteristic(
944
+ UUIDs3.goCubeStateCharacteristic
945
+ );
871
946
  debugLog({ goCubeStateCharacteristic });
872
947
  const cube = new GoCube(server, goCubeStateCharacteristic);
873
948
  await goCubeStateCharacteristic.startNotifications();
874
- goCubeStateCharacteristic.addEventListener("characteristicvaluechanged", cube.onCubeCharacteristicChanged.bind(cube));
949
+ goCubeStateCharacteristic.addEventListener(
950
+ "characteristicvaluechanged",
951
+ cube.onCubeCharacteristicChanged.bind(cube)
952
+ );
875
953
  return cube;
876
954
  }
877
955
  disconnect() {
@@ -885,7 +963,7 @@ var GoCube = class extends BluetoothPuzzle {
885
963
  this.alg = alg || new Alg();
886
964
  }
887
965
  resetOrientation() {
888
- this.homeQuatInverse = this.lastRawQuat.clone().inverse();
966
+ this.homeQuatInverse = this.lastRawQuat.clone().invert();
889
967
  this.currentQuat = new Quaternion3(0, 0, 0, 1);
890
968
  this.lastTarget = new Quaternion3(0, 0, 0, 1);
891
969
  }
@@ -899,8 +977,8 @@ var GoCube = class extends BluetoothPuzzle {
899
977
  for (let i = 3; i < buffer.byteLength - 4; i += 2) {
900
978
  const move = moveMap[buffer.getUint8(i)];
901
979
  this.alg = experimentalAppendMove(this.alg, move);
902
- this.dispatchMove({
903
- latestMove: moveMap[buffer.getUint8(i)],
980
+ this.dispatchAlgLeaf({
981
+ latestAlgLeaf: moveMap[buffer.getUint8(i)],
904
982
  timeStamp: event.timeStamp,
905
983
  debug: {
906
984
  stateStr: buf2hex2(buffer.buffer)
@@ -908,11 +986,13 @@ var GoCube = class extends BluetoothPuzzle {
908
986
  });
909
987
  }
910
988
  } else {
911
- const coords = bufferToString(buffer.buffer.slice(3, buffer.byteLength - 3)).split("#").map((s) => parseInt(s, 10) / 16384);
989
+ const coords = bufferToString(
990
+ buffer.buffer.slice(3, buffer.byteLength - 3)
991
+ ).split("#").map((s) => parseInt(s, 10) / 16384);
912
992
  const quat = new Quaternion3(coords[0], coords[1], coords[2], coords[3]);
913
993
  this.lastRawQuat = quat.clone();
914
994
  if (!this.homeQuatInverse) {
915
- this.homeQuatInverse = quat.clone().inverse();
995
+ this.homeQuatInverse = quat.clone().invert();
916
996
  }
917
997
  const targetQuat = quat.clone().multiply(this.homeQuatInverse.clone());
918
998
  targetQuat.y = -targetQuat.y;
@@ -955,16 +1035,27 @@ var HeykubeCube = class extends BluetoothPuzzle {
955
1035
  super();
956
1036
  this.server = server;
957
1037
  this.stateCharacteristic = stateCharacteristic;
958
- device.addEventListener("gattserverdisconnected", this.onDisconnect.bind(this));
1038
+ device.addEventListener(
1039
+ "gattserverdisconnected",
1040
+ this.onDisconnect.bind(this)
1041
+ );
959
1042
  this.stateCharacteristic.startNotifications();
960
1043
  this.startTrackingMoves();
961
1044
  }
962
1045
  static async connect(server, device) {
963
1046
  const service = await server.getPrimaryService(UUIDs4.heykubeService);
964
1047
  debugLog("Service:", service);
965
- const stateCharacteristic = await service.getCharacteristic(UUIDs4.stateCharacteristic);
1048
+ const stateCharacteristic = await service.getCharacteristic(
1049
+ UUIDs4.stateCharacteristic
1050
+ );
966
1051
  debugLog("Characteristic:", stateCharacteristic);
967
- const cube = new HeykubeCube(await puzzles["3x3x3"].kpuzzle(), service, device, server, stateCharacteristic);
1052
+ const cube = new HeykubeCube(
1053
+ await puzzles["3x3x3"].kpuzzle(),
1054
+ service,
1055
+ device,
1056
+ server,
1057
+ stateCharacteristic
1058
+ );
968
1059
  return cube;
969
1060
  }
970
1061
  name() {
@@ -977,12 +1068,15 @@ var HeykubeCube = class extends BluetoothPuzzle {
977
1068
  this.dispatchEvent(new CustomEvent("disconnect"));
978
1069
  }
979
1070
  startTrackingMoves() {
980
- this.stateCharacteristic.addEventListener("characteristicvaluechanged", (e) => this.onStateCharacteristic(e));
1071
+ this.stateCharacteristic.addEventListener(
1072
+ "characteristicvaluechanged",
1073
+ (e) => this.onStateCharacteristic(e)
1074
+ );
981
1075
  }
982
1076
  onStateCharacteristic(event) {
983
1077
  const state = this.decodeState(event.target.value);
984
- this.dispatchMove({
985
- latestMove: state.latestMove,
1078
+ this.dispatchAlgLeaf({
1079
+ latestAlgLeaf: state.latestMove,
986
1080
  timeStamp: event.timeStamp,
987
1081
  state: state.state
988
1082
  });
@@ -1008,7 +1102,9 @@ var HeykubeCube = class extends BluetoothPuzzle {
1008
1102
  for (let i = 0; i < dv.byteLength; i++) {
1009
1103
  b2[i] = flipBitOrder(dv.getUint8(i), 8);
1010
1104
  }
1011
- const components1 = twizzleBinaryToBinaryComponents(b2.slice(0, 11));
1105
+ const components1 = twizzleBinaryToBinaryComponents(
1106
+ b2.slice(0, 11)
1107
+ );
1012
1108
  const components2 = {
1013
1109
  epLex: flipBitOrder(components1.epLex, 29),
1014
1110
  eoMask: flipBitOrder(components1.eoMask, 12),
@@ -1049,7 +1145,10 @@ async function connectSmartPuzzle(options) {
1049
1145
 
1050
1146
  // src/cubing/bluetooth/smart-robot/GanRobot.ts
1051
1147
  function buf2hex3(buffer) {
1052
- return Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join(" ");
1148
+ return Array.prototype.map.call(
1149
+ new Uint8Array(buffer),
1150
+ (x) => ("00" + x.toString(16)).slice(-2)
1151
+ ).join(" ");
1053
1152
  }
1054
1153
  var MAX_NIBBLES_PER_WRITE = 18 * 2;
1055
1154
  var QUANTUM_TURN_DURATION_MS = 150;
@@ -1137,13 +1236,28 @@ var GanRobot = class extends EventTarget {
1137
1236
  };
1138
1237
  this.locked = false;
1139
1238
  this.moveQueue = new Alg();
1140
- device.addEventListener("gattserverdisconnected", this.onDisconnect.bind(this));
1239
+ device.addEventListener(
1240
+ "gattserverdisconnected",
1241
+ this.onDisconnect.bind(this)
1242
+ );
1141
1243
  }
1142
1244
  static async connect(server, device) {
1143
- const ganTimerService = await server.getPrimaryService(UUIDs5.ganRobotService);
1144
- const statusCharacteristic = await ganTimerService.getCharacteristic(UUIDs5.statusCharacteristic);
1145
- const moveCharacteristic = await ganTimerService.getCharacteristic(UUIDs5.moveCharacteristic);
1146
- const timer = new GanRobot(ganTimerService, server, device, statusCharacteristic, moveCharacteristic);
1245
+ const ganTimerService = await server.getPrimaryService(
1246
+ UUIDs5.ganRobotService
1247
+ );
1248
+ const statusCharacteristic = await ganTimerService.getCharacteristic(
1249
+ UUIDs5.statusCharacteristic
1250
+ );
1251
+ const moveCharacteristic = await ganTimerService.getCharacteristic(
1252
+ UUIDs5.moveCharacteristic
1253
+ );
1254
+ const timer = new GanRobot(
1255
+ ganTimerService,
1256
+ server,
1257
+ device,
1258
+ statusCharacteristic,
1259
+ moveCharacteristic
1260
+ );
1147
1261
  return timer;
1148
1262
  }
1149
1263
  name() {
@@ -1164,7 +1278,9 @@ var GanRobot = class extends EventTarget {
1164
1278
  }
1165
1279
  async writeNibbles(nibbles) {
1166
1280
  if (nibbles.length > MAX_NIBBLES_PER_WRITE) {
1167
- throw new Error(`Can only write ${MAX_NIBBLES_PER_WRITE} nibbles at a time!`);
1281
+ throw new Error(
1282
+ `Can only write ${MAX_NIBBLES_PER_WRITE} nibbles at a time!`
1283
+ );
1168
1284
  }
1169
1285
  const bytes = new Uint8Array(18);
1170
1286
  let i;
@@ -1193,7 +1309,9 @@ var GanRobot = class extends EventTarget {
1193
1309
  await sleep(this.experimentalOptions.postSleep);
1194
1310
  }
1195
1311
  async getStatus() {
1196
- const statusBytes = new Uint8Array((await this.statusCharacteristic.readValue()).buffer);
1312
+ const statusBytes = new Uint8Array(
1313
+ (await this.statusCharacteristic.readValue()).buffer
1314
+ );
1197
1315
  this.experimentalDebugLog("moves remaining:", statusBytes[0]);
1198
1316
  return {
1199
1317
  movesRemaining: statusBytes[0]
@@ -1248,12 +1366,18 @@ var GanRobot = class extends EventTarget {
1248
1366
  await this.queueMoves(new Alg([move]));
1249
1367
  } else if (move.family === (this.experimentalOptions.xAngle ? "B" : "U")) {
1250
1368
  await Promise.all([
1251
- this.queueMoves(this.experimentalOptions.xAngle ? F_B_SWAP : U_D_SWAP),
1252
- this.queueMoves(new Alg([
1253
- move.modified({
1254
- family: this.experimentalOptions.xAngle ? "F" : "D"
1255
- })
1256
- ]).concat(this.experimentalOptions.xAngle ? F_B_UNSWAP : U_D_UNSWAP))
1369
+ this.queueMoves(
1370
+ this.experimentalOptions.xAngle ? F_B_SWAP : U_D_SWAP
1371
+ ),
1372
+ this.queueMoves(
1373
+ new Alg([
1374
+ move.modified({
1375
+ family: this.experimentalOptions.xAngle ? "F" : "D"
1376
+ })
1377
+ ]).concat(
1378
+ this.experimentalOptions.xAngle ? F_B_UNSWAP : U_D_UNSWAP
1379
+ )
1380
+ )
1257
1381
  ]);
1258
1382
  }
1259
1383
  }
@@ -1286,14 +1410,26 @@ var GanTimer = class extends EventTarget {
1286
1410
  this.previousDetail = null;
1287
1411
  this.startPolling();
1288
1412
  console.log(server);
1289
- device.addEventListener("gattserverdisconnected", this.onDisconnect.bind(this));
1413
+ device.addEventListener(
1414
+ "gattserverdisconnected",
1415
+ this.onDisconnect.bind(this)
1416
+ );
1290
1417
  }
1291
1418
  static async connect(server, device) {
1292
- const ganTimerService = await server.getPrimaryService(UUIDs6.ganTimerService);
1419
+ const ganTimerService = await server.getPrimaryService(
1420
+ UUIDs6.ganTimerService
1421
+ );
1293
1422
  console.log("Service:", ganTimerService);
1294
- const timeCharacteristic = await ganTimerService.getCharacteristic(UUIDs6.timeCharacteristic);
1423
+ const timeCharacteristic = await ganTimerService.getCharacteristic(
1424
+ UUIDs6.timeCharacteristic
1425
+ );
1295
1426
  console.log("Characteristic:", timeCharacteristic);
1296
- const timer = new GanTimer(ganTimerService, server, device, timeCharacteristic);
1427
+ const timer = new GanTimer(
1428
+ ganTimerService,
1429
+ server,
1430
+ device,
1431
+ timeCharacteristic
1432
+ );
1297
1433
  return timer;
1298
1434
  }
1299
1435
  disconnect() {