|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +ArtPlayer.js is a modern, full-featured HTML5 video player. It's organized as a monorepo using Lerna with independent versioning. |
| 8 | + |
| 9 | +- **Homepage**: https://artplayer.org |
| 10 | +- **Online Editor**: https://artplayer.org (for testing examples) |
| 11 | +- **API Docs**: https://artplayer.org/document |
| 12 | + |
| 13 | +## Repository Structure |
| 14 | + |
| 15 | +``` |
| 16 | +packages/ |
| 17 | + artplayer/ # Core player package |
| 18 | + artplayer-plugin-*/ # 17+ plugins (danmuku, ads, chromecast, etc.) |
| 19 | + artplayer-proxy-*/ # Canvas, Mediabunny proxies |
| 20 | + artplayer-tool-*/ # iframe, thumbnail tools |
| 21 | + artplayer-vitepress/ # Documentation site |
| 22 | +
|
| 23 | +docs/ # Documentation and demo site |
| 24 | + assets/ # Example assets and TypeScript demos |
| 25 | + compiled/ # Built packages output |
| 26 | + document/ # Generated API documentation |
| 27 | + uncompiled/ # Development build output |
| 28 | + test/ # Browser test files |
| 29 | +
|
| 30 | +scripts/ # Build tooling |
| 31 | + build.js # Production build |
| 32 | + dev.js # Development server |
| 33 | + build-i18n.js # I18n bundle builder |
| 34 | + build-docs.js # Documentation generator |
| 35 | + build-llm.js # LLMs.txt generator |
| 36 | + plugin/create.js # New plugin scaffolding |
| 37 | +``` |
| 38 | + |
| 39 | +## Common Commands |
| 40 | + |
| 41 | +### Development |
| 42 | +```bash |
| 43 | +# Start dev server on port 8082 with hot reload |
| 44 | +npm run dev |
| 45 | + |
| 46 | +# Build for production (interactive prompt to select package) |
| 47 | +npm run build |
| 48 | + |
| 49 | +# Build all packages |
| 50 | +npm run build all |
| 51 | + |
| 52 | +# Build everything (packages, i18n, types, docs) + lint |
| 53 | +npm run build:all |
| 54 | +``` |
| 55 | + |
| 56 | +### Code Quality |
| 57 | +```bash |
| 58 | +# Lint with auto-fix (covers packages, scripts, tests, docs assets) |
| 59 | +npm run lint |
| 60 | +``` |
| 61 | + |
| 62 | +### Plugin Development |
| 63 | +```bash |
| 64 | +# Create new plugin from template |
| 65 | +npm run create:plugin <kebab-case-name> |
| 66 | + |
| 67 | +# Example: |
| 68 | +npm run create:plugin my-feature |
| 69 | +``` |
| 70 | + |
| 71 | +### I18n |
| 72 | +```bash |
| 73 | +# Build i18n bundles for all languages |
| 74 | +npm run build:i18n |
| 75 | +``` |
| 76 | + |
| 77 | +### TypeScript |
| 78 | +```bash |
| 79 | +# Generate TypeScript declaration files |
| 80 | +npm run build:ts |
| 81 | +``` |
| 82 | + |
| 83 | +## Architecture |
| 84 | + |
| 85 | +### Core Player (`packages/artplayer`) |
| 86 | + |
| 87 | +The main `Artplayer` class extends `Emitter` and initializes sub-components: |
| 88 | + |
| 89 | +```javascript |
| 90 | +// Key components instantiated in constructor: |
| 91 | +this.template = new Template(this) // DOM structure |
| 92 | +this.events = new Events(this) // Event handling |
| 93 | +this.player = new Player(this) // Video playback |
| 94 | +this.controls = new Control(this) // Control bar |
| 95 | +this.layers = new Layer(this) // Custom layers |
| 96 | +this.contextmenu = new Contextmenu(this) |
| 97 | +this.subtitle = new Subtitle(this) |
| 98 | +this.setting = new Setting(this) |
| 99 | +this.plugins = new Plugins(this) // Plugin manager |
| 100 | +// ... and more |
| 101 | +``` |
| 102 | + |
| 103 | +Source organization in `src/`: |
| 104 | +- `config/` - Default configuration values |
| 105 | +- `control/` - UI controls (play, progress, volume, etc.) |
| 106 | +- `events/` - Event handling (click, hover, resize, etc.) |
| 107 | +- `i18n/` - Localization files |
| 108 | +- `icons/` - SVG icons |
| 109 | +- `player/` - Video playback logic (hls, flv, dash, etc.) |
| 110 | +- `plugins/` - Built-in plugins |
| 111 | +- `setting/` - Settings panel components |
| 112 | +- `style/` - LESS stylesheets |
| 113 | +- `template.js` - HTML template generation |
| 114 | +- `utils/` - Utility functions |
| 115 | + |
| 116 | +### Plugin Architecture |
| 117 | + |
| 118 | +Plugins are functions that receive the player instance and options: |
| 119 | + |
| 120 | +```javascript |
| 121 | +// Template from scripts/plugin/template/src/index.js |
| 122 | +export default function artplayerPluginTemplate(option = {}) { |
| 123 | + return (art) => { |
| 124 | + // Plugin initialization |
| 125 | + // Access: art.player, art.controls, art.template, etc. |
| 126 | + |
| 127 | + return { |
| 128 | + name: 'artplayerPluginTemplate', |
| 129 | + // Expose methods to art.plugins['artplayerPluginTemplate'] |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +Plugin naming convention: |
| 136 | +- Package: `artplayer-plugin-<name>` |
| 137 | +- Global variable: `artplayerPlugin<Name>` (camelCase) |
| 138 | +- Exported function uses same name as global |
| 139 | + |
| 140 | +### Styling |
| 141 | + |
| 142 | +Uses LESS with inline imports: |
| 143 | +```javascript |
| 144 | +import style from './style/index.less?inline' |
| 145 | +``` |
| 146 | + |
| 147 | +Styles are injected at runtime via `utils.setStyleText()`. |
| 148 | + |
| 149 | +### Build System |
| 150 | + |
| 151 | +Uses Vite via custom Node.js scripts: |
| 152 | + |
| 153 | +**Development** (`scripts/dev.js`): |
| 154 | +- Builds IIFE bundle to `docs/uncompiled/<package>/` |
| 155 | +- Serves `docs/` directory on port 8082 |
| 156 | +- Watches source files for changes |
| 157 | + |
| 158 | +**Production** (`scripts/build.js`): |
| 159 | +- Builds 3 formats: UMD (`.js`), UMD legacy (`.legacy.js`), ESM (`.mjs`) |
| 160 | +- Outputs to `packages/<name>/dist/` |
| 161 | +- Copies to `docs/compiled/` |
| 162 | + |
| 163 | +### I18n System |
| 164 | + |
| 165 | +Language files in `packages/artplayer/src/i18n/`: |
| 166 | +- Base language: `zh-cn.js` |
| 167 | +- Additional languages: `en.js`, `fr.js`, etc. |
| 168 | +- Built as separate UMD/ESM bundles via `build-i18n.js` |
| 169 | +- Global naming: `artplayerI18n<Language>` (e.g., `artplayerI18nEn`) |
| 170 | + |
| 171 | +### Creating New Plugins |
| 172 | + |
| 173 | +The `npm run create:plugin <name>` command: |
| 174 | +1. Copies `scripts/plugin/template/` to `packages/artplayer-plugin-<name>/` |
| 175 | +2. Replaces placeholders in filenames and content |
| 176 | +3. Creates example file at `docs/assets/example/<name>.js` |
| 177 | + |
| 178 | +Plugin template structure: |
| 179 | +``` |
| 180 | +src/ |
| 181 | + index.js # Main plugin code |
| 182 | + style.less # Plugin styles |
| 183 | +package.json |
| 184 | +README.md |
| 185 | +types/ |
| 186 | + <name>.d.ts # TypeScript declarations (optional) |
| 187 | +``` |
| 188 | + |
| 189 | +### Utility Functions |
| 190 | + |
| 191 | +Core utilities in `packages/artplayer/src/utils/`: |
| 192 | +- `utils.js` - Common helpers (isMobile, isSafari, query, etc.) |
| 193 | +- `emitter.js` - Event emitter base class |
| 194 | +- `scheme.js` - Option validation schema |
| 195 | + |
| 196 | +## Development Notes |
| 197 | + |
| 198 | +- **Package manager**: Uses Yarn with Lerna |
| 199 | +- **Node version**: >= 20.0.0 |
| 200 | +- **ESLint**: Uses @antfu/eslint-config |
| 201 | +- **Browser support**: Last 1 Chrome version (ES2020), legacy builds target ES2015 |
| 202 | +- **UMD builds**: Always expose global even in AMD/RequireJS environments |
0 commit comments