refactor: idiomatic TypeScript (de-Java-fication) - #32
Merged
Conversation
LibUtils, GeometricDistances, and StandardLayers were Java-style "utility classes" (all-static members + private constructor). Convert them to plain module-level functions/consts and switch importers to namespace imports (`import * as X`), so call sites (`X.foo()`) are unchanged. No behavioral change.
Rename the 7 *Interface types (and their files) to idiomatic role-based names, avoiding DOM/existing-symbol collisions: GraphicsInterface -> Graphics ExportInterface -> Exporter ColorInterface -> Color TextInterface -> TextRenderer (DOM Text clash) ShapeInterface -> Shape PolygonInterface -> Polygon ProcessElementsInterface -> ElementProcessor Type-only rename; no behavioral change.
- Introduce `enum Tool` (src/circuit/controllers/Tool.ts) replacing the 15 `static readonly` int constants on ElementsEdtActions. Enum values are auto-incremented 0..14, identical to the originals, so the ordering-based dispatch (`tool > Tool.HAND`) is unchanged. - Update all 151 `ElementsEdtActions.<TOOL>` references to `Tool.<TOOL>` and drop now-dead ElementsEdtActions imports. - Remove dead GraphicPrimitive.DRAG_PRIMITIVE / RECT_SELECTION constants (only NO_DRAG was ever referenced). The .fcd wire-format bit flags (PrimitiveAdvText TEXT_BOLD/ITALIC/ MIRRORED) are intentionally left as numeric constants.
The only index loop in the codebase that was a pure stylistic Java-ism (string indexing). All other index loops use the index meaningfully (parallel arrays, strides, neighbor access, or semantic layer numbers) and are left as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stylistic follow-up to #31 (stacked on
lcf). Replaces Java-shaped idioms in the live code with idiomatic TypeScript. No behavioral change — 721 tests, production build, and byte-stable export fixtures all green.Commits
Static-utility classes → module functions —
LibUtils,GeometricDistances,StandardLayerswere all-static classes with aprivate constructor()(the Java "utility class" pattern). Converted to plain exported functions/consts; importers switched toimport * as X, so call sites (X.foo()) are unchanged.Drop the
Interfacesuffix from type names — renamed 7 types and their files to role-based names, avoiding DOM/existing-symbol collisions:GraphicsInterface→Graphics,ExportInterface→Exporter,ColorInterface→Color,TextInterface→TextRenderer(DOMTextclash),ShapeInterface→Shape,PolygonInterface→Polygon,ProcessElementsInterface→ElementProcessor.Toolenum — replaced 15static readonlyint constants onElementsEdtActionswithenum Tool. Values stay 0..14 (auto-increment), so the ordering-based dispatch (tool > Tool.HAND) is unchanged. Updated all 151 references; removed 2 dead drag constants.for…ofover characters inescapePdfString— the only index loop that was a pure stylistic Java-ism.Deliberately left as-is
.fcdwire-format constants —PrimitiveAdvTextTEXT_BOLD/ITALIC/MIRROREDare a serialized bitmask (powers of two OR'd together), not an enum; changing them would alter file output.get/setaccessor pairs — a mechanical method→field conversion is unsafe (shared accessor names across classes; no TS inline-to-field refactor).Verification
npm run verify(tsc strict + 721 tests) ✅npm run build✅npm run lint— 0 errors (3 pre-existing warnings) ✅