Skip to content

anbeime/skill / skills/hairline/hairline

hairline

Flagged

一句话生成跟随鼠标的交互式等轴测线框图(单文件、零依赖、双击即开),或把已有 SVG/Logo 重建为可交互线框。

FileKindSize
.github/FUNDING.ymlconfig20 B
.github/workflows/ci.ymlconfig1.2 KB
.github/workflows/consumers.ymlconfig954 B
.github/workflows/publish.ymlconfig3.0 KB
.gitignoreother351 B
.npmrcother55 B
CHANGELOG.mdmarkdown7.6 KB
CONTRIBUTING.mdmarkdown4.5 KB
LICENSEother1.0 KB
README.mdmarkdown11.5 KB
SKILL.mdskill md1.2 KB
apps/site/.gitignoreother82 B
apps/site/.vitest/json/output.jsonconfig22.3 KB
apps/site/app/docs/page.tsxother2.9 KB
apps/site/app/docs/sections.tsxother8.1 KB
apps/site/app/figures/page.tsxother2.4 KB
apps/site/app/globals.cssother43.7 KB
apps/site/app/inspo/page.tsxother14.0 KB
apps/site/app/layout.tsxother978 B
apps/site/app/llms.txt/route.tsscript228 B
apps/site/app/og/page.tsxother1.5 KB
apps/site/app/page.tsxother1.7 KB
apps/site/app/robots.tsscript382 B
apps/site/app/sitemap.tsscript382 B
apps/site/app/skills/page.tsxother6.2 KB
apps/site/components/anchor.tsxother1.3 KB
apps/site/components/assembly.tsxother10.2 KB
apps/site/components/catalogue.tsxother18.6 KB
apps/site/components/chrome.tsxother2.3 KB
apps/site/components/code-block.tsxother895 B
apps/site/components/command.tsxother1.6 KB
apps/site/components/copy.tsxother2.6 KB
apps/site/components/example-frame.tsxother3.1 KB
apps/site/components/install.tsxother1.7 KB
apps/site/components/made-frame.tsxother2.0 KB
apps/site/components/rail.tsxother11.0 KB
apps/site/components/skill-link.tsxother861 B
apps/site/components/tabs.tsxother4.1 KB
apps/site/next.config.mjsscript493 B
apps/site/package.jsonmanifest927 B
apps/site/playwright.config.tsscript485 B
apps/site/postcss.config.mjsscript60 B
apps/site/public/icon.svgother262 B
apps/site/public/inspo/craft.webpbinary61.9 KB
apps/site/public/inspo/dissection.webpbinary177.4 KB
apps/site/public/inspo/figures.webpbinary56.9 KB
apps/site/public/inspo/linear.webpbinary15.6 KB
apps/site/public/inspo/tune.webpbinary58.5 KB
apps/site/public/og.pngbinary94.3 KB
apps/site/public/skill/hairline-clearance.htmlother39.5 KB
apps/site/public/skill/hairline-cursor-tab.htmlother43.4 KB
apps/site/public/skill/hairline-deploy-liftoff.htmlother43.3 KB
apps/site/public/skill/hairline-firecrawl-reader.htmlother46.6 KB
apps/site/public/skill/hairline-funnel.htmlother40.4 KB
apps/site/public/skill/hairline-linear-cycle.htmlother43.5 KB
apps/site/public/skill/hairline-mastra.htmlother44.6 KB
apps/site/public/skill/hairline-notion.htmlother41.5 KB
apps/site/public/skill/hairline-resend-belt.htmlother46.5 KB
apps/site/public/skill/hairline-sidings.htmlother43.1 KB
apps/site/public/skill/hairline-storm.htmlother42.6 KB
apps/site/public/skill/hairline-vercel.htmlother40.6 KB
apps/site/test/catalogue.test.tsscript2.7 KB
apps/site/test/docs.test.tsscript8.9 KB
apps/site/test/figures.spec.tsscript15.0 KB
apps/site/test/share.test.tsscript652 B
apps/site/test/site.spec.tsscript44.8 KB
apps/site/test/skill.spec.tsscript17.8 KB
apps/site/test/skill.test.tsscript5.4 KB
apps/site/tsconfig.jsonconfig444 B
apps/site/turbo.jsonconfig364 B
apps/site/vercel.jsonconfig214 B
apps/site/vitest.config.tsscript265 B
assets/hero.gifbinary3.7 MB
fixtures/next-app/.gitignoreother123 B
fixtures/next-app/app/layout.tsxother281 B
fixtures/next-app/app/page.tsxother587 B
fixtures/next-app/app/registry/page.tsxother714 B
fixtures/next-app/app/vanilla.tsxother353 B
fixtures/next-app/next.config.mjsscript104 B
fixtures/next-app/package.jsonmanifest364 B
fixtures/next-app/tsconfig.jsonconfig590 B
fixtures/vite-vanilla/.gitignoreother38 B
fixtures/vite-vanilla/index.htmlother1.3 KB
fixtures/vite-vanilla/package.jsonmanifest245 B
fixtures/vite-vanilla/src/main.tsscript1.3 KB
fixtures/vite-vanilla/tsconfig.jsonconfig248 B
package.jsonmanifest895 B
packages/hairline/package.jsonmanifest2.4 KB
packages/hairline/playwright.config.tsscript637 B
packages/hairline/src/core/iso.tsscript9.1 KB
packages/hairline/src/core/motion.tsscript3.8 KB
packages/hairline/src/core/stage.tsscript15.0 KB
packages/hairline/src/core/styles.tsscript4.1 KB
packages/hairline/src/figures/basket.tsscript9.5 KB
packages/hairline/src/figures/branches.tsscript7.7 KB
packages/hairline/src/figures/cabinet.tsscript7.8 KB
packages/hairline/src/figures/dish.tsscript9.7 KB
packages/hairline/src/figures/drawer.tsscript7.5 KB
packages/hairline/src/figures/elevator.tsscript7.6 KB
packages/hairline/src/figures/exploded.tsscript5.2 KB
packages/hairline/src/figures/format.tsscript6.2 KB
packages/hairline/src/figures/hub.tsscript8.6 KB
packages/hairline/src/figures/keyboard.tsscript6.3 KB
packages/hairline/src/figures/laptop.tsscript7.3 KB
packages/hairline/src/figures/lockers.tsscript7.6 KB
packages/hairline/src/figures/loupe.tsscript6.1 KB
packages/hairline/src/figures/padlock.tsscript7.7 KB
packages/hairline/src/figures/patch.tsscript10.1 KB
packages/hairline/src/figures/phone.tsscript9.6 KB
packages/hairline/src/figures/phosphor.tsscript5.6 KB
packages/hairline/src/figures/plot.tsscript5.4 KB
packages/hairline/src/figures/plug.tsscript9.7 KB
packages/hairline/src/figures/query.tsscript8.8 KB
packages/hairline/src/figures/rail.tsscript4.9 KB
packages/hairline/src/figures/rebuild.tsscript10.3 KB
packages/hairline/src/figures/relay.tsscript8.0 KB
packages/hairline/src/figures/riffle-geometry.tsscript4.2 KB
packages/hairline/src/figures/riffle.tsscript5.2 KB
packages/hairline/src/figures/router.tsscript6.4 KB
packages/hairline/src/figures/settle.tsscript8.6 KB
packages/hairline/src/figures/sieve.tsscript5.9 KB
packages/hairline/src/figures/slow.tsscript7.2 KB
packages/hairline/src/figures/stack.tsscript5.5 KB
packages/hairline/src/figures/terminal.tsscript8.1 KB
packages/hairline/src/figures/terrain.tsscript4.4 KB
packages/hairline/src/figures/turntable-geometry.tsscript3.9 KB
packages/hairline/src/figures/turntable.tsscript6.5 KB
packages/hairline/src/figures/vault.tsscript9.8 KB
packages/hairline/src/index.tsscript17.9 KB
packages/hairline/src/intensity.tsscript3.2 KB
packages/hairline/src/mount.tsscript6.5 KB
packages/hairline/src/react.tsxother9.5 KB
packages/hairline/src/slab.tsscript3.1 KB
packages/hairline/test/browser/entry.tsscript1.4 KB
packages/hairline/test/browser/figures.spec.tsscript6.3 KB
packages/hairline/test/browser/harness.htmlother321 B
packages/hairline/test/browser/look.spec.tsscript9.5 KB
packages/hairline/test/browser/parity.spec.tsscript2.4 KB
packages/hairline/test/browser/read.spec.tsscript8.9 KB
packages/hairline/test/browser/serve.mjsscript1.7 KB
packages/hairline/test/browser/skill.spec.tsscript12.3 KB
packages/hairline/test/browser/theme.spec.tsscript3.9 KB
packages/hairline/test/dom.tsscript3.0 KB
packages/hairline/test/geometry.test.tsscript2.8 KB
packages/hairline/test/intensity.test.tsscript2.1 KB
packages/hairline/test/mount.test.tsscript33.1 KB
packages/hairline/test/parity/capture.mjsscript3.6 KB
packages/hairline/test/parity/clock.jsscript3.8 KB
packages/hairline/test/parity/driver.mjsscript1.9 KB
packages/hairline/test/parity/golden/exploded.jsonconfig24.7 KB
packages/hairline/test/parity/golden/phosphor.jsonconfig28.5 KB
packages/hairline/test/parity/golden/riffle.jsonconfig137.5 KB
packages/hairline/test/parity/golden/slow.jsonconfig41.4 KB
packages/hairline/test/parity/golden/terrain.jsonconfig216.7 KB
packages/hairline/test/parity/golden/turntable.jsonconfig32.3 KB
packages/hairline/test/parity/scripts.mjsscript2.8 KB
packages/hairline/test/react.test.tsxother7.5 KB
packages/hairline/test/skill/adopt.test.tsscript1.4 KB
packages/hairline/test/skill/build.test.tsscript3.3 KB
packages/hairline/test/skill/fixtures/broken.txtmarkdown19 B
packages/hairline/test/skill/fixtures/compound.svgother148 B
packages/hairline/test/skill/fixtures/illustrator.svgother334 B
packages/hairline/test/skill/fixtures/light.svgother123 B
packages/hairline/test/skill/fixtures/mark.svgother226 B
packages/hairline/test/skill/fixtures/mixed.svgother530 B
packages/hairline/test/skill/fixtures/moved.svgother182 B
packages/hairline/test/skill/fixtures/nested.svgother274 B
packages/hairline/test/skill/fixtures/rocket.svgother577 B
packages/hairline/test/skill/fixtures/scripted.svgother199 B
packages/hairline/test/skill/kernel.test.tsscript1.8 KB
packages/hairline/test/skill/look.test.tsscript2.2 KB
packages/hairline/test/skill/read.test.tsscript9.5 KB
packages/hairline/test/skill/shape.test.tsscript8.6 KB
packages/hairline/test/skill/validate.test.tsscript10.1 KB
packages/hairline/test/ssr.test.tsxother1.1 KB
packages/hairline/test/stage.test.tsscript11.6 KB
packages/hairline/test/types.test-d.tsxother4.9 KB
packages/hairline/tsconfig.jsonconfig212 B
packages/hairline/tsup.config.tsscript844 B
packages/hairline/vitest.config.tsscript163 B
pnpm-lock.yamlmanifest129.1 KB
pnpm-workspace.yamlconfig142 B
registry/build.mjsscript1.8 KB
registry/src/hairline.tsxother4.7 KB
registry/validate.mjsscript2.2 KB
scripts/base-url.mjsscript1.4 KB
scripts/changelog.mjsscript1.3 KB
scripts/consumers.mjsscript7.4 KB
scripts/kernel.mjsscript8.8 KB
scripts/og.mjsscript1.7 KB
scripts/release.mjsscript8.0 KB
tsconfig.base.jsonconfig442 B
turbo.jsonconfig620 B

