### Install and Build Cubedex
Source: https://github.com/poliva/cubedex/blob/main/README.md
Commands to install project dependencies and build the project for preview. Ensure you have Node.js and npm installed.
```bash
$ npm install
$ npm run build && npm run preview
```
--------------------------------
### Use Scramble State Hook for Guided Cube Setup
Source: https://context7.com/poliva/cubedex/llms.txt
This hook computes the optimal scramble sequence to set up a physical smartcube for the next algorithm. It tracks physical cube move progress against the scramble sequence and resolves when the cube matches the target state. Import `useScrambleState` and use its methods to manage the scramble process.
```tsx
import { useScrambleState } from './src/hooks/useScrambleState';
import type { CaseCardData } from './src/lib/case-cards';
function ScrambleExample({ currentCase, smartcubePattern }: any) {
const scramble = useScrambleState();
// scramble.scrambleMode: boolean
// scramble.remainingMoves: string[] — moves left to complete the scramble
// scramble.targetAlgorithm: string — the alg being scrambled to
async function startScramble() {
const started = await scramble.startScrambleTo(
currentCase.algorithm,
currentCase,
smartcubePattern,
true, // randomizeAUF
);
if (started) {
console.log('Scramble started, target:', scramble.targetAlgorithm);
}
}
// Called for each smartcube MOVE event while scramble.scrambleMode is true:
async function onMove(move: string) {
const completed = await scramble.advanceScramble(move, smartcubePattern);
if (completed) {
console.log('Cube is now in starting position — begin solve!');
}
}
return (
{scramble.scrambleMode && (
Remaining: {scramble.remainingMoves.join(' ')}
)}
);
}
```
--------------------------------
### `prepareTrainingAlgorithm(inputMoves, category, randomizeAUF)`
Source: https://context7.com/poliva/cubedex/llms.txt
Prepares an algorithm for training purposes. It can optionally add a random AUF (Adjust U Face) and simplifies the move sequence.
```APIDOC
## `prepareTrainingAlgorithm(inputMoves, category, randomizeAUF)` — Prepare algorithm for display
Optionally adds a random AUF (Adjust U Face) before/after the algorithm for PLL/ZBLL training, or verifies OLL symmetry to decide whether to add pre-AUF, then returns the final display algorithm and the underlying move array.
### Parameters
#### Path Parameters
- **inputMoves** (string[]) - Required - The initial sequence of moves.
- **category** (string) - Required - The training category (e.g., 'PLL', 'OLL').
- **randomizeAUF** (boolean) - Required - Whether to randomize the AUF.
### Request Example
```ts
import { prepareTrainingAlgorithm } from './src/lib/auf';
const prepared = await prepareTrainingAlgorithm(
["R", "U", "R'", "U'"], // input moves
'PLL',
true, // randomizeAUF: true
);
// prepared.displayAlgorithm: e.g. "U R U R' U' U'" (with random pre- and post-AUF)
// prepared.moves: ["U", "R", "U", "R'", "U2"] (simplified with cancellations)
// prepared.originalMoves: ["R", "U", "R'", "U'"] (unchanged input)
// Without AUF:
const exact = await prepareTrainingAlgorithm(["R", "U2", "R'"], 'OLL', false);
// exact.displayAlgorithm: "R U2 R'"
// exact.moves: ["R", "U2", "R'"]
```
### Response
#### Success Response
- **displayAlgorithm** (string) - The algorithm formatted for display, potentially with AUF.
- **moves** (string[]) - The simplified array of moves.
- **originalMoves** (string[]) - The original input moves.
```
--------------------------------
### Initialize Algorithm Library and Manage Case Selection with useCaseLibrary
Source: https://context7.com/poliva/cubedex/llms.txt
Initializes the algorithm library from IndexedDB and manages selection state. Provides callbacks to toggle subsets, select/deselect cases, and cycle learned status.
```tsx
import { useCaseLibrary } from './src/hooks/useCaseLibrary';
function LibraryComponent() {
const lib = useCaseLibrary({
autoUpdateLearningState: true,
smartReviewScheduling: true,
});
if (!lib.isReady) return
);
}
```
--------------------------------
### useCaseLibrary
Source: https://context7.com/poliva/cubedex/llms.txt
Initializes the algorithm library from IndexedDB, exposes the full category/subset/case tree, and manages selection state. Provides callbacks to toggle subsets, select/deselect individual cases, cycle learned status, and reload after import.
```APIDOC
## `useCaseLibrary(options)`
### Description
Initializes the algorithm library from IndexedDB, exposes the full category/subset/case tree, and manages selection state (all cases, by learned status, or manual). Provides callbacks to toggle subsets, select/deselect individual cases, cycle learned status, and reload after import.
### Parameters
* `options` (object) - Configuration options for the hook.
* `autoUpdateLearningState` (boolean) - Whether to automatically update learning state.
* `smartReviewScheduling` (boolean) - Whether to enable smart review scheduling.
### Returns
An object containing the following properties:
* `isReady` (boolean) - Indicates if the library is ready.
* `initError` (string | null) - An error message if initialization failed.
* `categories` (string[]) - An array of available categories.
* `selectedCategory` (string) - The currently selected category.
* `subsets` (string[]) - An array of available subsets.
* `caseCards` (CaseCardData[]) - An array of case card data.
* `selectedCaseIds` (string[]) - An array of selected case IDs.
* `setSelectedCategory` (function) - Function to set the selected category.
* `toggleSubset` (function) - Function to toggle a subset's selection state.
* `selectVisibleCases` (function) - Function to select all visible cases.
* `clearSelectedCases` (function) - Function to clear all selected cases.
* `cycleCaseLearnedState` (function) - Function to cycle the learned state of a case.
```
--------------------------------
### exportAlgorithms and exportBackup
Source: https://context7.com/poliva/cubedex/llms.txt
Provides functions to download algorithm data. `exportAlgorithms` downloads only the algorithm library, while `exportBackup` includes the library, stats, and SRS records in a versioned backup format.
```APIDOC
## exportAlgorithms() / exportBackup()
### Description
`exportAlgorithms()` downloads a JSON file containing only the algorithm library. `exportBackup()` includes both the library and all stats/SRS records in a versioned backup format.
### Method
`exportAlgorithms` or `exportBackup`
### Parameters
None
### Request Example
```ts
import { exportAlgorithms, exportBackup } from './src/lib/storage';
// Download just the algorithm library
await exportAlgorithms();
// Download a full backup
await exportBackup();
```
### Response
#### Success Response (void)
Initiates a file download containing the exported data.
#### Response Example (for exportBackup)
```json
{
"backupFormatVersion": 2,
"exportedAt": "2024-06-01T12:00:00.000Z",
"algorithms": { "OLL": [...], "PLL": [...] },
"stats": [{ "scopeId": "case:OLL:All%20Cases:R-U-Rp-U-R-U2-Rp", "attemptHistory": [...], "srs": {...}, ... }]
}
```
```
--------------------------------
### Prepare Algorithm for Training Display
Source: https://context7.com/poliva/cubedex/llms.txt
Prepares an algorithm for training by optionally adding random AUF (Adjust U Face) or verifying OLL symmetry. Returns the display algorithm and the underlying move array.
```ts
import { prepareTrainingAlgorithm } from './src/lib/auf';
const prepared = await prepareTrainingAlgorithm(
["R", "U", "R'", "U'"], // input moves
'PLL',
true, // randomizeAUF: true
);
// prepared.displayAlgorithm: e.g. "U R U R' U' U'" (with random pre- and post-AUF)
// prepared.moves: ["U", "R", "U", "R'", "U2"] (simplified with cancellations)
// prepared.originalMoves: ["R", "U", "R'", "U'"] (unchanged input)
// Without AUF:
const exact = await prepareTrainingAlgorithm(["R", "U2", "R'"], 'OLL', false);
// exact.displayAlgorithm: "R U2 R'"
// exact.moves: ["R", "U2", "R'"]
```
--------------------------------
### Initialize Cubedex Storage
Source: https://context7.com/poliva/cubedex/llms.txt
Initializes the IndexedDB database, migrates legacy data, and loads algorithms and stats into memory. Must be awaited before other storage operations.
```typescript
import defaultAlgs from './src/data/defaultAlgs.json';
import { initializeDefaultAlgorithms, getSavedAlgorithms } from './src/lib/storage';
// In main.tsx / React root
async function bootstrap() {
const result = await initializeDefaultAlgorithms(defaultAlgs as SavedAlgorithms);
if (result.alertMessage) {
// e.g. "Algorithms have been migrated to a new format…"
console.warn(result.alertMessage);
}
// result.migratedSavedAlgorithmsV1 === true when old v1 categories were found
const algorithms = getSavedAlgorithms();
// { OLL: [{ subset: 'All Cases', algorithms: [{ name: 'OLL-1', algorithm: 'R U2 R2 F R F U2 R F2' }, ...] }], PLL: [...], ... }
console.log(Object.keys(algorithms)); // ['OLL', 'PLL', 'CMLL', ...]
}
```
--------------------------------
### useAppSettings
Source: https://context7.com/poliva/cubedex/llms.txt
Reads and writes all user preferences from `localStorage` (theme, visualization, gyroscope, countdown mode, etc.) and exposes typed setters for each option.
```APIDOC
## `useAppSettings()`
### Description
Reads and writes all user preferences from `localStorage` (theme, visualization, gyroscope, countdown mode, always-scramble-to, flashing indicator, full stickering, cube size, etc.) and exposes typed setters for each option.
### Returns
An object containing the following properties:
* `theme` (string) - The current theme ('dark', 'light', 'system').
* `countdownMode` (boolean) - Whether countdown mode is enabled.
* `randomizeAUF` (boolean) - Whether to randomize AUF (in practiceToggles).
* `alwaysScrambleTo` (boolean) - Whether to always scramble to a specific state.
* `gyroscope` (boolean) - Whether gyroscope is enabled.
* `fullStickering` (boolean) - Whether full stickering is enabled.
* `flashingIndicatorEnabled` (boolean) - Whether the flashing indicator is enabled.
* `autoUpdateLearningState` (boolean) - Whether to automatically update learning state.
* `cubeSizePx` (number) - The size of the cube in pixels.
* `setCountdownMode` (function) - Function to set the countdown mode.
* `setAlwaysScrambleTo` (function) - Function to set the always scramble to option.
* `setCubeSizePx` (function) - Function to set the cube size in pixels.
```
--------------------------------
### Convert Smartcube State to Player Algorithm
Source: https://context7.com/poliva/cubedex/llms.txt
Converts the current Bluetooth cube state (`KPattern`) into the shortest algorithm to reach that state from solved. Useful for displaying scrambles on screen.
```ts
import { patternToPlayerAlg } from './src/lib/scramble';
import { solvedPattern } from './src/lib/cube-utils';
const pattern = await solvedPattern();
const playerAlg = patternToPlayerAlg(pattern);
// '' — already solved
// After applying some moves via smartcube events:
// const movedPattern = pattern.applyAlg("R U R' U'");
// patternToPlayerAlg(movedPattern) → "R U R' U'" (the inverse of the solve path)
```
--------------------------------
### getStickeringForCategory(category, fullStickeringEnabled)
Source: https://context7.com/poliva/cubedex/llms.txt
Maps a given algorithm category to its corresponding cube stickering scheme string. Falls back to 'full' for unrecognized categories or when full stickering is explicitly enabled.
```APIDOC
## getStickeringForCategory(category, fullStickeringEnabled)
### Description
Maps a category to its cubing.js stickering scheme string (e.g., `'OLL'`, `'PLL'`, `'F2L'`) for the 3-D cube visualization. Falls back to `'full'` for unrecognized categories or when full stickering is forced.
### Parameters
#### Path Parameters
- **category** (string) - Required - The algorithm category (e.g., 'OLL', 'PLL').
- **fullStickeringEnabled** (boolean) - Required - A flag to force full stickering.
### Request Example
```ts
import { getStickeringForCategory } from './src/lib/stickering';
getStickeringForCategory('OLL', false) // 'OLL'
getStickeringForCategory('PLL', false) // 'PLL'
getStickeringForCategory('CMLL', false) // 'CMLL'
getStickeringForCategory('My OLL Set', false) // 'OLL' (word match)
getStickeringForCategory('Unknown', false) // 'full' (fallback)
getStickeringForCategory('OLL', true) // 'full' (forced full stickering)
```
```
--------------------------------
### `patternToPlayerAlg(pattern)`
Source: https://context7.com/poliva/cubedex/llms.txt
Converts a smartcube state (`KPattern`) into the shortest algorithm to reach that state from a solved cube. This is useful for displaying scrambles on a 3D cube.
```APIDOC
## `patternToPlayerAlg(pattern)` — Convert smartcube state to displayable algorithm
Takes a `KPattern` (the current Bluetooth cube state) and returns the shortest algorithm that, when executed from solved, reaches that state — used to set up the on-screen 3-D cube as a "scramble" display.
### Parameters
#### Path Parameters
- **pattern** (KPattern) - Required - The current Bluetooth cube state.
### Request Example
```ts
import { patternToPlayerAlg } from './src/lib/scramble';
import { solvedPattern } from './src/lib/cube-utils';
const pattern = await solvedPattern();
const playerAlg = patternToPlayerAlg(pattern);
// '' — already solved
// After applying some moves via smartcube events:
// const movedPattern = pattern.applyAlg("R U R' U'");
// patternToPlayerAlg(movedPattern) → "R U R' U'" (the inverse of the solve path)
```
### Response
#### Success Response
- **playerAlg** (string) - The shortest algorithm to reach the given pattern from solved.
```
--------------------------------
### getCaseCards(savedAlgorithms, category, checkedSubsets, options)
Source: https://context7.com/poliva/cubedex/llms.txt
Builds practice card data by compiling algorithm information for a given category and subset selection. It enriches each algorithm with its best time, ao5, learned status, SRS due date, and urgency score.
```APIDOC
## getCaseCards(savedAlgorithms, category, checkedSubsets, options)
### Description
Builds practice card data for a given category and subset selection. Enriches each algorithm with its best time, ao5, learned status, SRS due date, and urgency score. This is the primary data structure consumed by the training state and case grid UI.
### Parameters
#### Path Parameters
- **savedAlgorithms** (Array