This commit is contained in:
gogongxt committed 2026-11-02 16:01:16 +08:00
1 parent 2ce1c9056a
commit 9a726dbd9f
13 files changed
+8547 -5835

No files matched your search

+74 -66
View File
@@ -4,93 +4,101 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Overview
This is a Chinese-language web-based utility toolbox (功能工具箱) that provides multiple practical tools through a single interface. It's a pure frontend application built with vanilla HTML, CSS, and JavaScript that requires no backend server or external dependencies.
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 application (SPA)** with modular tool architecture
- **Main entry point**: `index.html` - Central hub with collapsible sidebar navigation
- **Individual tools**: Separate HTML files loaded via iframe when selected
- **Pure client-side**: All processing happens in the browser, ensuring data privacy
- **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`.
### Tool Modules
### Tools
- **Electricity Calculator** (`electricity_calculator.html`): Calculate appliance electricity costs
- **Programmer Calculator** (`number.html`): Base conversion utility (binary, octal, decimal, hex)
- **Color Picker** (`color_pick.html`): Professional color selection and format conversion
- **Other Functions** (`other_function.html`): Placeholder for future tools (under construction)
| 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
### No build process
- **Static files**: Direct HTML/CSS/JS - no compilation needed
- **No dependencies**: Pure frontend with no npm packages or build tools
- **Simple deployment**: Can be served by any web server or opened directly in browser
Open `index.html` directly or serve the folder:
### Testing
```bash
python3 -m http.server 8000
```
- Open `index.html` directly in browser to test
- Test individual tools by opening their respective HTML files
- Check responsive design at different viewport sizes
- Verify keyboard shortcuts (Ctrl/Cmd + 1-5 for tool navigation)
### Testing checklist
### Adding New Tools
- 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.
1. Create new HTML file in root directory (following naming convention: `tool_name.html`)
2. Update `index.html` sidebar navigation to include new tool
3. Ensure new tool follows existing design patterns and styling
4. Test iframe loading and responsive behavior
### Adding a tool
### Code Style
1. Create `tool_name.html` using the shared assets:
```html
<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.
- **HTML5**: Semantic markup with Chinese UI text
- **CSS3**: Modern features (Flexbox, Grid, animations, gradients)
- **Vanilla JavaScript**: No external libraries, cross-browser compatible
- **Responsive design**: Mobile-first approach with media queries
- **Consistent styling**: Shared CSS patterns across all tools
### Code style
### Key Features to Maintain
- **Privacy-focused**: All processing happens locally, no external data transmission
- **User experience**: Smooth animations, collapsible sidebar, tooltips
- **Accessibility**: Semantic HTML and keyboard navigation support
- **Professional UI**: Gradient backgrounds, modern styling, clean layouts
- 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 # Main application hub with navigation
├── electricity_calculator.html # Electricity cost calculator
├── number.html # Programmer calculator (base conversion)
├── color_pick.html # Color picker and format converter
├── other_function.html # Future tools placeholder
└── CLAUDE.md # This file
├── 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
```
## Common Tasks
### Running the Application
```bash
# Serve with any web server (optional)
python3 -m http.server 8000
# or open directly in browser
open index.html
```
### Adding New Tools
- Follow existing HTML structure and CSS patterns
- Include Chinese interface text consistent with current tools
- Ensure responsive design for mobile devices
- Test iframe integration with main navigation
### Modifying Styles
- Main styles are embedded in individual HTML files
- Consistent color scheme and design patterns across tools
- Use CSS variables for easy theme maintenance if needed