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

@card-builder/renderer

v0.1.1

Published

Embeddable Three.js renderer for Card Builder cards and acrylic slabs

Readme

@card-builder/renderer

Embeddable Three.js 3D card renderer extracted from Card Builder. Renders NBA-style trading cards inside acrylic slab enclosures with PBR materials, holographic foil effects, and pointer-driven tilt interaction.

The package owns only its supplied canvas and host element. It never queries the DOM or reads host-application global state; product state, card texture rendering, and view persistence are the caller's responsibility via a bridge object.

Install

npm install @card-builder/renderer three

three (≥ 0.185) is a peer dependency. The ESM bundle leaves Three.js external; the UMD bundle expects the THREE global supplied by the classic Three.js CDN script.

Quick start

import { createCardRenderer } from "@card-builder/renderer";

const renderer = createCardRenderer({
  host: document.querySelector("#preview"),
  canvas: document.querySelector("#preview canvas"),
  bridge: {
    getState() { return myCardState; },
    setView(v) { Object.assign(myCardState, v); },
    flip()     { myCardState.flipped = !myCardState.flipped; },
    async renderCardCanvas(side, w, h) {
      // Draw the 2D card face onto a canvas and return it
      const c = document.createElement("canvas");
      c.width = w; c.height = h;
      await drawMyCard(c.getContext("2d"), side);
      return c;
    },
  },
});

// Push state updates
renderer.setState({ effect: "holographic", rarity: "gold", slabType: "acrylic" });

// High-res export
const exportCanvas = renderer.captureCanvas(2400, 3200);

// Cleanup
renderer.destroy();

CDN usage (no bundler)

<script type="importmap">
{
  "imports": {
    "three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
    "three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/",
    "@card-builder/renderer": "https://cdn.jsdelivr.net/npm/@card-builder/renderer/dist/card-renderer.esm.js"
  }
}
</script>
<script type="module">
  import { createCardRenderer } from "@card-builder/renderer";
  // ...
</script>

Or with a classic <script> tag (UMD):

<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@card-builder/renderer/dist/card-renderer.umd.js"></script>
<script>
  const renderer = CardBuilderRenderer.createCardRenderer({ /* ... */ });
</script>

API

createCardRenderer(options): CardRenderer

| Option | Type | Default | Description | |---|---|---|---| | host | HTMLElement | required | Container the renderer sizes itself to | | canvas | HTMLCanvasElement | required | WebGL output canvas | | status | HTMLElement \| null | null | Element for status text updates | | bridge | RendererBridge | required | Callbacks connecting to host app | | runtime | RendererRuntime | globalThis | Injected browser timers, media query, ResizeObserver and document capabilities | | eventTarget | EventTarget | runtime | Target for custom events | | documentTarget | Document | runtime.document | Document for off-screen canvases | | autoListen | boolean | true | Listen for cardbuilder:state/cardbuilder:view events |

RendererBridge

| Method | Signature | Purpose | |---|---|---| | getState | () => RendererState | Return initial card state | | setView | (view: ViewState) => void | Receive camera changes from OrbitControls | | flip | () => void | Request card flip on double-click | | renderCardCanvas | (side, w, h) => Promise<Canvas> | Render a 2D card face texture |

CardRenderer (returned object)

| Member | Description | |---|---| | ready | true after WebGL init, false after destroy() | | setState(state) | Push new card state (triggers slab rebuild if slabType changed) | | setView(view) | Reposition camera ({ rotX, rotY, viewScale, motionOn }) | | resize() | Force resize (normally automatic via ResizeObserver) | | rebuild() | Tear down and rebuild the slab shell | | captureCanvas(w, h) | Render to an off-screen canvas at given dimensions | | getHoverTiltState() | Read hover-tilt spring state for debugging | | destroy() | Release all WebGL resources and listeners |

Config exports

import { CARD_DIMENSIONS, SLAB_CONFIGS, HOLO_EFFECT_MODES, cardEdgeColor, normalizeRendererState } from "@card-builder/renderer";

| Export | Description | |---|---| | CARD_DIMENSIONS | Card width/height/depth in world units | | SLAB_CONFIGS | Physical configs for 7 slab types | | HOLO_EFFECT_MODES | Effect name → shader mode index | | cardEdgeColor(rarity) | Returns hex edge color for a rarity | | normalizeRendererState(input) | Clamp/default a raw state object |

Slab types

| Type | Description | |---|---| | none | Raw card, no enclosure | | magnetic | Thin magnetic case | | forge | Mid-depth display case | | museum | Warm-tinted exhibition case | | acrylic | Full acrylic slab (default) | | crystal | Ultra-clear thin crystal case | | gallery | Deep gallery-style enclosure |

Effects

none · diamond · lightning · rainbow · crystal · holographic · laser · flame · galaxy

Each maps to a WebGL shader mode with pointer-driven foil interaction.

TypeScript

Full type declarations ship with the package (src/index.d.ts, src/config.d.ts). No @types package needed.

Development

cd packages/renderer
npm install
npm test          # Run unit tests
npm run build     # Build ESM + UMD bundles in dist/

Commercial licensing & support

Looking to embed this renderer in your own card platform, need custom slab types or effects, or want integration support? Reach out:

License

MIT