anbeime/skill / skills/hairline/hairline
hairline
Flagged一句话生成跟随鼠标的交互式等轴测线框图(单文件、零依赖、双击即开),或把已有 SVG/Logo 重建为可交互线框。
packages/hairline/src/core/styles.ts
View on GitHub/**
* Hairline — the stylesheet, as a string, and the one function that puts it
* in a document or a shadow root.
*
* Every selector is inside `:where()`, so each rule has zero specificity: a
* rule of the page's always wins, and between these rules only their order
* decides. The order below is therefore part of the design. The six
* `--hairline-*` properties are the public theme; `--hl-*` are private and
* read them with the palette as the fallback.
*/
const LIGHT = { plate: "#ffffff", hi: "#232327", edge: "#a4a4ac", mid: "#c3c3c9", lo: "#e0e0e4" };
const DARK = { plate: "#08090a", hi: "#d0d6e0", edge: "#5b5d64", mid: "#3e3e44", lo: "#29292d" };
const KEYS = ["plate", "hi", "edge", "mid", "lo"] as const;
type Palette = Record<(typeof KEYS)[number], string>;
const vars = (p: Palette) => KEYS.map((k) => `--hl-${k}:var(--hairline-${k},${p[k]});`).join("");
const EASE = "cubic-bezier(0.5,0,0.1,1)";
const SVG = ":where([data-hairline]>svg)";
/** The stylesheet. `lightDark` adds the rule that follows the page's `color-scheme`, for browsers that have `light-dark()`. */
export function css(lightDark: boolean): string {
const both = Object.fromEntries(KEYS.map((k) => [k, `light-dark(${LIGHT[k]},${DARK[k]})`])) as Palette;
return [
// the box, and the palette: light unless something below says otherwise
`:where([data-hairline]){display:block;position:relative;aspect-ratio:5/4;touch-action:pan-y;user-select:none;-webkit-user-select:none;--hl-sw:var(--hairline-stroke,0.9);${vars(LIGHT)}}`,
// the page's color-scheme
lightDark ? `:where([data-hairline]){${vars(both)}}` : "",
// an ancestor that says dark
`:where(.dark,[data-theme="dark"]) :where([data-hairline]){${vars(DARK)}}`,
// the figure's own theme option
`:where([data-hairline][data-hairline-theme="light"]){${vars(LIGHT)}}`,
`:where([data-hairline][data-hairline-theme="dark"]){${vars(DARK)}}`,
`:where([data-hairline]:focus-visible){outline:1.5px solid var(--hl-hi);outline-offset:2px}`,
`${SVG}{position:absolute;inset:0;width:100%;height:100%;display:block}`,
// Riffle's live region: read, not seen
`:where([data-hairline]>[data-hairline-live]){position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}`,
// the drawing: plates are filled with the plate colour and painted back to front
`${SVG} :where(path,polygon,ellipse,line){fill:var(--hl-plate);stroke:var(--hl-mid);stroke-width:var(--hl-sw);vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round;transition:stroke 260ms ${EASE}}`,
`${SVG} :where(.nf){fill:none}`,
`${SVG} :where(.fo){stroke:none}`,
`${SVG} :where(.sil){stroke:var(--hl-edge)}`,
`${SVG} :where(.hi){stroke:var(--hl-hi)}`,
`${SVG} :where(.lo){stroke:var(--hl-lo)}`,
`${SVG} :where(.dash){stroke-dasharray:1 3}`,
`${SVG} :where(.dot){stroke:none;fill:var(--hl-hi);transition:fill 260ms ${EASE}}`,
`${SVG} :where(.dot.m){fill:var(--hl-edge)}`,
`${SVG} :where(.dot.off){fill:var(--hl-lo)}`,
`${SVG} :where(.ghost path){fill:none;stroke:var(--hl-mid)}`,
].join("");
}
const done = new WeakSet<Document | ShadowRoot>();
/** Puts the stylesheet in a document or a shadow root, once: adopted where that exists, a `<style>` element where it doesn't. */
export function inject(root: Document | ShadowRoot): void {
if (done.has(root)) return;
done.add(root);
const doc = root.nodeType === 9 ? (root as Document) : (root as ShadowRoot).ownerDocument;
const win = doc.defaultView;
const text = css(!!win?.CSS?.supports?.("color", "light-dark(#000,#fff)"));
if (win && "adoptedStyleSheets" in root) {
try {
const sheet = new win.CSSStyleSheet();
sheet.replaceSync(text);
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
return;
} catch {
// no constructable stylesheets here: fall through to an element
}
}
const style = doc.createElement("style");
style.setAttribute("data-hairline-style", "");
style.textContent = text;
(root.nodeType === 9 ? doc.head ?? doc.documentElement : root).appendChild(style);
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |