Skip to content

Commit

Permalink
meta: Update from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 27, 2024
1 parent 9e51210 commit d0a6ca4
Show file tree
Hide file tree
Showing 36 changed files with 1,539 additions and 533 deletions.
32 changes: 28 additions & 4 deletions src/libs/karm-math/radii.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,29 @@ struct Radii {
constexpr Radii(T a, T b, T c, T d, T e, T f, T g, T h)
: a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) {}

bool zero() const {
constexpr Radii(Radii const &other)
: radii(other.radii) {}

constexpr Radii(Radii const &&other)
: radii(std::move(other.radii)) {}

constexpr Radii &operator=(Radii const &other) {
radii = other.radii;
return *this;
}

constexpr Radii &operator=(Radii &&other) {
radii = std::move(other.radii);
return *this;
}

constexpr ~Radii() {
radii.~Array();
}

bool zero() const
requires(Meta::Equatable<T>)
{
return iter(radii).all([](T radii) {
return radii == T{};
});
Expand Down Expand Up @@ -143,9 +165,11 @@ struct Radii {
}

void repr(Io::Emit &_e) const {
if (zero()) {
_e("(radii {})", a);
return;
if constexpr (Meta::Equatable<T>) {
if (zero()) {
_e("(radii {})", a);
return;
}
}

_e("(radii {} {} {} {} {} {} {} {})", a, b, c, d, e, f, g, h);
Expand Down
19 changes: 16 additions & 3 deletions src/web/vaev-base/background.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <karm-mime/url.h>

#include "color.h"
#include "image.h"
#include "length.h"
#include "percent.h"

Expand Down Expand Up @@ -122,20 +123,32 @@ struct BackgroundRepeat {
}
};

struct BackgroundProps {
Color fill;
struct BackgroundLayer {
Opt<Image> image;
BackgroundAttachment attachment;
BackgroundPosition position;
BackgroundRepeat repeat;

void repr(Io::Emit &e) const {
e("(background");
e(" fill={}", fill);
e(" image={}", image);
e(" attachment={}", attachment);
e(" position={}", position);
e(" repeat={}", repeat);
e(")");
}
};

struct BackgroundProps {
Color color;
Vec<BackgroundLayer> layers = {};

void repr(Io::Emit &e) const {
e("(background");
e(" color={}", color);
e(" layers={}", layers);
e(")");
}
};

} // namespace Vaev
5 changes: 3 additions & 2 deletions src/web/vaev-base/borders.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <karm-gfx/fill.h>
#include <karm-math/radii.h>

#include "calc.h"
#include "color.h"
#include "length.h"
#include "percent.h"
Expand Down Expand Up @@ -34,7 +35,7 @@ enum struct BorderStyle {
};

struct Border {
Length width;
CalcValue<Length> width;
Gfx::BorderStyle style;
Color color = Color::CURRENT;

Expand All @@ -49,7 +50,7 @@ struct BorderProps {
static constexpr Length THICK = 5_px;

Border top, start, bottom, end;
Math::Radii<PercentOr<Length>> radii;
Math::Radii<CalcValue<PercentOr<Length>>> radii;

void all(Border b) {
top = start = bottom = end = b;
Expand Down
4 changes: 2 additions & 2 deletions src/web/vaev-base/calc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct CalcValue {
: CalcValue(T{}) {
}

constexpr CalcValue(T value)
: type(OpType::FIXED), lhs(value) {
constexpr CalcValue(Meta::Convertible<T> auto value)
: type(OpType::FIXED), lhs(T{value}) {
}

constexpr CalcValue(Value value)
Expand Down
89 changes: 89 additions & 0 deletions src/web/vaev-base/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,93 @@ Opt<SystemColor> parseSystemColor(Str name);

Gfx::Color resolve(Color c, Gfx::Color currentColor);

// MARK: Color Interpolation ---------------------------------------------------

// https://www.w3.org/TR/css-color-4/#typedef-color-space
struct ColorSpace {
enum struct _Type {
POLAR,
RECTANGULAR,

_LEN0,
};

using enum _Type;

// https://www.w3.org/TR/css-color-4/#typedef-rectangular-color-space
enum struct _Rectangular {
SRGB,
SRGB_LINEAR,
DISPLAY_P3,
A98_RGB,
PROPHOTO_RGB,
REC2020,
LAB,
OKLAB,
XYZ,
XYZ_D50,
XYZ_D65,

_LEN1,

};

using enum _Rectangular;

// https://www.w3.org/TR/css-color-4/#typedef-hue-interpolation-method
enum struct _Interpolation {
SHORTER,
LONGER,
INCREASING,
DECREASING,

_LEN2,
};

using enum _Interpolation;

// https://www.w3.org/TR/css-color-4/#typedef-polar-color-space
enum struct _Polar {
HSL,
HWB,
LCH,
OKLCH,

_LEN3,
};

using enum _Polar;

_Type type;

union {
_Rectangular rectangular;

struct {
_Polar polar;
_Interpolation interpolation;
};
};

constexpr ColorSpace(_Rectangular rectangular)
: type(_Type::RECTANGULAR), rectangular(rectangular) {
}

constexpr ColorSpace(_Polar polar, _Interpolation interpolation)
: type(_Type::POLAR), polar(polar), interpolation(interpolation) {
}

constexpr ColorSpace()
: type(_Type::RECTANGULAR), rectangular(_Rectangular::SRGB) {
}

void repr(Io::Emit &e) const {
if (type == ColorSpace::RECTANGULAR) {
e("{}", rectangular);
} else {
e("{} {}", polar, interpolation);
}
}
};

} // namespace Vaev
9 changes: 9 additions & 0 deletions src/web/vaev-base/flex.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ struct FlexBasis {
}
};

struct FlexItemProps {
FlexBasis flexBasis;
Number flexGrow, flexShrink;

void repr(Io::Emit &e) const {
e("({} {} {})", flexBasis, flexGrow, flexShrink);
}
};

struct FlexProps {
// FlexContainer
FlexDirection direction = FlexDirection::ROW;
Expand Down
143 changes: 143 additions & 0 deletions src/web/vaev-base/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#pragma once

#include <karm-mime/url.h>

#include "angle.h"
#include "color.h"
#include "percent.h"

// https://www.w3.org/TR/css-images-4/

namespace Vaev {

struct Image;

// MARK: Linear Gradient -------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#linear-gradients

struct LinearGradient {
struct Stop {
Gfx::Color color;
Percent position;

void repr(Io::Emit &e) const {
e("({} {})", color, position);
}
};

Angle angle;
ColorSpace colorSpace = ColorSpace::SRGB;
Vec<Stop> stops;

void repr(Io::Emit &e) const {
e("(linear-gradient {} {} {}", angle, colorSpace, stops);
}
};

// MARK: Radial Gradient -------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#radial-gradients

struct RadialGradient {
enum struct Shape {
CIRCLE,
ELLIPSE,

_LEN,
};

Math::Vec2f size;
Math::Vec2f position;
ColorSpace colorSpace = ColorSpace::SRGB;
Vec<LinearGradient::Stop> stops;

void repr(Io::Emit &e) const {
e("(radial-gradient {} {} {} {}", size, position, colorSpace, stops);
}
};

// MARK: Conic Gradient --------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#conic-gradients

struct ConicGradient {
struct Stop {
Gfx::Color color;
Angle angle;

void repr(Io::Emit &e) const {
e("({} {})", color, angle);
}
};

Angle angle;
Math::Vec2f position;
ColorSpace colorSpace = ColorSpace::SRGB;
Vec<LinearGradient::Stop> stops;

void repr(Io::Emit &e) const {
e("(conic-gradient {} {} {} {}", angle, position, colorSpace, stops);
}
};

// MARK: Cross Fade ------------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#cross-fade-function

struct CrossFade {
struct Layer {
Box<Image> image;
Percent opacity;

void repr(Io::Emit &e) const {
e("({} {})", image, opacity);
}
};

Vec<Layer> layers;

void repr(Io::Emit &e) const {
e("(cross-fade {}", layers);
}
};

// MARK: Stripes ---------------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#stripes

struct Stripes {
struct Strip {
Gfx::Color color;
Percent size;

void repr(Io::Emit &e) const {
e("({} {})", color, size);
}
};

Vec<Strip> stripes;

void repr(Io::Emit &e) const {
e("(stripes {}", stripes);
}
};

// MARK: Image -----------------------------------------------------------------
// https://www.w3.org/TR/css-images-4/#typedef-image

using _Image = Union<
Gfx::Color,
LinearGradient,
RadialGradient,
ConicGradient,
CrossFade,
Stripes,
Mime::Url>;

struct Image : public _Image {
using _Image::_Image;

void repr(Io::Emit &e) const {
visit([&](auto const &i) {
e("{}", i);
});
}
};

} // namespace Vaev
2 changes: 1 addition & 1 deletion src/web/vaev-base/insets.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum struct Position {

using Margin = Math::Insets<Width>;

using Padding = Math::Insets<PercentOr<Length>>;
using Padding = Math::Insets<CalcValue<PercentOr<Length>>>;

// https://www.w3.org/TR/CSS22/visuren.html#propdef-top
// https://www.w3.org/TR/CSS22/visuren.html#propdef-right
Expand Down
Loading

0 comments on commit d0a6ca4

Please sign in to comment.