# luke-chang/js-spatial-navigation architecture

> Architecture diagram of the GitHub repository luke-chang/js-spatial-navigation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luke-chang/js-spatial-navigation
- Repository: https://github.com/luke-chang/js-spatial-navigation

## Overview

##### Component Details

a) Core Navigation Engine (Central Component):
- Configuration Manager (handles global and per-section configs)
- Section Manager (manages different navigation sections)
- Focus Controller (handles focus state and transitions)
- Navigation Algorithm (determines next focus target)

b) Event System (Lower Layer):
Input Events:
- API Method Calls

Output Events:
- sn:willmove
- sn:willunfocus
- sn:unfocused
- sn:willfocus
- sn:focused
- sn:navigatefailed
- sn:enter-down
- sn:enter-up

c) DOM Integration (Top Layer):
- Element Selector System
- Focus Management
- Custom Attributes Handler (data-sn-*)
- jQuery Integration (optional component)

##### Important Notes

- Browser support requirements
- Key configuration options
- Critical initialization requirements

##### Flow Indicators

Primary flows:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Navigation Engine"]
        SN[SpatialNavigation]
        click SN "https://github.com/luke-chang/js-spatial-navigation/blob/master/spatial_navigation.js"
        
        subgraph ConfigSystem["Configuration System"]
            CM[Configuration Manager]
            click CM "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/1.4_basic_config.html"
        end
        
        subgraph NavSystem["Navigation System"]
            SM[Section Manager]
            click SM "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/2.1_multiple_sections.html"
            FC[Focus Controller]
            NA[Navigation Algorithm]
            click NA "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/1.6_specify_next_element.html"
        end
        
        SN --> CM
        SN --> SM
        SM --> FC
        FC --> NA
    end
    
    subgraph DOM["DOM Integration Layer"]
        ES[Element Selector]
        click ES "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/1.5_navigable_filter.html"
        FM[Focus Management]
        click FM "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/2.3_enter_to_last_focused.html"
        CAH[Custom Attributes Handler]
        JQ[jQuery Integration]:::optional
        
        ES --> FM
        ES --> CAH
        FM --> JQ
    end
    
    subgraph Events["Event System Layer"]
        direction TB
        
        subgraph InputEvents["Input Events"]
            KE[Keyboard Events]
            API[API Methods]
            click API "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/1.3_events.html"
        end
        
        subgraph OutputEvents["Output Events"]
            WM["sn:willmove"]
            WUF["sn:willunfocus"]
            UF["sn:unfocused"]
            WF["sn:willfocus"]
            F["sn:focused"]
            NF["sn:navigatefailed"]
            ED["sn:enter-down"]
            EU["sn:enter-up"]
        end
    end
    
    %% Connections
    KE --> SN
    API --> SN
    SN --> OutputEvents
    SN --> DOM
    
    %% Utilities
    UTIL[Utility Functions]
    click UTIL "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/js/util.js"
    UTIL --> SN
    
    %% Complete Implementation
    FULL[Complete Implementation]
    click FULL "https://github.com/luke-chang/js-spatial-navigation/blob/master/demo/3.1_put_all_together.html"
    FULL -.-> SN
    
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef dom fill:#90EE90,stroke:#333
    classDef events fill:#FFB347,stroke:#333
    classDef optional fill:#D3D3D3,stroke:#333
    classDef utility fill:#DDA0DD,stroke:#333
    
    class SN,ConfigSystem,NavSystem,CM,SM,FC,NA core
    class ES,FM,CAH,JQ dom
    class InputEvents,OutputEvents,KE,API,WM,WUF,UF,WF,F,NF,ED,EU events
    class JQ optional
    class UTIL utility
    
    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[DOM Integration]:::dom
        L3[Event System]:::events
        L4[Optional Features]:::optional
        L5[Utilities]:::utility
    end
```
