# scales


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Numeric Scale Definitions

Define the standard numeric scales used by Tailwind CSS:

------------------------------------------------------------------------

### generate_fractions

``` python

def generate_fractions(
    
)->List: # List of all valid Tailwind fraction strings sorted by value

```

*Generate all valid Tailwind fractions.*

## Scale Builders

Builders for creating utilities with different scale types:

------------------------------------------------------------------------

### ScaleConfig

``` python

def ScaleConfig(
    numeric:bool=True, decimals:bool=False, fractions:bool=False, named:Optional=None, special:Optional=None,
    negative:bool=False
)->None:

```

*Configuration for a scale builder.*

------------------------------------------------------------------------

### ScaledUtility

``` python

def ScaledUtility(
    prefix:str, # The utility prefix (e.g., 'w', 'h', 'p')
    config:ScaleConfig, # Configuration defining valid scales and values
    negative:bool=False, # Whether this is a negative variant
):

```

*Utility class with scale support.*

## Scale Factory

Enhanced factory that supports all scale types:

------------------------------------------------------------------------

### ScaledFactory

``` python

def ScaledFactory(
    prefix:Optional=None, # The utility prefix (e.g., 'w', 'h', 'p')
    config:Optional=None, # Configuration defining valid scales and values
    doc:Optional=None, # Optional documentation string
):

```

*Factory for creating scaled utilities with enhanced attribute access.*

------------------------------------------------------------------------

### NegativeFactory

``` python

def NegativeFactory(
    prefix:str, # The utility prefix (e.g., 'm', 'inset')
    config:ScaleConfig, # Configuration defining valid scales and values
):

```

*Factory for creating negative variants.*

## Directional Scale Factory

Factory for utilities with directional variants:

------------------------------------------------------------------------

### DirectionalScaledUtility

``` python

def DirectionalScaledUtility(
    prefix:str, # The base utility prefix (e.g., 'p' for padding)
    direction:Optional, # The direction suffix ('t', 'r', 'b', 'l', 'x', 'y')
    config:ScaleConfig, # Configuration defining valid scales and values
    negative:bool=False, # Whether this is a negative variant
):

```

*Directional utility with scale support.*

------------------------------------------------------------------------

### DirectionalScaledFactory

``` python

def DirectionalScaledFactory(
    prefix:str, # The base utility prefix (e.g., 'p' for padding, 'm' for margin)
    config:ScaleConfig, # Configuration defining valid scales and values
    doc:Optional=None, # Optional documentation string
):

```

*Factory for creating directional scaled utilities.*

## Pre-configured Scale Configs

Common scale configurations for different utility types:

## Examples

Test the scale builders with various configurations:

``` python
# Test basic numeric scales
w = ScaledFactory("w", SIZE_CONFIG)
assert str(w(4)) == "w-4"
assert str(w(2.5)) == "w-2.5"
assert str(w(0)) == "w-0"
```

``` python
# Test fraction support
assert str(w("1/2")) == "w-1/2"
assert str(w("3/4")) == "w-3/4"
assert str(w("2/3")) == "w-2/3"
```

``` python
# Test named scales
assert str(w.xs) == "w-xs"
assert str(w.sm) == "w-sm"
assert str(w.lg) == "w-lg"
assert str(w._2xl) == "w-2xl"  # Python identifiers can't start with numbers
```

``` python
# Test ScaledFactory tab-completion for special values and named scales
w = ScaledFactory("w", SIZE_CONFIG)

# Test special values have properties for tab-completion
assert hasattr(w, 'auto')
assert hasattr(w, 'px')
assert hasattr(w, 'full')
assert hasattr(w, 'screen')
assert hasattr(w, 'min')
assert hasattr(w, 'max')

# Verify these are properties
assert isinstance(type(w).auto, property)
assert isinstance(type(w).full, property)
assert isinstance(type(w).screen, property)

# Test named scales have properties for tab-completion  
assert hasattr(w, '_3xs')
assert hasattr(w, '_2xs')
assert hasattr(w, 'xs')
assert hasattr(w, 'sm')
assert hasattr(w, 'md')
assert hasattr(w, 'lg')
assert hasattr(w, 'xl')
assert hasattr(w, '_2xl')
assert hasattr(w, '_7xl')

# Verify named scales are properties
assert isinstance(type(w).xs, property)
assert isinstance(type(w).lg, property)
assert isinstance(type(w)._2xl, property)

# Test that they work correctly
assert str(w.auto) == "w-auto"
assert str(w.full) == "w-full"
assert str(w.xs) == "w-xs"
assert str(w._2xl) == "w-2xl"

# Test negative factory tab-completion
m = DirectionalScaledFactory("m", SPACING_CONFIG)
assert hasattr(m.negative, 'px')
assert isinstance(type(m.negative).px, property)
assert str(m.negative.px) == "-m-px"

print("✅ ScaledFactory tab-completion tests passed!")
```

    ✅ ScaledFactory tab-completion tests passed!

