Skip to content

refactor: strategy pattern + editor modularization#1

Open
SRjoeee wants to merge 6 commits intoglazes-pitfall:mainfrom
SRjoeee:refactor/strategy-pattern-modularize
Open

refactor: strategy pattern + editor modularization#1
SRjoeee wants to merge 6 commits intoglazes-pitfall:mainfrom
SRjoeee:refactor/strategy-pattern-modularize

Conversation

@SRjoeee
Copy link
Copy Markdown

@SRjoeee SRjoeee commented Mar 4, 2026

Summary

  • Python 后端:策略模式重构 — 将两个重复 436/490 行的后端文件合并为共享 core.py(310 行)+ 可插拔 ImageOps 适配器(CV2/NumPy),旧文件保留为 12 行薄包装,API 完全向后兼容
  • 前端编辑器:将 4954 行巨石 editor.html 拆分为 454 行 HTML 骨架 + 10 个独立 JS 模块 + 2 个 CSS 文件,零构建工具
  • 消除冗余:共享 CSS 变量/按钮样式/颜色转换函数,web_ui.html 不再与 editor.html 重复代码
  • 代码清理:14 处 print()logging,提取 Flask 共享 helper,统一错误码,修复 ComfyUI bare except

Test plan

🤖 Generated with Claude Code

SR.Joe and others added 6 commits March 4, 2026 18:41
Strategy pattern refactoring plan covering Python backend
deduplication, editor.html modularization, and code rot cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9-task plan covering Python backend deduplication, editor.html
modularization, web_app.py cleanup, and ComfyUI integration fixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ble ops

- Create ImageOps protocol (ops.py) with to_gray/sobel/normalize_1d/kmeans_2
- Create CV2Ops (backend_cv2.py) and NumpyOps (backend_numpy.py) adapters
- Move 350+ lines of shared algorithms to core.py
- Replace 14 print() calls with logging
- Remove grid_layout() debug visualization
- Rewire legacy files as backward-compatible thin wrappers
- Bump version to 0.2.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ctory

Split the monolithic 4954-line editor.html into:
- editor/shared.css: CSS variables + button styles (shared with web_ui)
- editor/editor.css: editor-specific styles
- editor/js/color-utils.js: rgbToHex, hexToRgb, hslToRgb, rgbToHsl
- editor/js/state.js: EditorState object + setActiveTool
- editor/js/history.js: undo/redo stack
- editor/js/selection.js: selection mask + marching ants
- editor/js/canvas-render.js: canvas init, zoom/pan, brush, flood fill
- editor/js/palette.js: color picker, palette panel, download
- editor/js/rotsprite.js: RotSprite rotation algorithm
- editor/js/canvas-size.js: canvas resize tool
- editor/js/tools.js: all tool implementations + transform system
- editor/js/main.js: DOMContentLoaded init + keyboard shortcuts

No ES modules — plain <script> tags, all functions remain global.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Link editor/shared.css (removes duplicated :root vars + .btn styles)
- Link editor/js/color-utils.js (removes inline rgbToHex/hexToRgb)
- Add /editor/<path> Flask route for serving editor/ static assets
- Remove stale comment from Phase 4

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant