{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "rough-lib", "title": "Rough Theme Config", "description": "Core Rough.js theme presets, getRoughOptions, stableSeed, randomSeed, CrumbleContext, and resolveRoughVars. Required by all byDefaultHuman components.", "dependencies": [ "roughjs" ], "files": [ { "path": "registry/new-york/lib/rough.ts", "content": "import type { Options } from \"roughjs/bin/core\";\nimport { createContext, type CSSProperties } from \"react\";\n\nexport type CrumbleTheme = \"pencil\" | \"ink\" | \"crayon\";\n\nexport type ComponentVariant = \"border\" | \"fill\" | \"interactive\" | \"chart\";\n\nexport const roughThemes: Record = {\n pencil: {\n roughness: 1.2,\n bowing: 1,\n strokeWidth: 1,\n fillStyle: \"hachure\",\n fillWeight: 0.8,\n hachureGap: 6,\n hachureAngle: -41,\n preserveVertices: false,\n },\n ink: {\n roughness: 0.6,\n bowing: 0.5,\n strokeWidth: 2,\n fillStyle: \"solid\",\n fillWeight: 2,\n preserveVertices: false,\n },\n crayon: {\n roughness: 2.4,\n bowing: 2,\n strokeWidth: 3.5,\n fillStyle: \"zigzag\",\n fillWeight: 1.5,\n hachureGap: 5,\n hachureAngle: -41,\n preserveVertices: false,\n },\n};\n\nexport const componentOverrides: Record<\n ComponentVariant,\n Partial>>\n> = {\n border: {\n pencil: { roughness: 0.8, strokeWidth: 1 },\n ink: { roughness: 0.4, strokeWidth: 1.5 },\n crayon: { roughness: 2, strokeWidth: 3 },\n },\n fill: {\n pencil: { roughness: 1, fillWeight: 0.6, hachureGap: 8 },\n ink: { roughness: 0.3, fillStyle: \"solid\" },\n crayon: { roughness: 2.2, fillWeight: 1.2, hachureGap: 4 },\n },\n interactive: {\n pencil: { roughness: 1.5, bowing: 1.2 },\n ink: { roughness: 0.8, bowing: 0.6 },\n crayon: { roughness: 2.8, bowing: 2.5 },\n },\n chart: {\n pencil: { roughness: 1, strokeWidth: 1.2, fillStyle: \"hachure\" },\n ink: { roughness: 0.5, strokeWidth: 2, fillStyle: \"solid\" },\n crayon: { roughness: 2, strokeWidth: 3, fillStyle: \"zigzag\" },\n },\n};\n\nexport function getRoughOptions(\n theme: CrumbleTheme,\n variant: ComponentVariant = \"border\",\n extra?: Partial,\n): Options {\n const base = roughThemes[theme];\n const override = componentOverrides[variant]?.[theme] ?? {};\n\n return { ...base, ...override, ...extra };\n}\n\nexport function stableSeed(id: string): number {\n let hash = 5381;\n\n for (let i = 0; i < id.length; i += 1) {\n hash = (hash * 33) ^ id.charCodeAt(i);\n }\n\n return Math.abs(hash);\n}\n\nexport function randomSeed(): number {\n return Math.floor(Math.random() * 2 ** 31);\n}\n\nexport interface CrumbleConfig {\n theme: CrumbleTheme;\n animateOnMount: boolean;\n animateOnHover: boolean;\n}\n\nconst config: CrumbleConfig = {\n theme: \"pencil\",\n animateOnMount: true,\n animateOnHover: true,\n};\n\nexport function configureCrumble(options: Partial): void {\n if (options.theme !== undefined) {\n config.theme = options.theme;\n }\n\n if (options.animateOnMount !== undefined) {\n config.animateOnMount = options.animateOnMount;\n }\n\n if (options.animateOnHover !== undefined) {\n config.animateOnHover = options.animateOnHover;\n }\n}\n\nexport function getCrumbleConfig(): CrumbleConfig {\n return { ...config };\n}\n\nexport interface CrumbleContextValue {\n theme: CrumbleTheme;\n animateOnMount: boolean;\n animateOnHover: boolean;\n}\n\nexport const CrumbleContext = createContext({\n theme: \"pencil\",\n animateOnMount: true,\n animateOnHover: true,\n});\n\nexport interface CrumbleColorProps {\n stroke?: string;\n strokeMuted?: string;\n fill?: string;\n}\n\nexport function resolveRoughVars({\n stroke,\n strokeMuted,\n fill,\n}: CrumbleColorProps = {}): CSSProperties {\n const resolved: Record = {\n \"--cr-stroke\": stroke,\n \"--cr-stroke-muted\":\n strokeMuted ??\n (stroke ? `color-mix(in srgb, ${stroke} 40%, transparent)` : undefined),\n \"--cr-fill\": fill,\n };\n\n return Object.fromEntries(\n Object.entries(resolved).filter(([, value]) => value !== undefined),\n ) as CSSProperties;\n}\n", "type": "registry:lib", "target": "lib/rough.ts" } ], "type": "registry:lib" }