``` python
# Test special values
assert str(w.auto) == "w-auto"
assert str(w.full) == "w-full"
assert str(w.screen) == "w-screen"
assert str(w.px) == "w-px"
```

``` python
# Test arbitrary values
assert str(w("10px")) == "w-[10px]"
assert str(w("2.5rem")) == "w-[2.5rem]"
assert str(w("calc(100% - 20px)")) == "w-[calc(100% - 20px)]"
```

``` python
# Test custom properties
assert str(w("--custom-width")) == "w-(--custom-width)"
```

### Test Directional Scales

``` python
# Test directional factory
p = DirectionalScaledFactory("p", SPACING_CONFIG)

# Test all directions
assert str(p(4)) == "p-4"
assert str(p.t(4)) == "pt-4"
assert str(p.r(4)) == "pr-4"
assert str(p.b(4)) == "pb-4"
assert str(p.l(4)) == "pl-4"
assert str(p.x(4)) == "px-4"
assert str(p.y(4)) == "py-4"
```

``` python
# Test directional with special values
assert str(p.x.auto) == "px-auto"
assert str(p.y(0)) == "py-0"
```

### Test Negative Values

``` python
# Test margin with negative values
m = DirectionalScaledFactory("m", SPACING_CONFIG)

# Test negative numeric values
assert str(m(4, negative=True)) == "-m-4"
assert str(m.negative(4)) == "-m-4"
assert str(m.t.negative(2)) == "-mt-2"
assert str(m.x.negative(8)) == "-mx-8"
```

``` python
# Test negative special values
assert str(m.negative.px) == "-m-px"
assert str(m.x.negative.px) == "-mx-px"
```

### Test Inset with Negative Values

``` python
# Test inset (top/right/bottom/left)
inset = DirectionalScaledFactory("inset", INSET_CONFIG)

# Regular values
assert str(inset(4)) == "inset-4"
assert str(inset("1/2")) == "inset-1/2"
assert str(inset.auto) == "inset-auto"
assert str(inset.full) == "inset-full"

# Negative values
assert str(inset.negative(4)) == "-inset-4"
assert str(inset.negative("1/2")) == "-inset-1/2"
assert str(inset.negative.full) == "-inset-full"
```

### Test All Fractions

``` python
# Show all generated fractions
print("Generated fractions:")
print(FRACTIONS)
```

    Generated fractions:
    ['1/12', '2/12', '1/6', '1/5', '1/4', '3/12', '4/12', '1/3', '2/6', '2/5', '5/12', '6/12', '1/2', '3/6', '2/4', '7/12', '3/5', '2/3', '8/12', '4/6', '9/12', '3/4', '4/5', '5/6', '10/12', '11/12']

``` python
# Test fraction edge cases
h = ScaledFactory("h", SIZE_CONFIG)
assert str(h("1/2")) == "h-1/2"
assert str(h("1/3")) == "h-1/3"
assert str(h("2/3")) == "h-2/3"
assert str(h("1/4")) == "h-1/4"
assert str(h("3/4")) == "h-3/4"
assert str(h("1/6")) == "h-1/6"
assert str(h("5/6")) == "h-5/6"
```

### Test Class Combination

``` python
# Test combining multiple utilities
from cjm_fasthtml_tailwind.core.base import combine_classes
w = ScaledFactory("w", SIZE_CONFIG)
h = ScaledFactory("h", SIZE_CONFIG)
p = DirectionalScaledFactory("p", SPACING_CONFIG)
m = DirectionalScaledFactory("m", SPACING_CONFIG)

# Create various utilities
w_util = w(32)
h_util = h.full
p_util = p.x(4)
m_util = m.y.auto

# Combine them
classes = combine_classes(w_util, h_util, p_util, m_util, "flex", "items-center")
assert classes == "w-32 h-full px-4 my-auto flex items-center"
```

