<commit_before>
import Patchwork.div
import Base: size

export inset,
       empty,
       container,
       offset,
       width,
       height,
       minwidth,
       minheight,
       maxwidth,
       maxheight,
       size,
       topleft,
       midtop,
       topright,
       midleft,
       middle,
       midright,
       bottomleft,
       midbottom,
       bottomright,
       vertical,
       horizontal,
       depth,
       left,
       right,
       top,
       bottom,
       inward,
       outward,
       floating,
       flow,
       hbox,
       vbox,
       vskip,
       hskip,
       grow,
       shrink,
       flex,
       wrap,
       axisstart,
       axisend,
       center,
       spacebetween,
       spacearound,
       stretch,
       packitems,
       packacross,
       packlines,
       space,
       pad,
       padcontent

# 0. Width and height

@api width => Width <: Tile begin
    doc("Set the width of a tile")
    typedarg(prefix::String="", hidedoc=true)
    arg(width::Length, doc="The width")
    curry(tile::Tile)
end
render(t::Width) = begin
    prefixed = t.prefix == "" ? "width" : t.prefix * "Width"
    render(t.tile) & style(@d(prefixed => t.width))
end

@api height => Height <: Tile begin
    doc("Set the height of a tile")
    typedarg(prefix::String="")
    arg(height::Length)
    curry(tile::Tile)
end

render(t::Height) =
    render(t.tile) &
        style(@d((t.prefix == "" ? "height" : t.prefix * "Height") => t.height))

minwidth(w, x...) = width("min", w, x...)
minheight(h, x...) = height("min", h, x...)

maxwidth(w, x...) = width("max", w, x...)
maxheight(h, x...) = height("max", h, x...)

size(w::Length, h::Length, t) =
    width(w, height(h, t))
size(w::Length, h::Length) =
    t -> size(w, h, t)

container(w, h) =
    empty |> size(w, h)

# 1. Placing a Tile inside another
abstract Position
abstract Corner <: Position

@terms Corner begin
    topleft => TopLeft
    midtop => MidTop
    topright => TopRight
    midleft => MidLeft
    middle => Middle
    midright => MidRight
    bottomleft => BottomLeft
    midbottom => MidBottom
    bottomright => BottomRight
end

name{C <: Corner}(::C) = string(C)

immutable Relative{T <: Corner} <: Position
    x::Length
    y::Length
    # z::Length
end

@api inset => Inset <: Tile begin
    typedarg(position::Position=topleft)
    arg(containing::Tile)
    curry(contained::Tile)
end

render_position(p::TopLeft, x, y) =
    @d(:top => y, :left => x)
render_position(p::MidTop, x, y) =
    @d(:left =>  50cent, :top => y,
     :transform => "translate(-50%)",
     :marginLeft => x)
render_position(p::TopRight, x, y) =
    @d(:top => x, :right => y)
render_position(p::MidLeft, x, y) =<commit_msg>fix missing offset function<commit_after>
import Patchwork.div
import Base: size

export inset,
       empty,
       container,
       offset,
       width,
       height,
       minwidth,
       minheight,
       maxwidth,
       maxheight,
       size,
       topleft,
       midtop,
       topright,
       midleft,
       middle,
       midright,
       bottomleft,
       midbottom,
       bottomright,
       vertical,
       horizontal,
       depth,
       left,
       right,
       top,
       bottom,
       inward,
       outward,
       floating,
       flow,
       hbox,
       vbox,
       vskip,
       hskip,
       grow,
       shrink,
       flex,
       wrap,
       axisstart,
       axisend,
       center,
       spacebetween,
       spacearound,
       stretch,
       packitems,
       packacross,
       packlines,
       space,
       pad,
       padcontent

# 0. Width and height

@api width => Width <: Tile begin
    doc("Set the width of a tile")
    typedarg(prefix::String="", hidedoc=true)
    arg(width::Length, doc="The width")
    curry(tile::Tile)
end
render(t::Width) = begin
    prefixed = t.prefix == "" ? "width" : t.prefix * "Width"
    render(t.tile) & style(@d(prefixed => t.width))
end

@api height => Height <: Tile begin
    doc("Set the height of a tile")
    typedarg(prefix::String="")
    arg(height::Length)
    curry(tile::Tile)
end

render(t::Height) =
    render(t.tile) &
        style(@d((t.prefix == "" ? "height" : t.prefix * "Height") => t.height))

minwidth(w, x...) = width("min", w, x...)
minheight(h, x...) = height("min", h, x...)

maxwidth(w, x...) = width("max", w, x...)
maxheight(h, x...) = height("max", h, x...)

size(w::Length, h::Length, t) =
    width(w, height(h, t))
size(w::Length, h::Length) =
    t -> size(w, h, t)

container(w, h) =
    empty |> size(w, h)

# 1. Placing a Tile inside another
abstract Position
abstract Corner <: Position

@terms Corner begin
    topleft => TopLeft
    midtop => MidTop
    topright => TopRight
    midleft => MidLeft
    middle => Middle
    midright => MidRight
    bottomleft => BottomLeft
    midbottom => MidBottom
    bottomright => BottomRight
end

name{C <: Corner}(::C) = string(C)

@api offset => Relative{T <: Corner} <: Position begin
    arg(c::T)
    arg(x::Length)
    arg(y::Length)
    # z::Length
end

@api inset => Inset <: Tile begin
    typedarg(position::Position=topleft)
    arg(containing::Tile)
    curry(contained::Tile)
end

render_position(p::TopLeft, x, y) =
    @d(:top => y, :left => x)
render_position(p::MidTop, x, y) =
    @d(:left =>  50cent, :top => y,
     :transform => "translate(-50%)",
     :marginLeft => x)
render_position(p::TopRight, x, y) =
    @d(:top => x, :right => y)
render_position(p::MidLeft, x, y) =
{'fraction_non_alphanumeric': 0.1523757509557619, 'fraction_numerical': 0.002184598580010923, 'mean_word_length': 2.2470449172576834, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5860455', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1875, 'n_words': 468}