Isometric line figures that answer the pointer. For React and for anything with a DOM.
Registry: the shadcn item, its URL from the environment, validated against shadcn's schema
Lucas Marquese91915957042
diff --git a/apps/site/.gitignore b/apps/site/.gitignorenew file mode 100644index 0000000..4b3fc13--- /dev/null+++ b/apps/site/.gitignore@@ -0,0 +1,4 @@+.next/+next-env.d.ts+# written by registry/build.mjs before every build+public/r/diff --git a/package.json b/package.jsonindex ae01217..b240517 100644--- a/package.json+++ b/package.json@@ -17,6 +17,7 @@"release": "node scripts/release.mjs"},"devDependencies": {+ "ajv": "8.20.0","turbo": "^2.10.5","typescript": "5.9.3"},diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f9bdc86..0243cc5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -8,6 +8,9 @@ importers:.:devDependencies:+ ajv:+ specifier: 8.20.0+ version: 8.20.0turbo:specifier: ^2.10.5version: 2.11.6@@ -832,6 +835,9 @@ packages:engines: {node: '>=0.4.0'}hasBin: true+ resolution: {integrity: sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==}+resolution: {integrity: sha512-BvU8nYgGQBxcmMuEeUEmNTvrMVjJNSH7RgW24vXexN4Ven6qCvy4TntnvlnwnMLTVlcRQQdbRY8NKnaIoeWDNg==}engines: {node: '>=18'}@@ -1004,6 +1010,12 @@ packages:resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==}engines: {node: '>=12.0.0'}+ resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==}++ resolution: {integrity: sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==}+resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==}engines: {node: '>=12.0.0'}@@ -1062,6 +1074,9 @@ packages:canvas:optional: true+ resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}+resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==}engines: {node: '>= 12.0.0'}@@ -2089,6 +2104,13 @@ snapshots:+ dependencies:+ fast-deep-equal: 3.1.3+ fast-uri: 3.1.8+ json-schema-traverse: 1.0.0+ require-from-string: 2.0.2+dependencies:environment: 1.1.0@@ -2276,6 +2298,10 @@ snapshots:+ [email protected]: {}++ [email protected]: {}+optionalDependencies:picomatch: 4.0.7@@ -2336,6 +2362,8 @@ snapshots:transitivePeerDependencies:- '@noble/hashes'+ [email protected]: {}+optional: truediff --git a/registry/build.mjs b/registry/build.mjsnew file mode 100644index 0000000..e4d9ca7--- /dev/null+++ b/registry/build.mjs@@ -0,0 +1,38 @@+#!/usr/bin/env node+/**+ * Writes the shadcn registry item into the site's public folder.+ *+ * `shadcn add` fetches an item by absolute URL, so a hostname has to be in the+ * output and may not be in the source: it comes from the environment (see+ * scripts/base-url.mjs). Everything under apps/site/public/r is generated.+ */+import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { FALLBACK, resolveBase } from "../scripts/base-url.mjs";++const SRC = join(import.meta.dirname, "src");+const OUT = join(import.meta.dirname, "..", "apps", "site", "public", "r");++const resolved = resolveBase();+if (resolved.source === "fallback") {+ console.warn(`[registry] no site URL in the environment; using ${FALLBACK}.\n[registry] A deployed build that prints this line has published an item that points at localhost.`);+}+const BASE = resolved.url.replace(/\/+$/, "");++const item = {+ $schema: "https://ui.shadcn.com/schema/registry-item.json",+ name: "hairline",+ type: "registry:ui",+ title: "Hairline",+ description: "Six isometric line figures that answer the pointer, with their palette mapped to your theme's tokens.",+ dependencies: ["@lucasmarkes/hairline"],+ files: [{ path: "components/ui/hairline.tsx", type: "registry:ui", content: readFileSync(join(SRC, "hairline.tsx"), "utf8") }],+ docs: `Docs: ${BASE}`,+};++rmSync(OUT, { recursive: true, force: true });+mkdirSync(OUT, { recursive: true });+writeFileSync(join(OUT, "hairline.json"), JSON.stringify(item, null, 2) + "\n");+writeFileSync(join(OUT, "registry.json"), JSON.stringify({ $schema: "https://ui.shadcn.com/schema/registry.json", name: "hairline", homepage: BASE, items: [item] }, null, 2) + "\n");++console.log(`[registry] ${BASE}/r/hairline.json (base from ${resolved.source})`);diff --git a/registry/src/hairline.tsx b/registry/src/hairline.tsxnew file mode 100644index 0000000..2f96204--- /dev/null+++ b/registry/src/hairline.tsx@@ -0,0 +1,43 @@+"use client";++import type { ComponentProps, CSSProperties } from "react";+import * as Hairline from "@lucasmarkes/hairline/react";++/**+ * hairline, wearing your theme. The six figures from @lucasmarkes/hairline,+ * with their palette mapped to shadcn's tokens, so they follow light, dark and+ * whatever you have made of them. A `style` you pass wins over the mapping.+ *+ * Docs: https://hairline.lucasmarkes.com+ */+const tokens = {+ "--hairline-plate": "var(--background)",+ "--hairline-hi": "var(--foreground)",+ "--hairline-edge": "var(--muted-foreground)",+ "--hairline-mid": "color-mix(in oklab, var(--muted-foreground) 55%, var(--background))",+ "--hairline-lo": "var(--border)",+} as CSSProperties;++export function Riffle({ style, ...props }: ComponentProps<typeof Hairline.Riffle>) {+ return <Hairline.Riffle style={{ ...tokens, ...style }} {...props} />;+}++export function Terrain({ style, ...props }: ComponentProps<typeof Hairline.Terrain>) {+ return <Hairline.Terrain style={{ ...tokens, ...style }} {...props} />;+}++export function Exploded({ style, ...props }: ComponentProps<typeof Hairline.Exploded>) {+ return <Hairline.Exploded style={{ ...tokens, ...style }} {...props} />;+}++export function Phosphor({ style, ...props }: ComponentProps<typeof Hairline.Phosphor>) {+ return <Hairline.Phosphor style={{ ...tokens, ...style }} {...props} />;+}++export function Slow({ style, ...props }: ComponentProps<typeof Hairline.Slow>) {+ return <Hairline.Slow style={{ ...tokens, ...style }} {...props} />;+}++export function Turntable({ style, ...props }: ComponentProps<typeof Hairline.Turntable>) {+ return <Hairline.Turntable style={{ ...tokens, ...style }} {...props} />;+}diff --git a/registry/validate.mjs b/registry/validate.mjsnew file mode 100644index 0000000..6693b94--- /dev/null+++ b/registry/validate.mjs@@ -0,0 +1,38 @@+#!/usr/bin/env node+/**+ * Checks the generated registry item against shadcn's own schema, fetched+ * from ui.shadcn.com, and against what this repository promises about it.+ *+ * node registry/build.mjs && node registry/validate.mjs+ */+import { readFileSync } from "node:fs";+import { join } from "node:path";+import Ajv from "ajv";++const SCHEMA = "https://ui.shadcn.com/schema/registry-item.json";+const file = join(import.meta.dirname, "..", "apps", "site", "public", "r", "hairline.json");++let item;+try { item = JSON.parse(readFileSync(file, "utf8")); }+catch { console.error(`No item at ${file}. Run \`node registry/build.mjs\` first.`); process.exit(1); }++const response = await fetch(SCHEMA);+if (!response.ok) { console.error(`Could not fetch ${SCHEMA}: ${response.status}`); process.exit(1); }+const schema = await response.json();+// The schema names its draft by an https URL that Ajv does not know; draft-07 is Ajv's default.+delete schema.$schema;+const validate = new Ajv({ strict: false, allErrors: true }).compile(schema);++const problems = [];+if (!validate(item)) for (const e of validate.errors) problems.push(`schema: ${e.instancePath || "/"} ${e.message}`);+const [source] = item.files ?? [];+if (item.dependencies?.join() !== "@lucasmarkes/hairline") problems.push("dependencies must be exactly @lucasmarkes/hairline");+if (source?.path !== "components/ui/hairline.tsx") problems.push("the file must be components/ui/hairline.tsx");+if (!source?.content?.startsWith('"use client";')) problems.push('the file must start with "use client"');+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable"]) {+ if (!source?.content?.includes(`export function ${name}(`)) problems.push(`the file does not export ${name}`);+}+if (/localhost/.test(JSON.stringify(item)) && process.env.VERCEL) problems.push("the item points at localhost in a deployed build");++if (problems.length) { console.error(problems.map((p) => ` ✗ ${p}`).join("\n")); process.exit(1); }+console.log(" ✓ hairline.json is a valid shadcn registry item");diff --git a/scripts/base-url.mjs b/scripts/base-url.mjsnew file mode 100644index 0000000..21b7283--- /dev/null+++ b/scripts/base-url.mjs@@ -0,0 +1,35 @@+/**+ * Where this build thinks it lives.+ *+ * Two things need an absolute URL in their output and may not have one in+ * their source: the shadcn registry item, which `shadcn add` fetches by URL,+ * and the Open Graph tags, which crawlers do not resolve relatively. Both ask+ * here, so localhost, a preview and production differ only by environment.+ *+ * The ladder goes from the most specific answer to the least. An explicit+ * override wins; production names itself; anything else on Vercel is a preview+ * and names itself too, which is what makes a preview testable: its registry+ * item installs from that preview.+ */++export const FALLBACK = "http://localhost:3000";++export function resolveBase() {+ const explicit = process.env.HAIRLINE_REGISTRY_URL?.trim();+ if (explicit) return { url: explicit, source: "HAIRLINE_REGISTRY_URL" };++ const productionHost = process.env.VERCEL_PROJECT_PRODUCTION_URL?.trim();+ if (process.env.VERCEL_ENV === "production" && productionHost) {+ return { url: `https://${productionHost}`, source: "VERCEL_PROJECT_PRODUCTION_URL" };+ }++ const deploymentHost = process.env.VERCEL_URL?.trim();+ if (deploymentHost) return { url: `https://${deploymentHost}`, source: "VERCEL_URL" };++ return { url: FALLBACK, source: "fallback" };+}++/** The same answer without trailing slashes, ready to have a path added. */+export function resolveBaseUrl() {+ return resolveBase().url.replace(/\/+$/, "");+}