## Helper Functions

Utility functions for working with scales:

------------------------------------------------------------------------

### list_scale_values

``` python

def list_scale_values(
    config:ScaleConfig, # The scale configuration to extract values from
)->Dict: # Dictionary mapping scale types to their values

```

*List all possible values for a scale configuration.*

``` python
# Test listing scale values
size_values = list_scale_values(SIZE_CONFIG)
print(f"Size scale has {len(size_values['numeric'])} numeric values")
print(f"Size scale has {len(size_values['fractions'])} fraction values")
print(f"Named sizes: {size_values['named'][:5]}...")  # First 5
print(f"Special sizes: {size_values['special']}")
```

    Size scale has 97 numeric values
    Size scale has 26 fraction values
    Named sizes: ['3xs', '2xs', 'xs', 'sm', 'md']...
    Special sizes: ['auto', 'px', 'full', 'screen', 'svw', 'svh', 'lvw', 'lvh', 'dvw', 'dvh', 'min', 'max', 'fit', 'lh']

## Simple Factory

A factory for utilities that use simple string values with dot notation
access:

------------------------------------------------------------------------

### SimpleFactory

``` python

def SimpleFactory(
    values_dict:Optional=None, # Dictionary mapping attribute names to CSS values
    doc:Optional=None, # Optional documentation string
):

```

*Factory for utilities that are simple string values with modifier
support.*

``` python
# Test SimpleFactory with modifier support
test_values = {
    "auto": "auto-value",
    "none": "none-value",
    "multi-word": "multi-word-value"
}

factory = SimpleFactory(test_values)

# Test basic access (now returns utilities)
assert str(factory.auto) == "auto-value"
assert str(factory.none) == "none-value"
assert str(factory.multi_word) == "multi-word-value"

# Test with modifiers
assert str(factory.auto.hover) == "hover:auto-value"
assert str(factory.none.md) == "md:none-value"
assert str(factory.multi_word.dark) == "dark:multi-word-value"

# Test chained modifiers
assert str(factory.auto.hover.lg) == "lg:hover:auto-value"
assert str(factory.none.dark.focus) == "focus:dark:none-value"

# Test that cached instances work correctly
auto1 = factory.auto
auto2 = factory.auto
assert auto1 is auto2  # Should be the same cached instance

# Test tab-completion attributes are present
assert hasattr(factory, 'auto')
assert hasattr(factory, 'none')
assert hasattr(factory, 'multi_word')

# Verify these are properties
assert isinstance(type(factory).auto, property)
assert isinstance(type(factory).none, property)
assert isinstance(type(factory).multi_word, property)

print("✅ SimpleFactory with modifiers and tab-completion tests passed!")
```

    ✅ SimpleFactory with modifiers and tab-completion tests passed!

``` python
# Test SimpleFactory subclasses with tab-completion support
class TestSubFactory(SimpleFactory):
    """Test subclass of SimpleFactory."""
    
    def __init__(self):
        test_values = {
            "option1": "test-option1",
            "option2": "test-option2",
            "multi-word": "test-multi-word"
        }
        super().__init__(test_values, "Test subclass factory")

# Create instance and test
sub_factory = TestSubFactory()

# Test basic access
assert str(sub_factory.option1) == "test-option1"
assert str(sub_factory.option2) == "test-option2"
assert str(sub_factory.multi_word) == "test-multi-word"

# Test tab-completion attributes are present
assert hasattr(sub_factory, 'option1')
assert hasattr(sub_factory, 'option2')
assert hasattr(sub_factory, 'multi_word')

# Verify these are properties
assert isinstance(type(sub_factory).option1, property)
assert isinstance(type(sub_factory).option2, property)
assert isinstance(type(sub_factory).multi_word, property)

# Test with modifiers
assert str(sub_factory.option1.hover) == "hover:test-option1"
assert str(sub_factory.option2.md) == "md:test-option2"

print("✅ SimpleFactory subclass with tab-completion tests passed!")
```

    ✅ SimpleFactory subclass with tab-completion tests passed!

------------------------------------------------------------------------

### enums_to_simple_factory

``` python

def enums_to_simple_factory(
    prefix:str, # The factory prefix
    src_enums:List, # The source enums
    doc:Optional=None, # The factory docstring.
)->SimpleFactory: # The resulting simple factory

```

*Create a SimpleFactory using a string prefix and the values from a list
of enums*
