lightning-js / blits

The Lightning 3 App Development Framework
https://blits-demo.lightningjs.io/
Apache License 2.0
64 stars 12 forks source link

Processing color values in the template parser #79

Closed uguraslan closed 6 months ago

uguraslan commented 7 months ago

Example:

<Element :color="$backgroundColor">
  <Element color="{top: '#44037a', bottom: '#240244'}" />
  <Element color="#44037a" />
  <Element color="{top: '#44037a'}" :effects="[$shader('radius', {radius: $radius})]" />
  <Element color="transparent" :effects="[$shader('border', {width: 20, color: '#60a5fa'})]" />
  <Element color="#fba" /> 
</Element>

The template parser outputs an object. But to visualise how it process colors, the following can be considered the equivalent of the template above after the template parser processes color values:

<Element :color="$backgroundColor">
  <Element color="{top: '0x44037aff', bottom: '0x240244ff'}" />
  <Element color="0x44037aff" />
  <Element color="{top: '0x44037aff'}" :effects="[$shader('radius', {radius: $radius})]" />
  <Element color="transparent" :effects="[$shader('border', {width: 20, color: '0x60a5faff'})]" />
  <Element color="0xffbbaaff" /> 
</Element>
sandeep-vedam commented 7 months ago

I have verified the PR and here are the observations:

  1. The template parser is returning template objects with normalised color codes/values. Before the value is '#44037a' After the conversion value is '0x44037aff'

  2. Here is the coverage for before this fix and after this fix

S.No Code Before Fix After Fix
1 lib/templateparser 94.16 100
2 lib/setup 39.11 40.04
3 lib/reactivity 34.67 34.67
4 /lib/colors 97.89 100
5 lib/codegenerator 100 100
6 lib 70.09 70.09
7 components 34.22 34.22
8 source 36.66 35.46
9 announcer 55.42 55.42
S.No Desc Total Tests Tests Passed Tests Failed Comments
1 Before 218 188 30
2 After 239 238 1 Generate code for a template with a simple for-loop on an Element with a key attribute