4.9 KiB
4.9 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Chinese-language browser toolbox (功能工具箱) offering multiple practical utilities through one interface. Pure frontend: vanilla HTML, CSS, and JavaScript with no build step and no backend. All processing happens in the browser.
Architecture
Core Structure
- Single-page shell (
index.html): collapsible sidebar, top bar, searchable tool cards, hash-based routing. - Tool pages: standalone HTML files loaded in an iframe when selected, so each tool also works when opened directly.
- Shared design system:
assets/styles.css(tokens + components) andassets/common.js(theme, toast, clipboard, helpers) are used by every page. - No dependencies except jsPDF, loaded from CDN by
image_to_pdf.html.
Tools
| File | Tool |
|---|---|
electricity_calculator.html |
电费计算器 (single + peak/valley pricing) |
number.html |
程序员计算器 (binary/octal/decimal/hex, arbitrary precision) |
color_pick.html |
颜色选择器 (SV/H hue picker, HSV/RGB/HEX/HSL) |
json_formatter.html |
JSON 格式化 (pretty, minify, sort keys, highlight) |
url_encoder.html |
URL 编解码 (URI component/full/form/Base64) |
image_to_pdf.html |
图片转 PDF (ordering, preview, page settings) |
image_compressor.html |
图片压缩 (quality, format, resize, batch download) |
other_function.html |
其他功能 (roadmap) |
Shared assets
assets/styles.css: design tokens for light/dark themes, resets, and reusable components (.card,.btn,.field,.segmented,.editor-app,.image-grid,.dropzone,.toast, etc.). Tool pages should reuse these instead of adding ad-hoc styles.assets/common.js: exposeswindow.Toolboxwiththeme(),setTheme(),toggleTheme(),onThemeChange(),toast(),copy(),copyWithToast(),formatBytes(),escapeHtml(),debounce(). It also wires[data-theme-toggle]buttons and declarative copy buttons (data-copy-text/data-copy-target).
Theme
- Theme is stored in
localStorageundertoolbox-theme; without a stored value the system preference is used. common.jsapplies the theme before paint and listens tostorageevents, which keeps the parent page and iframe in sync live.- Theme toggles use
<svg class="icon-moon">+<svg class="icon-sun">inside a[data-theme-toggle]element.
Routing
- Hashes map to tools:
#calculator,#number,#color,#json,#url,#image2pdf,#image-compressor,#other. index.htmluseshistory.pushStatepluspopstate/hashchangelisteners.- Keyboard shortcuts:
Ctrl/Cmd + Kfocuses search,Ctrl/Cmd + 1…8opens tools,Esccloses mobile sidebar.
Development
No build process
Open index.html directly or serve the folder:
python3 -m http.server 8000
Testing checklist
- Open
index.html; verify sidebar collapse, mobile drawer, search, theme toggle, hash links. - Open each tool directly; verify it works standalone and inside the iframe.
- Test light and dark themes; check contrast and iframe theme sync.
- Test mobile widths (≈375px) and desktop (≈1440px).
- Verify localStorage persists theme, sidebar state, and color history.
- Image tools: add multiple files, reorder/delete, change options, generate/compress, download.
Adding a tool
- Create
tool_name.htmlusing the shared assets:<link rel="stylesheet" href="assets/styles.css" /> <script src="assets/common.js"></script> - Use the
.tool-page/.tool-header/.cardlayout and existing components; add a theme toggle in.header-actions. - Add the tool to the
TOOLSarray inindex.html(name, description, URL, hash, icon, tint). The sidebar and home cards are generated from that array. - Add an icon
<symbol>to the sprite at the top ofindex.htmlif needed; useviewBox="0 0 24 24"and stroke-style paths. - Test inside the iframe and standalone, in both themes and on mobile.
Code style
- Semantic HTML5, Chinese UI text, accessible labels (
aria-label,role, visible focus). - Vanilla ES5+/ES2020 browser JavaScript; no frameworks.
- Prefer shared CSS variables and components over inline styling.
- Keep all processing local; do not add backend calls or telemetry.
File Structure
/
├── index.html # App shell, sidebar, routing, tool registry
├── electricity_calculator.html
├── number.html
├── color_pick.html
├── json_formatter.html
├── url_encoder.html
├── image_to_pdf.html
├── image_compressor.html
├── other_function.html
├── assets/
│ ├── styles.css # Shared design tokens and components
│ ├── common.js # Theme, toast, clipboard, helpers
│ └── favicon.svg # App icon
└── CLAUDE.md