Methods

The Web Cube element has a few methods that you can use to interact with the cube.

setState

Sets the state of the cube. You can use the Face enum to represent the faces of the cube to help you set the state.

Parameters

newState

The new state of the cube.

Example

index.ts
import { WebCube, Face } from "@web-cube/web-cube";
const $cube = document.querySelector("web-cube") as WebCube;
$cube.setState({
[Face.Up]: [
[Face.Up, Face.Up],
[Face.Up, Face.Down],
],
[Face.Down]: [
[Face.Down, Face.Down],
[Face.Down, Face.Up],
],
[Face.Left]: [
[Face.Left, Face.Left],
[Face.Left, Face.Right],
],
[Face.Right]: [
[Face.Right, Face.Right],
[Face.Right, Face.Left],
],
[Face.Front]: [
[Face.Front, Face.Front],
[Face.Front, Face.Back],
],
[Face.Back]: [
[Face.Back, Face.Back],
[Face.Back, Face.Front],
});

getState

Gets the state of the cube.

Returns

rotateCube

Rotates the entire cube with an animation.

Parameters

options

The options for the rotation.

Returns

  • Type: Promise<void>

Example

index.ts
import { WebCube } from "@web-cube/web-cube";
const $cube = document.querySelector("web-cube") as WebCube;
$cube.rotateCube({ axis: "x", angle: 90, backwards: false, speed: 500 });

rotateLayer

Rotates a layer of the cube.

Parameters

options

The options for the rotation.

Returns

  • Type: Promise<void>

Example

index.ts
import { WebCube } from "@web-cube/web-cube";
const $cube = document.querySelector("web-cube") as WebCube;
$cube.rotateLayer({
axis: "x",
layer: 0,
angle: 90,
backwards: false,
speed: 500,
});
© 2025 Axford