@houstonp/rubiks-cube 2.1.0 → 3.0.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 +304 -77
- package/package.json +18 -8
- package/src/{core.js → core/index.js} +72 -41
- package/src/rubiksCube/index.js +3 -0
- package/src/rubiksCube/rubiksCubeController.js +111 -0
- package/src/{three → rubiksCube3D}/centerPiece.js +37 -2
- package/src/{three → rubiksCube3D}/cornerPiece.js +56 -2
- package/src/rubiksCube3D/cubeConfig.js +87 -0
- package/src/rubiksCube3D/cubeSettings.js +30 -0
- package/src/{three → rubiksCube3D}/edgePiece.js +2 -1
- package/src/rubiksCube3D/index.js +3 -0
- package/src/rubiksCube3D/rubiksCube3D.js +383 -0
- package/src/{three → rubiksCube3D}/sticker.js +5 -4
- package/src/state/index.js +4 -0
- package/src/state/rubiksCubeState.js +471 -0
- package/src/state/slice.js +236 -0
- package/src/state/stickerState.js +185 -0
- package/src/{camera → webComponent}/cameraState.js +17 -25
- package/src/webComponent/constants.js +67 -0
- package/src/webComponent/index.js +7 -0
- package/src/webComponent/rubiksCubeElement.js +379 -0
- package/src/{settings.js → webComponent/settings.js} +36 -23
- package/tests/common.js +3 -20
- package/tests/core.test.js +56 -0
- package/tests/rubiksCube.solves.test.js +41 -0
- package/tests/rubiksCube3D.solves.test.js +185 -0
- package/tests/rubiksCubeState.solves.test.js +35 -0
- package/tests/testScrambles.js +194 -0
- package/types/{core.d.ts → core/index.d.ts} +45 -48
- package/types/rubiksCube/index.d.ts +3 -0
- package/types/rubiksCube/rubiksCubeController.d.ts +62 -0
- package/types/rubiksCube3D/centerPiece.d.ts +27 -0
- package/types/rubiksCube3D/cornerPiece.d.ts +38 -0
- package/types/rubiksCube3D/cubeConfig.d.ts +32 -0
- package/types/rubiksCube3D/cubeSettings.d.ts +33 -0
- package/types/{three → rubiksCube3D}/edgePiece.d.ts +5 -3
- package/types/rubiksCube3D/index.d.ts +3 -0
- package/types/rubiksCube3D/rubiksCube3D.d.ts +120 -0
- package/types/rubiksCube3D/sticker.d.ts +18 -0
- package/types/state/index.d.ts +5 -0
- package/types/state/rubiksCubeState.d.ts +108 -0
- package/types/state/slice.d.ts +46 -0
- package/types/state/stickerState.d.ts +34 -0
- package/types/webComponent/cameraState.d.ts +22 -0
- package/types/webComponent/constants.d.ts +57 -0
- package/types/webComponent/index.d.ts +6 -0
- package/types/webComponent/rubiksCubeElement.d.ts +89 -0
- package/types/{settings.d.ts → webComponent/settings.d.ts} +5 -8
- package/src/cube/animationSlice.js +0 -205
- package/src/cube/animationState.js +0 -96
- package/src/cube/cubeSettings.js +0 -19
- package/src/cube/cubeState.js +0 -337
- package/src/cube/stickerState.js +0 -188
- package/src/index.js +0 -621
- package/src/three/cube.js +0 -492
- package/tests/cube.five.test.js +0 -126
- package/tests/cube.four.test.js +0 -126
- package/tests/cube.seven.test.js +0 -126
- package/tests/cube.six.test.js +0 -126
- package/tests/cube.three.test.js +0 -151
- package/tests/cube.two.test.js +0 -125
- package/types/camera/cameraState.d.ts +0 -19
- package/types/cube/animationSlice.d.ts +0 -26
- package/types/cube/animationState.d.ts +0 -41
- package/types/cube/cubeSettings.d.ts +0 -17
- package/types/cube/cubeState.d.ts +0 -47
- package/types/cube/stickerState.d.ts +0 -21
- package/types/index.d.ts +0 -87
- package/types/three/centerPiece.d.ts +0 -15
- package/types/three/cornerPiece.d.ts +0 -24
- package/types/three/cube.d.ts +0 -130
- package/types/three/sticker.d.ts +0 -15
- /package/src/{debouncer.js → webComponent/debouncer.js} +0 -0
- /package/src/{globals.ts → webComponent/globals.ts} +0 -0
- /package/types/{debouncer.d.ts → webComponent/debouncer.d.ts} +0 -0
- /package/types/{globals.d.ts → webComponent/globals.d.ts} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default class RubiksCubeController {
|
|
2
|
+
/**
|
|
3
|
+
* @param {CubeType} cubeType
|
|
4
|
+
* @param {RubiksCubeViewInterface} view
|
|
5
|
+
* */
|
|
6
|
+
constructor(cubeType: CubeType, view: RubiksCubeViewInterface);
|
|
7
|
+
state: RubiksCubeState;
|
|
8
|
+
view: RubiksCubeViewInterface;
|
|
9
|
+
/**
|
|
10
|
+
* @param {Movement} movement
|
|
11
|
+
* @param {AnimationOptions} [options]
|
|
12
|
+
* @returns {Promise<string>}
|
|
13
|
+
*/
|
|
14
|
+
movement(movement: Movement, options?: AnimationOptions): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* @param {Rotation} rotation
|
|
17
|
+
* @param {AnimationOptions} [options]
|
|
18
|
+
* @returns {Promise<string>}
|
|
19
|
+
*/
|
|
20
|
+
rotation(rotation: Rotation, options?: AnimationOptions): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* @param {(Rotation | Movement)[]} actions
|
|
23
|
+
* @param {AnimationOptions} [options]
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
do(actions: (Rotation | Movement)[], options?: AnimationOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* @returns {string}
|
|
29
|
+
*/
|
|
30
|
+
reset(): string;
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} kociembaState
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
setState(kociembaState: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
getState(): string;
|
|
40
|
+
/**
|
|
41
|
+
* @param {CubeType} cubeType
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
setType(cubeType: CubeType): string;
|
|
45
|
+
}
|
|
46
|
+
export type AnimationOptions = {
|
|
47
|
+
translate?: boolean;
|
|
48
|
+
animationSpeedMs?: number;
|
|
49
|
+
reverse?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type RubiksCubeViewInterface = {
|
|
52
|
+
slice: (arg0: Slice, arg1: any | undefined) => Promise<void>;
|
|
53
|
+
setState: (arg0: StickerState) => void;
|
|
54
|
+
reset: () => void;
|
|
55
|
+
setType: (arg0: CubeType) => void;
|
|
56
|
+
};
|
|
57
|
+
import { RubiksCubeState } from '../state';
|
|
58
|
+
import type { Movement } from '../core';
|
|
59
|
+
import type { Rotation } from '../core';
|
|
60
|
+
import type { CubeType } from '../core';
|
|
61
|
+
import type { Slice } from '../state/slice';
|
|
62
|
+
import type { StickerState } from '../state/stickerState';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @import {Vector3Like} from 'three' */
|
|
2
|
+
/** @typedef {{ positon: Vector3Like, rotation: Vector3Like }} CenterPieceUserData */
|
|
3
|
+
export class CenterPiece extends Object3D<import("three").Object3DEventMap> {
|
|
4
|
+
constructor();
|
|
5
|
+
frontSticker: CenterSticker;
|
|
6
|
+
/** @type {Mesh<PlaneGeometry, MeshStandardMaterial> | null} */
|
|
7
|
+
logo: Mesh<PlaneGeometry, MeshStandardMaterial> | null;
|
|
8
|
+
get stickers(): CenterSticker[];
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} logoPath
|
|
11
|
+
*/
|
|
12
|
+
addLogo(logoPath: string): void;
|
|
13
|
+
removeLogo(): void;
|
|
14
|
+
}
|
|
15
|
+
export class CenterSticker extends Sticker {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
export type CenterPieceUserData = {
|
|
19
|
+
positon: Vector3Like;
|
|
20
|
+
rotation: Vector3Like;
|
|
21
|
+
};
|
|
22
|
+
import { Object3D } from 'three';
|
|
23
|
+
import { Mesh } from 'three';
|
|
24
|
+
import { PlaneGeometry } from 'three';
|
|
25
|
+
import { MeshStandardMaterial } from 'three';
|
|
26
|
+
import { Sticker } from './sticker';
|
|
27
|
+
import type { Vector3Like } from 'three';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @import {Vector3Like} from 'three' */
|
|
2
|
+
/** @import {Face} from "../core" */
|
|
3
|
+
/** @typedef {{ positon: Vector3Like, rotation: Vector3Like }} CornerPieceUserData */
|
|
4
|
+
/**
|
|
5
|
+
* @param {Material} frontMaterial
|
|
6
|
+
* @param {Material} rightMaterial
|
|
7
|
+
* @param {Material} topMaterial
|
|
8
|
+
* @param {Material} coreMaterial
|
|
9
|
+
* @returns {Group}
|
|
10
|
+
*/
|
|
11
|
+
export class CornerPiece extends Object3D<import("three").Object3DEventMap> {
|
|
12
|
+
constructor();
|
|
13
|
+
frontSticker: CornerSticker;
|
|
14
|
+
rightSticker: CornerSticker;
|
|
15
|
+
topSticker: CornerSticker;
|
|
16
|
+
get stickers(): CornerSticker[];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Face} face
|
|
19
|
+
* @param {string} logoPath
|
|
20
|
+
*/
|
|
21
|
+
addLogo(face: Face, logoPath: string): void;
|
|
22
|
+
logo: Mesh<PlaneGeometry, MeshStandardMaterial, import("three").Object3DEventMap>;
|
|
23
|
+
removeLogo(): void;
|
|
24
|
+
}
|
|
25
|
+
export class CornerSticker extends Sticker {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
28
|
+
export type CornerPieceUserData = {
|
|
29
|
+
positon: Vector3Like;
|
|
30
|
+
rotation: Vector3Like;
|
|
31
|
+
};
|
|
32
|
+
import { Object3D } from 'three';
|
|
33
|
+
import type { Face } from "../core";
|
|
34
|
+
import { PlaneGeometry } from 'three';
|
|
35
|
+
import { MeshStandardMaterial } from 'three';
|
|
36
|
+
import { Mesh } from 'three';
|
|
37
|
+
import { Sticker } from './sticker';
|
|
38
|
+
import type { Vector3Like } from 'three';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** @import {CubeType, Face} from '../core' */
|
|
2
|
+
/** @import {ColorRepresentation} from 'three' */
|
|
3
|
+
/**
|
|
4
|
+
* @typedef CubeConfig
|
|
5
|
+
* @property {number[]} layers
|
|
6
|
+
* @property {number} pieceSize
|
|
7
|
+
* @property {number} coreSize
|
|
8
|
+
* @property {number} outerLayerMultiplier
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @param {CubeType} cubeType
|
|
12
|
+
* @return {CubeConfig}
|
|
13
|
+
*/
|
|
14
|
+
export function getCubeConfig(cubeType: CubeType): CubeConfig;
|
|
15
|
+
export namespace FaceColors {
|
|
16
|
+
let B: string;
|
|
17
|
+
let D: string;
|
|
18
|
+
let F: string;
|
|
19
|
+
let L: string;
|
|
20
|
+
let R: string;
|
|
21
|
+
let U: string;
|
|
22
|
+
}
|
|
23
|
+
export function ColorToFace(color: ColorRepresentation): Face;
|
|
24
|
+
export type CubeConfig = {
|
|
25
|
+
layers: number[];
|
|
26
|
+
pieceSize: number;
|
|
27
|
+
coreSize: number;
|
|
28
|
+
outerLayerMultiplier: number;
|
|
29
|
+
};
|
|
30
|
+
import type { CubeType } from '../core';
|
|
31
|
+
import type { ColorRepresentation } from 'three';
|
|
32
|
+
import type { Face } from '../core';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @import {CubeType} from '../core' */
|
|
2
|
+
/**
|
|
3
|
+
* @typedef RubiksCube3DSettingsOptions
|
|
4
|
+
* @property {CubeType} [cubeType]
|
|
5
|
+
* @property {number} [pieceGap]
|
|
6
|
+
* @property {number} [animationSpeedMs]
|
|
7
|
+
* @property {gsap.EaseString | gsap.EaseFunction} [animationStyle]
|
|
8
|
+
* @property {string | null} [logo]
|
|
9
|
+
*/
|
|
10
|
+
export default class RubiksCube3DSettings {
|
|
11
|
+
/**
|
|
12
|
+
* @param {RubiksCube3DSettingsOptions} [options]
|
|
13
|
+
*/
|
|
14
|
+
constructor(options?: RubiksCube3DSettingsOptions);
|
|
15
|
+
/** @type {CubeType} */
|
|
16
|
+
cubeType: CubeType;
|
|
17
|
+
/** @type {number} */
|
|
18
|
+
pieceGap: number;
|
|
19
|
+
/** @type {number} */
|
|
20
|
+
animationSpeedMs: number;
|
|
21
|
+
/** @type {gsap.EaseString | gsap.EaseFunction} */
|
|
22
|
+
animationStyle: gsap.EaseString | gsap.EaseFunction;
|
|
23
|
+
/** @type {string | null} */
|
|
24
|
+
logo: string | null;
|
|
25
|
+
}
|
|
26
|
+
export type RubiksCube3DSettingsOptions = {
|
|
27
|
+
cubeType?: CubeType;
|
|
28
|
+
pieceGap?: number;
|
|
29
|
+
animationSpeedMs?: number;
|
|
30
|
+
animationStyle?: gsap.EaseString | gsap.EaseFunction;
|
|
31
|
+
logo?: string | null;
|
|
32
|
+
};
|
|
33
|
+
import type { CubeType } from '../core';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/** @
|
|
1
|
+
/** @import {Vector3Like} from 'three' */
|
|
2
|
+
/** @typedef {{ positon: Vector3Like, rotation: Vector3Like }} EdgePieceUserData*/
|
|
2
3
|
export class EdgePiece extends Object3D<import("three").Object3DEventMap> {
|
|
3
4
|
constructor();
|
|
4
5
|
frontSticker: EdgeSticker;
|
|
@@ -9,8 +10,9 @@ export class EdgeSticker extends Sticker {
|
|
|
9
10
|
constructor();
|
|
10
11
|
}
|
|
11
12
|
export type EdgePieceUserData = {
|
|
12
|
-
positon:
|
|
13
|
-
rotation:
|
|
13
|
+
positon: Vector3Like;
|
|
14
|
+
rotation: Vector3Like;
|
|
14
15
|
};
|
|
15
16
|
import { Object3D } from 'three';
|
|
16
17
|
import { Sticker } from './sticker';
|
|
18
|
+
import type { Vector3Like } from 'three';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @implements {RubiksCubeViewInterface}
|
|
3
|
+
*/
|
|
4
|
+
export default class RubiksCube3D extends Object3D<import("three").Object3DEventMap> implements RubiksCubeViewInterface {
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
* @param {RubiksCube3DSettings} cubeSettings
|
|
8
|
+
*/
|
|
9
|
+
constructor(cubeSettings: RubiksCube3DSettings);
|
|
10
|
+
/** @type {RubiksCube3DSettings} */
|
|
11
|
+
_cubeSettings: RubiksCube3DSettings;
|
|
12
|
+
/** @type {number} */
|
|
13
|
+
_pieceGap: number;
|
|
14
|
+
/** @type {CubeType} */
|
|
15
|
+
_cubeType: CubeType;
|
|
16
|
+
/** @type {CubeConfig} */
|
|
17
|
+
_cubeConfig: CubeConfig;
|
|
18
|
+
/** @type {Group} */
|
|
19
|
+
_mainGroup: Group;
|
|
20
|
+
/** @type {Group} */
|
|
21
|
+
_animationGroup: Group;
|
|
22
|
+
/** @type {GSAPAnimation | undefined} */
|
|
23
|
+
_currentAnimation: GSAPAnimation | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Creates the main group containing all the pieces of the cube in their default position and rotation. Should only be called once during initialization.
|
|
26
|
+
* @private
|
|
27
|
+
**/
|
|
28
|
+
private createCubeGroup;
|
|
29
|
+
/**
|
|
30
|
+
* @param {Group} group
|
|
31
|
+
* @returns {(CornerPiece | EdgePiece | CenterPiece)[]}
|
|
32
|
+
*/
|
|
33
|
+
_getPieces(group?: Group): (CornerPiece | EdgePiece | CenterPiece)[];
|
|
34
|
+
/**
|
|
35
|
+
* Returns the sticker state of the cube. Can only be called when an Animation is not in progress as not all pieces would be in the main group.
|
|
36
|
+
* @returns {StickerState}
|
|
37
|
+
*/
|
|
38
|
+
getStickerState(): StickerState;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the sticker state of the cube. Can only be called when an Animation is not in progress as not all pieces would be in the main group.
|
|
41
|
+
* @private
|
|
42
|
+
* @param {StickerState} stickerState
|
|
43
|
+
*/
|
|
44
|
+
private setStickerState;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {string} logo
|
|
48
|
+
*/
|
|
49
|
+
addLogo(logo: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the pieces that should be rotated for a given slice. If the slice has no layers, all pieces will be returned. Should only be called before an Animation is started.
|
|
52
|
+
* @private
|
|
53
|
+
* @param {Slice} slice
|
|
54
|
+
* @returns {Object3D[]}
|
|
55
|
+
*/
|
|
56
|
+
private getRotationLayer;
|
|
57
|
+
/**
|
|
58
|
+
* Updates the gap of the pieces. To be used when the cube is not rotating
|
|
59
|
+
* @private
|
|
60
|
+
* @param {number} pieceGap
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
private updateGap;
|
|
64
|
+
/**
|
|
65
|
+
* Adds pieces in the rotationGroup back into the main group.
|
|
66
|
+
* Updates the position and rotation of the pieces according to their world position and rotation, then resets the rotation of the rotation group.
|
|
67
|
+
* Should only be called when a rotation is in progress.
|
|
68
|
+
* @private
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
private clearAnimationGroup;
|
|
72
|
+
/**
|
|
73
|
+
* @private
|
|
74
|
+
* @param {Slice} slice
|
|
75
|
+
*/
|
|
76
|
+
private fillAnimationGroup;
|
|
77
|
+
/**
|
|
78
|
+
* @public
|
|
79
|
+
* @param {number} animationSpeedMs
|
|
80
|
+
*/
|
|
81
|
+
public setCurrentAnimationSpeed(animationSpeedMs: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
public reset(): void;
|
|
86
|
+
/**
|
|
87
|
+
* @public
|
|
88
|
+
* @param {StickerState} stickerState
|
|
89
|
+
*/
|
|
90
|
+
public setState(stickerState: StickerState): void;
|
|
91
|
+
/**
|
|
92
|
+
* sets the state of the cube
|
|
93
|
+
* @public
|
|
94
|
+
* @param {CubeType} cubeType
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
public setType(cubeType: CubeType): void;
|
|
98
|
+
/**
|
|
99
|
+
* @public
|
|
100
|
+
* @param {Slice} slice
|
|
101
|
+
* @param {{animationSpeedMs: number?, ease: gsap.EaseString | gsap.EaseFunction | undefined}} [options]
|
|
102
|
+
* @returns {Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
public slice(slice: Slice, options?: {
|
|
105
|
+
animationSpeedMs: number | null;
|
|
106
|
+
ease: gsap.EaseString | gsap.EaseFunction | undefined;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
export type RubiksCubeViewInterface = _RubiksCubeViewInterface;
|
|
110
|
+
import { Object3D } from 'three';
|
|
111
|
+
import RubiksCube3DSettings from './cubeSettings';
|
|
112
|
+
import type { CubeType } from '../core';
|
|
113
|
+
import type { CubeConfig } from './cubeConfig';
|
|
114
|
+
import { Group } from 'three';
|
|
115
|
+
import { CornerPiece } from './cornerPiece';
|
|
116
|
+
import { EdgePiece } from './edgePiece';
|
|
117
|
+
import { CenterPiece } from './centerPiece';
|
|
118
|
+
import type { StickerState } from '../state/stickerState';
|
|
119
|
+
import type { Slice } from '../state/slice';
|
|
120
|
+
import type { RubiksCubeViewInterface as _RubiksCubeViewInterface } from '../rubiksCube/rubiksCubeController';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @import {BufferGeometry, ColorRepresentation} from 'three' */
|
|
2
|
+
export class Sticker extends Mesh<BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>, import("three").Material | import("three").Material[], import("three").Object3DEventMap> {
|
|
3
|
+
/**
|
|
4
|
+
* @param {BufferGeometry} geometry
|
|
5
|
+
*/
|
|
6
|
+
constructor(geometry: BufferGeometry);
|
|
7
|
+
/**
|
|
8
|
+
* @param {ColorRepresentation} color
|
|
9
|
+
*/
|
|
10
|
+
set color(color: ColorRepresentation);
|
|
11
|
+
/**
|
|
12
|
+
* @returns {ColorRepresentation} color
|
|
13
|
+
*/
|
|
14
|
+
get color(): ColorRepresentation;
|
|
15
|
+
}
|
|
16
|
+
import type { BufferGeometry } from 'three';
|
|
17
|
+
import { Mesh } from 'three';
|
|
18
|
+
import type { ColorRepresentation } from 'three';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export class RubiksCubeState {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {CubeType} cubeType
|
|
5
|
+
*/
|
|
6
|
+
constructor(cubeType: CubeType);
|
|
7
|
+
cubeType: CubeType;
|
|
8
|
+
/** @type {StickerState?} */
|
|
9
|
+
stickerState: StickerState | null;
|
|
10
|
+
/** @type {number[]} */
|
|
11
|
+
layers: number[];
|
|
12
|
+
/** @type {pieceState[]} */
|
|
13
|
+
corners: pieceState[];
|
|
14
|
+
/** @type {pieceState[]} */
|
|
15
|
+
edges: pieceState[];
|
|
16
|
+
/** @type {pieceState[]} */
|
|
17
|
+
centers: pieceState[];
|
|
18
|
+
reset(): void;
|
|
19
|
+
/**
|
|
20
|
+
* @param {StickerState} stickerState
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
setState(stickerState: StickerState): void;
|
|
24
|
+
/**
|
|
25
|
+
* @return {StickerState}
|
|
26
|
+
*/
|
|
27
|
+
getState(): StickerState;
|
|
28
|
+
/**
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
getKociemba(): string;
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} kociembaString
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
setKociemba(kociembaString: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param {Slice} slice
|
|
40
|
+
*/
|
|
41
|
+
slice(slice: Slice): void;
|
|
42
|
+
/**
|
|
43
|
+
* @param {Movement} movement
|
|
44
|
+
* @param {MoveOptions} [options]
|
|
45
|
+
* @returns {Slice?}
|
|
46
|
+
*/
|
|
47
|
+
move(movement: Movement, options?: MoveOptions): Slice | null;
|
|
48
|
+
/**
|
|
49
|
+
* @param {Rotation} rotation
|
|
50
|
+
* @param {RotationOptions} [options]
|
|
51
|
+
* @returns {Slice?}
|
|
52
|
+
*/
|
|
53
|
+
rotate(rotation: Rotation, options?: RotationOptions): Slice | null;
|
|
54
|
+
/**
|
|
55
|
+
* @param {(Rotation | Movement)[]} actions
|
|
56
|
+
* @param {MoveOptions | RotationOptions } [options]
|
|
57
|
+
*/
|
|
58
|
+
do(actions: (Rotation | Movement)[], options?: MoveOptions | RotationOptions): void;
|
|
59
|
+
/**
|
|
60
|
+
* @private
|
|
61
|
+
* @param {number} position
|
|
62
|
+
* @returns {number}
|
|
63
|
+
*/
|
|
64
|
+
private _getLayerNumber;
|
|
65
|
+
}
|
|
66
|
+
export function corners(layers: number[]): {
|
|
67
|
+
position: vector;
|
|
68
|
+
rotation: vector;
|
|
69
|
+
}[];
|
|
70
|
+
export function centers(layers: number[]): {
|
|
71
|
+
position: vector;
|
|
72
|
+
rotation: vector;
|
|
73
|
+
}[];
|
|
74
|
+
export function edges(layers: number[]): {
|
|
75
|
+
position: vector;
|
|
76
|
+
rotation: vector;
|
|
77
|
+
}[];
|
|
78
|
+
export type state = {
|
|
79
|
+
corners: pieceState[];
|
|
80
|
+
edges: pieceState[];
|
|
81
|
+
centers: pieceState[];
|
|
82
|
+
};
|
|
83
|
+
export type pieceState = {
|
|
84
|
+
position: vector;
|
|
85
|
+
rotation: vector;
|
|
86
|
+
stickers: {
|
|
87
|
+
face: Face;
|
|
88
|
+
direction: vector;
|
|
89
|
+
}[];
|
|
90
|
+
};
|
|
91
|
+
export type vector = {
|
|
92
|
+
x: number;
|
|
93
|
+
y: number;
|
|
94
|
+
z: number;
|
|
95
|
+
};
|
|
96
|
+
export type MoveOptions = {
|
|
97
|
+
translate?: boolean | undefined;
|
|
98
|
+
reverse?: boolean | undefined;
|
|
99
|
+
};
|
|
100
|
+
export type RotationOptions = {
|
|
101
|
+
reverse?: boolean | undefined;
|
|
102
|
+
};
|
|
103
|
+
import type { CubeType } from '../core';
|
|
104
|
+
import type { StickerState } from './stickerState';
|
|
105
|
+
import type { Slice } from './slice';
|
|
106
|
+
import type { Movement } from '../core';
|
|
107
|
+
import type { Rotation } from '../core';
|
|
108
|
+
import type { Face } from '../core';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A slice represents an action or movement of a 3D rubiks cube. layers
|
|
3
|
+
* @typedef Slice
|
|
4
|
+
* @property {Axis} axis the axis that pieces rotate around
|
|
5
|
+
* @property {number[]} layerIds starting from 0 to the size of the cube. Layers represent what layers are included in the movement.
|
|
6
|
+
* @property {number} direction the direction and magnitude of the rotation
|
|
7
|
+
**/
|
|
8
|
+
/**
|
|
9
|
+
* @param {Movement} movement
|
|
10
|
+
* @param {number} layerCount
|
|
11
|
+
* @returns {Slice | undefined}
|
|
12
|
+
*/
|
|
13
|
+
export function GetMovementSlice(movement: Movement, layerCount: number): Slice | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @param {Rotation} rotation
|
|
16
|
+
* @param {number} layerCount
|
|
17
|
+
* @returns {Slice | undefined}
|
|
18
|
+
*/
|
|
19
|
+
export function GetRotationSlice(rotation: Rotation, layerCount: number): Slice | undefined;
|
|
20
|
+
/** @import {Movement, Rotation} from '../core' */
|
|
21
|
+
/** @typedef {typeof Axi[keyof typeof Axi]} Axis */
|
|
22
|
+
export const Axi: Readonly<{
|
|
23
|
+
x: "x";
|
|
24
|
+
y: "y";
|
|
25
|
+
z: "z";
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* A slice represents an action or movement of a 3D rubiks cube. layers
|
|
29
|
+
*/
|
|
30
|
+
export type Slice = {
|
|
31
|
+
/**
|
|
32
|
+
* the axis that pieces rotate around
|
|
33
|
+
*/
|
|
34
|
+
axis: Axis;
|
|
35
|
+
/**
|
|
36
|
+
* starting from 0 to the size of the cube. Layers represent what layers are included in the movement.
|
|
37
|
+
*/
|
|
38
|
+
layerIds: number[];
|
|
39
|
+
/**
|
|
40
|
+
* the direction and magnitude of the rotation
|
|
41
|
+
*/
|
|
42
|
+
direction: number;
|
|
43
|
+
};
|
|
44
|
+
export type Axis = (typeof Axi)[keyof typeof Axi];
|
|
45
|
+
import type { Movement } from '../core';
|
|
46
|
+
import type { Rotation } from '../core';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {vector} stickerDirection
|
|
3
|
+
* @param {vector} piecePosition
|
|
4
|
+
* @param {number[]} layers
|
|
5
|
+
* @returns {{face: Face, i: number, j: number}}
|
|
6
|
+
*/
|
|
7
|
+
export function getStickerFaceIndex(stickerDirection: vector, piecePosition: vector, layers: number[]): {
|
|
8
|
+
face: Face;
|
|
9
|
+
i: number;
|
|
10
|
+
j: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @param {StickerState} stickerState
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function toKociemba(stickerState: StickerState): string;
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} kociembaString
|
|
19
|
+
* @returns {StickerState | undefined} stickerState
|
|
20
|
+
*/
|
|
21
|
+
export function fromKociemba(kociembaString: string): StickerState | undefined;
|
|
22
|
+
export function defaultStickerState(cubeType: CubeType): StickerState;
|
|
23
|
+
export function getEmptyStickerState(cubeType: CubeType): StickerState;
|
|
24
|
+
export type StickerState = {
|
|
25
|
+
U: Face[][];
|
|
26
|
+
D: Face[][];
|
|
27
|
+
F: Face[][];
|
|
28
|
+
B: Face[][];
|
|
29
|
+
L: Face[][];
|
|
30
|
+
R: Face[][];
|
|
31
|
+
};
|
|
32
|
+
import type { vector } from './rubiksCubeState';
|
|
33
|
+
import type { Face } from '../core';
|
|
34
|
+
import type { CubeType } from '../core';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @import {PeekAction, PeekState} from './constants' */
|
|
2
|
+
export class CameraState {
|
|
3
|
+
/**
|
|
4
|
+
* @param {boolean} up
|
|
5
|
+
* @param {boolean} right
|
|
6
|
+
*/
|
|
7
|
+
constructor(up?: boolean, right?: boolean);
|
|
8
|
+
/** @type {boolean} */
|
|
9
|
+
Up: boolean;
|
|
10
|
+
/** @type {boolean} */
|
|
11
|
+
Right: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @param {PeekAction} action
|
|
14
|
+
*/
|
|
15
|
+
peekCamera(action: PeekAction): void;
|
|
16
|
+
/**
|
|
17
|
+
* @returns {PeekState}
|
|
18
|
+
*/
|
|
19
|
+
toPeekState(): PeekState;
|
|
20
|
+
}
|
|
21
|
+
import type { PeekAction } from './constants';
|
|
22
|
+
import type { PeekState } from './constants';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef CameraOptions
|
|
3
|
+
* @property {number} [cameraSpeedMs]
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {typeof AnimationStyles[keyof typeof AnimationStyles]} AnimationStyle
|
|
7
|
+
*/
|
|
8
|
+
export const AnimationStyles: Readonly<{
|
|
9
|
+
Exponential: "exponential";
|
|
10
|
+
Linear: "linear";
|
|
11
|
+
Next: "next";
|
|
12
|
+
Fixed: "fixed";
|
|
13
|
+
Match: "match";
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {typeof PeekStates [keyof typeof PeekStates]} PeekState
|
|
17
|
+
*/
|
|
18
|
+
export const PeekStates: Readonly<{
|
|
19
|
+
RightUp: "rightUp";
|
|
20
|
+
RightDown: "rightDown";
|
|
21
|
+
LeftUp: "leftUp";
|
|
22
|
+
LeftDown: "leftDown";
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {typeof PeekActions [keyof typeof PeekActions]} PeekAction
|
|
26
|
+
*/
|
|
27
|
+
export const PeekActions: Readonly<{
|
|
28
|
+
Horizontal: "horizontal";
|
|
29
|
+
Vertical: "vertical";
|
|
30
|
+
Right: "right";
|
|
31
|
+
Left: "left";
|
|
32
|
+
Up: "up";
|
|
33
|
+
Down: "down";
|
|
34
|
+
RightUp: "rightUp";
|
|
35
|
+
RightDown: "rightDown";
|
|
36
|
+
LeftUp: "leftUp";
|
|
37
|
+
LeftDown: "leftDown";
|
|
38
|
+
}>;
|
|
39
|
+
export namespace AttributeNames {
|
|
40
|
+
let cubeType: "cube-type";
|
|
41
|
+
let pieceGap: "piece-gap";
|
|
42
|
+
let animationSpeed: "animation-speed-ms";
|
|
43
|
+
let animationStyle: "animation-style";
|
|
44
|
+
let cameraSpeed: "camera-speed-ms";
|
|
45
|
+
let cameraRadius: "camera-radius";
|
|
46
|
+
let cameraFieldOfView: "camera-field-of-view";
|
|
47
|
+
let cameraPeekAngleHorizontal: "camera-peek-angle-horizontal";
|
|
48
|
+
let cameraPeekAngleVertical: "camera-peek-angle-vertical";
|
|
49
|
+
let logo: "logo";
|
|
50
|
+
}
|
|
51
|
+
export type CameraOptions = {
|
|
52
|
+
cameraSpeedMs?: number;
|
|
53
|
+
};
|
|
54
|
+
export type AnimationStyle = (typeof AnimationStyles)[keyof typeof AnimationStyles];
|
|
55
|
+
export type PeekState = (typeof PeekStates)[keyof typeof PeekStates];
|
|
56
|
+
export type PeekAction = (typeof PeekActions)[keyof typeof PeekActions];
|
|
57
|
+
export type AttributeName = (typeof AttributeNames)[keyof typeof AttributeNames];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { RubiksCubeElement } from "./rubiksCubeElement";
|
|
2
|
+
export type PeekState = import("./constants").PeekState;
|
|
3
|
+
export type PeekAction = import("./constants").PeekAction;
|
|
4
|
+
export type CameraOptions = import("./constants").CameraOptions;
|
|
5
|
+
export type AnimationStyle = import("./constants").AnimationStyle;
|
|
6
|
+
export { AttributeNames, PeekStates, PeekActions, AnimationStyles } from "./constants";
|