Files
tools/CLAUDE.md
T
2026-11-02 16:01:16 +08:00

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) and assets/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: exposes window.Toolbox with theme(), 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 localStorage under toolbox-theme; without a stored value the system preference is used.
  • common.js applies the theme before paint and listens to storage events, 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.html uses history.pushState plus popstate / hashchange listeners.
  • Keyboard shortcuts: Ctrl/Cmd + K focuses search, Ctrl/Cmd + 1…8 opens tools, Esc closes 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

  1. Create tool_name.html using the shared assets:
    <link rel="stylesheet" href="assets/styles.css" />
    <script src="assets/common.js"></script>
    
  2. Use the .tool-page / .tool-header / .card layout and existing components; add a theme toggle in .header-actions.
  3. Add the tool to the TOOLS array in index.html (name, description, URL, hash, icon, tint). The sidebar and home cards are generated from that array.
  4. Add an icon <symbol> to the sprite at the top of index.html if needed; use viewBox="0 0 24 24" and stroke-style paths.
  5. 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