-
-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Planned by Gemini.
Thoughts?
cssstyle Refactoring Project: Split PR Plan
Objective: To decouple CSSStyleDeclaration and migrate property logic to lib/properties through a series of reviewable, incremental steps.
Overall Roadmap
| Order | Category | PR Title Draft | Main Changes | Impact Scope |
|---|---|---|---|---|
| 1 | Foundation | Add shared parsers and property interface | Addition of shared parsers, creation of directory structure. | No impact on existing code. |
| 2 | Core | Refactor CSSStyleDeclaration core & registry | Overhaul of CSSStyleDeclaration.js, implementation of the registry. | Breaking Changes (Unmigrated properties will temporarily stop working). |
| 3 | Migration | Port basic properties (Color, Font, etc.) | Migration of basic properties, fixing E2E tests. | Restoration of basic functionality. |
| 4 | Migration | Port remaining properties (Batch 1-N) | Mechanical/Manual migration of remaining properties. | Restoration of full functionality. |
| 5 | Cleanup | Remove legacy generator scripts | Removal of old scripts/generateProperties.js, etc. | Cleanup. |
Detailed PR Plans
PR 1: Foundation
Goal: Prepare the common functions required by the new property definition files.
- Changes:
- Create lib/parsers/utils.js (or lib/parsers/*.js).
- Implement utility functions for parsing colors (parseColor), lengths (parseLength), and processing keywords.
- Create the lib/properties/ directory (initially empty or with a .gitkeep).
- Review Points:
- Are the regular expressions and logic for the parsers correct?
- Are unit tests (test/parsers.js, etc.) added?
PR 2: The Core Swap
Goal: Discard the previous tightly coupled CSSStyleDeclaration and replace it with the generic container version.
- Changes:
- Rewrite lib/CSSStyleDeclaration.js to the new Map-based implementation.
- Create lib/properties/index.js (the registry).
- Important: Since most properties will be unregistered at this point, many existing tests may fail. Add only 1-2 sample properties (like color or display) to lib/properties/ to prove the core logic works minimally.
- Review Points:
- Is the generic logic for setProperty / getPropertyValue correct?
- Is dynamic loading from the registry functioning correctly?
PR 3: Core Properties Migration
Goal: Migrate frequently used major properties and establish the "pattern" for the project.
- Changes:
- Create major properties like color, font-size, background, margin, padding in lib/properties/*.js.
- Register them in lib/properties/index.js.
- Ensure existing tests regarding these properties pass.
- Review Points:
- Are initialValue and inherited settings correct?
- Are the parsers created in PR 1 being used correctly?
PR 4: Bulk Migration
Goal: Migrate all remaining hundreds of properties to the new format.
Note: Due to the volume, split this into further PRs if necessary (e.g., PR 4-1: Layout props, PR 4-2: SVG props).
- Changes:
- Split all remaining properties into individual files.
- Register all of them in the registry.
- Review Points:
- Are there any mechanical errors (copy-paste errors)?
- Do all test cases (including WPT) pass?
PR 5: Cleanup
Goal: Remove unnecessary generation scripts and old definition files to clean up the project.
- Changes:
- Remove scripts/generateProperties.js.
- Remove the lib/generated/ directory.
- Modify build scripts in package.json (remove the generation step).
- Review Points:
- Is anything forgotten to be deleted?
- Does a clean install (npm ci) followed by test execution work correctly?
Development & Merge Strategy Recommendation
This change will cause temporary dysfunction (many properties will disappear) at the stage of PR 2. Therefore, the following strategy is recommended:
- Use a Feature Branch: Do not merge directly into the main branch. Instead, create a long-lived feature branch (e.g., refactor/decouple-properties) and merge PRs 1 through 5 into it.
- Alternative (Parallel Existence - High Difficulty): It is possible to include a "fallback to new implementation" within the old implementation in PR 2 to allow coexistence, but this complicates the code. Thus, the feature branch strategy is recommended for this refactoring.