# REQ-tv-d00003: JavaScript Extraction

**Level**: Dev | **Status**: Draft | **Implements**: REQ-tv-p00001

## Assertions

A. All JavaScript code SHALL be extracted from Python string literals to a standalone `scripts.js` file located at `templates/partials/scripts.js`.

B. The JavaScript file SHALL contain all functionality currently generated by `_generate_side_panel_js()` and any other JavaScript-generating methods.

C. The JavaScript file SHALL be a valid JavaScript document that can be parsed by standard JavaScript tools and linters.

D. The JavaScript file SHALL be readable by IDEs with proper syntax highlighting, autocomplete, and error detection.

E. JavaScript code SHALL be organized using a module pattern with a single namespace object (e.g., `TraceView`).

F. The module pattern SHALL group related functions into logical sub-objects: `panel`, `codeViewer`, `editMode`, `state`.

G. JavaScript content SHALL be loaded from the file at template render time.

H. The extracted JavaScript SHALL produce functionally identical behavior to the current inline JavaScript generation.

I. Global state variables (e.g., `reqCardStack`, `pendingMoves`) SHALL be encapsulated within the module namespace.

J. Event handlers for dynamically created elements SHALL be bound using `addEventListener` rather than inline `onclick` attributes.

K. The JavaScript file SHALL include JSDoc comments for all public functions.

## Rationale

The current implementation embeds 736 lines of JavaScript in `_generate_side_panel_js()` as a Python string literal containing 28 functions. This approach:
- Prevents IDE JavaScript support (linting, type checking, error detection)
- Makes debugging difficult (errors reference Python line numbers, not JS)
- Couples behavior changes to Python code changes
- Uses global variables without encapsulation

The module pattern provides:
- Clear namespace to avoid global pollution
- Logical grouping of related functionality
- Encapsulated state management
- Better testability

*End* *JavaScript Extraction* | **Hash**: 297cf4c0
