hand painted syntax / no highlight library

一种带有琥珀光泽与夜航感的代码块。

这套配色不模仿常见主题:浅色像旧纸、蜂蜜和陶土,深色像紫黑夜幕里的暖灯。 语法颜色保持高对比,但避免过度霓虹。

src/orbit-store.ts
  1. type Listener<T> = (state: Readonly<T>) => void;
  2. interface Patch<T> {
  3. name: string;
  4. apply: (draft: T) => void;
  5. }
  6. export class OrbitStore<T extends object> {
  7. private state: T;
  8. private history: Patch<T>[] = [];
  9. private listeners = new Set<Listener<T>>();
  10. constructor(initial: T) {
  11. this.state = structuredClone(initial);
  12. }
  13. read() {
  14. return Object.freeze(structuredClone(this.state));
  15. }
  16. commit(name: string, apply: Patch<T>["apply"]) {
  17. const draft = structuredClone(this.state);
  18. apply(draft);
  19. this.state = draft;
  20. this.history.push({ name, apply });
  21. this.emit();
  22. }
  23. subscribe(listener: Listener<T>) {
  24. this.listeners.add(listener); return () => this.listeners.delete(listener);
  25. }
  26. private emit() { this.listeners.forEach(l => l(this.read())); }
  27. }
tools/palette_poet.py
  1. from dataclasses import dataclass
  2. from math import sqrt
  3. # Pick a readable accent color by measuring distance in RGB space.
  4. @dataclass(frozen=True)
  5. class Swatch:
  6. name: str
  7. hex: str
  8. def rgb(self) -> tuple[int, int, int]:
  9. raw = self.hex.lstrip("#")
  10. return tuple(int(raw[i:i + 2], 16) for i in (0, 2, 4))
  11. def distance(a: Swatch, b: Swatch) -> float:
  12. pairs = zip(a.rgb(), b.rgb())
  13. return sqrt(sum((x - y) ** 2 for x, y in pairs))
  14. def choose_accent(base: Swatch, colors: list[Swatch]) -> Swatch:
  15. ranked = sorted(colors, key=lambda item: distance(base, item))
  16. candidates = [c for c in ranked if distance(base, c) > 110]
  17. return candidates[0] if candidates else ranked[-1]
  18. palette = [
  19. Swatch("amber", "#ffb86b"),
  20. Swatch("lagoon", "#7bdff2"),
  21. Swatch("orchid", "#c792ff"),
  22. Swatch("rose", "#ff7a90"),
  23. ]
  24. if __name__ == "__main__":
  25. paper = Swatch("paper", "#fff9ec")
  26. accent = choose_accent(paper, palette)
  27. print(f"Use {accent.name} as the spark color: {accent.hex}")
crates/quiet_router.rs
  1. use std::collections::HashMap;
  2. type Handler = fn(Request) -> Response;
  3. #[derive(Clone)]
  4. pub struct Request {
  5. pub path: String,
  6. pub body: String,
  7. }
  8. pub struct Response {
  9. pub status: u16,
  10. pub body: String,
  11. }
  12. pub struct Router {
  13. routes: HashMap<String, Handler>,
  14. fallback: Handler,
  15. }
  16. impl Router {
  17. pub fn new() -> Self {
  18. Self { routes: HashMap::new(), fallback: not_found }
  19. }
  20. pub fn get(mut self, path: &str, handler: Handler) -> Self {
  21. self.routes.insert(path.to_string(), handler);
  22. self
  23. }
  24. pub fn serve(&self, req: Request) -> Response {
  25. let handler = self.routes.get(&req.path).copied().unwrap_or(self.fallback);
  26. handler(req)
  27. }
  28. }
  29. fn not_found(req: Request) -> Response {
  30. Response { status: 404, body: format!("No route for {}", req.path) }
  31. }