Metadata-Version: 2.4
Name: comfy-dynamic-widgets
Version: 0.0.7
Summary: Dynamic widget visibility for ComfyUI nodes via simple metadata
Project-URL: Homepage, https://github.com/PozzettiAndrea/comfy-dynamic-widgets
Project-URL: Repository, https://github.com/PozzettiAndrea/comfy-dynamic-widgets
Project-URL: Issues, https://github.com/PozzettiAndrea/comfy-dynamic-widgets/issues
Author: Andrea Pozzetti
License: MIT
License-File: LICENSE
Keywords: comfyui,conditional,dynamic,visibility,widgets
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Description-Content-Type: text/markdown

# comfy-dynamic-widgets

A Python library that enables conditional widget visibility in ComfyUI nodes via simple metadata.

## Installation

```bash
pip install comfy-dynamic-widgets
```

## Usage

### For Node Authors

Add `visible_when` metadata to widget definitions:

```python
@classmethod
def INPUT_TYPES(cls):
    return {
        "required": {
            "backend": (["option_a", "option_b", "option_c"], {"default": "option_a"}),
        },
        "optional": {
            "param_for_a": ("FLOAT", {
                "default": 0.1,
                "visible_when": {"backend": ["option_a"]},
            }),
            "param_for_b_and_c": ("INT", {
                "default": 10,
                "visible_when": {"backend": ["option_b", "option_c"]},
            }),
        }
    }
```

### For Custom Node Package Authors

In your `prestartup_script.py`:

```python
import json
import os

def generate_widget_mappings():
    try:
        from comfy_dynamic_widgets import scan_all_nodes, generate_mappings

        configs = scan_all_nodes()
        if not configs:
            return

        mappings = generate_mappings(configs)

        output_path = os.path.join(
            os.path.dirname(__file__), "web", "js", "mappings.json"
        )
        with open(output_path, "w") as f:
            json.dump(mappings, f, indent=2)

    except ImportError:
        print("comfy-dynamic-widgets not installed")

generate_widget_mappings()
```

Copy the `dynamic_widgets.js` from this package to your `web/js/` folder and update the mappings path.

## API

### `scan_all_nodes() -> dict`

Scans all registered ComfyUI nodes and extracts `visible_when` metadata.

### `generate_mappings(configs: dict) -> dict`

Transforms node visibility configs into a JS-friendly JSON format.

## License

MIT
