Skip to content

refactor: idiomatic TypeScript (de-Java-fication) - #32

Merged
DanteCpp merged 4 commits into
mainfrom
refactor/ts-idioms
Jun 24, 2026
Merged

refactor: idiomatic TypeScript (de-Java-fication)#32
DanteCpp merged 4 commits into
mainfrom
refactor/ts-idioms

Conversation

@DanteCpp

Copy link
Copy Markdown
Owner

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.

Stacked on #31. Base is lcf; once #31 merges to main, this can be retargeted to main.

Commits

  1. Static-utility classes → module functionsLibUtils, GeometricDistances, StandardLayers were all-static classes with a private constructor() (the Java "utility class" pattern). Converted to plain exported functions/consts; importers switched to import * as X, so call sites (X.foo()) are unchanged.

  2. Drop the Interface suffix 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 (DOM Text clash), ShapeInterface→Shape, PolygonInterface→Polygon, ProcessElementsInterface→ElementProcessor.

  3. Tool enum — replaced 15 static readonly int constants on ElementsEdtActions with enum 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.

  4. for…of over characters in escapePdfString — the only index loop that was a pure stylistic Java-ism.

Deliberately left as-is

  • .fcd wire-format constantsPrimitiveAdvText TEXT_BOLD/ITALIC/MIRRORED are a serialized bitmask (powers of two OR'd together), not an enum; changing them would alter file output.
  • Most index loops — they use the index meaningfully (parallel arrays, strides, neighbor access, or semantic layer numbers), so they are not Java-isms.
  • get/set accessor 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) ✅

DanteCpp added 4 commits June 24, 2026 20:29
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.
Base automatically changed from lcf to main June 24, 2026 19:03
@DanteCpp
DanteCpp merged commit 7f1ee64 into main Jun 24, 2026
@DanteCpp
DanteCpp deleted the refactor/ts-idioms branch June 24, 2026 20:14
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