Skip to content

Commit e636bf5

Browse files
committed
feat: implement accent color picker and update related styles
1 parent 73bfde1 commit e636bf5

9 files changed

Lines changed: 110 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</p>
1414

1515
<p align="center">
16-
<a href="https://pypi.org/project/codebread/"><img alt="PyPI" src="https://img.shields.io/pypi/v/codebread?color=b0541c&label=pypi"></a>
16+
<a href="https://pypi.org/project/codebread/"><img alt="PyPI" src="https://img.shields.io/pypi/v/codebread?color=0e7490&label=pypi&cacheSeconds=3600"></a>
1717
<a href="https://github.com/honow48-tech/CodeBread/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/honow48-tech/CodeBread/actions/workflows/ci.yml/badge.svg"></a>
1818
<img alt="Python 3.9+" src="https://img.shields.io/badge/python-3.9%2B-5f5c55">
1919
<img alt="No dependencies" src="https://img.shields.io/badge/dependencies-none-5f5c55">
@@ -66,6 +66,12 @@ it, all the way from a frontend `fetch()` to the database table.
6666

6767
Read any file with an outline and syntax highlighting, without leaving the page.
6868

69+
### Your colours
70+
71+
The report follows your system's light or dark mode. Click the dot at the
72+
right of the top bar to pick an accent colour; your choice is saved in your
73+
browser.
74+
6975
<p align="center">
7076
<img src="https://cdn.jsdelivr.net/gh/honow48-tech/CodeBread@main/assets/code.png" alt="The Code view: file tree, function outline and highlighted source" width="880">
7177
</p>
@@ -112,7 +118,7 @@ codebread --path . --html report.html --no-serve
112118
| Python | ✓ | Flask, FastAPI, Django | requests, httpx, aiohttp | SQLAlchemy, Django, peewee |
113119
| JavaScript / TypeScript | ✓ | Express, Fastify, Koa, NestJS | fetch, axios | Prisma, Mongoose, Sequelize, Knex, TypeORM |
114120
| Vue / Svelte | ✓ | same as JS | fetch, axios | same as JS |
115-
| PHP | ✓ | Laravel | – | raw SQL |
121+
| PHP | ✓ | Laravel (incl. closures) | – | Eloquent, migrations, raw SQL |
116122
| Java | ✓ | Spring | – | raw SQL |
117123
| C# | ✓ | ASP.NET | – | raw SQL |
118124
| Go | ✓ | Gin, net/http | – | raw SQL |
@@ -138,7 +144,7 @@ structural regex with brace matching and gets parameter names only.
138144
| Java | regex | ✓ | ✓ | ✓ | – | – | ✓ | ✓ | – |
139145
| C# | regex | ✓ | ✓ | ✓ | – | – | ✓ | ✓ | – |
140146
| Go | regex | ✓ | structs | ✓ | – | – | ✓ | ✓ | – |
141-
| PHP | regex | ✓ | ✓ | ✓ | – | – | ✓ | ✓ | ✓ |
147+
| PHP | regex | ✓ | ✓ | ✓ | – | Eloquent + migrations | ✓ | ✓ | ✓ |
142148
| Ruby | regex | ✓ | ✓ | ✓ | – | – | ✓ | ✓ | ✓ |
143149
| SQL | regex | – | – | – | – | tables + columns | ✓ | – | – |
144150
| Config (`.env`, json, yaml, toml, ini, xml) | key scan | – | – | – | – | – | – | – | – |

‎assets/code.png‎

5.02 KB
Loading

‎assets/connections.gif‎

53.6 KB
Loading

‎assets/map.png‎

4.66 KB
Loading

‎assets/overview.gif‎

-9.46 KB
Loading

