cube-state-engine 1.0.2 → 1.0.4
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/{src/index.js → dist/index.d.mts} +133 -51
- package/dist/index.d.ts +357 -0
- package/dist/index.js +364 -0
- package/dist/index.mjs +341 -0
- package/package.json +10 -4
- package/babel.config.js +0 -3
- package/index.html +0 -107
- package/jest.config.js +0 -198
- package/main.js +0 -62
- package/styles.css +0 -3
- package/test/cube-engine.test.js +0 -649
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __typeError = (msg) => {
|
|
6
|
+
throw TypeError(msg);
|
|
7
|
+
};
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
22
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
23
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateX_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn;
|
|
27
|
+
var CubeEngine = class {
|
|
28
|
+
constructor() {
|
|
29
|
+
__privateAdd(this, _CubeEngine_instances);
|
|
30
|
+
__publicField(this, "MOVES", []);
|
|
31
|
+
// States object for the rotation
|
|
32
|
+
__publicField(this, "STATES", {
|
|
33
|
+
UPPER: [
|
|
34
|
+
// (White)
|
|
35
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
36
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
37
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]]
|
|
38
|
+
],
|
|
39
|
+
LEFT: [
|
|
40
|
+
// (Orange)
|
|
41
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
42
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
43
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]]
|
|
44
|
+
],
|
|
45
|
+
FRONT: [
|
|
46
|
+
// (Green)
|
|
47
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
48
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
49
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]]
|
|
50
|
+
],
|
|
51
|
+
RIGHT: [
|
|
52
|
+
// (Red)
|
|
53
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
54
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
55
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]]
|
|
56
|
+
],
|
|
57
|
+
BACK: [
|
|
58
|
+
// (Blue)
|
|
59
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
60
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
61
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]]
|
|
62
|
+
],
|
|
63
|
+
DOWN: [
|
|
64
|
+
// (Yellow)
|
|
65
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
66
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
67
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Rotates the (UPPER) layer clockwise or counterclockwise.
|
|
73
|
+
*/
|
|
74
|
+
rotateU(clockwise = true) {
|
|
75
|
+
if (clockwise) {
|
|
76
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
|
|
77
|
+
this.MOVES.push("U");
|
|
78
|
+
} else {
|
|
79
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
|
|
80
|
+
this.MOVES.push("U'");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Rotates the (FRONT) layer clockwise or counterclockwise.
|
|
85
|
+
*/
|
|
86
|
+
rotateF(clockwise = true) {
|
|
87
|
+
if (clockwise) {
|
|
88
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
|
|
89
|
+
this.MOVES.push("F");
|
|
90
|
+
} else {
|
|
91
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
|
|
92
|
+
this.MOVES.push("F'");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Rotates the (RIGHT) layer clockwise or counterclockwise.
|
|
97
|
+
*/
|
|
98
|
+
rotateR(clockwise = true) {
|
|
99
|
+
if (clockwise) {
|
|
100
|
+
__privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, true);
|
|
101
|
+
this.MOVES.push("R");
|
|
102
|
+
} else {
|
|
103
|
+
__privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, false);
|
|
104
|
+
this.MOVES.push("R'");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Rotates the (LEFT) layer clockwise or counterclockwise.
|
|
109
|
+
*/
|
|
110
|
+
rotateL(clockwise = true) {
|
|
111
|
+
if (clockwise) {
|
|
112
|
+
__privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, true);
|
|
113
|
+
this.MOVES.push("L");
|
|
114
|
+
} else {
|
|
115
|
+
__privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, false);
|
|
116
|
+
this.MOVES.push("L'");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Rotates the (DOWN) layer clockwise or counterclockwise.
|
|
121
|
+
*/
|
|
122
|
+
rotateD(clockwise = true) {
|
|
123
|
+
if (clockwise) {
|
|
124
|
+
__privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, true);
|
|
125
|
+
this.MOVES.push("D");
|
|
126
|
+
} else {
|
|
127
|
+
__privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, false);
|
|
128
|
+
this.MOVES.push("D'");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Rotates the (x) axis clockwise or counterclockwise.
|
|
133
|
+
*/
|
|
134
|
+
rotateX(clockwise = true) {
|
|
135
|
+
if (clockwise) {
|
|
136
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
137
|
+
this.MOVES.push("x");
|
|
138
|
+
} else {
|
|
139
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
140
|
+
this.MOVES.push("x'");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Rotates the (y) axis clockwise or counterclockwise.
|
|
145
|
+
*/
|
|
146
|
+
rotateY(clockwise = true) {
|
|
147
|
+
if (clockwise) {
|
|
148
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
149
|
+
this.MOVES.push("y");
|
|
150
|
+
} else {
|
|
151
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
152
|
+
this.MOVES.push("y'");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Logs the current state of the cube.
|
|
157
|
+
*/
|
|
158
|
+
state() {
|
|
159
|
+
return __spreadValues({}, this.STATES);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Indicates if the cube is solve or not in all layers.
|
|
163
|
+
*/
|
|
164
|
+
isSolved() {
|
|
165
|
+
const temp = __spreadValues({}, this.STATES);
|
|
166
|
+
const layersSolved = Object.keys(temp).map((layer) => {
|
|
167
|
+
const mixedMatrix = [
|
|
168
|
+
...temp[layer][0],
|
|
169
|
+
...temp[layer][1],
|
|
170
|
+
...temp[layer][2]
|
|
171
|
+
];
|
|
172
|
+
const centerColor = mixedMatrix[4];
|
|
173
|
+
return mixedMatrix.every((currentColor) => currentColor === centerColor);
|
|
174
|
+
});
|
|
175
|
+
return layersSolved.every((isLayerSolved) => isLayerSolved);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns the history of all movements made.
|
|
179
|
+
*
|
|
180
|
+
* @param {boolean} asString - If true, returns the history as a string; otherwise, returns it as an array.
|
|
181
|
+
* @returns {string|array} The history of movements as an array or string.
|
|
182
|
+
*/
|
|
183
|
+
getMoves(asString = true) {
|
|
184
|
+
return asString ? this.MOVES : this.MOVES.join(" ");
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
_CubeEngine_instances = new WeakSet();
|
|
188
|
+
rotateU_fn = function(clockwise = true) {
|
|
189
|
+
if (clockwise) {
|
|
190
|
+
this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
|
|
191
|
+
const tempFront = [...this.STATES.FRONT[0]];
|
|
192
|
+
const tempRight = [...this.STATES.RIGHT[0]];
|
|
193
|
+
const tempLeft = [...this.STATES.LEFT[0]];
|
|
194
|
+
const tempBack = [...this.STATES.BACK[0]];
|
|
195
|
+
this.STATES.FRONT[0] = [...tempRight];
|
|
196
|
+
this.STATES.LEFT[0] = [...tempFront];
|
|
197
|
+
this.STATES.BACK[0] = [...tempLeft];
|
|
198
|
+
this.STATES.RIGHT[0] = [...tempBack];
|
|
199
|
+
} else {
|
|
200
|
+
this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
|
|
201
|
+
const tempFront = [...this.STATES.FRONT[0]];
|
|
202
|
+
const tempRight = [...this.STATES.RIGHT[0]];
|
|
203
|
+
const tempLeft = [...this.STATES.LEFT[0]];
|
|
204
|
+
const tempBack = [...this.STATES.BACK[0]];
|
|
205
|
+
this.STATES.FRONT[0] = [...tempLeft];
|
|
206
|
+
this.STATES.LEFT[0] = [...tempBack];
|
|
207
|
+
this.STATES.BACK[0] = [...tempRight];
|
|
208
|
+
this.STATES.RIGHT[0] = [...tempFront];
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
rotateF_fn = function(clockwise = true) {
|
|
212
|
+
if (clockwise) {
|
|
213
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
214
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
|
|
215
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
216
|
+
} else {
|
|
217
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
218
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
|
|
219
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
rotateR_fn = function(clockwise = true) {
|
|
223
|
+
if (clockwise) {
|
|
224
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
225
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
226
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
|
|
227
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
228
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
229
|
+
} else {
|
|
230
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
231
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
232
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
|
|
233
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
234
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
rotateL_fn = function(clockwise = true) {
|
|
238
|
+
if (clockwise) {
|
|
239
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
240
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
241
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
|
|
242
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
243
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
244
|
+
} else {
|
|
245
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
246
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
247
|
+
__privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
|
|
248
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
249
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
rotateD_fn = function(clockwise = true) {
|
|
253
|
+
if (clockwise) {
|
|
254
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
255
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
|
|
256
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
257
|
+
} else {
|
|
258
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
|
|
259
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
|
|
260
|
+
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
rotateX_fn = function(clockwise = true) {
|
|
264
|
+
const tempFront = structuredClone(this.STATES.FRONT);
|
|
265
|
+
const tempDown = structuredClone(this.STATES.DOWN);
|
|
266
|
+
const tempUpper = structuredClone(this.STATES.UPPER);
|
|
267
|
+
const tempBack = structuredClone(this.STATES.BACK);
|
|
268
|
+
const tempLeft = structuredClone(this.STATES.LEFT);
|
|
269
|
+
const tempRight = structuredClone(this.STATES.RIGHT);
|
|
270
|
+
if (clockwise) {
|
|
271
|
+
this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
|
|
272
|
+
this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
|
|
273
|
+
this.STATES.FRONT = [...tempDown];
|
|
274
|
+
this.STATES.UPPER = [...tempFront];
|
|
275
|
+
this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
|
|
276
|
+
this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
|
|
277
|
+
} else {
|
|
278
|
+
this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
|
|
279
|
+
this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
|
|
280
|
+
this.STATES.FRONT = [...tempUpper];
|
|
281
|
+
this.STATES.DOWN = [...tempFront];
|
|
282
|
+
this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
|
|
283
|
+
this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
rotateY_fn = function(clockwise = true) {
|
|
287
|
+
const tempFront = structuredClone(this.STATES.FRONT);
|
|
288
|
+
const tempRight = structuredClone(this.STATES.RIGHT);
|
|
289
|
+
const tempBack = structuredClone(this.STATES.BACK);
|
|
290
|
+
const tempLeft = structuredClone(this.STATES.LEFT);
|
|
291
|
+
if (clockwise) {
|
|
292
|
+
this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
|
|
293
|
+
this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
|
|
294
|
+
this.STATES.FRONT = [...tempRight];
|
|
295
|
+
this.STATES.RIGHT = [...tempBack];
|
|
296
|
+
this.STATES.LEFT = [...tempFront];
|
|
297
|
+
this.STATES.BACK = [...tempLeft];
|
|
298
|
+
} else {
|
|
299
|
+
this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
|
|
300
|
+
this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
|
|
301
|
+
this.STATES.FRONT = [...tempLeft];
|
|
302
|
+
this.STATES.RIGHT = [...tempFront];
|
|
303
|
+
this.STATES.LEFT = [...tempBack];
|
|
304
|
+
this.STATES.BACK = [...tempRight];
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Rotate the entire face in the direction set
|
|
309
|
+
*/
|
|
310
|
+
switchMatrix_fn = function(matrix, clockwise = true) {
|
|
311
|
+
const clone = structuredClone(matrix);
|
|
312
|
+
const tempMatrix = [...clone[0], ...clone[1], ...clone[2]];
|
|
313
|
+
if (clockwise) {
|
|
314
|
+
return [
|
|
315
|
+
[tempMatrix[6], tempMatrix[3], tempMatrix[0]],
|
|
316
|
+
[tempMatrix[7], tempMatrix[4], tempMatrix[1]],
|
|
317
|
+
[tempMatrix[8], tempMatrix[5], tempMatrix[2]]
|
|
318
|
+
];
|
|
319
|
+
} else {
|
|
320
|
+
return [
|
|
321
|
+
[tempMatrix[2], tempMatrix[5], tempMatrix[8]],
|
|
322
|
+
[tempMatrix[1], tempMatrix[4], tempMatrix[7]],
|
|
323
|
+
[tempMatrix[0], tempMatrix[3], tempMatrix[6]]
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
specialFlip_fn = function(matrix) {
|
|
328
|
+
return structuredClone(matrix).reverse().map((row) => [...row].reverse());
|
|
329
|
+
};
|
|
330
|
+
var COLOR = {
|
|
331
|
+
W: ["W", "W", "W", "W", "W", "W", "W", "W", "W"],
|
|
332
|
+
G: ["G", "G", "G", "G", "G", "G", "G", "G", "G"],
|
|
333
|
+
R: ["R", "R", "R", "R", "R", "R", "R", "R", "R"],
|
|
334
|
+
B: ["B", "B", "B", "B", "B", "B", "B", "B", "B"],
|
|
335
|
+
O: ["O", "O", "O", "O", "O", "O", "O", "O", "O"],
|
|
336
|
+
Y: ["Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"]
|
|
337
|
+
};
|
|
338
|
+
export {
|
|
339
|
+
COLOR,
|
|
340
|
+
CubeEngine
|
|
341
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cube-state-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "An efficient representation in memory for tracking the Rubik's cube state on each movement.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
6
8
|
"scripts": {
|
|
7
|
-
"test": "jest --watch"
|
|
9
|
+
"test": "jest --watch",
|
|
10
|
+
"build": "tsup src/index.js --format cjs,esm --dts",
|
|
11
|
+
"lint": "tsc"
|
|
8
12
|
},
|
|
9
13
|
"keywords": [
|
|
10
14
|
"rubiks-cube",
|
|
@@ -23,6 +27,8 @@
|
|
|
23
27
|
"@babel/core": "7.26.0",
|
|
24
28
|
"@babel/preset-env": "7.26.0",
|
|
25
29
|
"babel-jest": "29.7.0",
|
|
26
|
-
"jest": "29.7.0"
|
|
30
|
+
"jest": "29.7.0",
|
|
31
|
+
"tsup": "8.3.5",
|
|
32
|
+
"typescript": "5.7.2"
|
|
27
33
|
}
|
|
28
34
|
}
|
package/babel.config.js
DELETED
package/index.html
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<script src="https://cdn.tailwindcss.com"></script>
|
|
7
|
-
<link href="styles.css" rel="stylesheet" />
|
|
8
|
-
<script
|
|
9
|
-
src="https://cdn.cubing.net/v0/js/cubing/twisty"
|
|
10
|
-
type="module"
|
|
11
|
-
></script>
|
|
12
|
-
<title>Cube Engine Sample</title>
|
|
13
|
-
</head>
|
|
14
|
-
<body class="max-w-xl p-10 mx-auto font-serif">
|
|
15
|
-
<h1 class="mt-5 mb-5 text-2xl text-center font-bold">CUBE STATE ENGINE</h1>
|
|
16
|
-
<p class="mb-10">
|
|
17
|
-
It's a core state manager that should be able to integrate with custom 3D
|
|
18
|
-
cube models, making it easy to track and update the cube's state after
|
|
19
|
-
every move, providing context information, such as when it's solved.
|
|
20
|
-
</p>
|
|
21
|
-
|
|
22
|
-
<h3 class="font-bold">Docs</h3>
|
|
23
|
-
|
|
24
|
-
<pre class="mb-5">
|
|
25
|
-
class CubeEngine {
|
|
26
|
-
isSolved():boolean,
|
|
27
|
-
state(): {
|
|
28
|
-
UPPER: string[][];
|
|
29
|
-
LEFT: string[][];
|
|
30
|
-
FRONT: string[][];
|
|
31
|
-
RIGHT: string[][];
|
|
32
|
-
BACK: string[][];
|
|
33
|
-
DOWN: string[][];
|
|
34
|
-
}
|
|
35
|
-
rotateU(clockwise: boolean): void,
|
|
36
|
-
rotateF(clockwise: boolean): void,
|
|
37
|
-
rotateD(clockwise: boolean): void,
|
|
38
|
-
rotateX(clockwise: boolean): void,
|
|
39
|
-
rotateY(clockwise: boolean): void,
|
|
40
|
-
rotateL(clockwise: boolean): void,
|
|
41
|
-
rotateR(clockwise: boolean): void,
|
|
42
|
-
}
|
|
43
|
-
</pre
|
|
44
|
-
>
|
|
45
|
-
|
|
46
|
-
<h3 class="font-bold mb-5">Sample usage</h3>
|
|
47
|
-
<p>
|
|
48
|
-
In this example, I am demonstrating 3D visualization of a Rubik's Cube
|
|
49
|
-
using the Cubing.js library. You can replace it with any other
|
|
50
|
-
configuration if desired. I have set up the controls to work with the
|
|
51
|
-
keyboard, allowing you to interact with the cube. Specially, you can track
|
|
52
|
-
when the cube is solved.
|
|
53
|
-
</p>
|
|
54
|
-
|
|
55
|
-
<pre class="mt-5 animate-pulse">
|
|
56
|
-
CONTROLS_KEYBOARD: {
|
|
57
|
-
LEFT_HAND: A,S,D,F,G,E,T,
|
|
58
|
-
RIGHT_HAND: H,J,K,L,Ñ/;,I,B,Y
|
|
59
|
-
}
|
|
60
|
-
</pre
|
|
61
|
-
>
|
|
62
|
-
<section
|
|
63
|
-
class="flex flex-col items-center justify-center gap-10 sm:flex-row"
|
|
64
|
-
>
|
|
65
|
-
<div class="flex-col">
|
|
66
|
-
<h2 class="mb-3 font-bold">3D</h2>
|
|
67
|
-
<twisty-player
|
|
68
|
-
style="width: 200px; height: 200px"
|
|
69
|
-
controlPanel="none"
|
|
70
|
-
back-view="top-right"
|
|
71
|
-
></twisty-player>
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<div class="flex-col">
|
|
75
|
-
<h2 class="mb-3 font-bold">Memory</h2>
|
|
76
|
-
<div
|
|
77
|
-
class="w-[200px] h-[200px] flex justify-center items-center relative text-xs"
|
|
78
|
-
>
|
|
79
|
-
<div class="absolute top-16 left-1" id="LEFT"></div>
|
|
80
|
-
|
|
81
|
-
<div class="absolute top-16 left-12" id="FRONT"></div>
|
|
82
|
-
|
|
83
|
-
<div class="absolute top-16 left-24" id="RIGHT"></div>
|
|
84
|
-
|
|
85
|
-
<div class="absolute top-16 left-36" id="BACK"></div>
|
|
86
|
-
|
|
87
|
-
<div class="absolute top-0 left-12" id="UPPER"></div>
|
|
88
|
-
|
|
89
|
-
<div class="absolute top-32 left-12" id="DOWN"></div>
|
|
90
|
-
</div>
|
|
91
|
-
</div>
|
|
92
|
-
</section>
|
|
93
|
-
|
|
94
|
-
<section class="w-full mt-5 text-start">
|
|
95
|
-
<div class="font-black">
|
|
96
|
-
isSolved?: <span class="font-normal" id="is-solve">true</span>
|
|
97
|
-
</div>
|
|
98
|
-
<div class="font-black">
|
|
99
|
-
Moves: <span class="font-normal" id="total">0</span>
|
|
100
|
-
</div>
|
|
101
|
-
<div>
|
|
102
|
-
<span class="font-black">Historial: </span><span id="moves"></span>
|
|
103
|
-
</div>
|
|
104
|
-
</section>
|
|
105
|
-
<script src="main.js" type="module"></script>
|
|
106
|
-
</body>
|
|
107
|
-
</html>
|
package/jest.config.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/** @type {import('jest').Config} */
|
|
7
|
-
const config = {
|
|
8
|
-
// All imported modules in your tests should be mocked automatically
|
|
9
|
-
// automock: false,
|
|
10
|
-
|
|
11
|
-
// Stop running tests after `n` failures
|
|
12
|
-
// bail: 0,
|
|
13
|
-
|
|
14
|
-
// The directory where Jest should store its cached dependency information
|
|
15
|
-
// cacheDirectory: "C:\\Users\\bryan\\AppData\\Local\\Temp\\jest",
|
|
16
|
-
|
|
17
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
18
|
-
clearMocks: true,
|
|
19
|
-
|
|
20
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
21
|
-
collectCoverage: true,
|
|
22
|
-
|
|
23
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
24
|
-
// collectCoverageFrom: undefined,
|
|
25
|
-
|
|
26
|
-
// The directory where Jest should output its coverage files
|
|
27
|
-
coverageDirectory: "coverage",
|
|
28
|
-
|
|
29
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
30
|
-
// coveragePathIgnorePatterns: [
|
|
31
|
-
// "\\\\node_modules\\\\"
|
|
32
|
-
// ],
|
|
33
|
-
|
|
34
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
35
|
-
coverageProvider: "v8",
|
|
36
|
-
|
|
37
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
38
|
-
// coverageReporters: [
|
|
39
|
-
// "json",
|
|
40
|
-
// "text",
|
|
41
|
-
// "lcov",
|
|
42
|
-
// "clover"
|
|
43
|
-
// ],
|
|
44
|
-
|
|
45
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
46
|
-
// coverageThreshold: undefined,
|
|
47
|
-
|
|
48
|
-
// A path to a custom dependency extractor
|
|
49
|
-
// dependencyExtractor: undefined,
|
|
50
|
-
|
|
51
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
52
|
-
// errorOnDeprecated: false,
|
|
53
|
-
|
|
54
|
-
// The default configuration for fake timers
|
|
55
|
-
// fakeTimers: {
|
|
56
|
-
// "enableGlobally": false
|
|
57
|
-
// },
|
|
58
|
-
|
|
59
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
60
|
-
// forceCoverageMatch: [],
|
|
61
|
-
|
|
62
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
63
|
-
// globalSetup: undefined,
|
|
64
|
-
|
|
65
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
66
|
-
// globalTeardown: undefined,
|
|
67
|
-
|
|
68
|
-
// A set of global variables that need to be available in all test environments
|
|
69
|
-
// globals: {},
|
|
70
|
-
|
|
71
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
72
|
-
// maxWorkers: "50%",
|
|
73
|
-
|
|
74
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
75
|
-
// moduleDirectories: [
|
|
76
|
-
// "node_modules"
|
|
77
|
-
// ],
|
|
78
|
-
|
|
79
|
-
// An array of file extensions your modules use
|
|
80
|
-
// moduleFileExtensions: [
|
|
81
|
-
// "js",
|
|
82
|
-
// "mjs",
|
|
83
|
-
// "cjs",
|
|
84
|
-
// "jsx",
|
|
85
|
-
// "ts",
|
|
86
|
-
// "tsx",
|
|
87
|
-
// "json",
|
|
88
|
-
// "node"
|
|
89
|
-
// ],
|
|
90
|
-
|
|
91
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
92
|
-
// moduleNameMapper: {},
|
|
93
|
-
|
|
94
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
95
|
-
// modulePathIgnorePatterns: [],
|
|
96
|
-
|
|
97
|
-
// Activates notifications for test results
|
|
98
|
-
// notify: false,
|
|
99
|
-
|
|
100
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
101
|
-
// notifyMode: "failure-change",
|
|
102
|
-
|
|
103
|
-
// A preset that is used as a base for Jest's configuration
|
|
104
|
-
// preset: undefined,
|
|
105
|
-
|
|
106
|
-
// Run tests from one or more projects
|
|
107
|
-
// projects: undefined,
|
|
108
|
-
|
|
109
|
-
// Use this configuration option to add custom reporters to Jest
|
|
110
|
-
// reporters: undefined,
|
|
111
|
-
|
|
112
|
-
// Automatically reset mock state before every test
|
|
113
|
-
// resetMocks: false,
|
|
114
|
-
|
|
115
|
-
// Reset the module registry before running each individual test
|
|
116
|
-
// resetModules: false,
|
|
117
|
-
|
|
118
|
-
// A path to a custom resolver
|
|
119
|
-
// resolver: undefined,
|
|
120
|
-
|
|
121
|
-
// Automatically restore mock state and implementation before every test
|
|
122
|
-
// restoreMocks: false,
|
|
123
|
-
|
|
124
|
-
// The root directory that Jest should scan for tests and modules within
|
|
125
|
-
// rootDir: undefined,
|
|
126
|
-
|
|
127
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
128
|
-
// roots: [
|
|
129
|
-
// "<rootDir>"
|
|
130
|
-
// ],
|
|
131
|
-
|
|
132
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
133
|
-
// runner: "jest-runner",
|
|
134
|
-
|
|
135
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
136
|
-
// setupFiles: [],
|
|
137
|
-
|
|
138
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
139
|
-
// setupFilesAfterEnv: [],
|
|
140
|
-
|
|
141
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
142
|
-
// slowTestThreshold: 5,
|
|
143
|
-
|
|
144
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
145
|
-
// snapshotSerializers: [],
|
|
146
|
-
|
|
147
|
-
// The test environment that will be used for testing
|
|
148
|
-
testEnvironment: "node",
|
|
149
|
-
|
|
150
|
-
// Options that will be passed to the testEnvironment
|
|
151
|
-
// testEnvironmentOptions: {},
|
|
152
|
-
|
|
153
|
-
// Adds a location field to test results
|
|
154
|
-
// testLocationInResults: false,
|
|
155
|
-
|
|
156
|
-
// The glob patterns Jest uses to detect test files
|
|
157
|
-
// testMatch: [
|
|
158
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
159
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
160
|
-
// ],
|
|
161
|
-
|
|
162
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
163
|
-
// testPathIgnorePatterns: [
|
|
164
|
-
// "\\\\node_modules\\\\"
|
|
165
|
-
// ],
|
|
166
|
-
|
|
167
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
168
|
-
// testRegex: [],
|
|
169
|
-
|
|
170
|
-
// This option allows the use of a custom results processor
|
|
171
|
-
// testResultsProcessor: undefined,
|
|
172
|
-
|
|
173
|
-
// This option allows use of a custom test runner
|
|
174
|
-
// testRunner: "jest-circus/runner",
|
|
175
|
-
|
|
176
|
-
// A map from regular expressions to paths to transformers
|
|
177
|
-
// transform: undefined,
|
|
178
|
-
|
|
179
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
180
|
-
// transformIgnorePatterns: [
|
|
181
|
-
// "\\\\node_modules\\\\",
|
|
182
|
-
// "\\.pnp\\.[^\\\\]+$"
|
|
183
|
-
// ],
|
|
184
|
-
|
|
185
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
186
|
-
// unmockedModulePathPatterns: undefined,
|
|
187
|
-
|
|
188
|
-
// Indicates whether each individual test should be reported during the run
|
|
189
|
-
// verbose: undefined,
|
|
190
|
-
|
|
191
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
192
|
-
// watchPathIgnorePatterns: [],
|
|
193
|
-
|
|
194
|
-
// Whether to use watchman for file crawling
|
|
195
|
-
// watchman: true,
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
module.exports = config;
|