Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Deduplicate ANSI subsystem shared logic into ansi-shared package

Đang mở
#696 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
build-system, tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
1
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jcollard/LuaInTheWeb

Tất cả issue của jcollard/LuaInTheWeb

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.