@hunterdoesdata/scratch-ticket
v0.1.0
Published
Skinnable WebAssembly-powered scratch-off ticket for TypeScript and Node web apps
Maintainers
Readme
ScratchNWin
@scratchnwin/scratch-ticket is a plug-and-play browser package for scratch-off games powered by Rust/WebAssembly.
Install
npm install @scratchnwin/scratch-ticketQuick Start
Use the unified factory:
import { createScratchGame } from "@scratchnwin/scratch-ticket";
const host = document.getElementById("scratch-zone");
if (host instanceof HTMLElement) {
await createScratchGame(host, {
prizeHtml: "<strong>$500</strong>"
});
}Matrix Example
import { createScratchGame } from "@scratchnwin/scratch-ticket";
const host = document.getElementById("scratch-zone");
if (host instanceof HTMLElement) {
await createScratchGame(host, {
mode: "matrix",
variant: "match",
symbols: ["🍒", "🍋", "⭐", "💎"],
matchCount: 3,
maxScratches: 3,
playId: "play_123",
singleUse: true,
callbackUrl: "/api/scratch-result"
});
}Why It’s Simple
- built JavaScript is included
- the wasm asset is included
- base styles auto-inject by default
@scratchnwin/scratch-ticket/style.cssis available if an app wants explicit CSS ownership- no consumer Rust build step
- no manual wasm copying
Main API
createScratchGame(host, options)
createScratchTicket(host, options)
createMatrixScratchGame(host, options)Most apps should start with createScratchGame().
Replay-Safe Integration
If the integrating app wants replay protection, pass a backend-issued playId and post results to a server endpoint with callbackUrl. singleUse: true blocks local resets after completion, but the backend is what actually enforces single-use play records.
More
For full options, React and Next.js examples, matrix variants, callback payloads, and packaging notes, see docs/INTEGRATION.md.
Development
npm install
npm run build
npm run demo