packages/hairline/src/figures/plug.ts

View on GitHub
import { Cam, circ, clamp, fit, hull, lerp, open, poly, proj, rad, rrect, run, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
import { spring, stepS } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount } from "../core/stage";

/**
 * Plug: a wall plate with a socket, and a plug lying on the floor at the end
 * of a cord that curves away out of the frame. The pointer draws the plug up
 * toward the socket on a spring, and the cord pays out behind it. It never
 * seats: it stops short, and falls back when the pointer leaves. At rest it
 * lies on the floor, its two pins bright, the socket's holes bare. The slider
 * is how much of the way to the socket the plug can come.
 *
 * The pattern: follow a position. One spring on how far along its way the
 * plug is, set from where the pointer falls on the screen line from the
 * plug's rest to the socket, which never moves. Where the plug is and how far
 * it has turned to face the wall are both read from that one number.
 */

const PT = 3, PH = 21, ZC = 30, PR = 7, B = 1.4;           // the plate: thickness, half its side, the socket's height, corner radius, crease inset
const HOLE = 2.6, HS = 8, RECESS = 13;                     // the socket: hole radius, the holes' offset from its centre, the recess round them
const BW = 11, BH = 6.5, BR = 4.5, BL = 18;                // the plug's body: half width, half height, corner radius, length
const PIN = 2, PL = 11, SL = 7, S0 = 4.6, S1 = 3, CR = 1.8; // pin radius, pin length, the sleeve's length and two radii, the cord's radius
const REST: Vec2 = [48, 8], YAW = 100, TURN = 0.7, S = 2.8; // the pins' face on the floor, its heading, the share of the way the turn takes, scale
const EDGE = 398;                                          // where the cord leaves the picture: the viewBox's right edge, less a stroke
const ss = (t: number) => t * t * (3 - 2 * t);

