mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 00:08:05 -04:00
ADDED css min(), max() and clamp() for lengths css-wide keywords inherit, initial, unset, revert (incl. shorthands) added currentColor keyword to css colors can parse oklch(), lab() and hwb() added css text-align: justify css white-space: pre-wrap and break-spaces added css word-break: break-word parses css image-rendering: crisp-edges (point sampling) added css inset shorthand now parses 1–4 values in the css border-width shorthand added css transition-duration, -delay, -property and -timing-function longhands css :has() now supports descendant selectors added css opacity percentages added css overflow: auto (maps to scroll) added css gap: normal added css filter: none css transform: scale() now takes comma-separated args css animations now accept ms units added more css justify-content, align-* and text-align keywords (start, end, …) parses css dvh/svh/lvh/dvw viewport units (treated as vh/vw) parses css object-fit: scale-down (treated as contain) added css margin-block / margin-inline (+ the logical margin sides) added css padding-block / padding-inline (+ the logical padding sides) added css inset-block / inset-inline (+ the logical inset sides) added the css flex-flow shorthand added the css font shorthand added css font-size keywords (xx-small … xxx-large) css letter-spacing and word-spacing now accept normal added css font-smooth: none css aspect-ratio now accepts the auto form css font-family now maps generic families (serif, sans-serif, monospace) added css flex-flow added css font FIXED fixed css !important dropping the whole declaration css line-height without units is now a multiplier fixed css calc() division and full-expression parsing fixed the css flex shorthand for single-number and three-value forms fixed the css transition shorthand when the property is omitted css font-family now uses the first family in a comma stack colors now parse fully in the css background shorthand an unknown css @-rule no longer drops the whole stylesheet css variables no longer match on partial tokens injected css variables are kept across stylesheet hotloads fixed css selector specificity overflowing when comparing rules css background: none now resets the background (image and colour) css filter: none now overrides a filter set by a base class css transform: none now overrides a transform set by a base class IMPROVED css rule matching is ~3–5× faster on large stylesheets (rules indexed by class) ~2× fewer allocations in css transitions (snapshot styles once, not per property) finished css animations no longer re-layout every frame less GC in css sibling/child selector queries (no list copies or wrappers) less GC diffing active css rules (no LINQ or hashsets) faster, lower-GC Yoga layout wrapper css stylesheet hotload now watches newly imported files
171 lines
4.0 KiB
C#
171 lines
4.0 KiB
C#
|
|
namespace Sandbox.UI;
|
|
|
|
/// <summary>
|
|
/// Describes transition of a single CSS property, a.k.a. the values of a <c>transition</c> CSS property.
|
|
/// <para>Utility to create a transition by comparing the
|
|
/// panel style before and after the scope.</para>
|
|
/// </summary>
|
|
public struct TransitionDesc
|
|
{
|
|
/// <summary>
|
|
/// The CSS property to transition.
|
|
/// </summary>
|
|
public string Property;
|
|
|
|
/// <summary>
|
|
/// Duration of the transition between old value and new value.
|
|
/// </summary>
|
|
public float? Duration;
|
|
|
|
/// <summary>
|
|
/// If set, delay before starting the transition after the property was changed.
|
|
/// </summary>
|
|
public float? Delay;
|
|
|
|
/// <summary>
|
|
/// The timing or "easing" function. <c>transition-timing-function</c> CSS property.
|
|
/// Example values would be <c>ease</c>, <c>ease-in</c>, <c>ease-out</c> and <c>ease-in-out</c>.
|
|
/// </summary>
|
|
public string TimingFunction;
|
|
|
|
internal static TransitionList ParseProperty( string property, string value, TransitionList list )
|
|
{
|
|
var p = new Parse( value );
|
|
|
|
if ( list == null )
|
|
list = new TransitionList();
|
|
|
|
if ( property == "transition" )
|
|
{
|
|
while ( !p.IsEnd )
|
|
{
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( p.IsEnd ) break;
|
|
|
|
var sub = p.ReadUntilOrEnd( ",", true, true );
|
|
if ( !p.IsEnd ) p.Pointer++;
|
|
|
|
if ( string.IsNullOrWhiteSpace( sub ) ) continue;
|
|
|
|
var transition = Parse( sub );
|
|
list.Add( transition );
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
// Longhand properties (transition-duration/-delay/-property/-timing-function). Each is a
|
|
// comma-separated list whose i-th value updates the i-th transition entry, creating entries
|
|
// with sensible defaults as needed.
|
|
var items = value.Split( ',' );
|
|
for ( int i = 0; i < items.Length; i++ )
|
|
{
|
|
var item = items[i].Trim();
|
|
if ( string.IsNullOrEmpty( item ) ) continue;
|
|
|
|
while ( list.List.Count <= i )
|
|
list.List.Add( new TransitionDesc { Property = "all", TimingFunction = "ease", Delay = 0, Duration = 0 } );
|
|
|
|
var t = list.List[i];
|
|
|
|
switch ( property )
|
|
{
|
|
case "transition-property":
|
|
t.Property = StyleParser.GetPropertyFromAlias( item.ToLower() );
|
|
break;
|
|
|
|
case "transition-duration":
|
|
{
|
|
var pp = new Parse( item );
|
|
if ( pp.TryReadTime( out var d ) ) t.Duration = d;
|
|
}
|
|
break;
|
|
|
|
case "transition-delay":
|
|
{
|
|
var pp = new Parse( item );
|
|
if ( pp.TryReadTime( out var d ) ) t.Delay = d;
|
|
}
|
|
break;
|
|
|
|
case "transition-timing-function":
|
|
t.TimingFunction = item;
|
|
break;
|
|
|
|
default:
|
|
Log.Warning( $"Didn't handle transition style: {property}" );
|
|
return null;
|
|
}
|
|
|
|
list.List[i] = t;
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
static TransitionDesc Parse( string value )
|
|
{
|
|
var p = new Parse( value );
|
|
|
|
var t = new TransitionDesc();
|
|
t.Delay = 0;
|
|
t.TimingFunction = "ease"; // default is ease
|
|
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
|
|
// The property is optional and defaults to 'all' (eg "transition: 0.3s ease"). If the first
|
|
// token reads as a time then there's no property - don't consume it as one.
|
|
var probe = p;
|
|
if ( probe.TryReadTime( out _ ) )
|
|
{
|
|
t.Property = "all";
|
|
}
|
|
else
|
|
{
|
|
t.Property = p.ReadWord( null, true ).ToLower();
|
|
t.Property = StyleParser.GetPropertyFromAlias( t.Property );
|
|
if ( p.IsEnd ) return t;
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( p.IsEnd ) return t;
|
|
}
|
|
|
|
//
|
|
// Duration is mandatory
|
|
//
|
|
if ( !p.TryReadTime( out var duration ) )
|
|
throw new System.Exception( "Expecting time in transition" );
|
|
|
|
t.Duration = duration;
|
|
|
|
if ( p.IsEnd ) return t;
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( p.IsEnd ) return t;
|
|
|
|
//
|
|
// Try to read the delay now, since it could be here
|
|
//
|
|
if ( p.TryReadTime( out var delay ) )
|
|
{
|
|
t.Delay = delay;
|
|
}
|
|
|
|
if ( p.IsEnd ) return t;
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( p.IsEnd ) return t;
|
|
|
|
t.TimingFunction = p.ReadWord( null, true, true );
|
|
|
|
if ( p.IsEnd ) return t;
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( p.IsEnd ) return t;
|
|
|
|
if ( p.TryReadTime( out delay ) )
|
|
{
|
|
t.Delay = delay;
|
|
}
|
|
|
|
return t;
|
|
}
|
|
}
|