Repository Public
1import type { ReactNode } from "react";23/**4 * Marks: the house set of small duotone signs — list bullets, verdict signs and the emblem of each callout.5 * Drawn for this renderer on a 24×24 grid: a soft fill of the current colour, a firm outline, a white detail where6 * the sign is solid. They take their colour from `color` (currentColor), so every theme and tone applies.7 */8export const MARKS = ["bullet", "check", "cross", "warn", "note", "tip", "definition", "theorem", "example", "assumption", "arrow", "star"] as const;9export type MarkName = (typeof MARKS)[number];1011const S = { fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" } as const;12const soft = { fill: "currentColor", fillOpacity: 0.16, stroke: "none" } as const;13const solid = { fill: "currentColor", stroke: "none" } as const;14const ink = { fill: "none", stroke: "var(--sh-surface, #fff)", strokeWidth: 2.1, strokeLinecap: "round", strokeLinejoin: "round" } as const;1516const GLYPHS: Record<MarkName, ReactNode> = {17 // A cut gem: solid lozenge, one lit facet, a spark.18 bullet: <>19 <path {...solid} d="M12 3.2 20.8 12 12 20.8 3.2 12Z" />20 <path fill="var(--sh-surface, #fff)" fillOpacity={0.34} d="M12 3.2 3.2 12H12Z" />21 <path fill="var(--sh-surface, #fff)" fillOpacity={0.14} d="M12 12h8.8L12 20.8Z" />22 </>,23 // A seal: twelve-point rosette with the tick cut out in white.24 check: <>25 <path {...solid} d="M12 2.2l2.1 1.7 2.7-.3 1.1 2.5 2.5 1.1-.3 2.7L21.8 12l-1.7 2.1.3 2.7-2.5 1.1-1.1 2.5-2.7-.3L12 21.8l-2.1-1.7-2.7.3-1.1-2.5-2.5-1.1.3-2.7L2.2 12l1.7-2.1-.3-2.7 2.5-1.1 1.1-2.5 2.7.3Z" />26 <path {...ink} d="m7.9 12.3 2.8 2.8 5.4-5.9" />27 </>,28 cross: <>29 <path {...solid} d="M8.2 2.8h7.6l5.4 5.4v7.6l-5.4 5.4H8.2l-5.4-5.4V8.2Z" />30 <path {...ink} d="m8.8 8.8 6.4 6.4M15.2 8.8l-6.4 6.4" />31 </>,32 warn: <>33 <path {...solid} d="M10.3 4.1a2 2 0 0 1 3.4 0l7.6 13.1a2 2 0 0 1-1.7 3H4.4a2 2 0 0 1-1.7-3Z" />34 <path {...ink} d="M12 9v4.6" /><circle cx="12" cy="16.9" r="1.25" fill="var(--sh-surface, #fff)" />35 </>,36 // A margin note: a sheet with a folded corner and an i.37 note: <>38 <path {...soft} d="M5 3.5h10L20 8.5V19a1.5 1.5 0 0 1-1.5 1.5h-13A1.5 1.5 0 0 1 4 19V5a1.5 1.5 0 0 1 1-1.5Z" />39 <path {...S} d="M5.5 3.5H15l5 5V19a1.5 1.5 0 0 1-1.5 1.5h-13A1.5 1.5 0 0 1 4 19V5a1.5 1.5 0 0 1 1.5-1.5Z" /><path {...S} d="M15 3.5v5h5" />40 <path {...S} strokeWidth={2} d="M11.5 12.2v4.6" /><circle cx="11.5" cy="9.3" r="1.1" {...solid} />41 </>,42 // A bulb with its filament and three rays.43 tip: <>44 <path {...soft} d="M12 5.2a5.6 5.6 0 0 0-3.4 10c.6.5.9 1.1.9 1.8h5c0-.7.3-1.3.9-1.8A5.6 5.6 0 0 0 12 5.2Z" />45 <path {...S} d="M12 5.2a5.6 5.6 0 0 0-3.4 10c.6.5.9 1.1.9 1.8h5c0-.7.3-1.3.9-1.8A5.6 5.6 0 0 0 12 5.2Z" />46 <path {...S} d="M9.8 20h4.4M10.4 12.2l1.6 1.6 1.6-1.6M12 13.8V17M12 1.6v1.3M4.6 4.6l.9.9M19.4 4.6l-.9.9" />47 </>,48 // An open book with a ribbon.49 definition: <>50 <path {...soft} d="M3 5.5c3-1 6-.6 9 1.2 3-1.8 6-2.2 9-1.2v12.8c-3-1-6-.6-9 1.2-3-1.8-6-2.2-9-1.2Z" />51 <path {...S} d="M3 5.5c3-1 6-.6 9 1.2 3-1.8 6-2.2 9-1.2v12.8c-3-1-6-.6-9 1.2-3-1.8-6-2.2-9-1.2ZM12 6.7v12.8" />52 <path {...solid} d="M15.2 5.3v6.2l1.6-1.3 1.6 1.3V4.9c-1.1 0-2.1.1-3.2.4Z" />53 </>,54 // Therefore: a hexagonal plate with the three dots of ∴.55 theorem: <>56 <path {...soft} d="m12 2.6 8.2 4.7v9.4L12 21.4l-8.2-4.7V7.3Z" /><path {...S} d="m12 2.6 8.2 4.7v9.4L12 21.4l-8.2-4.7V7.3Z" />57 <circle cx="12" cy="8.6" r="1.55" {...solid} /><circle cx="8.3" cy="14.6" r="1.55" {...solid} /><circle cx="15.7" cy="14.6" r="1.55" {...solid} />58 </>,59 // A flask with its liquid and two bubbles.60 example: <>61 <path {...soft} d="M7.4 14.5h9.2l2.3 3.9a1.6 1.6 0 0 1-1.4 2.4H6.5a1.6 1.6 0 0 1-1.4-2.4Z" />62 <path {...S} d="M9.3 3.2h5.4M10.2 3.2v6.1l-5.1 9.1a1.6 1.6 0 0 0 1.4 2.4h11a1.6 1.6 0 0 0 1.4-2.4l-5.1-9.1V3.2M7.4 14.5h9.2" />63 <circle cx="10.6" cy="17.6" r="0.9" {...solid} /><circle cx="13.9" cy="16.6" r="0.6" {...solid} />64 </>,65 // A balance at rest.66 assumption: <>67 <path {...soft} d="M2.6 13.4 5.4 7l2.8 6.4a2.8 2.8 0 0 1-5.6 0ZM15.8 13.4 18.6 7l2.8 6.4a2.8 2.8 0 0 1-5.6 0Z" />68 <path {...S} d="M12 3.4v16.8M8 20.4h8M5.4 7h13.2M2.6 13.4 5.4 7l2.8 6.4a2.8 2.8 0 0 1-5.6 0ZM15.8 13.4 18.6 7l2.8 6.4a2.8 2.8 0 0 1-5.6 0Z" />69 <circle cx="12" cy="3.6" r="1.2" {...solid} />70 </>,71 arrow: <>72 <path {...solid} d="M12 2.5a9.5 9.5 0 1 0 0 19 9.5 9.5 0 0 0 0-19Z" /><path {...ink} d="M7.5 12h8.6M12.6 8.3l3.7 3.7-3.7 3.7" />73 </>,74 star: <>75 <path {...soft} d="m12 2.8 2.7 6 6.5.7-4.9 4.4 1.4 6.4L12 17l-5.7 3.3 1.4-6.4-4.9-4.4 6.5-.7Z" />76 <path {...S} d="m12 2.8 2.7 6 6.5.7-4.9 4.4 1.4 6.4L12 17l-5.7 3.3 1.4-6.4-4.9-4.4 6.5-.7Z" />77 </>,78};7980/** One mark. Decorative by default; give `label` when the sign itself carries meaning (a ✓ in a table cell). */81export function Mark({ name, size = 18, label, className }: { name: MarkName; size?: number | string; label?: string; className?: string }) {82 return (83 <svg className={`sh-mark sh-mark--${name}${className ? ` ${className}` : ""}`} width={size} height={size} viewBox="0 0 24 24" focusable="false"84 {...(label ? { role: "img", "aria-label": label } : { "aria-hidden": true })}>{GLYPHS[name]}</svg>85 );86}8788/** Typed signs an author writes in running text, drawn as marks: ✓ ✔ ✅ → check, ✗ ✘ ✕ ❌ → cross, ⚠ → warn, ★ → star. */89export const SIGN_RE = /(✓|✔|✅|☑|✗|✘|✕|❌|⚠️?|★|⭐)️?/gu;90export function signMark(sign: string): { name: MarkName; label: string } {91 if ("✓✔✅☑".includes(sign[0])) return { name: "check", label: "✓" };92 if ("✗✘✕❌".includes(sign[0])) return { name: "cross", label: "✗" };93 if (sign[0] === "⚠") return { name: "warn", label: "⚠" };94 return { name: "star", label: "★" };95}96