/** Cuts the loops an inner offset makes where the cord bends tighter than its radius on screen. */
function untangle(L: Vec2[]): Vec2[] {
  for (let i = 0; i < L.length - 3; i++) for (let j = L.length - 2; j > i + 1; j--) {
    const p = L[i], q = L[i + 1], r = L[j], s = L[j + 1];
    const e0 = q[0] - p[0], e1 = q[1] - p[1], f0 = s[0] - r[0], f1 = s[1] - r[1], g0 = r[0] - p[0], g1 = r[1] - p[1], d = e0 * f1 - e1 * f0;
    if (!d) continue;
    const t = (g0 * f1 - g1 * f0) / d, u = (g0 * e1 - g1 * e0) / d;
    if (t > 0 && t < 1 && u > 0 && u < 1) { L.splice(i + 1, j - i, [p[0] + t * e0, p[1] + t * e1]); break; }
  }
  return L;
}

/** A screen line up to where it first crosses x = X, ending on it. */
function upTo(L: Vec2[], X: number): Vec2[] {
  const i = L.findIndex((p) => p[0] > X);
  if (i < 1) return i < 0 ? L : [];
  const p = L[i - 1], q = L[i], f = (X - p[0]) / (q[0] - p[0]);
  return [...L.slice(0, i), [X, p[1] + (q[1] - p[1]) * f]];
}

/** The cord's outline: its screen centre line offset by its radius, the plug's end a round cut, the far end cut off at x = X with no line across it, as the frame would. */
function tube(Q: readonly Vec2[], rho: number, X: number): string {
  const n = Q.length, A: Vec2[] = [], Bk: Vec2[] = [];
  for (let i = 0; i < n; i++) {
    const a = Q[Math.max(i - 1, 0)], c = Q[i], b = Q[Math.min(i + 1, n - 1)];
    let tx = b[0] - a[0], ty = b[1] - a[1];
    const l = Math.hypot(tx, ty) || 1; tx /= l; ty /= l;
    A.push([c[0] - ty * rho, c[1] + tx * rho]); Bk.push([c[0] + ty * rho, c[1] - tx * rho]);
  }
  const cap = (c: Vec2) => { const o: Vec2[] = []; for (let k = 7; k >= 1; k--) { const t = (Math.PI * k) / 8; o.push([c[0] + rho * Math.cos(t), c[1] + rho * 0.5 * Math.sin(t)]); } return o; };
  return open([...upTo(untangle(Bk), X).reverse(), ...cap(Q[0]), ...upTo(untangle(A), X)]);
}

/** Where the plug is s of the way to the socket: the centre of its pins' face, its heading (w) and its width (u). Up is up. */
function pose(s: number): { c: Vec3; w: Vec3; u: Vec3 } {
  const th = rad(lerp(YAW, 180, ss(clamp(s / TURN, 0, 1))));
  return {
    c: [lerp(REST[0], PL, s), lerp(REST[1], 0, s), lerp(BH, ZC, Math.sin((s * Math.PI) / 2))],
    w: [Math.cos(th), Math.sin(th), 0],
    u: [-Math.sin(th), Math.cos(th), 0],
  };
}