‎codebread/web/app.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ window.addEventListener("resize", invalidateRectCache);
7171
/* ---------------- boot ---------------- */
7272
function boot(data) {
7373
S.data = data;
74+
bindAccent(); // first, so a saved accent applies before anything animates in
7475
indexData();
7576
renderHeader();
7677
renderLanguages();
@@ -2413,6 +2414,55 @@ function esc(s) {
24132414
}
24142415

24152416

2417+
/* ---------------- accent color ----------------
2418+
The viewer's pick sets --accent-pick; CSS derives everything else (--soft,
2419+
focus rings, highlights). Dark mode gets a lightened mix so it stays legible.
2420+
Saved per browser: it's a personal preference, not part of the report. */
2421+
const ACCENTS = [["Cyan (logo)", null], ["Blue", "#2563eb"], ["Crust", "#b0541c"],
2422+
["Green", "#3f7d3a"], ["Violet", "#7c4dbd"], ["Rose", "#c2416b"], ["Graphite", "#3f3f46"]];
2423+
const ACCENT_DEFAULT = "#0e7490"; // keep in sync with --accent in style.css
2424+
const ACCENT_KEY = "codebread_accent";
2425+
2426+
function applyAccent(hex, save = true) {
2427+
const st = document.documentElement.style;
2428+
if (hex) {
2429+
st.setProperty("--accent-pick", hex);
2430+
st.setProperty("--accent-pick-dark", `color-mix(in srgb, ${hex} 62%, white)`);
2431+
} else {
2432+
st.removeProperty("--accent-pick");
2433+
st.removeProperty("--accent-pick-dark");
2434+
}
2435+
if (save) {
2436+
try { hex ? localStorage.setItem(ACCENT_KEY, hex) : localStorage.removeItem(ACCENT_KEY); } catch (e) { /* no storage */ }
2437+
}
2438+
document.querySelectorAll(".swatch").forEach(b => b.classList.toggle("on", (b.dataset.hex || null) === hex));
2439+
$("accent-input").value = hex || ACCENT_DEFAULT;
2440+
}
2441+
2442+
function bindAccent() {
2443+
$("accent-swatches").innerHTML = ACCENTS.map(([name, hex]) =>
2444+
`<button class="swatch" ${hex ? `data-hex="${hex}"` : ""} title="${name}" aria-label="${name}" ` +
2445+
`style="background:${hex || ACCENT_DEFAULT}"></button>`).join("");
2446+
let saved = null;
2447+
try { saved = localStorage.getItem(ACCENT_KEY); } catch (e) { /* no storage */ }
2448+
applyAccent(saved, false);
2449+
2450+
const btn = $("accent-btn"), pop = $("accent-pop");
2451+
const toggle = (open) => {
2452+
pop.classList.toggle("hidden", !open);
2453+
btn.setAttribute("aria-expanded", String(open));
2454+
};
2455+
btn.addEventListener("click", () => toggle(pop.classList.contains("hidden")));
2456+
$("accent-swatches").addEventListener("click", (ev) => {
2457+
const sw = ev.target.closest(".swatch");
2458+
if (sw) applyAccent(sw.dataset.hex || null);
2459+
});
2460+
$("accent-input").addEventListener("input", (ev) => applyAccent(ev.target.value));
2461+
$("accent-reset").addEventListener("click", () => applyAccent(null));
2462+
document.addEventListener("click", (ev) => { if (!ev.target.closest("#accent-wrap")) toggle(false); });
2463+
document.addEventListener("keydown", (ev) => { if (ev.key === "Escape") toggle(false); });
2464+
}
2465+
24162466
/* ---------------- start ----------------
24172467
Must run after every top-level const above is initialized: the static
24182468
--html export inlines CODEBREAD_DATA, so boot() runs synchronously and

‎codebread/web/index.html‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
<button data-layer="database">Database</button>
4848
<button data-layer="config">Config</button>
4949
</nav>
50+
51+
<div id="accent-wrap">
52+
<button id="accent-btn" title="Accent color" aria-label="Accent color"
53+
aria-haspopup="dialog" aria-expanded="false"><span></span></button>
54+
<div id="accent-pop" class="hidden" role="dialog" aria-label="Accent color">
55+
<div class="kicker">Accent color</div>
56+
<div id="accent-swatches"></div>
57+
<div class="accent-row">
58+
<label class="accent-custom"><input type="color" id="accent-input"> Custom</label>
59+
<button id="accent-reset" class="chip">Reset</button>
60+
</div>
61+
</div>
62+
</div>
5063
</header>
5164

5265
<div id="main">

‎codebread/web/style.css‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
--ink-3: #9a978e;
1515
--line: #e3e0d7;
1616
--line2: #cfcbc0;
17-
--accent: #b0541c;
17+
/* default: the logo's cyan, deepened for text contrast on paper (~5:1).
18+
Viewers can pick another from the top bar, see applyAccent() */
19+
--accent: var(--accent-pick, #0e7490);
1820
--accent-ink: #fff;
19-
--soft: rgba(176, 84, 28, 0.08);
21+
--soft: color-mix(in srgb, var(--accent) 9%, transparent);
2022
--warn: #98580f;
2123
--bad: #a3372a;
2224
--shadow: 0 18px 40px -22px rgba(30, 24, 12, 0.35);
@@ -51,9 +53,9 @@
5153
--ink-3: #6c6a63;
5254
--line: #2a2a27;
5355
--line2: #3a3934;
54-
--accent: #e59a62;
55-
--accent-ink: #1a0f08;
56-
--soft: rgba(229, 154, 98, 0.11);
56+
--accent: var(--accent-pick-dark, #67e8f9); /* the logo's exact cyan */
57+
--accent-ink: #062a33;
58+
--soft: color-mix(in srgb, var(--accent) 12%, transparent);
5759
--warn: #e2a85c;
5860
--bad: #ef8a7a;
5961
--shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
@@ -162,6 +164,36 @@ kbd {
162164
.sr-item .sr-path { margin-left: auto; color: var(--ink-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
163165
.sr-empty { padding: 10px 12px; color: var(--ink-3); font-size: 13px; }
164166

167+
/* ---------- accent picker ------------------------------------------------ */
168+
169+
#accent-wrap { position: relative; }
170+
#accent-btn {
171+
width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer;
172+
background: none; border: 1px solid var(--line2); border-radius: 50%;
173+
transition: border-color .2s, transform .15s;
174+
}
175+
#accent-btn:hover { border-color: var(--ink); }
176+
#accent-btn:active { transform: scale(.94); }
177+
#accent-btn span { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); transition: background .3s; }
178+
#accent-pop {
179+
position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 236px;
180+
padding: 14px; background: var(--panel); border: 1px solid var(--line2); border-radius: 12px;
181+
box-shadow: var(--shadow); animation: drop .18s var(--ease);
182+
}
183+
#accent-swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0; }
184+
.swatch {
185+
aspect-ratio: 1; border-radius: 50%; cursor: pointer; padding: 0;
186+
border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line2);
187+
transition: box-shadow .2s, transform .15s;
188+
}
189+
.swatch:hover { transform: scale(1.1); }
190+
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
191+
.accent-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
192+
.accent-custom { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
193+
#accent-input { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line2); border-radius: 6px; background: none; cursor: pointer; }
194+
#accent-input::-webkit-color-swatch-wrapper { padding: 2px; }
195+
#accent-input::-webkit-color-swatch { border: 0; border-radius: 4px; }
196+
165197
/* ---------- layout ----------------------------------------------------- */
166198

167199
#main { display: flex; flex: 1; min-height: 0; position: relative; }

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "codebread"
7-
version = "1.1.3"
7+
version = "1.1.4"
88
description = "Interactive codebase analyzer & visualizer — slice open a project and see how it's wired together."
99
readme = "README.md"
1010
requires-python = ">=3.9"

0 commit comments

Comments
 (0)