UNPKG

tiny-dices

Version:

Tiny Dices adds a sprinkle of fun and a touch of magic to your dice-rolling adventures โ€” fully customizable with CSS and JavaScript to match your style, theme, or imagination! ๐ŸŽฒโœจ

121 lines (75 loc) โ€ข 2.78 kB
## ๐ŸŽฒ Dice Management Control and manage individual 3D dice, from creating and styling them to inserting or clearing them from the display area. --- ### ๐Ÿ”ข `addCubeId()` Increments and returns the current internal cube ID used for z-index stacking. ```js const id = dice.addCubeId(); ``` Returns: `number` โ€“ The current cube ID before incrementing. ๐Ÿง  Each new die receives a unique ID so it appears above older ones. --- ### โž• `addElement(item)` Adds a new dice element to the internal list. ```js const success = dice.addElement({ faces: [face1, face2, face3, face4, face5, face6], container: outerDiv, wrapper: innerCube }); ``` | Param | Type | Description | |-------|------|-------------| | `item` | `{ faces: HTMLElement[], container: HTMLElement, wrapper: HTMLElement }` | The die element with 6 faces and container elements. | Returns: `boolean` โ€“ `true` if added successfully; otherwise `false`. โœ… This ensures each die has the correct structure. --- ### ๐ŸŽจ `updateDiceFaceSkin(face)` Applies current visual styles (color, image, etc.) to a single face of a die. ```js dice.updateDiceFaceSkin(faceElement); ``` | Param | Type | Description | |-------|------|-------------| | `face` | `HTMLElement` | A single die face element. | Returns: `void` --- ### ๐ŸŽฒ `updateDiceSkin(index)` Updates the skin of a specific die by index (color, border, text, and image). ```js const updated = dice.updateDiceSkin(0); ``` | Param | Type | Description | |-------|------|-------------| | `index` | `number \| string` | Index of the die to update. | Returns: `boolean` โ€“ `true` if the die was found and updated; otherwise `false`. --- ### ๐Ÿงฎ `updateDicesSkin()` Updates the skin of **all** dice currently on screen. ```js dice.updateDicesSkin(); ``` Returns: `void` ๐Ÿš€ Uses the current active skin settings and reapplies them to every die. --- ### ๐ŸŽ `insertDiceElement(result, max, canZero, rollInfinity)` Creates and inserts a 3D dice into the display area. ```js const sequence = dice.insertDiceElement(4, 6, false, true); ``` | Param | Type | Description | |--------|-----------|-------------| | `result` | `number` | Value shown on the front face of the die. | | `max` | `number` | Maximum value (i.e. the "sides" of the die). | | `canZero` | `boolean` | Whether face value can be 0. | | `rollInfinity` | `boolean` | Whether the die rolls forever. | Returns: `number[]` โ€“ The randomized sequence of values assigned to the six faces. ๐ŸŽฒ Each die gets animated, rendered, and z-stacked dynamically. --- ### ๐Ÿงผ `clearDiceArea()` Removes **all** dice from the display and resets internal IDs. ```js dice.clearDiceArea(); ``` Returns: `void` ๐Ÿงน Great for resetting the board or starting fresh.