```python:inference/core/workflows/core_steps/classical_cv/mask_area_measurement/v1.py
import cv2 as cv
import numpy as np
import supervision as sv
from inference.core.workflows.prototypes.block import BlockResult, WorkflowBlock

OUTPUT_KEY = "areas"


def get_detection_area(detection: sv.Detections, index: int) -> float:
    """Compute the area of a single detection in square pixels.

    If a segmentation mask is available, the area is computed from the largest
    contour found in the mask using ``cv2.contourArea``.  Otherwise the area
    falls back to bounding-box width * height.

    Args:
        detection: A supervision Detections object.
        index: Index of the detection to measure.

    Returns:
        Area in square pixels.
    """
    if detection.mask is not None:
        mask = detection.mask[index].astype(np.uint8)
        contours, _ = cv.findContours(mask, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
        if contours:
            largest_contour = max(contours, key=cv.contourArea)
            area = cv.contourArea(largest_contour)
            if area > 0:
                return float(area)

    bbox = detection.xyxy[index]
    w = bbox[2] - bbox[0]
    h = bbox[3] - bbox[1]
    return float(w * h)


class MaskAreaMeasurementBlockV1(WorkflowBlock):

    def run(
        self,
        predictions: sv.Detections,
    ) -> BlockResult:
        if predictions.mask is not None:
            areas = []
            for i in range(len(predictions)):
                areas.append(get_detection_area(predictions, i))
        else:
            xyxy = predictions.xyxy
            widths = xyxy[:, 2] - xyxy[:, 0]
            heights = xyxy[:, 3] - xyxy[:, 1]
            areas = (widths * heights).tolist()
        return {OUTPUT_KEY: areas}
```