cube-state-engine 1.0.2 → 1.0.3

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/dist/index.mjs ADDED
@@ -0,0 +1,261 @@
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, switchMatrix_fn, specialFlip_fn;
27
+ var CubeEngine = class {
28
+ constructor() {
29
+ __privateAdd(this, _CubeEngine_instances);
30
+ // States object for the rotation
31
+ __publicField(this, "STATES", {
32
+ UPPER: [
33
+ // (White)
34
+ [COLOR.W[0], COLOR.W[1], COLOR.W[2]],
35
+ [COLOR.W[3], COLOR.W[4], COLOR.W[5]],
36
+ [COLOR.W[6], COLOR.W[7], COLOR.W[8]]
37
+ ],
38
+ LEFT: [
39
+ // (Orange)
40
+ [COLOR.O[0], COLOR.O[1], COLOR.O[2]],
41
+ [COLOR.O[3], COLOR.O[4], COLOR.O[5]],
42
+ [COLOR.O[6], COLOR.O[7], COLOR.O[8]]
43
+ ],
44
+ FRONT: [
45
+ // (Green)
46
+ [COLOR.G[0], COLOR.G[1], COLOR.G[2]],
47
+ [COLOR.G[3], COLOR.G[4], COLOR.G[5]],
48
+ [COLOR.G[6], COLOR.G[7], COLOR.G[8]]
49
+ ],
50
+ RIGHT: [
51
+ // (Red)
52
+ [COLOR.R[0], COLOR.R[1], COLOR.R[2]],
53
+ [COLOR.R[3], COLOR.R[4], COLOR.R[5]],
54
+ [COLOR.R[6], COLOR.R[7], COLOR.R[8]]
55
+ ],
56
+ BACK: [
57
+ // (Blue)
58
+ [COLOR.B[0], COLOR.B[1], COLOR.B[2]],
59
+ [COLOR.B[3], COLOR.B[4], COLOR.B[5]],
60
+ [COLOR.B[6], COLOR.B[7], COLOR.B[8]]
61
+ ],
62
+ DOWN: [
63
+ // (Yellow)
64
+ [COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
65
+ [COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
66
+ [COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
67
+ ]
68
+ });
69
+ }
70
+ /**
71
+ * Rotates the top (U) layer clockwise or counterclockwise.
72
+ */
73
+ rotateU(clockwise = true) {
74
+ if (clockwise) {
75
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
76
+ const tempFront = [...this.STATES.FRONT[0]];
77
+ const tempRight = [...this.STATES.RIGHT[0]];
78
+ const tempLeft = [...this.STATES.LEFT[0]];
79
+ const tempBack = [...this.STATES.BACK[0]];
80
+ this.STATES.FRONT[0] = [...tempRight];
81
+ this.STATES.LEFT[0] = [...tempFront];
82
+ this.STATES.BACK[0] = [...tempLeft];
83
+ this.STATES.RIGHT[0] = [...tempBack];
84
+ } else {
85
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
86
+ const tempFront = [...this.STATES.FRONT[0]];
87
+ const tempRight = [...this.STATES.RIGHT[0]];
88
+ const tempLeft = [...this.STATES.LEFT[0]];
89
+ const tempBack = [...this.STATES.BACK[0]];
90
+ this.STATES.FRONT[0] = [...tempLeft];
91
+ this.STATES.LEFT[0] = [...tempBack];
92
+ this.STATES.BACK[0] = [...tempRight];
93
+ this.STATES.RIGHT[0] = [...tempFront];
94
+ }
95
+ }
96
+ /**
97
+ * Rotates the front (F) layer clockwise or counterclockwise.
98
+ */
99
+ rotateF(clockwise = true) {
100
+ if (clockwise) {
101
+ this.rotateX(true);
102
+ this.rotateU(true);
103
+ this.rotateX(false);
104
+ } else {
105
+ this.rotateX(true);
106
+ this.rotateU(false);
107
+ this.rotateX(false);
108
+ }
109
+ }
110
+ rotateR(clockwise = true) {
111
+ if (clockwise) {
112
+ this.rotateY(true);
113
+ this.rotateX(true);
114
+ this.rotateU(true);
115
+ this.rotateX(false);
116
+ this.rotateY(false);
117
+ } else {
118
+ this.rotateY(true);
119
+ this.rotateX(true);
120
+ this.rotateU(false);
121
+ this.rotateX(false);
122
+ this.rotateY(false);
123
+ }
124
+ }
125
+ rotateL(clockwise = true) {
126
+ if (clockwise) {
127
+ this.rotateY(false);
128
+ this.rotateX(true);
129
+ this.rotateU(true);
130
+ this.rotateX(false);
131
+ this.rotateY(true);
132
+ } else {
133
+ this.rotateY(false);
134
+ this.rotateX(true);
135
+ this.rotateU(false);
136
+ this.rotateX(false);
137
+ this.rotateY(true);
138
+ }
139
+ }
140
+ rotateD(clockwise = true) {
141
+ if (clockwise) {
142
+ this.rotateX(true);
143
+ this.rotateF(true);
144
+ this.rotateX(false);
145
+ } else {
146
+ this.rotateX(true);
147
+ this.rotateF(false);
148
+ this.rotateX(false);
149
+ }
150
+ }
151
+ /**
152
+ * Rotates the (x) axis clockwise or counterclockwise.
153
+ */
154
+ rotateX(clockwise = true) {
155
+ const tempFront = structuredClone(this.STATES.FRONT);
156
+ const tempDown = structuredClone(this.STATES.DOWN);
157
+ const tempUpper = structuredClone(this.STATES.UPPER);
158
+ const tempBack = structuredClone(this.STATES.BACK);
159
+ const tempLeft = structuredClone(this.STATES.LEFT);
160
+ const tempRight = structuredClone(this.STATES.RIGHT);
161
+ if (clockwise) {
162
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
163
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
164
+ this.STATES.FRONT = [...tempDown];
165
+ this.STATES.UPPER = [...tempFront];
166
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
167
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
168
+ } else {
169
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
170
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
171
+ this.STATES.FRONT = [...tempUpper];
172
+ this.STATES.DOWN = [...tempFront];
173
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
174
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
175
+ }
176
+ }
177
+ /**
178
+ * Rotates the (y) axis clockwise or counterclockwise.
179
+ */
180
+ rotateY(clockwise = true) {
181
+ const tempFront = structuredClone(this.STATES.FRONT);
182
+ const tempRight = structuredClone(this.STATES.RIGHT);
183
+ const tempBack = structuredClone(this.STATES.BACK);
184
+ const tempLeft = structuredClone(this.STATES.LEFT);
185
+ if (clockwise) {
186
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
187
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
188
+ this.STATES.FRONT = [...tempRight];
189
+ this.STATES.RIGHT = [...tempBack];
190
+ this.STATES.LEFT = [...tempFront];
191
+ this.STATES.BACK = [...tempLeft];
192
+ } else {
193
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
194
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
195
+ this.STATES.FRONT = [...tempLeft];
196
+ this.STATES.RIGHT = [...tempFront];
197
+ this.STATES.LEFT = [...tempBack];
198
+ this.STATES.BACK = [...tempRight];
199
+ }
200
+ }
201
+ /**
202
+ * Logs the current state of the cube.
203
+ */
204
+ state() {
205
+ console.clear();
206
+ console.log(__spreadValues({}, this.STATES));
207
+ return __spreadValues({}, this.STATES);
208
+ }
209
+ /**
210
+ * Indicates if the cube is solve or not in all layers.
211
+ */
212
+ isSolved() {
213
+ const temp = __spreadValues({}, this.STATES);
214
+ const layersSolved = Object.keys(temp).map((layer) => {
215
+ const mixedMatrix = [
216
+ ...temp[layer][0],
217
+ ...temp[layer][1],
218
+ ...temp[layer][2]
219
+ ];
220
+ const centerColor = mixedMatrix[4];
221
+ return mixedMatrix.every((currentColor) => currentColor === centerColor);
222
+ });
223
+ return layersSolved.every((isLayerSolved) => isLayerSolved);
224
+ }
225
+ };
226
+ _CubeEngine_instances = new WeakSet();
227
+ /**
228
+ * Rotate the entire face in the direction set
229
+ */
230
+ switchMatrix_fn = function(matrix, clockwise = true) {
231
+ const clone = structuredClone(matrix);
232
+ const tempMatrix = [...clone[0], ...clone[1], ...clone[2]];
233
+ if (clockwise) {
234
+ return [
235
+ [tempMatrix[6], tempMatrix[3], tempMatrix[0]],
236
+ [tempMatrix[7], tempMatrix[4], tempMatrix[1]],
237
+ [tempMatrix[8], tempMatrix[5], tempMatrix[2]]
238
+ ];
239
+ } else {
240
+ return [
241
+ [tempMatrix[2], tempMatrix[5], tempMatrix[8]],
242
+ [tempMatrix[1], tempMatrix[4], tempMatrix[7]],
243
+ [tempMatrix[0], tempMatrix[3], tempMatrix[6]]
244
+ ];
245
+ }
246
+ };
247
+ specialFlip_fn = function(matrix) {
248
+ return structuredClone(matrix).reverse().map((row) => [...row].reverse());
249
+ };
250
+ var COLOR = {
251
+ W: ["W", "W", "W", "W", "W", "W", "W", "W", "W"],
252
+ G: ["G", "G", "G", "G", "G", "G", "G", "G", "G"],
253
+ R: ["R", "R", "R", "R", "R", "R", "R", "R", "R"],
254
+ B: ["B", "B", "B", "B", "B", "B", "B", "B", "B"],
255
+ O: ["O", "O", "O", "O", "O", "O", "O", "O", "O"],
256
+ Y: ["Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y"]
257
+ };
258
+ export {
259
+ COLOR,
260
+ CubeEngine
261
+ };
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "cube-state-engine",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "An efficient representation in memory for tracking the Rubik's cube state on each movement.",
5
- "main": "./src/index.js",
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
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: [["@babel/preset-env", { targets: { node: "current" } }]],
3
- };
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;
package/main.js DELETED
@@ -1,62 +0,0 @@
1
- import { CubeEngine } from "./src/index.js";
2
-
3
- window.CubeEngine = new CubeEngine();
4
- render();
5
-
6
- const player = document.querySelector("twisty-player");
7
- const moves = [];
8
-
9
- /**
10
- * Key listener for cube movements.
11
- */
12
- document.addEventListener("keyup", (e) => {
13
- const movesMap = {
14
- f: { move: () => window.CubeEngine.rotateU(false), notation: "U'" },
15
- j: { move: () => window.CubeEngine.rotateU(true), notation: "U" },
16
- g: { move: () => window.CubeEngine.rotateF(false), notation: "F'" },
17
- h: { move: () => window.CubeEngine.rotateF(true), notation: "F" },
18
- i: { move: () => window.CubeEngine.rotateR(true), notation: "R" },
19
- k: { move: () => window.CubeEngine.rotateR(false), notation: "R'" },
20
- d: { move: () => window.CubeEngine.rotateL(true), notation: "L" },
21
- e: { move: () => window.CubeEngine.rotateL(false), notation: "L'" },
22
- t: { move: () => window.CubeEngine.rotateX(true), notation: "x" },
23
- y: { move: () => window.CubeEngine.rotateX(true), notation: "x" },
24
- b: { move: () => window.CubeEngine.rotateX(false), notation: "x'" },
25
- n: { move: () => window.CubeEngine.rotateX(false), notation: "x'" },
26
- ñ: { move: () => window.CubeEngine.rotateY(true), notation: "y" },
27
- a: { move: () => window.CubeEngine.rotateY(false), notation: "y'" },
28
- s: { move: () => window.CubeEngine.rotateD(true), notation: "D" },
29
- l: { move: () => window.CubeEngine.rotateD(false), notation: "D'" },
30
- };
31
-
32
- const key = e.key.toLowerCase();
33
- const moveObj = movesMap[key];
34
-
35
- if (moveObj) {
36
- moveObj.move();
37
- moves.push(moveObj.notation);
38
-
39
- // sync UI
40
- document.querySelector("#total").textContent = moves.length;
41
- document.querySelector("#moves").textContent = moves.join(" ");
42
- document.querySelector(
43
- "#is-solve"
44
- ).textContent = `${window.CubeEngine.isSolved()}`;
45
- player.alg = moves.join(" ");
46
- render();
47
- }
48
- });
49
-
50
- function render() {
51
- const state = window.CubeEngine.state();
52
- Object.keys(state).forEach((layer) => {
53
- const layerContent = state[layer]
54
- .map(
55
- (row) =>
56
- `<div>${row.map((cell) => `<span>${cell}</span>`).join("")}</div>`
57
- )
58
- .join("");
59
-
60
- document.querySelector(`#${layer}`).innerHTML = layerContent;
61
- });
62
- }
package/styles.css DELETED
@@ -1,3 +0,0 @@
1
- body {
2
- background-color: beige;
3
- }