github-friendly-sudoku
v0.1.1
Published
Embeddable GitHub-friendly Sudoku game for the browser.
Maintainers
Readme
GitHub Friendly Sudoku
An embeddable browser Sudoku library with a GitHub-inspired default theme. The project has been refactored from a standalone page into a reusable TypeScript package with separated core logic, DOM rendering, portable styles, and a demo app for local development.
Installation
npm install github-friendly-sudokuImport the library and the default stylesheet:
import "github-friendly-sudoku/styles/base.css";
import { createSudoku } from "github-friendly-sudoku";Basic usage
import "github-friendly-sudoku/styles/base.css";
import { createSudoku } from "github-friendly-sudoku";
const game = createSudoku({
target: "#sudoku-container",
theme: "github-dark",
difficulty: "medium",
showTimer: true,
showMistakes: true,
allowNotes: true,
});
game.start();Public API
The createSudoku factory returns a controller with these methods:
start()newGame(difficulty?)restart()destroy()setTheme(theme)setDifficulty(difficulty)getState()validate()solve()toggleNotesMode()selectCell(row, col)inputValue(value)clearSelectedCell()applyHint()subscribe(listener)
Configuration options
target: CSS selector orHTMLElementtheme:"github-dark"or"github-light"difficulty:"easy" | "medium" | "hard"showTimershowMistakesshowHintsallowNotesallowKeyboardInputliveValidationlabels: partial label overridescolors: partial color overrides for theme variablescallbacks.onWincallbacks.onChangecallbacks.onMistakecallbacks.onGameStart
Styling
- Default styles live in
src/styles/base.css - All classes are namespaced with the
gsudoku-prefix - Consumers can import the default stylesheet or override the exposed CSS variables
- Theme changes can be handled through
setTheme("github-dark" | "github-light")
Project structure
src/
core/
renderers/
styles/
index.ts
demo/
index.html
main.tsLocal development
npm install
npm run devOpen the Vite demo and use the toolbar in demo/ to switch theme, change difficulty, toggle notes, restart, and start new games using only the public API.
Build
npm run buildThe package is configured for ESM output and type definitions through Vite and TypeScript.
Publishing notes
Before publishing:
npm run typecheck
npm run build
npm login
npm publishNotes:
- The package now emits both the runtime bundle and
.d.tstype definitions intodist/ prepublishOnlyruns typecheck and build automatically before publish- The package is configured for Node
20+ - If the package name is already taken on npm, update the
namefield inpackage.jsonbefore publishing - If you want to publish under an npm scope later, you may also want to add
publishConfig.access
