@houstonp/rubiks-cube 2.0.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 +494 -63
- package/package.json +22 -12
- package/src/core/index.js +478 -0
- package/src/rubiksCube/index.js +3 -0
- package/src/rubiksCube/rubiksCubeController.js +111 -0
- package/src/rubiksCube3D/centerPiece.js +79 -0
- package/src/rubiksCube3D/cornerPiece.js +114 -0
- package/src/rubiksCube3D/cubeConfig.js +87 -0
- package/src/rubiksCube3D/cubeSettings.js +30 -0
- package/src/rubiksCube3D/edgePiece.js +51 -0
- package/src/rubiksCube3D/index.js +3 -0
- package/src/rubiksCube3D/rubiksCube3D.js +383 -0
- package/src/rubiksCube3D/sticker.js +38 -0
- 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/{cameraState.js → webComponent/cameraState.js} +17 -25
- package/src/webComponent/constants.js +67 -0
- package/src/{debouncer.js → webComponent/debouncer.js} +1 -1
- package/src/webComponent/index.js +7 -0
- package/src/webComponent/rubiksCubeElement.js +379 -0
- package/src/{settings.js → webComponent/settings.js} +47 -22
- package/tests/common.js +10 -0
- 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/setup.js +36 -0
- package/tests/testScrambles.js +194 -0
- package/types/core/index.d.ts +451 -0
- 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/rubiksCube3D/edgePiece.d.ts +18 -0
- 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} +9 -8
- package/src/core.js +0 -127
- package/src/cube/cube.js +0 -324
- package/src/cube/cubeRotation.js +0 -79
- package/src/cube/cubeSettings.js +0 -18
- package/src/cube/cubeState.js +0 -192
- package/src/cube/slice.js +0 -143
- package/src/index.js +0 -496
- package/src/schema.js +0 -22
- package/src/threejs/materials.js +0 -54
- package/src/threejs/pieces.js +0 -100
- package/src/threejs/stickers.js +0 -40
- package/types/cameraState.d.ts +0 -19
- package/types/core.d.ts +0 -125
- package/types/cube/cube.d.ts +0 -102
- package/types/cube/cubeRotation.d.ts +0 -33
- package/types/cube/cubeSettings.d.ts +0 -17
- package/types/cube/cubeState.d.ts +0 -16
- package/types/cube/slice.d.ts +0 -15
- package/types/index.d.ts +0 -65
- package/types/schema.d.ts +0 -11
- package/types/threejs/materials.d.ts +0 -21
- package/types/threejs/pieces.d.ts +0 -28
- package/types/threejs/stickers.d.ts +0 -6
- /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,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";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference path="globals.d.ts" preserve="true" />
|
|
2
|
+
export class RubiksCubeElement extends HTMLElement {
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} tagName the name of the tag to register the web component under
|
|
5
|
+
*/
|
|
6
|
+
static register(tagName?: string): void;
|
|
7
|
+
static get observedAttributes(): ("cube-type" | "piece-gap" | "animation-speed-ms" | "animation-style" | "camera-speed-ms" | "camera-radius" | "camera-field-of-view" | "camera-peek-angle-horizontal" | "camera-peek-angle-vertical" | "logo")[];
|
|
8
|
+
/** @private @type {HTMLCanvasElement} */
|
|
9
|
+
private canvas;
|
|
10
|
+
/** @private @type {Settings} */
|
|
11
|
+
private settings;
|
|
12
|
+
/** @private @type {RubiksCube3D?} */
|
|
13
|
+
private _rubiksCube3D;
|
|
14
|
+
/** @private @type {RubiksCubeController?} */
|
|
15
|
+
private _rubiksCube;
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} name
|
|
19
|
+
* @param {string?} oldVal
|
|
20
|
+
* @param {string?} newVal
|
|
21
|
+
* */
|
|
22
|
+
attributeChangedCallback(name: string, oldVal: string | null, newVal: string | null): void;
|
|
23
|
+
/** @private */
|
|
24
|
+
private animateCameraSetting;
|
|
25
|
+
/** @private */
|
|
26
|
+
private animateCameraRadius;
|
|
27
|
+
/** @private */
|
|
28
|
+
private updateCameraFOV;
|
|
29
|
+
/** @internal @typedef {{eventId: string, move: Movement, reason: string}} MovementFailedEventData */
|
|
30
|
+
/**
|
|
31
|
+
* @param {Movement} move
|
|
32
|
+
* @param {AnimationOptions} [options]
|
|
33
|
+
* @returns {Promise<string>}
|
|
34
|
+
*/
|
|
35
|
+
move(move: Movement, options?: AnimationOptions): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* @param {Rotation} rotation
|
|
38
|
+
* @param {AnimationOptions} [options]
|
|
39
|
+
* @returns {Promise<string>}
|
|
40
|
+
*/
|
|
41
|
+
rotate(rotation: Rotation, options?: AnimationOptions): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* @returns {string}
|
|
44
|
+
*/
|
|
45
|
+
reset(): string;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} kociembaState
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
setState(kociembaState: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
getState(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @param {CubeType} cubeType
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
59
|
+
setType(cubeType: CubeType): string;
|
|
60
|
+
/**
|
|
61
|
+
* @private
|
|
62
|
+
**/
|
|
63
|
+
private _rebuild;
|
|
64
|
+
/** @internal @typedef {{eventId: string, action: PeekAction, options: CameraOptions?}} CameraPeekEventData */
|
|
65
|
+
/** @internal @typedef {{eventId: string, peekState: PeekState }} CameraPeekCompleteEventData */
|
|
66
|
+
/**
|
|
67
|
+
* Animates the camera to a new "peek" position.
|
|
68
|
+
*
|
|
69
|
+
* The camera tracks two independent boolean axes (horizontal: Right/Left, vertical: Up/Down), giving four
|
|
70
|
+
* reachable positions (the {@link PeekState}s). Each `PeekAction` operates on this state machine: actions like
|
|
71
|
+
* `RightUp` set both axes; `Up`/`Right`/`Left`/`Down` set one axis and leave the other untouched;
|
|
72
|
+
* `Horizontal`/`Vertical` toggle one axis relative to its current value. The result of a partial action
|
|
73
|
+
* therefore depends on the current peek state.
|
|
74
|
+
*
|
|
75
|
+
* @param {PeekAction} action
|
|
76
|
+
* @param {CameraOptions?} options
|
|
77
|
+
* @returns {Promise<PeekState>}
|
|
78
|
+
*/
|
|
79
|
+
peek(action: PeekAction, options?: CameraOptions | null): Promise<PeekState>;
|
|
80
|
+
/** @private */
|
|
81
|
+
private init;
|
|
82
|
+
}
|
|
83
|
+
import type { Movement } from '../core';
|
|
84
|
+
import type { AnimationOptions } from '../rubiksCube';
|
|
85
|
+
import type { Rotation } from '../core';
|
|
86
|
+
import type { CubeType } from '../core';
|
|
87
|
+
import type { PeekAction } from './constants';
|
|
88
|
+
import type { CameraOptions } from './constants';
|
|
89
|
+
import type { PeekState } from './constants';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export default class Settings {
|
|
2
|
-
/** @type {
|
|
3
|
-
|
|
4
|
-
/** @type {number} */
|
|
5
|
-
animationSpeedMs: number;
|
|
6
|
-
/** @type {import("./cube/cubeSettings").AnimationStyle} */
|
|
7
|
-
animationStyle: import("./cube/cubeSettings").AnimationStyle;
|
|
2
|
+
/** @type {RubiksCube3DSettings} */
|
|
3
|
+
rubiksCube3DSettings: RubiksCube3DSettings;
|
|
8
4
|
/** @type {number} */
|
|
9
5
|
cameraSpeedMs: number;
|
|
10
6
|
/** @type {number} */
|
|
@@ -15,12 +11,14 @@ export default class Settings {
|
|
|
15
11
|
cameraPeekAngleHorizontal: number;
|
|
16
12
|
/** @type {number} */
|
|
17
13
|
cameraPeekAngleVertical: number;
|
|
14
|
+
/** @param {any} value */
|
|
15
|
+
setCubeType(value: any): void;
|
|
18
16
|
/** @param {string | null} value*/
|
|
19
17
|
setPieceGap(value: string | null): void;
|
|
20
18
|
/** @param {string | null} value in ms */
|
|
21
19
|
setAnimationSpeed(value: string | null): void;
|
|
22
|
-
/** @param {
|
|
23
|
-
setAnimationStyle(value:
|
|
20
|
+
/** @param {any} value */
|
|
21
|
+
setAnimationStyle(value: any): void;
|
|
24
22
|
/** @param {string | null} value in ms */
|
|
25
23
|
setCameraSpeed(value: string | null): void;
|
|
26
24
|
/** @param {string | null} value */
|
|
@@ -31,4 +29,7 @@ export default class Settings {
|
|
|
31
29
|
setCameraPeekAngleVertical(value: string | null): void;
|
|
32
30
|
/** @param {string | null} value in ms */
|
|
33
31
|
setCameraFieldOfView(value: string | null): void;
|
|
32
|
+
/** @param {string | null} value in ms */
|
|
33
|
+
setLogo(value: string | null): void;
|
|
34
34
|
}
|
|
35
|
+
import RubiksCube3DSettings from '../rubiksCube3D/cubeSettings';
|
package/src/core.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {typeof Movements[keyof typeof Movements]} Movement
|
|
4
|
-
*/
|
|
5
|
-
export const Movements = Object.freeze({
|
|
6
|
-
R: 'R',
|
|
7
|
-
R2: 'R2',
|
|
8
|
-
RP: "R'",
|
|
9
|
-
L: 'L',
|
|
10
|
-
L2: 'L2',
|
|
11
|
-
LP: "L'",
|
|
12
|
-
U: 'U',
|
|
13
|
-
U2: 'U2',
|
|
14
|
-
UP: "U'",
|
|
15
|
-
D: 'D',
|
|
16
|
-
D2: 'D2',
|
|
17
|
-
DP: "D'",
|
|
18
|
-
F: 'F',
|
|
19
|
-
F2: 'F2',
|
|
20
|
-
FP: "F'",
|
|
21
|
-
B: 'B',
|
|
22
|
-
B2: 'B2',
|
|
23
|
-
BP: "B'",
|
|
24
|
-
// Wide moves
|
|
25
|
-
r: 'r',
|
|
26
|
-
r2: 'r2',
|
|
27
|
-
rP: "r'",
|
|
28
|
-
l: 'l',
|
|
29
|
-
l2: 'l2',
|
|
30
|
-
lP: "l'",
|
|
31
|
-
u: 'u',
|
|
32
|
-
u2: 'u2',
|
|
33
|
-
uP: "u'",
|
|
34
|
-
d: 'd',
|
|
35
|
-
d2: 'd2',
|
|
36
|
-
dP: "d'",
|
|
37
|
-
f: 'f',
|
|
38
|
-
f2: 'f2',
|
|
39
|
-
fP: "f'",
|
|
40
|
-
b: 'b',
|
|
41
|
-
b2: 'b2',
|
|
42
|
-
bP: "b'",
|
|
43
|
-
// Slice moves
|
|
44
|
-
M: 'M',
|
|
45
|
-
M2: 'M2',
|
|
46
|
-
MP: "M'",
|
|
47
|
-
E: 'E',
|
|
48
|
-
E2: 'E2',
|
|
49
|
-
EP: "E'",
|
|
50
|
-
S: 'S',
|
|
51
|
-
S2: 'S2',
|
|
52
|
-
SP: "S'",
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {typeof Rotations[keyof typeof Rotations]} Rotation
|
|
57
|
-
*/
|
|
58
|
-
export const Rotations = Object.freeze({
|
|
59
|
-
x: 'x',
|
|
60
|
-
x2: 'x2',
|
|
61
|
-
xP: "x'",
|
|
62
|
-
y: 'y',
|
|
63
|
-
y2: 'y2',
|
|
64
|
-
yP: "y'",
|
|
65
|
-
z: 'z',
|
|
66
|
-
z2: 'z2',
|
|
67
|
-
zP: "z'",
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @typedef {typeof Axi[keyof typeof Axi]} Axis
|
|
72
|
-
*/
|
|
73
|
-
export const Axi = Object.freeze({
|
|
74
|
-
x: 'x',
|
|
75
|
-
y: 'y',
|
|
76
|
-
z: 'z',
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @typedef {typeof Faces [keyof typeof Faces]} Face
|
|
81
|
-
*/
|
|
82
|
-
export const Faces = Object.freeze({
|
|
83
|
-
up: 'U',
|
|
84
|
-
down: 'D',
|
|
85
|
-
left: 'L',
|
|
86
|
-
right: 'R',
|
|
87
|
-
front: 'F',
|
|
88
|
-
back: 'B',
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @typedef {typeof FaceColours [keyof typeof FaceColours]} FaceColour
|
|
93
|
-
*/
|
|
94
|
-
export const FaceColours = Object.freeze({
|
|
95
|
-
up: 'white',
|
|
96
|
-
down: 'yellow',
|
|
97
|
-
left: 'orange',
|
|
98
|
-
right: 'red',
|
|
99
|
-
front: 'green',
|
|
100
|
-
back: 'blue',
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @typedef {typeof PeekTypes [keyof typeof PeekTypes]} PeekType
|
|
105
|
-
*/
|
|
106
|
-
export const PeekTypes = Object.freeze({
|
|
107
|
-
Horizontal: 'horizontal',
|
|
108
|
-
Vertical: 'vertical',
|
|
109
|
-
Right: 'right',
|
|
110
|
-
Left: 'left',
|
|
111
|
-
Up: 'up',
|
|
112
|
-
Down: 'down',
|
|
113
|
-
RightUp: 'rightUp',
|
|
114
|
-
RightDown: 'rightDown',
|
|
115
|
-
LeftUp: 'leftUp',
|
|
116
|
-
LeftDown: 'leftDown',
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @typedef {typeof PeekStates [keyof typeof PeekStates]} PeekState
|
|
121
|
-
*/
|
|
122
|
-
export const PeekStates = Object.freeze({
|
|
123
|
-
RightUp: 'rightUp',
|
|
124
|
-
RightDown: 'rightDown',
|
|
125
|
-
LeftUp: 'leftUp',
|
|
126
|
-
LeftDown: 'leftDown',
|
|
127
|
-
});
|