Skip to content

refactor: migrate renderer utilities to TypeScript modules - #68

Open
nihmadev wants to merge 1 commit into
cdmtn:mainfrom
nihmadev:refactor/lib-typescript-modules
Open

refactor: migrate renderer utilities to TypeScript modules#68
nihmadev wants to merge 1 commit into
cdmtn:mainfrom
nihmadev:refactor/lib-typescript-modules

Conversation

@nihmadev

Copy link
Copy Markdown

assets/js/lib.js combined unrelated concerns in a 1,000-line browser module: text and encoding helpers, DOM behavior, Electron adapters, bug/history state, runtime diagnostics, sandbox execution, UI classes, registry initialization, and legacy globals. Because the renderer loads native ESM directly from disk, this could not be replaced with a TypeScript file without also preserving the emitted .js URLs consumed by the application.

Source and build layout

  • Adds assets/ts/lib.ts as the compatibility entry point and assets/ts/lib/* as the typed source modules.
  • Adds tsconfig.renderer.json for strict browser ESM compilation with DOM libraries.
  • Emits JavaScript and declarations into assets/js, preserving the paths already used by renderer imports.
  • Extends npm run build with the renderer TypeScript project and adds npm run build:renderer for focused work.
  • Keeps generated .js and .d.ts files in the repository because packaged and development builds load renderer modules directly from assets/js without a bundler or runtime TypeScript loader.

Module boundaries

  • text: escaping, capitalization, initials, truncation, linkification, camel-case splitting, and dedent.
  • encoding: UTF-8 base64 conversion and DOM identifier encoding.
  • format: editor mode lookup, Unix date formatting, path normalization, time conversion, and color alpha conversion.
  • values: runtime value classification and the existing object/array predicates.
  • dom: tab labels, status transitions, popup behavior, scrolling, generated avatars, CSS variable discovery, code-window visibility, tag replacement, and editor sizing.
  • platform: notifications, theme access, clipboard, Twemoji, application title, and GitHub token access.
  • history: adapters for the existing global history and bug stores.
  • runtimeErrors: runtime error state and bottom-window rendering.
  • sandbox: captured console execution and parser/runtime checks.
  • ui: reload notification behavior.
  • validation: the value validation contract used by notifications without importing the modal engine.

Compatibility retained

The generated assets/js/lib.js remains the public compatibility facade. Existing consumers do not need import changes.

  • All 65 named exports are retained with the same names.
  • The historical capitilize spelling remains available.
  • Existing false, null, and undefined sentinel behavior is preserved where consumers rely on it.
  • window.Notificator, window.addToBug, window.addToHistory, window.showIndicator, and window.animate are still assigned.
  • Image and font language registration still runs when the facade loads.
  • Input focus-state initialization still runs at module evaluation time.
  • Class exports retain identity with their existing _ClassName implementations.

Dependency graph changes

Three classes previously imported the compatibility facade that imported those same classes, creating circular module graphs:

  • EditorAdapter now imports the language registry directly.
  • Options now imports transparentColor from lib/format.js.
  • TopBarElement now imports idify from lib/encoding.js.

createNotify now uses the leaf validation module instead of importing modalsHandler/engine.js. Importing notification utilities therefore no longer initializes the modal backdrop and the complete modal component graph.

The debugger window also receives an explicit module-scoped debuggerWindow reference instead of assigning an undeclared global.

Types and documentation

The renderer project is compiled with strict: true. Browser globals that are provided by preload scripts or external scripts are declared in assets/ts/globals.d.ts. Public utility behavior is documented with focused TSDoc comments rather than repeating function names or implementation details.

Verification

  • npm run build
  • npm test (6/6 tests pass)
  • Automated comparison of the old and new facade: all 65 exports match
  • Characterization coverage for HTML escaping, capitalization, initials, truncation, dedent, UTF-8 base64, identifier encoding, editor mode lookup, path normalization, time conversion, color conversion, JSON classification, and legacy null behavior
  • Confirmed that libClasses no longer import lib.js
  • Confirmed that the existing sidebar behavior fix is not included in this PR

@cdmtn-dev cdmtn-dev closed this Aug 7, 2026
@cdmtn-dev cdmtn-dev reopened this Aug 7, 2026
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.

2 participants