export let flow_clamp = (value, min_value, max_value) => {
let clamped = value < min_value ? min_value : (value > max_value ? max_value : value)
clamped
}
export let flow_label_box = (b, label, default_font_size, default_min_width, default_max_width, default_min_height, default_padding_x, default_padding_y) => {
let font_size = attr_or(b, "font_size", default_font_size)
let line_height = attr_or(b, "line_height", 1.2)
let pad_x = attr_or(b, "label_padding_x", default_padding_x)
let pad_y = attr_or(b, "label_padding_y", default_padding_y)
let min_w = attr_or(b, "min_width", default_min_width)
let max_w = attr_or(b, "max_width", default_max_width)
let min_h = attr_or(b, "min_height", default_min_height)
let requested_w = attr_or(b, "width", 0)
let requested_h = attr_or(b, "height", 0)
let max_label_w = max_w - pad_x * 2
let initial = measure_text({ content = label, font_size = font_size, line_height = line_height, max_width = max_label_w })
let auto_w = wdoc::flow_clamp(initial.width + pad_x * 2, min_w, max_w)
let w = requested_w > 0 ? requested_w : auto_w
let label_w = w - pad_x * 2
let final_metrics = measure_text({ content = label, font_size = font_size, line_height = line_height, max_width = label_w })
let auto_h = final_metrics.height + pad_y * 2
let h = requested_h > 0 ? requested_h : (auto_h < min_h ? min_h : auto_h)
{ width = w, height = h, label_width = label_w, font_size = font_size, line_height = line_height }
}
export let widget_flowchart = (b) => {
let min_w = attr_or(b, "min_width", 260)
let min_h = attr_or(b, "min_height", 180)
let w = attr_or(b, "width", min_w)
let h = attr_or(b, "height", min_h)
let label = attr_or(b, "label", "Flowchart")
let color = attr_or(b, "color", "var(--color-nav-border)")
let surface_fill = attr_or(b, "surface_fill", "none")
let border_stroke = attr_or(b, "border_stroke", color)
let label_fill = attr_or(b, "label_fill", "currentColor")
let radius = attr_or(b, "radius", 8)
let border_width = attr_or(b, "border_width", 1.5)
let dash = attr_or(b, "stroke_dasharray", "8,4")
let frame = [
{ kind = "rect", x = 0, y = 0, width = w, height = h, rx = radius,
fill = surface_fill, stroke = border_stroke, stroke_width = border_width,
stroke_dasharray = dash, _wdoc_full_container = true }
]
let title = label != "" ? [
{ kind = "text", x = 12, y = 6, width = w - 24, height = 20,
content = label, font_size = 12, anchor = "start", fill = label_fill }
] : []
concat(frame, title)
}