# Path: weasyprint/layout/min_max.py
# def handle_min_max_height(function):
#     """Decorate a function setting used height, handling {min,max}-height."""
#     @functools.wraps(function)
#     def wrapper(box, *args):
#         computed_margins = box.margin_top, box.margin_bottom
#         result = function(box, *args)
#         if box.height > box.max_height:
#             box.height = box.max_height
#             box.margin_top, box.margin_bottom = computed_margins
#             result = function(box, *args)
#         if box.height < box.min_height:
#             box.height = box.min_height
#             box.margin_top, box.margin_bottom = computed_margins
#             result = function(box, *args)
#         return result
#     wrapper.without_min_max = function
#     return wrapper
# 
# def handle_min_max_width(function):
#     """Decorate a function setting used width, handling {min,max}-width."""
#     @functools.wraps(function)
#     def wrapper(box, *args):
#         computed_margins = box.margin_left, box.margin_right
#         result = function(box, *args)
#         if box.width > box.max_width:
#             box.width = box.max_width
#             box.margin_left, box.margin_right = computed_margins
#             result = function(box, *args)
#         if box.width < box.min_width:
#             box.width = box.min_width
#             box.margin_left, box.margin_right = computed_margins
#             result = function(box, *args)
#         return result
#     wrapper.without_min_max = function
#     return wrapper
# 
# Path: weasyprint/layout/percent.py
# def percentage(value, refer_to):
#     """Return the percentage of the reference value, or the value unchanged.
# 
#     ``refer_to`` is the length for 100%. If ``refer_to`` is not a number, it
#     just replaces percentages.
# 
#     """
#     if value is None or value == 'auto':
#         return value
#     elif value.unit == 'px':
#         return value.value
#     else:
#         assert value.unit == '%'
#         return refer_to * value.value / 100


from .min_max import handle_min_max_height, handle_min_max_width
from .percent import percentage
    from .block import block_level_width
    from .block import block_level_width
    from .float import avoid_collisions
    from .block import block_level_width
        box.height = min_height


def block_replaced_box_layout(context, box, containing_block):
    """Lay out the block :class:`boxes.ReplacedBox` ``box``."""

    box = box.copy()
    if box.style['width'] == 'auto' and box.style['height'] == 'auto':
        computed_margins = box.margin_left, box.margin_right
        block_replaced_width.without_min_max(
            box, containing_block)
        replaced_box_height.without_min_max(box)
        min_max_auto_replaced(box)
        box.margin_left, box.margin_right = computed_margins
        block_level_width.without_min_max(box, containing_block)
    else:
        block_replaced_width(box, containing_block)
        replaced_box_height(box)

    # Don't collide with floats
    # http://www.w3.org/TR/CSS21/visuren.html#floats
    box.position_x, box.position_y, _ = avoid_collisions(
        context, box, containing_block, outer=False)
    resume_at = None
    next_page = {'break': 'any', 'page': None}
    adjoining_margins = []
    collapsing_through = False
    return box, resume_at, next_page, adjoining_margins, collapsing_through



# Path: weasyprint/layout/min_max.py
# def handle_min_max_height(function):
#     """Decorate a function setting used height, handling {min,max}-height."""
#     @functools.wraps(function)
#     def wrapper(box, *args):
#         computed_margins = box.margin_top, box.margin_bottom
#         result = function(box, *args)
#         if box.height > box.max_height:
#             box.height = box.max_height
#             box.margin_top, box.margin_bottom = computed_margins
#             result = function(box, *args)
#         if box.height < box.min_height:
#             box.height = box.min_height
#             box.margin_top, box.margin_bottom = computed_margins
#             result = function(box, *args)
#         return result
#     wrapper.without_min_max = function
#     return wrapper
# 
# def handle_min_max_width(function):
#     """Decorate a function setting used width, handling {min,max}-width."""
#     @functools.wraps(function)
#     def wrapper(box, *args):
#         computed_margins = box.margin_left, box.margin_right
#         result = function(box, *args)
#         if box.width > box.max_width:
#             box.width = box.max_width
#             box.margin_left, box.margin_right = computed_margins
#             result = function(box, *args)
#         if box.width < box.min_width:
#             box.width = box.min_width
#             box.margin_left, box.margin_right = computed_margins
#             result = function(box, *args)
#         return result
#     wrapper.without_min_max = function
#     return wrapper
# 
# Path: weasyprint/layout/percent.py
# def percentage(value, refer_to):
#     """Return the percentage of the reference value, or the value unchanged.
# 
#     ``refer_to`` is the length for 100%. If ``refer_to`` is not a number, it
#     just replaces percentages.
# 
#     """
#     if value is None or value == 'auto':
#         return value
#     elif value.unit == 'px':
#         return value.value
#     else:
#         assert value.unit == '%'
#         return refer_to * value.value / 100


# Path: weasyprint/layout/replaced.py
from .min_max import handle_min_max_height, handle_min_max_width
from .percent import percentage
    from .block import block_level_width
    from .block import block_level_width
    from .float import avoid_collisions
    from .block import block_level_width

        box.height = min_height


def block_replaced_box_layout(context, box, containing_block):
    """Lay out the block :class:`boxes.ReplacedBox` ``box``."""

    box = box.copy()
    if box.style['width'] == 'auto' and box.style['height'] == 'auto':
        computed_margins = box.margin_left, box.margin_right
        block_replaced_width.without_min_max(
            box, containing_block)
        replaced_box_height.without_min_max(box)
        min_max_auto_replaced(box)
        box.margin_left, box.margin_right = computed_margins
        block_level_width.without_min_max(box, containing_block)
    else:
        block_replaced_width(box, containing_block)
        replaced_box_height(box)

    # Don't collide with floats
    # http://www.w3.org/TR/CSS21/visuren.html#floats
    box.position_x, box.position_y, _ = avoid_collisions(
        context, box, containing_block, outer=False)
    resume_at = None
    next_page = {'break': 'any', 'page': None}
    adjoining_margins = []
    collapsing_through = False
    return box, resume_at, next_page, adjoining_margins, collapsing_through



@handle_min_max_width