freedice
v1.0.0
Published
Framework-independent interactive 3D dice library
Maintainers
Readme
FreeDice
FreeDice is a framework-independent TypeScript library for two interactive, procedurally modeled D6 dice. It uses Three.js, Rapier and Web Audio, with no mandatory server, external assets, paid services or subscription. This repository is preparing v1.0; the approved [email protected] package is private in this repository and unpublished.
Physical fairness warning. The production physical roll failed its 100,000-roll statistical certification: individual faces and combined totals showed significant distribution bias. The project owner accepted this known failure as a limited release exception and deferred physical redesign and recertification. FreeDice is not certified fair and is not suitable for fairness-critical applications. Experimental A+B orientation/inertia prototypes separately showed remembered-face dependence on short gestures; that prototype is not the production runtime. The 2D fallback uses cryptographic rejection sampling and passed separate statistical cohorts, which do not establish fairness of physical rolls. See GUIDE.md and the M07 reports for evidence.
Features
- Two white, black-pipped 16 mm D6s with 2.5 mm rounded corners, glass table, shadows, adaptive rendering and a 45° rolling camera that moves to a 90° result view.
- Upward swipe, backward slingshot and keyboard controls; real Rapier motion, face detection, selective invalid-die recovery and exactly-once results.
- Typed configuration, procedural impact audio, optional vibration, accessible controls, opt-in last-result persistence and a labelled 2D fallback when initial WebGL or physics capability is unavailable.
- Standalone mode and transport-independent controller/spectator playback. Your application supplies networking, authentication, authority and turn management.
Installation and quick start
The package has not been published. Source: GitHub repository; documentation: freedice.aclub.it/docs/; issues: GitHub Issues. After publication, install [email protected] with npm and import FreeDice from freedice. After npm publication, the intended version-pinned CDN entry is https://cdn.jsdelivr.net/npm/[email protected]/dist/freedice.js. This URL is unverified and unavailable until publication. Keep all relative lazy chunks beside it; do not copy only the entry file. For local development:
npm ci
npm run verify
npm run build
npm run build:demo
npm run devOpen the local demo at http://127.0.0.1:5173/demo/ (Vite's displayed port is authoritative). For LAN testing use npm run dev:lan and port 3010; it binds to the local network, so use it only on a trusted LAN. A production application needs the complete built package, including lazy chunks; a standalone copy of freedice.js is insufficient.
// Use after publication, or replace with a local package import.
import { FreeDice } from 'freedice';
const dice = new FreeDice({ container: document.body, sound: true, vibration: false });
dice.on('result', ({ id, values, total }) => console.log(id, values, total));
dice.on('error', error => console.error(error));
await dice.open();
// Later: dice.close(); then dice.destroy() when the host removes this experience.The overlay supplies its own Roll and Continue controls. A successful result includes a unique ID, individual values and total. Call activateAudio() from a user gesture if browser audio activation is needed.
Controls and lifecycle
Swipe upward to throw, or pull the dice backward and release to launch in the opposite direction. Crossing the release boundary launches immediately. Up arrow throws; hold Down to charge a slingshot and release Down to launch. Left/right moves laterally without rolling, and combines with Up or Down for diagonal throws. Tab and Shift+Tab navigate controls; Enter/Space activate them. Escape closes only in a permitted lifecycle state. Spectators cannot roll.
FreeDice exposes initialize, open, close, reset, updateConfig, setAuthority, receive, getPlaybackSnapshot, activateAudio, on, off and destroy, plus state, config, authority and lastResult. initialize() and open() are asynchronous. Config changes are rejected during active gestures and rolls; reset() is for ready/error recovery. destroy() is idempotent and releases owned resources. See GUIDE.md for exact signatures, state and event rules.
Customization and persistence
All supported options are optional. Defaults include two D6s, 16 mm size, 5 g mass per die, 600 CSS px desktop maximum, adaptive blur, 700 ms camera transition, sound on, volume 0.45 and vibration off. Appearance, size, supported physics coefficients, results, camera timing, audio, vibration and performance settings are typed and validated. Unsafe combinations and unknown fields throw; changing physics or size requires independent realism and fairness assessment. Experimental 3 s/5 s duration profiles are demo-only and unavailable in the public API.
Set persistence: { key: 'your-app:account:game:instance' } to remember the last successful local faces through refresh/restart on the same origin. Storage is opt-in, scoped by your key, and may fail nonfatally (persistenceError). Incomplete and spectator rolls never overwrite the saved result. Stored faces are display state and never determine future physical outcomes.
Multiplayer
mode: 'controller' emits replication packets; mode: 'spectator' accepts validated packets through receive() and emits spectatorResult separately from the local authoritative result. Provide an explicit { sessionId, controllerId, epoch } authority using setAuthority. Send getPlaybackSnapshot() to late joiners and fresh keyframes after interruptions. The library provides no network transport, authorization, player count limit, server or anti-cheat guarantee. See GUIDE.md for an example and packet limits.
Compatibility, performance and accessibility
The tested scope includes user-reported Mac/iPhone Safari interaction and 12/12 keyboard/accessibility checks. Owner-reported 20-reload P95 readiness figures met numerical targets: Mac Safari 26.6.2 84 ms navigation-to-ready; iPhone Safari 27.2 613 ms, with an unexplained 11,684 ms iPhone outlier. These are rAF readiness timings, not GPU presentation or controlled cold-start measurements. Adaptive DPR/blur and a labelled 2D fallback support weaker or unavailable graphics; fallback results are sampled, not physical. iOS Safari vibration is unavailable through the standard API. The embedded Rapier WASM chunk still causes a build-size warning.
Accepted M07 verification exceptions: actual WebGL context loss/restoration, retained browser resources and memory leaks, controlled cold-start and GPU presentation, remaining browser coverage including Edge and Android, and exact missing device/OS details were not verified. Do not infer support for an untested combination. See M07 closure review. Physical fairness is a separate failed criterion as disclosed above.
Development, contribution and security
Run npm ci, then npm run verify (lint, strict type check/build, routine tests, smoke). npm run build:demo builds the playground and diagnostics. Extended fairness scripts and archived raw evidence are separate from routine tests. See CONTRIBUTING.md, SECURITY.md and CHANGELOG.md. Do not commit node_modules, dist, build, local secrets or archived raw research data. Source is MIT licensed; see LICENSE and THIRD_PARTY_NOTICES.md. The mandatory project budget remains €0.
