Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Deduplicate ANSI subsystem shared logic into ansi-shared package

Aperta
#696 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript

Direzione di ricerca

Start by comparing the paired files in packages/lua-runtime/src/ and lua-learning-website/src/components/AnsiGraphicsEditor/, then inspect packages/ansi-shared/src/index.ts and the existing package build configuration. Extract the listed types, rendering, compositing, and cell utilities, rewire both consumers, remove the ANSI exclusions from .jscpd.json, and run the existing tests plus npm run duplicates.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

The ANSI subsystem has intentionally duplicated code between packages/lua-runtime/src/ (runtime) and lua-learning-website/src/components/AnsiGraphicsEditor/ (editor). This duplication is currently suppressed in jscpd via ignore patterns, but the shared logic can be extracted into the existing packages/ansi-shared/ package — eliminating drift risk and removing the need for jscpd exclusions.

Pairs with Extractable Shared Logic

1. Core Types (~60% overlap)
  • Runtime: packages/lua-runtime/src/screenTypes.ts
  • Editor: lua-learning-website/src/components/AnsiGraphicsEditor/types.ts
  • Shared: RGBColor, AnsiCell, AnsiGrid, Rect, TextAlign, ANSI_COLS, ANSI_ROWS, DEFAULT_FG, DEFAULT_BG, DEFAULT_CELL, TRANSPARENT_HALF, TRANSPARENT_BG, HALF_BLOCK, isGroupLayer(), isDrawableLayer()
  • Stays separate: Editor-only types (BrushMode, ScaleMode, DrawTool, BorderStyle, LayerState, richer Layer hierarchy). Runtime-only simplified LayerData types.
2. Text Layer Rendering (~85% identical)
  • Runtime: packages/lua-runtime/src/textLayerGrid.ts
  • Editor: lua-learning-website/src/components/AnsiGraphicsEditor/textLayerGrid.ts
  • Shared: wrapText(), buildRawIndexMap(), justifyLine(), renderTextLayerGrid() — identical implementations
  • Stays separate: Editor-only cursorPosToVisual() function
3. Compositing Core (4 identical functions)
  • Runtime: packages/lua-runtime/src/screenCompositor.ts
  • Editor: lua-learning-website/src/components/AnsiGraphicsEditor/layerUtils.ts
  • Shared: hiddenGroupIds(), visibleDrawableLayers(), compositeCellCore(), compositeGrid()
  • Stays separate: 47 editor-only functions (layer manipulation, creation, cloning, display ordering). Requires abstract layer interface to bridge LayerData (runtime) and Layer (editor) types.
4. Cell Comparison Utility
  • Runtime: packages/lua-runtime/src/ansiStringRenderer.ts → cellsEqual()
  • Editor: lua-learning-website/src/components/AnsiGraphicsEditor/terminalBuffer.ts → cellsEqual()
  • Shared: Identical cellsEqual() function
  • Note: The rest of these two files are fundamentally different (stateless ANSI string generation vs. stateful double buffer) and should NOT be merged.

NOT in Scope

  • serialization.ts — editor-only, no runtime counterpart (not actually duplicated)
  • packages/export/src/runtime/** — architecturally different execution model (single-threaded direct draw vs. multi-threaded command queue), cannot be deduplicated
  • terminalBuffer.ts / ansiStringRenderer.ts beyond cellsEqual() — fundamentally different abstractions

Implementation Approach

The packages/ansi-shared/ package already exists (currently contains only playbackEngine.ts). New shared modules:

  1. ansi-shared/src/screenTypes.ts — Core types + constants
  2. ansi-shared/src/textRendering.ts — Text wrapping and grid rendering
  3. ansi-shared/src/compositing.ts — Layer compositing with abstract interfaces
  4. ansi-shared/src/cellUtils.ts — cellsEqual() utility
  5. Update ansi-shared/src/index.ts — Export all new modules

Both lua-runtime and the editor import from @lua-learning/ansi-shared instead of maintaining their own copies. The compositing module will need abstract interfaces (e.g., HasVisibility & HasId) that both LayerData and Layer satisfy.

Acceptance Criteria

  • Shared types, text rendering, compositing, and cellsEqual live in ansi-shared
  • packages/lua-runtime/src/ imports shared code from @lua-learning/ansi-shared
  • lua-learning-website/src/components/AnsiGraphicsEditor/ imports shared code from @lua-learning/ansi-shared
  • No copy-pasted logic remains between the paired files (only side-specific extensions)
  • jscpd ANSI exclusions removed from .jscpd.json (no longer needed)
  • All existing tests pass
  • npm run duplicates shows reduced clone count with no new ANSI cross-package hits
  • Build order respected: ansi-shared builds before lua-runtime and lua-learning-website

Complexity

Medium (~6-8 tasks). Mostly mechanical extraction + import rewiring, but the compositing abstract interface requires care.

Lingua principale
TypeScript
Stelle
1
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jcollard/LuaInTheWeb

Tutte le issue di jcollard/LuaInTheWeb

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.