Table of Contents

Struct CssUrl

Namespace
Egami.Css
Assembly
Egami.Css.dll

A URL from url(...) (quoted or not) or src(...).

public readonly record struct CssUrl : IEquatable<CssUrl>
Implements
Inherited Members

Examples

bool isLength = CssLength.TryParse("1.5em", out CssLength length);       // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px);  // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle);        // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);

// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
    CssUnit.Percent => 3,   // a percent of a 300px box
    CssUnit.Em => 16,
    CssUnit.Px => 1,
    _ => double.NaN,
});                                                       // 268

Constructors

CssUrl(string)

A URL from url(...) (quoted or not) or src(...).

public CssUrl(string Url)

Parameters

Url string

The URL text, unresolved.

Examples

bool isLength = CssLength.TryParse("1.5em", out CssLength length);       // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px);  // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle);        // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);

// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
    CssUnit.Percent => 3,   // a percent of a 300px box
    CssUnit.Em => 16,
    CssUnit.Px => 1,
    _ => double.NaN,
});                                                       // 268

Properties

Url

The URL text, unresolved.

public string Url { get; init; }

Property Value

string

Methods

ToString()

Formats the URL as CSS text: url("...").

public override string ToString()

Returns

string

The text.

TryParse(CssComponentValue, out CssUrl)

Parses one component value: a url token, or a url() or src() function whose first argument is a string.

public static bool TryParse(CssComponentValue value, out CssUrl url)

Parameters

value CssComponentValue

The component value.

url CssUrl

The URL.

Returns

bool

True when the value is a URL. URL modifiers after the string are ignored.

TryParse(string, out CssUrl)

Parses url(...) or src(...) text.

public static bool TryParse(string text, out CssUrl url)

Parameters

text string

The CSS text.

url CssUrl

The URL.

Returns

bool

True when the text is one URL.