# cube-3d-js

> Provides a 3D cube carousel display with perspective.

Latest version **1.2.0** (published 2024-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install cube-3d-js
pnpm add cube-3d-js
yarn add cube-3d-js
bun add cube-3d-js
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-09-12 |
| First published | 2023-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ryohidaka |
| Maintainers | hidaka |
| Keywords | cube, carousel, 3D |

## Links

- npm: https://www.npmjs.com/package/cube-3d-js
- Repository: https://github.com/ryohidaka/cube-3d-js
- Homepage: https://github.com/ryohidaka/cube-3d-js#readme
- Issues: https://github.com/ryohidaka/cube-3d-js/issues
- npm.io page: https://npm.io/package/cube-3d-js

## Alternatives

- [adhdev](https://npm.io/package/adhdev.md) — 11.1K weekly downloads
- [react-slide-button](https://npm.io/package/react-slide-button.md) — 310 weekly downloads
- [better](https://npm.io/package/better.md) — 42 weekly downloads
- [react-native-swipe-image](https://npm.io/package/react-native-swipe-image.md) — 22 weekly downloads
- [nl.fokkezb.pulltorefresh](https://npm.io/package/nl.fokkezb.pulltorefresh.md) — 11 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2024-09-12
- 1.1.0 — 2024-05-06
- 1.0.1 — 2023-09-25

## README

# cube-3d-js

[![NPM Version](https://img.shields.io/npm/v/cube-3d-js?logo=npm)](https://www.npmjs.com/package/cube-3d-js)
![build](https://github.com/ryohidaka/cube-3d-js/workflows/Build/badge.svg)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B6TVH92)

Provides a 3D cube carousel display with perspective.

## Installation

You can install this library using npm:

```shell
npm install cube-3d-js
```

## Usage

### HTML

```html
<body>
  <div id="cube-3d">
    <div><h1>1</h1></div>
    <div><h1>2</h1></div>
    <div><h1>3</h1></div>
  </div>
  <style>
    #cube-3d-base > div {
      box-sizing: border-box;
      border: 0.5px solid black;
      color: blue;
      background-color: rgb(255 255 255 / 0.5);
    }
  </style>
</body>
```

### JavaScript

```javascript
import { init, onRotate, getFaceByIndex } from "cube-3d";

// Initialize the library with optional configuration
init("cube-3d", {
  width: 500,
  height: 500,
  initialRotation: 0,
});

// Register a callback for when the rotation changes
onRotate((currentFaceIndex: number, previousFaceIndex: number) => {
  // Your callback logic here
  console.log(
    `Face index changed from: ${previousFaceIndex} to: ${currentFaceIndex}`
  );
});

// Retrieve a specific face element by index
const faceElement = getFaceByIndex(1);
```

## API Documentation

### `init(targetId: string, config?: Cube3DConfig)`

Initializes the application with optional configuration parameters.

- `targetId` (string, optional): The ID of the target element (default is `cube-3d`).
- `config` (object, optional): Optional configuration object for width, height, baseId, initialRotation, intensity, scrollIntensity, and swipeIntensity.

#### Config

| Property Name     | Description                            | Default Value  |
| ----------------- | -------------------------------------- | -------------- |
| `width`           | Sets the width.                        | `500`          |
| `height`          | Sets the height.                       | `500`          |
| `baseId`          | Sets the baseElement ID.               | `cube-3d-base` |
| `initialRotation` | Sets the initial rotation degree.      | `0`            |
| `intensity`       | Sets the intensity of light.           | `0.2`          |
| `scrollIntensity` | Sets the intensity of light on scroll. | `1.5`          |
| `swipeIntensity`  | Sets the intensity of light on swipe.  | `75`           |

### `onRotate(callback: (currentFaceIndex: number, previousFaceIndex: number) => void)`

Registers a callback function to be executed when the rotation changes.

- `callback` (function): A function to call when the rotation changes with the detected face index and the previous face index.

### `getFaceByIndex(index: number): HTMLElement`

Retrieves a specific face element by its index.

- `index` (number): The index of the face element to retrieve.
- Returns: The element corresponding to the specified index.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
_Source: https://npm.io/package/cube-3d-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
