mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
Added CSS light-dark function support (https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark).
Fix minor bug in SyntaxTokenizer. Fix default Google chepeast model.
This commit is contained in:
@@ -152,8 +152,8 @@
|
||||
"max_tokens": 1000000
|
||||
},
|
||||
{
|
||||
"name": "gemini-2.0-flash-lite-preview",
|
||||
"display_name": "Gemini 2.0 Flash Lite",
|
||||
"name": "gemini-2.5-flash-lite",
|
||||
"display_name": "Gemini 2.5 Flash Lite",
|
||||
"max_tokens": 1000000,
|
||||
"cheapest": true
|
||||
},
|
||||
|
||||
@@ -1092,6 +1092,12 @@ or one of the special constants.
|
||||
|
||||
---
|
||||
|
||||
### light-dark
|
||||
|
||||
Read [light-dark](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) documentation.
|
||||
|
||||
---
|
||||
|
||||
### line-spacing
|
||||
|
||||
Sets a extra line spacing to the line box.
|
||||
@@ -2099,6 +2105,12 @@ Sets the current value to an element that accepts values.
|
||||
|
||||
---
|
||||
|
||||
### var
|
||||
|
||||
Read [var](https://developer.mozilla.org/en-US/docs/Web/CSS/var) documentation.
|
||||
|
||||
---
|
||||
|
||||
### vertical-expand
|
||||
|
||||
In a progress bar enables/disables if the progress bar filler should be expanded vertically to the element
|
||||
|
||||
@@ -39,11 +39,11 @@ class EE_API StyleSheetProperty {
|
||||
bool cachedProperty = false );
|
||||
|
||||
explicit StyleSheetProperty( const std::string& name, const std::string& value,
|
||||
const bool& trimValue = true, const Uint32& specificity = 0,
|
||||
bool trimValue = true, const Uint32& specificity = 0,
|
||||
const Uint32& index = 0 );
|
||||
|
||||
explicit StyleSheetProperty( const std::string& name, const std::string& value,
|
||||
const Uint32& specificity, const bool& isVolatile = false,
|
||||
const Uint32& specificity, bool isVolatile = false,
|
||||
const Uint32& index = 0 );
|
||||
|
||||
Uint32 getId() const;
|
||||
@@ -66,9 +66,9 @@ class EE_API StyleSheetProperty {
|
||||
|
||||
void setValue( const std::string& value, bool updateHash = false );
|
||||
|
||||
const bool& isVolatile() const;
|
||||
bool isVolatile() const;
|
||||
|
||||
void setVolatile( const bool& isVolatile );
|
||||
void setVolatile( bool isVolatile );
|
||||
|
||||
bool operator==( const StyleSheetProperty& property ) const;
|
||||
|
||||
@@ -138,7 +138,9 @@ class EE_API StyleSheetProperty {
|
||||
|
||||
const ShorthandDefinition* getShorthandDefinition() const;
|
||||
|
||||
const bool& isVarValue() const;
|
||||
bool isVarValue() const;
|
||||
|
||||
bool isLightDarkValue() const;
|
||||
|
||||
size_t getPropertyIndexCount() const;
|
||||
|
||||
@@ -189,16 +191,17 @@ class EE_API StyleSheetProperty {
|
||||
String::HashType mValueHash;
|
||||
Uint32 mSpecificity;
|
||||
Uint32 mIndex;
|
||||
bool mVolatile;
|
||||
bool mImportant;
|
||||
bool mIsVarValue;
|
||||
bool mCachedProperty{ false };
|
||||
bool mVolatile : 1 { false };
|
||||
bool mImportant : 1 { false };
|
||||
bool mIsVarValue : 1 { false };
|
||||
bool mIsLightDarkValue : 1 { false };
|
||||
bool mCachedProperty : 1 { false };
|
||||
const PropertyDefinition* mPropertyDefinition;
|
||||
const ShorthandDefinition* mShorthandDefinition;
|
||||
std::vector<StyleSheetProperty> mIndexedProperty;
|
||||
std::vector<VariableFunctionCache> mVarCache;
|
||||
|
||||
explicit StyleSheetProperty( const bool& isVolatile, const PropertyDefinition* definition,
|
||||
explicit StyleSheetProperty( bool isVolatile, const PropertyDefinition* definition,
|
||||
const std::string& value, const Uint32& specificity = 0,
|
||||
const Uint32& index = 0 );
|
||||
|
||||
|
||||
@@ -99,6 +99,10 @@ class EE_API UIStyle : public UIState {
|
||||
|
||||
void applyVarValues( CSS::StyleSheetProperty* style );
|
||||
|
||||
void applyLightDarkValues( CSS::StyleSheetProperty* style );
|
||||
|
||||
void applyLightDarkValue( std::string& newValue );
|
||||
|
||||
void setVariableFromValue( CSS::StyleSheetProperty* property, const std::string& value );
|
||||
|
||||
void updateState();
|
||||
|
||||
@@ -42,8 +42,7 @@ StyleSheetProperty::StyleSheetProperty( const PropertyDefinition* definition,
|
||||
}
|
||||
}
|
||||
|
||||
StyleSheetProperty::StyleSheetProperty( const bool& isVolatile,
|
||||
const PropertyDefinition* definition,
|
||||
StyleSheetProperty::StyleSheetProperty( bool isVolatile, const PropertyDefinition* definition,
|
||||
const std::string& value, const Uint32& /*specificity*/,
|
||||
const Uint32& index ) :
|
||||
mName( definition->getName() ),
|
||||
@@ -67,7 +66,7 @@ StyleSheetProperty::StyleSheetProperty( const bool& isVolatile,
|
||||
}
|
||||
|
||||
StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::string& value,
|
||||
const bool& trimValue, const Uint32& specificity,
|
||||
bool trimValue, const Uint32& specificity,
|
||||
const Uint32& index ) :
|
||||
mName( String::toLower( String::trim( name ) ) ),
|
||||
mNameHash( String::hash( mName ) ),
|
||||
@@ -93,7 +92,7 @@ StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::stri
|
||||
}
|
||||
|
||||
StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::string& value,
|
||||
const Uint32& specificity, const bool& isVolatile,
|
||||
const Uint32& specificity, bool isVolatile,
|
||||
const Uint32& index ) :
|
||||
mName( String::toLower( String::trim( name ) ) ),
|
||||
mNameHash( String::hash( mName ) ),
|
||||
@@ -165,11 +164,11 @@ void StyleSheetProperty::setValue( const std::string& value, bool updateHash ) {
|
||||
createIndexed();
|
||||
}
|
||||
|
||||
const bool& StyleSheetProperty::isVolatile() const {
|
||||
bool StyleSheetProperty::isVolatile() const {
|
||||
return mVolatile;
|
||||
}
|
||||
|
||||
void StyleSheetProperty::setVolatile( const bool& isVolatile ) {
|
||||
void StyleSheetProperty::setVolatile( bool isVolatile ) {
|
||||
mVolatile = isVolatile;
|
||||
}
|
||||
|
||||
@@ -215,6 +214,8 @@ void StyleSheetProperty::checkVars() {
|
||||
mIsVarValue = true;
|
||||
mVarCache = std::move( varCache );
|
||||
}
|
||||
|
||||
mIsLightDarkValue = mValue.find( "light-dark(" ) != std::string::npos;
|
||||
}
|
||||
|
||||
static void varToVal( VariableFunctionCache& varCache, const std::string& varDef ) {
|
||||
@@ -536,10 +537,14 @@ const ShorthandDefinition* StyleSheetProperty::getShorthandDefinition() const {
|
||||
return mShorthandDefinition;
|
||||
}
|
||||
|
||||
const bool& StyleSheetProperty::isVarValue() const {
|
||||
bool StyleSheetProperty::isVarValue() const {
|
||||
return mIsVarValue;
|
||||
}
|
||||
|
||||
bool StyleSheetProperty::isLightDarkValue() const {
|
||||
return mIsLightDarkValue;
|
||||
}
|
||||
|
||||
size_t StyleSheetProperty::getPropertyIndexCount() const {
|
||||
return mIndexedProperty.size();
|
||||
}
|
||||
|
||||
@@ -880,6 +880,33 @@ static SyntaxDefinition loadTextMateLanguage( const nlohmann::json& json, Syntax
|
||||
return def;
|
||||
}
|
||||
|
||||
static void parseRepositoryItem( SyntaxDefinition& def, const std::string& name,
|
||||
const nlohmann::json& item ) {
|
||||
std::vector<SyntaxPattern> ptrns;
|
||||
if ( item.contains( "match" ) || item.contains( "begin" ) ) {
|
||||
ptrns.emplace_back( parsePattern( item ) );
|
||||
} else if ( item.contains( "patterns" ) && item["patterns"].is_array() ) {
|
||||
const auto& patterns = item["patterns"];
|
||||
for ( const auto& pattern : patterns ) {
|
||||
if ( pattern.size() == 1 && pattern.contains( "comment" ) )
|
||||
continue;
|
||||
ptrns.emplace_back( parsePattern( pattern ) );
|
||||
}
|
||||
} else if ( item.is_array() ) {
|
||||
for ( const auto& pattern : item )
|
||||
ptrns.emplace_back( parsePattern( pattern ) );
|
||||
}
|
||||
|
||||
if ( item.contains( "repository" ) && item["repository"].is_object() ) {
|
||||
for ( const auto& [iname, iitem] : item["repository"].items() ) {
|
||||
parseRepositoryItem( def, iname, iitem );
|
||||
}
|
||||
}
|
||||
|
||||
auto rname( name );
|
||||
def.addRepository( std::move( rname ), std::move( ptrns ) );
|
||||
};
|
||||
|
||||
static SyntaxDefinition loadLanguage( const nlohmann::json& json ) {
|
||||
SyntaxDefinition def;
|
||||
|
||||
@@ -894,25 +921,8 @@ static SyntaxDefinition loadLanguage( const nlohmann::json& json ) {
|
||||
|
||||
if ( json.contains( "repository" ) && json["repository"].is_object() ) {
|
||||
const auto& repository = json["repository"];
|
||||
for ( const auto& [name, repository] : repository.items() ) {
|
||||
std::vector<SyntaxPattern> ptrns;
|
||||
if ( repository.contains( "match" ) || repository.contains( "begin" ) ) {
|
||||
ptrns.emplace_back( parsePattern( repository ) );
|
||||
} else if ( repository.contains( "patterns" ) &&
|
||||
repository["patterns"].is_array() ) {
|
||||
const auto& patterns = repository["patterns"];
|
||||
for ( const auto& pattern : patterns ) {
|
||||
if ( pattern.size() == 1 && pattern.contains( "comment" ) )
|
||||
continue;
|
||||
ptrns.emplace_back( parsePattern( pattern ) );
|
||||
}
|
||||
} else if ( repository.is_array() ) {
|
||||
for ( const auto& pattern : repository )
|
||||
ptrns.emplace_back( parsePattern( pattern ) );
|
||||
}
|
||||
auto rname( name );
|
||||
def.addRepository( std::move( rname ), std::move( ptrns ) );
|
||||
}
|
||||
for ( const auto& [name, item] : repository.items() )
|
||||
parseRepositoryItem( def, name, item );
|
||||
}
|
||||
|
||||
if ( ( json.contains( "$schema" ) && json["$schema"].is_string() &&
|
||||
|
||||
@@ -535,10 +535,10 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax
|
||||
fullMatchEnd - fullMatchStart ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastStart = start;
|
||||
lastEnd = end;
|
||||
lastStart = start;
|
||||
lastEnd = end;
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastEnd < fullMatchEnd ) {
|
||||
|
||||
@@ -209,6 +209,37 @@ void UIStyle::unsubscribeRelated( UIWidget* widget ) {
|
||||
mRelatedWidgets.erase( widget );
|
||||
}
|
||||
|
||||
void UIStyle::applyLightDarkValue( std::string& value ) {
|
||||
std::string::size_type tokenStart = 0;
|
||||
std::string::size_type tokenEnd = 0;
|
||||
|
||||
while ( true ) {
|
||||
tokenStart = value.find( "light-dark(", tokenStart );
|
||||
if ( tokenStart != std::string::npos ) {
|
||||
tokenEnd = String::findCloseBracket( value, tokenStart, '(', ')' );
|
||||
if ( tokenEnd != std::string::npos ) {
|
||||
auto fn( value.substr( tokenStart, tokenEnd + 1 ) );
|
||||
auto function( FunctionString::parse( fn ) );
|
||||
auto size = function.getParameters().size();
|
||||
if ( size > 0 ) {
|
||||
String::replaceAll(
|
||||
value, fn,
|
||||
function.getParameters()
|
||||
[size == 1 || mWidget->getUISceneNode()->getColorSchemePreference() ==
|
||||
ColorSchemePreference::Light
|
||||
? 0
|
||||
: 1] );
|
||||
}
|
||||
tokenStart = tokenEnd;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void UIStyle::setVariableFromValue( StyleSheetProperty* property, const std::string& value ) {
|
||||
if ( !property->getVarCache().empty() ) {
|
||||
std::string newValue( value );
|
||||
@@ -221,12 +252,20 @@ void UIStyle::setVariableFromValue( StyleSheetProperty* property, const std::str
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( property->isLightDarkValue() )
|
||||
applyLightDarkValue( newValue );
|
||||
property->setValue( newValue );
|
||||
} else if ( property->isLightDarkValue() ) {
|
||||
std::string newValue( value );
|
||||
applyLightDarkValue( newValue );
|
||||
property->setValue( newValue );
|
||||
}
|
||||
}
|
||||
|
||||
void UIStyle::applyLightDarkValues( CSS::StyleSheetProperty* style ) {}
|
||||
|
||||
void UIStyle::applyVarValues( StyleSheetProperty* property ) {
|
||||
if ( property->isVarValue() ) {
|
||||
if ( property->isVarValue() || property->isLightDarkValue() ) {
|
||||
if ( NULL != property->getPropertyDefinition() &&
|
||||
property->getPropertyDefinition()->isIndexed() ) {
|
||||
for ( size_t i = 0; i < property->getPropertyIndexCount(); i++ ) {
|
||||
|
||||
Reference in New Issue
Block a user