react-rubiks-cube 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 chahe-dridi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ <div align="center">
2
+
3
+ # cubex
4
+
5
+ **A beautiful, self-solving 3D Rubik's Cube component for React.**
6
+
7
+ It scrambles and solves itself in an endless loop, tumbles gently in 3D, and — when you click it — opens a fullscreen playground where you can drag faces to turn them or drive it with Rubik's-notation buttons. Fully themeable, ~8&nbsp;kB gzipped, zero configuration to drop in.
8
+
9
+ [![npm](https://img.shields.io/npm/v/react-rubiks-cube?color=E05C28)](https://www.npmjs.com/package/react-rubiks-cube)
10
+ [![license](https://img.shields.io/github/license/chahe-dridi/cubex?color=00C9A7)](./LICENSE)
11
+ [![stars](https://img.shields.io/github/stars/chahe-dridi/cubex?style=social)](https://github.com/chahe-dridi/cubex/stargazers)
12
+
13
+ [Features](#features) · [Install](#install) · [Quick start](#quick-start) · [Props](#props) · [Theming](#theming) · [Advanced](#advanced)
14
+
15
+ **Like it? [⭐ Star the repo](https://github.com/chahe-dridi/cubex) — it genuinely helps others find it.**
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## Features
22
+
23
+ - 🎲 **Self-solving** — realistic scramble → solve loop, with occasional flourishes and dual concurrent slice turns.
24
+ - 🖱️ **Interactive** — click to expand into a fullscreen overlay; drag a face to turn a slice, orbit to look around, or use the notation buttons (U, R, F, M, x/y/z…).
25
+ - 🎨 **Themeable** — ships with a warm `brand` palette and the `classic` Rubik's colours, or pass your own per-face colours.
26
+ - 🪶 **Light** — one shared geometry, pooled quaternions, no per-frame allocations. ~8&nbsp;kB gzipped, everything heavy stays a peer dependency.
27
+ - 🧩 **Composable** — use the one-line `<RubiksCube />`, or drop the underlying scenes into your own `<Canvas>`.
28
+ - 🔒 **TypeScript** — full typings included.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ npm install react-rubiks-cube
34
+ ```
35
+
36
+ > The package is published as **`react-rubiks-cube`**; the project/brand name is **cubex**. Import from `react-rubiks-cube`.
37
+
38
+ `cubex` relies on a few peers you probably already have in a react-three project. Install them if you don't:
39
+
40
+ ```bash
41
+ npm install react react-dom three @react-three/fiber @react-three/drei framer-motion
42
+ ```
43
+
44
+ > Installing straight from GitHub also works and builds automatically:
45
+ > ```bash
46
+ > npm install github:chahe-dridi/cubex
47
+ > ```
48
+
49
+ ## Quick start
50
+
51
+ ```jsx
52
+ import { RubiksCube } from 'react-rubiks-cube'
53
+
54
+ export default function App() {
55
+ return <RubiksCube size={400} />
56
+ }
57
+ ```
58
+
59
+ That's it — you get an auto-solving, tumbling cube that expands into an interactive playground on click. It renders its own `<Canvas>`, so it works anywhere in your app.
60
+
61
+ ## Props
62
+
63
+ All props are optional.
64
+
65
+ | Prop | Type | Default | Description |
66
+ | ---------------- | -------------------------------------- | ---------------- | ---------------------------------------------------------------------- |
67
+ | `size` | `number \| string` | `400` | Width in px (number) or any CSS size. |
68
+ | `height` | `number \| string` | `size` | Height. Defaults to a square. |
69
+ | `palette` | `PaletteInput` | brand palette | Colour override — see [Theming](#theming). |
70
+ | `accent` | `string` | `'#E05C28'` | Accent colour for the overlay's active mode toggle. |
71
+ | `autoplay` | `boolean` | `true` | Run the scramble → solve loop. |
72
+ | `tumble` | `boolean` | `true` | Slowly tumble the whole cube in 3D. |
73
+ | `interactive` | `boolean` | `true` | Click to open the fullscreen interactive overlay. |
74
+ | `scrollTilt` | `boolean` | `false` | Tilt the cube as the element scrolls through the viewport. |
75
+ | `scale` | `number` | `0.72` | Cube scale inside the canvas. |
76
+ | `cameraPosition` | `[number, number, number]` | `[7, 6, 7]` | Camera position. |
77
+ | `fov` | `number` | `24` | Camera field of view. |
78
+ | `background` | `string` | `'transparent'` | Canvas background (e.g. `'#0a0908'`). |
79
+ | `ambient` | `number` | `0.22` | Ambient light intensity. |
80
+ | `onExpand` | `() => void` | — | Called when the interactive overlay opens. |
81
+ | `className` / `style` | — | — | Applied to the wrapper `<div>`. |
82
+
83
+ ### Examples
84
+
85
+ ```jsx
86
+ // A calm, non-interactive hero cube that reacts to scroll
87
+ <RubiksCube size="min(80vw, 460px)" interactive={false} scrollTilt />
88
+
89
+ // Classic Rubik's colours on a solid background
90
+ <RubiksCube palette={{ base: 'classic' }} background="#0a0908" accent="#009B48" />
91
+
92
+ // Static showpiece — no tumble, no autoplay
93
+ <RubiksCube tumble={false} autoplay={false} />
94
+ ```
95
+
96
+ ## Theming
97
+
98
+ A palette defines the six sticker faces (`right`, `left`, `up`, `down`, `front`, `back`) plus the `inner` body. Each entry is `{ color, roughness, metalness }`.
99
+
100
+ Pass a **partial** palette and it's merged over a base. Pick the base with `base: 'brand'` (default) or `base: 'classic'`:
101
+
102
+ ```jsx
103
+ <RubiksCube
104
+ palette={{
105
+ base: 'classic',
106
+ up: { color: '#fafafa' }, // override just one face
107
+ front:{ color: '#8b5cf6', roughness: 0.25 },
108
+ }}
109
+ />
110
+ ```
111
+
112
+ You can also import the built-in palettes and helper directly:
113
+
114
+ ```jsx
115
+ import { BRAND_PALETTE, CLASSIC_PALETTE, resolvePalette } from 'react-rubiks-cube'
116
+ ```
117
+
118
+ ## Advanced
119
+
120
+ Want the cube inside your own scene? Import the underlying pieces and render them in a `<Canvas>` you control.
121
+
122
+ ```jsx
123
+ import { Canvas } from '@react-three/fiber'
124
+ import { AutoCubeScene, Lights, resolvePalette } from 'react-rubiks-cube'
125
+
126
+ const palette = resolvePalette({ base: 'classic' })
127
+
128
+ function Scene() {
129
+ return (
130
+ <Canvas flat camera={{ position: [7, 6, 7], fov: 24 }}>
131
+ <Lights ambient={0.25} />
132
+ <AutoCubeScene palette={palette} tumble autoplay />
133
+ </Canvas>
134
+ )
135
+ }
136
+ ```
137
+
138
+ Building a custom control UI? `InteractiveCubeScene` reads moves from a queue ref, and `MOVE_GROUPS` gives you the full Rubik's-notation move set to render buttons from:
139
+
140
+ ```jsx
141
+ import { useRef } from 'react'
142
+ import { Canvas } from '@react-three/fiber'
143
+ import { InteractiveCubeScene, MOVE_GROUPS, Lights, resolvePalette } from 'react-rubiks-cube'
144
+
145
+ function Playground() {
146
+ const queue = useRef([]) // push { axis, layer, dir } to turn a slice
147
+ const palette = resolvePalette()
148
+ return (
149
+ <>
150
+ <Canvas flat camera={{ position: [5, 4, 5], fov: 34 }}>
151
+ <Lights ambient={0.4} />
152
+ <InteractiveCubeScene palette={palette} queueRef={queue} />
153
+ </Canvas>
154
+ <button onClick={() => queue.current.push({ axis: 'y', layer: 1, dir: -1 })}>U</button>
155
+ </>
156
+ )
157
+ }
158
+ ```
159
+
160
+ ### A move
161
+
162
+ ```ts
163
+ { axis: 'x' | 'y' | 'z', layer: -1 | 0 | 1 | null, dir: 1 | -1 }
164
+ ```
165
+
166
+ `layer` selects which of the three slices along `axis` turns; `null` rotates the whole cube. `dir` is the turn direction.
167
+
168
+ ## Local development
169
+
170
+ ```bash
171
+ git clone https://github.com/chahe-dridi/cubex.git
172
+ cd cubex
173
+ npm install
174
+ npm run dev # runs the interactive demo in example/
175
+ npm run build # builds the library into dist/
176
+ ```
177
+
178
+ ## Support
179
+
180
+ If cubex saved you some time or just made you smile:
181
+
182
+ - ⭐ **[Star it on GitHub](https://github.com/chahe-dridi/cubex)** — the single biggest thing that helps others discover it.
183
+ - 🐦 **Share it** — a quick post or link to the repo goes a long way.
184
+ - 🐛 **[Open an issue](https://github.com/chahe-dridi/cubex/issues)** for bugs or ideas, or send a PR.
185
+
186
+ Every star and share is genuinely appreciated. 🙏
187
+
188
+ ## License
189
+
190
+ [MIT](./LICENSE) © chahe-dridi