@houstonp/rubiks-cube 1.5.2 → 2.1.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.
- package/README.md +280 -170
- package/package.json +33 -3
- package/src/camera/cameraState.js +81 -0
- package/src/core.js +447 -0
- package/src/cube/animationSlice.js +205 -0
- package/src/cube/animationState.js +96 -0
- package/src/cube/cubeSettings.js +19 -0
- package/src/cube/cubeState.js +285 -139
- package/src/cube/stickerState.js +188 -0
- package/src/debouncer.js +16 -0
- package/src/globals.ts +9 -0
- package/src/index.js +621 -0
- package/src/settings.js +138 -0
- package/src/three/centerPiece.js +44 -0
- package/src/three/cornerPiece.js +60 -0
- package/src/three/cube.js +492 -0
- package/src/three/edgePiece.js +50 -0
- package/src/three/sticker.js +37 -0
- package/tests/common.js +27 -0
- package/tests/cube.five.test.js +126 -0
- package/tests/cube.four.test.js +126 -0
- package/tests/cube.seven.test.js +126 -0
- package/tests/cube.six.test.js +126 -0
- package/tests/cube.three.test.js +151 -0
- package/tests/cube.two.test.js +125 -0
- package/tests/setup.js +36 -0
- package/types/camera/cameraState.d.ts +19 -0
- package/types/core.d.ts +454 -0
- package/types/cube/animationSlice.d.ts +26 -0
- package/types/cube/animationState.d.ts +41 -0
- package/types/cube/cubeSettings.d.ts +17 -0
- package/types/cube/cubeState.d.ts +47 -0
- package/types/cube/stickerState.d.ts +21 -0
- package/types/debouncer.d.ts +13 -0
- package/types/globals.d.ts +7 -0
- package/types/index.d.ts +87 -0
- package/types/settings.d.ts +38 -0
- package/types/three/centerPiece.d.ts +15 -0
- package/types/three/cornerPiece.d.ts +24 -0
- package/types/three/cube.d.ts +130 -0
- package/types/three/edgePiece.d.ts +16 -0
- package/types/three/sticker.d.ts +15 -0
- package/.prettierrc +0 -7
- package/index.js +0 -274
- package/src/cube/cube.js +0 -276
- package/src/cube/cubeRotation.js +0 -63
- package/src/threejs/materials.js +0 -42
- package/src/threejs/pieces.js +0 -103
- package/src/threejs/stickers.js +0 -48
- package/src/utils/debouncer.js +0 -7
- package/src/utils/rotation.js +0 -53
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import './setup.js';
|
|
3
|
+
import { describe, it, expect, test } from 'bun:test';
|
|
4
|
+
import { CubeTypes, Movements, Rotations } from '../src/core.js';
|
|
5
|
+
import { toKociemba } from '../src/cube/stickerState.js';
|
|
6
|
+
import { createTestCube, drainUpdates } from './common.js';
|
|
7
|
+
|
|
8
|
+
describe('2x2 Tests', () => {
|
|
9
|
+
it('Valid initial Kociemba state string', () => {
|
|
10
|
+
//Arange
|
|
11
|
+
const cube = createTestCube(CubeTypes.Two);
|
|
12
|
+
|
|
13
|
+
//Act
|
|
14
|
+
const state = toKociemba(cube._cubeInfo.initialStickerState);
|
|
15
|
+
|
|
16
|
+
//Assert
|
|
17
|
+
expect(state.length).toBe(24);
|
|
18
|
+
for (const ch of state) {
|
|
19
|
+
expect('UDLRFB').toContain(ch);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const counts = {
|
|
23
|
+
U: 0,
|
|
24
|
+
D: 0,
|
|
25
|
+
L: 0,
|
|
26
|
+
R: 0,
|
|
27
|
+
F: 0,
|
|
28
|
+
B: 0,
|
|
29
|
+
};
|
|
30
|
+
for (const ch of state) {
|
|
31
|
+
const face = /** @type {"R" | "U" | "F" | "L" | "D" | "B"} */ (ch);
|
|
32
|
+
counts[face]++;
|
|
33
|
+
}
|
|
34
|
+
expect(Object.values(counts).every((c) => c === 4)).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('reset method returns the cube to the initial state', () => {
|
|
38
|
+
// Arrange
|
|
39
|
+
const cube = createTestCube(CubeTypes.Two);
|
|
40
|
+
const initialState = toKociemba(cube._cubeInfo.initialStickerState);
|
|
41
|
+
/** @type {string?} */
|
|
42
|
+
let completedState = null;
|
|
43
|
+
/** @type {string?} */
|
|
44
|
+
let failedReason = null;
|
|
45
|
+
cube.movement(
|
|
46
|
+
Movements.Single.R,
|
|
47
|
+
(state) => {
|
|
48
|
+
completedState = state;
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
(reason) => {
|
|
52
|
+
failedReason = reason;
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
drainUpdates(cube);
|
|
57
|
+
|
|
58
|
+
// Act
|
|
59
|
+
/** @type {string?} */
|
|
60
|
+
let resetState = null;
|
|
61
|
+
cube.reset((state) => {
|
|
62
|
+
resetState = state;
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
drainUpdates(cube);
|
|
66
|
+
|
|
67
|
+
// Assert
|
|
68
|
+
expect(failedReason).toBeNull();
|
|
69
|
+
expect(completedState).not.toBeNull();
|
|
70
|
+
expect(completedState).not.toBe(initialState);
|
|
71
|
+
expect(/** @type {string?} **/ (resetState)).toBe(initialState);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('solve', () => {
|
|
75
|
+
// Arrange
|
|
76
|
+
const cube = createTestCube(CubeTypes.Two);
|
|
77
|
+
const scramble = "D U R2 B2 D' B2 D R2 F2 L2 R B U2 R2 U' B' L D' R U' R";
|
|
78
|
+
const scrambleMoves = /** @type {import('../src/core.js').Movement[]} */ (scramble.split(' '));
|
|
79
|
+
|
|
80
|
+
for (const move of scrambleMoves) {
|
|
81
|
+
cube.movement(
|
|
82
|
+
move,
|
|
83
|
+
() => {},
|
|
84
|
+
() => {
|
|
85
|
+
throw new Error('Movement failed unexpectedly');
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
drainUpdates(cube);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Act
|
|
92
|
+
const solution =
|
|
93
|
+
"D L R' F R D2 R U' R' F U R U2' R' U R U' R' U' L U L' D U L' U' L U2 L' U L L F' L' F U R' U2 R U2' R' U R U2' R' U R U2' R' U' R U y'";
|
|
94
|
+
const solutionActions = /** @type {(import('../src/core.js').Movement | import('../src/core.js').Rotation)[]} */ (solution.split(' '));
|
|
95
|
+
|
|
96
|
+
let finalState = null;
|
|
97
|
+
for (const action of solutionActions) {
|
|
98
|
+
if (action.includes('x') || action.includes('y') || action.includes('z')) {
|
|
99
|
+
cube.rotate(
|
|
100
|
+
/** @type {import('../src/core.js').Rotation} */ (action),
|
|
101
|
+
(state) => {
|
|
102
|
+
finalState = state;
|
|
103
|
+
},
|
|
104
|
+
() => {
|
|
105
|
+
throw new Error('Rotation failed unexpectedly');
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
cube.movement(
|
|
110
|
+
/** @type {import('../src/core.js').Movement} */ (action),
|
|
111
|
+
(state) => {
|
|
112
|
+
finalState = state;
|
|
113
|
+
},
|
|
114
|
+
() => {
|
|
115
|
+
throw new Error('Movement failed unexpectedly');
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
drainUpdates(cube);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Assert
|
|
123
|
+
expect(/** @type {string?} **/ (finalState)).toBe(toKociemba(cube._cubeInfo.initialStickerState));
|
|
124
|
+
});
|
|
125
|
+
});
|
package/tests/setup.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
|
|
3
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
|
|
4
|
+
url: 'http://localhost',
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
global.window = dom.window;
|
|
8
|
+
global.document = dom.window.document;
|
|
9
|
+
global.DOMParser = dom.window.DOMParser;
|
|
10
|
+
global.XMLSerializer = dom.window.XMLSerializer;
|
|
11
|
+
global.Node = dom.window.Node;
|
|
12
|
+
global.window.HTMLCanvasElement.prototype.getContext = function () {
|
|
13
|
+
return {
|
|
14
|
+
fillRect: () => {},
|
|
15
|
+
clearRect: () => {},
|
|
16
|
+
getImageData: (x, y, w, h) => ({ data: new Uint8ClampedArray(w * h * 4) }),
|
|
17
|
+
setTransform: () => {},
|
|
18
|
+
drawImage: () => {},
|
|
19
|
+
save: () => {},
|
|
20
|
+
restore: () => {},
|
|
21
|
+
beginPath: () => {},
|
|
22
|
+
moveTo: () => {},
|
|
23
|
+
lineTo: () => {},
|
|
24
|
+
closePath: () => {},
|
|
25
|
+
stroke: () => {},
|
|
26
|
+
fill: () => {},
|
|
27
|
+
measureText: () => ({ width: 0 }),
|
|
28
|
+
_fillStyle: 'rgba(0,0,0,0)',
|
|
29
|
+
get fillStyle() {
|
|
30
|
+
return this._fillStyle;
|
|
31
|
+
},
|
|
32
|
+
set fillStyle(val) {
|
|
33
|
+
this._fillStyle = val;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class CameraState {
|
|
2
|
+
/**
|
|
3
|
+
* @param {boolean} up
|
|
4
|
+
* @param {boolean} right
|
|
5
|
+
*/
|
|
6
|
+
constructor(up?: boolean, right?: boolean);
|
|
7
|
+
/** @type {boolean} */
|
|
8
|
+
Up: boolean;
|
|
9
|
+
/** @type {boolean} */
|
|
10
|
+
Right: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @param {import("../core").PeekType} peekType
|
|
13
|
+
*/
|
|
14
|
+
peekCamera(peekType: import("../core").PeekType): void;
|
|
15
|
+
/**
|
|
16
|
+
* @returns {import("../core").PeekState}
|
|
17
|
+
*/
|
|
18
|
+
toPeekState(): import("../core").PeekState;
|
|
19
|
+
}
|
package/types/core.d.ts
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {typeof Movements.Single[keyof typeof Movements.Single]} SingleMove
|
|
3
|
+
* @typedef {typeof Movements.Wide[keyof typeof Movements.Wide]} WideMove
|
|
4
|
+
* @typedef {typeof Movements.Two[keyof typeof Movements.Two]} TwoMove
|
|
5
|
+
* @typedef {typeof Movements.Three[keyof typeof Movements.Three]} ThreeMove
|
|
6
|
+
* @typedef {typeof Movements.Four[keyof typeof Movements.Four]} FourMove
|
|
7
|
+
* @typedef {typeof Movements.Five[keyof typeof Movements.Five]} FiveMove
|
|
8
|
+
* @typedef {typeof Movements.Six[keyof typeof Movements.Six]} SixMove
|
|
9
|
+
* @typedef {SingleMove | WideMove | TwoMove | ThreeMove | FourMove | FiveMove | SixMove} Movement
|
|
10
|
+
*/
|
|
11
|
+
export const Movements: Readonly<{
|
|
12
|
+
Single: Readonly<{
|
|
13
|
+
R: "R";
|
|
14
|
+
R2: "R2";
|
|
15
|
+
RP: "R'";
|
|
16
|
+
L: "L";
|
|
17
|
+
L2: "L2";
|
|
18
|
+
LP: "L'";
|
|
19
|
+
U: "U";
|
|
20
|
+
U2: "U2";
|
|
21
|
+
UP: "U'";
|
|
22
|
+
D: "D";
|
|
23
|
+
D2: "D2";
|
|
24
|
+
DP: "D'";
|
|
25
|
+
F: "F";
|
|
26
|
+
F2: "F2";
|
|
27
|
+
FP: "F'";
|
|
28
|
+
B: "B";
|
|
29
|
+
B2: "B2";
|
|
30
|
+
BP: "B'";
|
|
31
|
+
M: "M";
|
|
32
|
+
M2: "M2";
|
|
33
|
+
MP: "M'";
|
|
34
|
+
E: "E";
|
|
35
|
+
E2: "E2";
|
|
36
|
+
EP: "E'";
|
|
37
|
+
S: "S";
|
|
38
|
+
S2: "S2";
|
|
39
|
+
SP: "S'";
|
|
40
|
+
}>;
|
|
41
|
+
Wide: Readonly<{
|
|
42
|
+
Rw: "Rw";
|
|
43
|
+
Rw2: "Rw2";
|
|
44
|
+
RwP: "Rw'";
|
|
45
|
+
r: "r";
|
|
46
|
+
r2: "r2";
|
|
47
|
+
rP: "r'";
|
|
48
|
+
Lw: "Lw";
|
|
49
|
+
Lw2: "Lw2";
|
|
50
|
+
LwP: "Lw'";
|
|
51
|
+
l: "l";
|
|
52
|
+
l2: "l2";
|
|
53
|
+
lP: "l'";
|
|
54
|
+
Fw: "Fw";
|
|
55
|
+
Fw2: "Fw2";
|
|
56
|
+
FwP: "Fw'";
|
|
57
|
+
f: "f";
|
|
58
|
+
f2: "f2";
|
|
59
|
+
fP: "f'";
|
|
60
|
+
Bw: "Bw";
|
|
61
|
+
Bw2: "Bw2";
|
|
62
|
+
BwP: "Bw'";
|
|
63
|
+
b: "b";
|
|
64
|
+
b2: "b2";
|
|
65
|
+
bP: "b'";
|
|
66
|
+
Uw: "Uw";
|
|
67
|
+
Uw2: "Uw2";
|
|
68
|
+
UwP: "Uw'";
|
|
69
|
+
u: "u";
|
|
70
|
+
u2: "u2";
|
|
71
|
+
uP: "u'";
|
|
72
|
+
Dw: "Dw";
|
|
73
|
+
Dw2: "D2";
|
|
74
|
+
DwP: "Dw'";
|
|
75
|
+
d: "d";
|
|
76
|
+
d2: "d2";
|
|
77
|
+
dP: "d'";
|
|
78
|
+
}>;
|
|
79
|
+
Two: Readonly<{
|
|
80
|
+
Rw: "2Rw";
|
|
81
|
+
Rw2: "2Rw2";
|
|
82
|
+
RwP: "2Rw'";
|
|
83
|
+
r: "2r";
|
|
84
|
+
r2: "2r2";
|
|
85
|
+
rP: "2r'";
|
|
86
|
+
R: "2R";
|
|
87
|
+
R2: "2R2";
|
|
88
|
+
RP: "2R'";
|
|
89
|
+
Lw: "2Lw";
|
|
90
|
+
Lw2: "2Lw2";
|
|
91
|
+
LwP: "2Lw'";
|
|
92
|
+
l: "2l";
|
|
93
|
+
l2: "2l2";
|
|
94
|
+
lP: "2l'";
|
|
95
|
+
L: "2L";
|
|
96
|
+
L2: "2L2";
|
|
97
|
+
LP: "2L'";
|
|
98
|
+
Fw: "2Fw";
|
|
99
|
+
Fw2: "2Fw2";
|
|
100
|
+
FwP: "2Fw'";
|
|
101
|
+
f: "2f";
|
|
102
|
+
f2: "2f2";
|
|
103
|
+
fP: "2f'";
|
|
104
|
+
F: "2F";
|
|
105
|
+
F2: "2F2";
|
|
106
|
+
FP: "2F'";
|
|
107
|
+
Bw: "2Bw";
|
|
108
|
+
Bw2: "2Bw2";
|
|
109
|
+
BwP: "2Bw'";
|
|
110
|
+
b: "2b";
|
|
111
|
+
b2: "2b2";
|
|
112
|
+
bP: "2b'";
|
|
113
|
+
B: "2B";
|
|
114
|
+
B2: "2B2";
|
|
115
|
+
BP: "2B'";
|
|
116
|
+
Uw: "2Uw";
|
|
117
|
+
Uw2: "2Uw2";
|
|
118
|
+
UwP: "2Uw'";
|
|
119
|
+
u: "2u";
|
|
120
|
+
u2: "2u2";
|
|
121
|
+
uP: "2u'";
|
|
122
|
+
U: "2U";
|
|
123
|
+
U2: "2U2";
|
|
124
|
+
UP: "2U'";
|
|
125
|
+
Dw: "2Dw";
|
|
126
|
+
Dw2: "2Dw2";
|
|
127
|
+
DwP: "2Dw'";
|
|
128
|
+
d: "2d";
|
|
129
|
+
d2: "2d2";
|
|
130
|
+
dP: "2d'";
|
|
131
|
+
D: "2D";
|
|
132
|
+
D2: "2D2";
|
|
133
|
+
DP: "2D'";
|
|
134
|
+
}>;
|
|
135
|
+
Three: Readonly<{
|
|
136
|
+
Rw: "3Rw";
|
|
137
|
+
Rw2: "3Rw2";
|
|
138
|
+
RwP: "3Rw'";
|
|
139
|
+
r: "3r";
|
|
140
|
+
r2: "3r2";
|
|
141
|
+
rP: "3r'";
|
|
142
|
+
R: "3R";
|
|
143
|
+
R2: "3R2";
|
|
144
|
+
RP: "3R'";
|
|
145
|
+
Lw: "3Lw";
|
|
146
|
+
Lw2: "3Lw2";
|
|
147
|
+
LwP: "3Lw'";
|
|
148
|
+
l: "3l";
|
|
149
|
+
l2: "3l2";
|
|
150
|
+
lP: "3l'";
|
|
151
|
+
L: "3L";
|
|
152
|
+
L2: "3L2";
|
|
153
|
+
LP: "3L'";
|
|
154
|
+
Fw: "3Fw";
|
|
155
|
+
Fw2: "3Fw2";
|
|
156
|
+
FwP: "3Fw'";
|
|
157
|
+
f: "3f";
|
|
158
|
+
f2: "3f2";
|
|
159
|
+
fP: "3f'";
|
|
160
|
+
F: "3F";
|
|
161
|
+
F2: "3F2";
|
|
162
|
+
FP: "3F'";
|
|
163
|
+
Bw: "3Bw";
|
|
164
|
+
Bw2: "3Bw2";
|
|
165
|
+
BwP: "3Bw'";
|
|
166
|
+
b: "3b";
|
|
167
|
+
b2: "3b2";
|
|
168
|
+
bP: "3b'";
|
|
169
|
+
B: "3B";
|
|
170
|
+
B2: "3B2";
|
|
171
|
+
BP: "3B'";
|
|
172
|
+
Uw: "3Uw";
|
|
173
|
+
Uw2: "3Uw2";
|
|
174
|
+
UwP: "3Uw'";
|
|
175
|
+
u: "3u";
|
|
176
|
+
u2: "3u2";
|
|
177
|
+
uP: "3u'";
|
|
178
|
+
U: "3U";
|
|
179
|
+
U2: "3U2";
|
|
180
|
+
UP: "3U'";
|
|
181
|
+
Dw: "3Dw";
|
|
182
|
+
Dw2: "3Dw2";
|
|
183
|
+
DwP: "3Dw'";
|
|
184
|
+
d: "3d";
|
|
185
|
+
d2: "3d2";
|
|
186
|
+
dP: "3d'";
|
|
187
|
+
D: "3D";
|
|
188
|
+
D2: "3D2";
|
|
189
|
+
DP: "3D'";
|
|
190
|
+
}>;
|
|
191
|
+
Four: Readonly<{
|
|
192
|
+
Rw: "4Rw";
|
|
193
|
+
Rw2: "4Rw2";
|
|
194
|
+
RwP: "4Rw'";
|
|
195
|
+
r: "4r";
|
|
196
|
+
r2: "4r2";
|
|
197
|
+
rP: "4r'";
|
|
198
|
+
R: "4R";
|
|
199
|
+
R2: "4R2";
|
|
200
|
+
RP: "4R'";
|
|
201
|
+
Lw: "4Lw";
|
|
202
|
+
Lw2: "4Lw2";
|
|
203
|
+
LwP: "4Lw'";
|
|
204
|
+
l: "4l";
|
|
205
|
+
l2: "4l2";
|
|
206
|
+
lP: "4l'";
|
|
207
|
+
L: "4L";
|
|
208
|
+
L2: "4L2";
|
|
209
|
+
LP: "4L'";
|
|
210
|
+
Fw: "4Fw";
|
|
211
|
+
Fw2: "4Fw2";
|
|
212
|
+
FwP: "4Fw'";
|
|
213
|
+
f: "4f";
|
|
214
|
+
f2: "4f2";
|
|
215
|
+
fP: "4f'";
|
|
216
|
+
F: "4F";
|
|
217
|
+
F2: "4F2";
|
|
218
|
+
FP: "4F'";
|
|
219
|
+
Bw: "4Bw";
|
|
220
|
+
Bw2: "4Bw2";
|
|
221
|
+
BwP: "4Bw'";
|
|
222
|
+
b: "4b";
|
|
223
|
+
b2: "4b2";
|
|
224
|
+
bP: "4b'";
|
|
225
|
+
B: "4B";
|
|
226
|
+
B2: "4B2";
|
|
227
|
+
BP: "4B'";
|
|
228
|
+
Uw: "4Uw";
|
|
229
|
+
Uw2: "4Uw2";
|
|
230
|
+
UwP: "4Uw'";
|
|
231
|
+
u: "4u";
|
|
232
|
+
u2: "4u2";
|
|
233
|
+
uP: "4u'";
|
|
234
|
+
U: "4U";
|
|
235
|
+
U2: "4U2";
|
|
236
|
+
UP: "4U'";
|
|
237
|
+
Dw: "4Dw";
|
|
238
|
+
Dw2: "4Dw2";
|
|
239
|
+
DwP: "4Dw'";
|
|
240
|
+
d: "4d";
|
|
241
|
+
d2: "4d2";
|
|
242
|
+
dP: "4d'";
|
|
243
|
+
D: "4D";
|
|
244
|
+
D2: "4D2";
|
|
245
|
+
DP: "4D'";
|
|
246
|
+
}>;
|
|
247
|
+
Five: Readonly<{
|
|
248
|
+
Rw: "5Rw";
|
|
249
|
+
Rw2: "5Rw2";
|
|
250
|
+
RwP: "5Rw'";
|
|
251
|
+
r: "5r";
|
|
252
|
+
r2: "5r2";
|
|
253
|
+
rP: "5r'";
|
|
254
|
+
R: "5R";
|
|
255
|
+
R2: "5R2";
|
|
256
|
+
RP: "5R'";
|
|
257
|
+
Lw: "5Lw";
|
|
258
|
+
Lw2: "5Lw2";
|
|
259
|
+
LwP: "5Lw'";
|
|
260
|
+
l: "5l";
|
|
261
|
+
l2: "5l2";
|
|
262
|
+
lP: "5l'";
|
|
263
|
+
L: "5L";
|
|
264
|
+
L2: "5L2";
|
|
265
|
+
LP: "5L'";
|
|
266
|
+
Fw: "5Fw";
|
|
267
|
+
Fw2: "5Fw2";
|
|
268
|
+
FwP: "5Fw'";
|
|
269
|
+
f: "5f";
|
|
270
|
+
f2: "5f2";
|
|
271
|
+
fP: "5f'";
|
|
272
|
+
F: "5F";
|
|
273
|
+
F2: "5F2";
|
|
274
|
+
FP: "5F'";
|
|
275
|
+
Bw: "5Bw";
|
|
276
|
+
Bw2: "5Bw2";
|
|
277
|
+
BwP: "5Bw'";
|
|
278
|
+
b: "5b";
|
|
279
|
+
b2: "5b2";
|
|
280
|
+
bP: "5b'";
|
|
281
|
+
B: "5B";
|
|
282
|
+
B2: "5B2";
|
|
283
|
+
BP: "5B'";
|
|
284
|
+
Uw: "5Uw";
|
|
285
|
+
Uw2: "5Uw2";
|
|
286
|
+
UwP: "5Uw'";
|
|
287
|
+
u: "5u";
|
|
288
|
+
u2: "5u2";
|
|
289
|
+
uP: "5u'";
|
|
290
|
+
U: "5U";
|
|
291
|
+
U2: "5U2";
|
|
292
|
+
UP: "5U'";
|
|
293
|
+
Dw: "5Dw";
|
|
294
|
+
Dw2: "5Dw2";
|
|
295
|
+
DwP: "5Dw'";
|
|
296
|
+
d: "5d";
|
|
297
|
+
d2: "5d2";
|
|
298
|
+
dP: "5d'";
|
|
299
|
+
D: "5D";
|
|
300
|
+
D2: "5D2";
|
|
301
|
+
DP: "5D'";
|
|
302
|
+
}>;
|
|
303
|
+
Six: Readonly<{
|
|
304
|
+
Rw: "6Rw";
|
|
305
|
+
Rw2: "6Rw2";
|
|
306
|
+
RwP: "6Rw'";
|
|
307
|
+
r: "6r";
|
|
308
|
+
r2: "6r2";
|
|
309
|
+
rP: "6r'";
|
|
310
|
+
R: "6R";
|
|
311
|
+
R2: "6R2";
|
|
312
|
+
RP: "6R'";
|
|
313
|
+
Lw: "6Lw";
|
|
314
|
+
Lw2: "6Lw2";
|
|
315
|
+
LwP: "6Lw'";
|
|
316
|
+
l: "6l";
|
|
317
|
+
l2: "6l2";
|
|
318
|
+
lP: "6l'";
|
|
319
|
+
L: "6L";
|
|
320
|
+
L2: "6L2";
|
|
321
|
+
LP: "6L'";
|
|
322
|
+
Fw: "6Fw";
|
|
323
|
+
Fw2: "6Fw2";
|
|
324
|
+
FwP: "6Fw'";
|
|
325
|
+
f: "6f";
|
|
326
|
+
f2: "6f2";
|
|
327
|
+
fP: "6f'";
|
|
328
|
+
F: "6F";
|
|
329
|
+
F2: "6F2";
|
|
330
|
+
FP: "6F'";
|
|
331
|
+
Bw: "6Bw";
|
|
332
|
+
Bw2: "6Bw2";
|
|
333
|
+
BwP: "6Bw'";
|
|
334
|
+
b: "6b";
|
|
335
|
+
b2: "6b2";
|
|
336
|
+
bP: "6b'";
|
|
337
|
+
B: "6B";
|
|
338
|
+
B2: "6B2";
|
|
339
|
+
BP: "6B'";
|
|
340
|
+
Uw: "6Uw";
|
|
341
|
+
Uw2: "6Uw2";
|
|
342
|
+
UwP: "6Uw'";
|
|
343
|
+
u: "6u";
|
|
344
|
+
u2: "6u2";
|
|
345
|
+
uP: "6u'";
|
|
346
|
+
U: "6U";
|
|
347
|
+
U2: "6U2";
|
|
348
|
+
UP: "6U'";
|
|
349
|
+
Dw: "6Dw";
|
|
350
|
+
Dw2: "6Dw2";
|
|
351
|
+
DwP: "6Dw'";
|
|
352
|
+
d: "6d";
|
|
353
|
+
d2: "6d2";
|
|
354
|
+
dP: "6d'";
|
|
355
|
+
D: "6D";
|
|
356
|
+
D2: "6D2";
|
|
357
|
+
DP: "6D'";
|
|
358
|
+
}>;
|
|
359
|
+
}>;
|
|
360
|
+
/**
|
|
361
|
+
* @typedef {typeof Rotations[keyof typeof Rotations]} Rotation
|
|
362
|
+
*/
|
|
363
|
+
export const Rotations: Readonly<{
|
|
364
|
+
x: "x";
|
|
365
|
+
x2: "x2";
|
|
366
|
+
xP: "x'";
|
|
367
|
+
y: "y";
|
|
368
|
+
y2: "y2";
|
|
369
|
+
yP: "y'";
|
|
370
|
+
z: "z";
|
|
371
|
+
z2: "z2";
|
|
372
|
+
zP: "z'";
|
|
373
|
+
}>;
|
|
374
|
+
/**
|
|
375
|
+
* @typedef {typeof Faces [keyof typeof Faces]} Face
|
|
376
|
+
*/
|
|
377
|
+
export const Faces: Readonly<{
|
|
378
|
+
U: "U";
|
|
379
|
+
D: "D";
|
|
380
|
+
L: "L";
|
|
381
|
+
R: "R";
|
|
382
|
+
F: "F";
|
|
383
|
+
B: "B";
|
|
384
|
+
}>;
|
|
385
|
+
/**
|
|
386
|
+
* @typedef {typeof CubeTypes [keyof typeof CubeTypes]} CubeType
|
|
387
|
+
*/
|
|
388
|
+
export const CubeTypes: Readonly<{
|
|
389
|
+
Two: "Two";
|
|
390
|
+
Three: "Three";
|
|
391
|
+
Four: "Four";
|
|
392
|
+
Five: "Five";
|
|
393
|
+
Six: "Six";
|
|
394
|
+
Seven: "Seven";
|
|
395
|
+
}>;
|
|
396
|
+
/**
|
|
397
|
+
* @typedef {typeof AnimationStyles[keyof typeof AnimationStyles]} AnimationStyle
|
|
398
|
+
*/
|
|
399
|
+
export const AnimationStyles: Readonly<{
|
|
400
|
+
Exponential: "exponential";
|
|
401
|
+
Next: "next";
|
|
402
|
+
Fixed: "fixed";
|
|
403
|
+
Match: "match";
|
|
404
|
+
}>;
|
|
405
|
+
/**
|
|
406
|
+
* @typedef {typeof FaceColours [keyof typeof FaceColours]} FaceColour
|
|
407
|
+
*/
|
|
408
|
+
export const FaceColours: Readonly<{
|
|
409
|
+
U: "white";
|
|
410
|
+
D: "yellow";
|
|
411
|
+
L: "#fc9a05";
|
|
412
|
+
R: "red";
|
|
413
|
+
F: "#2cbf13";
|
|
414
|
+
B: "blue";
|
|
415
|
+
}>;
|
|
416
|
+
/**
|
|
417
|
+
* @typedef {typeof PeekTypes [keyof typeof PeekTypes]} PeekType
|
|
418
|
+
*/
|
|
419
|
+
export const PeekTypes: Readonly<{
|
|
420
|
+
Horizontal: "horizontal";
|
|
421
|
+
Vertical: "vertical";
|
|
422
|
+
Right: "right";
|
|
423
|
+
Left: "left";
|
|
424
|
+
Up: "up";
|
|
425
|
+
Down: "down";
|
|
426
|
+
RightUp: "rightUp";
|
|
427
|
+
RightDown: "rightDown";
|
|
428
|
+
LeftUp: "leftUp";
|
|
429
|
+
LeftDown: "leftDown";
|
|
430
|
+
}>;
|
|
431
|
+
/**
|
|
432
|
+
* @typedef {typeof PeekStates [keyof typeof PeekStates]} PeekState
|
|
433
|
+
*/
|
|
434
|
+
export const PeekStates: Readonly<{
|
|
435
|
+
RightUp: "rightUp";
|
|
436
|
+
RightDown: "rightDown";
|
|
437
|
+
LeftUp: "leftUp";
|
|
438
|
+
LeftDown: "leftDown";
|
|
439
|
+
}>;
|
|
440
|
+
export type SingleMove = (typeof Movements.Single)[keyof typeof Movements.Single];
|
|
441
|
+
export type WideMove = (typeof Movements.Wide)[keyof typeof Movements.Wide];
|
|
442
|
+
export type TwoMove = (typeof Movements.Two)[keyof typeof Movements.Two];
|
|
443
|
+
export type ThreeMove = (typeof Movements.Three)[keyof typeof Movements.Three];
|
|
444
|
+
export type FourMove = (typeof Movements.Four)[keyof typeof Movements.Four];
|
|
445
|
+
export type FiveMove = (typeof Movements.Five)[keyof typeof Movements.Five];
|
|
446
|
+
export type SixMove = (typeof Movements.Six)[keyof typeof Movements.Six];
|
|
447
|
+
export type Movement = SingleMove | WideMove | TwoMove | ThreeMove | FourMove | FiveMove | SixMove;
|
|
448
|
+
export type Rotation = (typeof Rotations)[keyof typeof Rotations];
|
|
449
|
+
export type Face = (typeof Faces)[keyof typeof Faces];
|
|
450
|
+
export type CubeType = (typeof CubeTypes)[keyof typeof CubeTypes];
|
|
451
|
+
export type AnimationStyle = (typeof AnimationStyles)[keyof typeof AnimationStyles];
|
|
452
|
+
export type FaceColour = (typeof FaceColours)[keyof typeof FaceColours];
|
|
453
|
+
export type PeekType = (typeof PeekTypes)[keyof typeof PeekTypes];
|
|
454
|
+
export type PeekState = (typeof PeekStates)[keyof typeof PeekStates];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @typedef {{axis: Axis, layers: number[], direction: number}} Slice */
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('../core').Movement } outerBlockMovement
|
|
4
|
+
* @param {import('../core').CubeType} cubeType
|
|
5
|
+
* @param {boolean} prioritiseStandardMovement
|
|
6
|
+
* @returns {Slice | undefined}
|
|
7
|
+
*/
|
|
8
|
+
export function GetLayerSlice(outerBlockMovement: import("../core").Movement, cubeType: import("../core").CubeType, prioritiseStandardMovement?: boolean): Slice | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* @param {import("../core").Rotation} rotation
|
|
11
|
+
* @param {import('../core').CubeType} cubeType
|
|
12
|
+
* @returns {Slice | undefined}
|
|
13
|
+
*/
|
|
14
|
+
export function GetRotationSlice(rotation: import("../core").Rotation, cubeType: import("../core").CubeType): Slice | undefined;
|
|
15
|
+
/** @typedef {typeof Axi[keyof typeof Axi]} Axis */
|
|
16
|
+
export const Axi: Readonly<{
|
|
17
|
+
x: "x";
|
|
18
|
+
y: "y";
|
|
19
|
+
z: "z";
|
|
20
|
+
}>;
|
|
21
|
+
export type Slice = {
|
|
22
|
+
axis: Axis;
|
|
23
|
+
layers: number[];
|
|
24
|
+
direction: number;
|
|
25
|
+
};
|
|
26
|
+
export type Axis = (typeof Axi)[keyof typeof Axi];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** @typedef {AnimationStatus[keyof AnimationStatus]} AnimationStatusType */
|
|
2
|
+
export const AnimationStatus: Readonly<{
|
|
3
|
+
Pending: "pending";
|
|
4
|
+
Initialised: "initialised";
|
|
5
|
+
InProgress: "inProgress";
|
|
6
|
+
Complete: "complete";
|
|
7
|
+
Disposed: "disposed";
|
|
8
|
+
}>;
|
|
9
|
+
export class AnimationState {
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('./animationSlice').Slice} slice
|
|
12
|
+
* @param {((state: string) => void )} completedCallback
|
|
13
|
+
* @param {((reason: string) => void )} failedCallback
|
|
14
|
+
*/
|
|
15
|
+
constructor(slice: import("./animationSlice").Slice, completedCallback: ((state: string) => void), failedCallback: ((reason: string) => void));
|
|
16
|
+
/** @type {((state: string) => void )} */
|
|
17
|
+
completedCallback: ((state: string) => void);
|
|
18
|
+
/** @type {((reason: string) => void )} */
|
|
19
|
+
failedCallback: ((reason: string) => void);
|
|
20
|
+
/** @type {import('./animationSlice').Slice} */
|
|
21
|
+
slice: import("./animationSlice").Slice;
|
|
22
|
+
/** @type {AnimationStatusType} */
|
|
23
|
+
status: AnimationStatusType;
|
|
24
|
+
/** @type {number} */
|
|
25
|
+
timestampMs: number;
|
|
26
|
+
/** @type {number | undefined} */
|
|
27
|
+
_lastUpdatedTimeMs: number | undefined;
|
|
28
|
+
/** @type {number} */
|
|
29
|
+
_rotationPercentage: number;
|
|
30
|
+
initialise(): void;
|
|
31
|
+
/** @param {string} state */
|
|
32
|
+
complete(state: string): void;
|
|
33
|
+
/** @param {string} reason */
|
|
34
|
+
abort(reason: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* @param {number} speedMs
|
|
37
|
+
* @returns {number} rotationIncrement
|
|
38
|
+
*/
|
|
39
|
+
update(speedMs: number): number;
|
|
40
|
+
}
|
|
41
|
+
export type AnimationStatusType = "pending" | "initialised" | "inProgress" | "complete" | "disposed";
|