npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trailofdad/morphkit-calculator

v0.4.0

Published

Ball python breeding calculator built on morphkit: parent selection, zygosity, folded outcomes and morph labels.

Readme

@trailofdad/morphkit-calculator

A ball python breeding calculator built on morphkit and the morphkit-dictionary.

morphkit does the genetics: Punnett squares, sex linkage, combos, lethals. This package is the calculator layer on top of it:

  • parent and trait selection, including allelic-group compounds (Yellowbelly + Asphalt) and Banana male-maker / female-maker
  • zygosity options per inheritance type
  • outcomes grouped one row per visual phenotype
  • the "66% Het" convention
  • labels, combo descriptions and short names
  • a framework-free state reducer

The core has no React or DOM dependency. An optional React layer lives at /react.

Install

npm install @trailofdad/morphkit-calculator @trailofdad/morphkit

@trailofdad/morphkit is a peer dependency. So is react (18.2+), but only if you use /react.

React

import { Calculator } from '@trailofdad/morphkit-calculator/react';
import '@trailofdad/morphkit-calculator/styles.css'; // optional default theme

export function Page() {
  return <Calculator />; // loads the pinned dictionary, with loading and retry states
}

Pass dictionary if you already hold one. parentActions={(parent) => …} adds header controls to each parent panel (e.g. "load from collection"). Children render inside the calculator's provider, so useCalculator() works there, e.g. to loadGenetics('sire', animal.genetics) from a deep link.

The pieces can also be used on their own:

| Export | What it is | | ---------------------------------------- | -------------------------------------------------------------------------------- | | CalculatorProvider / useCalculator() | Pairing state, results and actions for the components below it | | useCalculatorController(dictionary) | The same, as a plain hook | | useDictionary(options?) | loading / ready / error with retry(); one request per URL per page | | ParentPanel, Results | One parent's trait input, and the results, bound to the provider | | TraitPicker | Context-free trait search + selected list; also suits an "edit animal" form | | OutcomeList | Context-free list of folded outcomes, with renderActions / renderCombo hooks | | MorphChip, GeneticsChips | A trait chip, and an animal's stored genetics as chips |

Styling

Components ship unstyled. Each element carries a stable mkc-* class, and state appears as attributes (data-inheritance, data-parent, data-lethal, data-sex, aria-selected). Then either:

  • import styles.css and theme it by overriding the --mkc-* variables (light and dark included), or
  • skip it and pass your own classes through each component's className and classNames slots, e.g. <TraitPicker classNames={{ input: 'h-11 rounded-xl border' }} />.

renderZygosity on TraitPicker / ParentPanel swaps the default radio group for your own segmented control. renderCombo on OutcomeList / Results wraps a combo chip, for example in your own tooltip.

Playground

npm run playground   # Vite on http://localhost:5199, running against src/

Core usage

import {
  buildAlleleList,
  calculate,
  calculatorReducer,
  createCalculatorState,
  loadDictionary,
  possHetPercent,
  traitFromSuggestion,
} from '@trailofdad/morphkit-calculator';

const dict = await loadDictionary(); // pinned morphkit-dictionary release
const alleles = buildAlleleList(dict);
const pick = (id: string) => traitFromSuggestion(alleles.find((a) => a.alleleId === id)!);

let state = createCalculatorState();
state = calculatorReducer(state, { type: 'addTrait', parent: 'sire', trait: pick('pastel') });
state = calculatorReducer(state, { type: 'addTrait', parent: 'dam', trait: pick('spider') });

const result = calculate(state, dict);
if (result.status === 'ok') {
  for (const o of result.outcomes) {
    console.log(o.comboName ?? o.phenotypeNames.join(' '), o.percentageProbability, o.isLethal);
    for (const h of o.possibleHets) console.log(`  ${possHetPercent(h.probability)}% het`, h);
  }
}

Lower-level pieces are exported too:

  • runPairing / calcPairing take parent states or raw LocusInput[] genotypes.
  • fromLocusInputs loads stored genetics into selections.
  • resolveTargetGenotype carries a grouped outcome forward as a new parent.
  • morphTag, traitLabel, describeCombo and comboParts produce labels.
  • searchAlleles ranks alleles for a query by name, then alias, then gene name (so "piebald" finds Pied).

Loading the dictionary

loadDictionary() fetches a pinned morphkit-dictionary release from jsDelivr (DEFAULT_DICTIONARY_VERSION). Pass { version }, { url } or { fetch } to override it. Every failure (network, HTTP status, a payload that isn't a dictionary) throws a DictionaryLoadError, so the caller can show an error state. You can also pass in any MorphkitDictionary you already hold.

Development

npm install
npm test           # vitest
npm run typecheck
npm run lint
npm run build      # tsup → dist/ (ESM + CJS + .d.ts, plus styles.css)

Tests run offline against a pinned copy of the dictionary in tests/fixtures/. React tests run in jsdom.

Releases are tag-driven. Bump version with npm version, then push the commit and the v* tag. CI stages the release on npm via trusted publishing, and a maintainer approves it with npm stage approve <stage-id>.

License

MIT