Open-Source Browser Graphics & CSPRNG Reference

Canvas Story & Deck Kit: 1080x1920 Safe-Zone Canvas2D & Unbiased 78-Card Shuffles

Zero-dependency JavaScript primitives for instant 9:16 Story PNG export without html2canvas, metric-callback greedy word-wrapping, 180-degree center-pivot card matrices, privacy-safe payload stripping, and rejection-sampled Web Crypto Fisher-Yates deck draws.

Interactive 1080x1920 Story Canvas Verifier & Live PNG Exporter

Powered directly in your browser by deck-story-kit.mjs. Switch spread layouts, inspect the y: 220..1660 social UI safe zones, test privacy prompt stripping, and export a true 1080x1920 PNG.

Canvas2D Render Time 0.0 ms
9:16 Safe-Zone Check y: 220..1660 OK
Lead Card Pivot Matrix [1, 0, 0, 1, 0, 0]
78-Card Rejection Cutoff 4,294,967,274 (tail 22)

1. Direct 1080x1920 Canvas2D Primitives vs. DOM-to-Canvas Cloners

DOM-scraping libraries like html2canvas and SVG <foreignObject> serialize the entire document stylesheet, often stalling the mobile main thread for 400ms to 800ms while triggering WebKit tainted-canvas exceptions or missing webfont glyphs on iOS Safari. Painting directly onto an offscreen 1080x1920 2D context completes in under 12ms and hands a native PNG File directly to navigator.share({ files }).

9:16 Story Zone Pixel Range (1080x1920) Platform Overlay Hazard
Top Header Unsafe Zone y: 0 .. 220 (220px) Story progress bars, creator avatar, audio ticker, and close icon
Active Safe Stage y: 220 .. 1660 (1440px) Unobstructed region for card artwork, badges, wrapped insights, and attribution
Bottom Reply Unsafe Zone y: 1660 .. 1920 (260px) Send-message input pill, reaction bar, and mobile home indicator
// 180-degree center-pivot affine matrix for reversed cards:
// T(cx, cy) * R(pi) * T(-cx, -cy) = [cos pi, sin pi, -sin pi, cos pi, 2*cx, 2*cy]
const pivotMatrix = [-1, 0, 0, -1, 2 * cx, 2 * cy];
ctx.transform(...pivotMatrix); // Rotates card upside-down while keeping [x, x+w] x [y, y+h] invariant

2. Pure Metric-Callback Greedy Word-Wrap & Ellipsis Clamping

Canvas2D provides ctx.measureText(str).width but zero built-in multi-line text layout. Accepting a pure width callback (text) => width lets the exact same greedy line-breaker, long-token hyphenator, and trailing-punctuation ellipsis clamper run inside browser 2D contexts and zero-DOM Node.js unit tests:

import { wrapParagraphToLines } from "./deck-story-kit.mjs";

const lines = wrapParagraphToLines(
  paragraphText,
  828, // maxWidth inside 912px safe stage minus 42px card padding
  (str) => ctx.measureText(str).width,
  { maxLines: 4, ellipsis: "…" }
);

3. Rejection-Sampled Web Crypto Shuffling & Local-Date Daily Seeds

Reducing a random 32-bit unsigned integer with u32 % 78 introduces modulo bias because 2^32 = 4,294,967,296 = 55,063,683 * 78 + 22. Rejecting the top 22 values (u32 >= 4,294,967,274) guarantees exact equiprobability across all 78 cards. For reproducible daily draws, formatLocalDateSeed() anchors the seed to local calendar components (getFullYear, getMonth + 1, getDate) instead of UTC toISOString() so cards roll over at local midnight.

import {
  createStandard78TarotDeck,
  drawSpreadWithOrientation,
  formatLocalDateSeed,
} from "./deck-story-kit.mjs";

const deck = createStandard78TarotDeck();

// Unbiased Web Crypto 3-card spread with independent 1-bit orientation flags
const spread = drawSpreadWithOrientation(deck, 3, {
  slotLabels: ["Signal", "Friction", "Next Move"],
});

// Deterministic daily card anchored to the user's local YYYY-MM-DD date
const daily = drawSpreadWithOrientation(deck, 1, {
  seed: formatLocalDateSeed(new Date(), "daily-vibe"),
});

4. Privacy-by-Architecture Story Payload Stripping

Reflection and tarot tools frequently invite visitors to type deeply personal career or relationship prompts before drawing cards. Rather than hiding typed text visually, buildPrivacySafeStoryPayload() enforces an explicit allowlist and strips private fields (question, prompt, notes, rawInput) before any Canvas2D draw command runs.

5. Production Browser Implementations

These zero-login browser tools run the rejection-sampled 78-card shuffle, local-date daily seed, and privacy-safe 1080x1920 Story Canvas2D exporter in production:

6. Run the Zero-Dependency Node.js Test Suite

Clone github.com/kaiyilu/canvas-story-deck-kit and run the unit test suite on Node.js 18+:

git clone https://github.com/kaiyilu/canvas-story-deck-kit.git
cd canvas-story-deck-kit
node --test
node deck-story-kit.mjs