export const mount: FigureMount = ({ stage, svg, read }, value) => {
  const bag = disposer();
  const C = Cam(45, 0.5, S), zf = Math.sqrt(1 - C.k * C.k);
  /** Toward the camera: a face whose normal has a positive dot with this is seen. */
  const V: Vec3 = [Math.sin(C.az) * zf, Math.cos(C.az) * zf, C.k];
  const dot = (a: Vec3, b: Vec3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  /** A point in the plug's own frame: a across, b up, d along its heading from the pins' face. */
  const at = (o: ReturnType<typeof pose>, a: number, b: number, d: number): Vec3 =>
    [o.c[0] + a * o.u[0] + d * o.w[0], o.c[1] + a * o.u[1] + d * o.w[1], o.c[2] + b];

  // The camera is fitted to the plate and the plug at both ends of its way.
  const ext: Vec3[] = [];
  for (const x of [0, -PT]) for (const y of [-PH, PH]) for (const z of [ZC - PH, ZC + PH]) ext.push([x, y, z]);
  for (const s of [0, 1]) { const o = pose(s); for (const a of [-BW, BW]) for (const b of [-BH, BH]) for (const d of [PL, -BL - SL]) ext.push(at(o, a, b, d)); }
  fit(C, ext, 200, 166);
  const P = proj(C), Pv = (p: Vec3) => P(p[0], p[1], p[2]);

  // The plate: a thin slab on the wall, its face toward +x, the recess and two holes cut into it.
  const g = mk("g", {}, svg);
  const face = rrect(-PH, ZC - PH, PH, ZC + PH, PR, 6), lip = rrect(-PH + B, ZC - PH + B, PH - B, ZC + PH - B, PR - B, 6);
  put(solid(g), {
    sil: poly(hull(face.map((q) => P(0, q.u, q.v)).concat(face.map((q) => P(-PT, q.u, q.v))))),
    crease: open(run(lip, (q) => q.nu * V[1] + q.nv * V[2] > 0).map((q) => P(0, q.u, q.v))),
  });
  mk("path", { class: "nf lo", d: poly(circ(RECESS, 48).map((q) => P(0, q.u, ZC + q.v))) }, g);
  mk("path", { class: "nf", d: [-HS, HS].map((y) => poly(circ(HOLE, 16).map((q) => P(0, y + q.u, ZC + q.v)))).join("") }, g);

  // The plug, back to front as it lies; the order turns over with it.
  const pg = mk("g", {}, svg);
  const cord = mk("path", { class: "sil" }, pg), sleeve = mk("path", { class: "sil" }, pg), body = solid(pg), pins = mk("path", { class: "sil hi" }, pg);
  const s0 = circ(S0, 16), s1 = circ(S1, 16);
  /** An end rounded over rr: the cross-section f(inset) in four steps, from the face at d inward along dir. */
  const rounded = (f: (k: number) => Ring, rr: number, d: number, dir: number) =>
    [0, 30, 60, 90].map((a): [Ring, number] => [f(rr * (1 - Math.sin(rad(a)))), d + dir * rr * (1 - Math.cos(rad(a)))]);
  const box = (k: number) => rrect(-BW + k, -BH + k, BW - k, BH - k, BR - k), rod = (k: number) => circ(PIN - k, 12);
  const inner = box(2), shell = [...rounded(box, 2, 0, -1), ...rounded(box, 2, -BL, 1)], prong = [[rod(0), 0] as [Ring, number], ...rounded(rod, PIN * 0.8, PL, -1)];
  /** The silhouette of a solid swept through cross-sections, each a ring at a distance along the heading, a0 across. */
  const sweep = (o: ReturnType<typeof pose>, parts: Array<[Ring, number]>, a0 = 0) =>
    poly(hull(parts.flatMap(([r, d]) => r.map((q) => Pv(at(o, a0 + q.u, q.v, d))))));

  // The cord's floor end, past the frame's right edge, and the floor point it bends round; neither moves.
  // The cord is drawn only up to just inside that edge, so it runs out of the picture without leaving the viewBox.
  const end: Vec3 = [...unproj(C, 440, 150, CR), CR], bend: Vec3 = [REST[0] + 18, REST[1] - 52, CR];
  let front = true, drawn = NaN;
  const sp = spring(0, { eps: 0.002 });

  function draw() {
    if (sp.x === drawn) return;
    drawn = sp.x;
    const o = pose(sp.x), pinsFace = dot(o.w, V) > 0, vu = dot(o.u, V);
    if (pinsFace !== front) { front = pinsFace; pg.append(...(front ? [cord, sleeve, body.g, pins] : [pins, body.g, cord, sleeve])); }
    const dEnd = front ? 0 : -BL;
    put(body, {
      sil: sweep(o, shell),
      crease: open(run(inner, (q) => q.nu * vu + q.nv * V[2] > 0).map((q) => Pv(at(o, q.u, q.v, dEnd)))),
    });
    pins.setAttribute("d", [-HS, HS].map((a) => sweep(o, prong, a)).join(""));
    sleeve.setAttribute("d", sweep(o, [[s0, -BL], [s1, -BL - SL]]));
    // The cord: a cubic from inside the sleeve's end, leaving along the plug's heading, round the bend to the floor end.
    const t0 = at(o, 0, 0, -BL - SL + 2), t1 = at(o, 0, 0, -BL - SL - 26), Q: Vec2[] = [];
    for (let i = 0; i <= 40; i++) {
      const t = i / 40, a = (1 - t) ** 3, b = 3 * (1 - t) ** 2 * t, c = 3 * (1 - t) * t * t, d = t ** 3;
      Q.push(P(a * t0[0] + b * t1[0] + c * bend[0] + d * end[0], a * t0[1] + b * t1[1] + c * bend[1] + d * end[1], a * t0[2] + b * t1[2] + c * bend[2] + d * end[2]));
    }
    cord.setAttribute("d", tube(Q, CR * S, EDGE));
  }

  const loop = register(stage, (dt) => { const m = stepS(sp, dt); draw(); return m; });
  bag.add(loop.unregister);

  // The line the pointer is read along: from the pins' face at rest to the socket, on screen. Neither moves.
  const A = Pv(pose(0).c), Bs = P(0, 0, ZC), ab: Vec2 = [Bs[0] - A[0], Bs[1] - A[1]], ab2 = ab[0] * ab[0] + ab[1] * ab[1];
  let pull = value, along = -1;
  function retarget() {
    sp.t = along < 0 ? 0 : Math.min(along, pull);
    // the gap from the pins' tips to the socket, read from the target, never the pose on screen
    const o = pose(sp.t), tip = at(o, 0, 0, PL);
    read.textContent = along < 0 ? "rest" : `gap ${Math.round(Math.hypot(tip[0], tip[1], tip[2] - ZC))} · 0 V`;
    loop.wake();
  }
  retarget();
  draw();

  bag.add(pointer(stage, {
    move: (p) => { along = clamp(((p[0] - A[0]) * ab[0] + (p[1] - A[1]) * ab[1]) / ab2, 0, 1); retarget(); },
    leave: () => { along = -1; retarget(); },
  }));
  bag.add(() => svg.replaceChildren());

  return { set: (v) => { pull = v; retarget(); }, destroy: bag.dispose };
};
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall