Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# 0.0.7

- Backport comma-separated selector lists in pseudo-classes (`:is()`, `:not()`, `:where()`, `:has()`) from [elabx/less.php#1](https://github.com/elabx/less.php/pull/1) (Less.js 4.2 / wikimedia/less.php#136) to bundled less.php 4.1.1, 5.4.0, and 5.5.0.
- Backport native CSS color function passthrough (e.g. `rgba(0, 0, 0, var(--opacity))`) from wikimedia/less.php 5.5.0 (T405815) to bundled less.php 4.1.1 and 5.4.0.
- Added Wikimedia LESS v5.5.0 with PHP 8.5 compatibility fixes.

# 0.0.6

- Added Wikimedia LESS v5.4.0 in addition to existing v4.1.1.
- Made LESS version selectable in module config.
- Made it auto select newest supported version when installing module.
- Note: if upgrading it will use 4.1.1 unless you select newer version in module config.
- Note: if upgrading it will use 4.1.1 unless you select newer version in module config.
2 changes: 1 addition & 1 deletion Less.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Less extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => 'Less',
'version' => 6,
'version' => 7,
'summary' => 'Less CSS preprocessor for ProcessWire using Wikimedia Less.',
'author' => 'Bernhard Baumrock, Ryan Cramer',
'icon' => 'css3',
Expand Down
78 changes: 57 additions & 21 deletions less/4.1.1/lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,76 @@ public static function scaled( $n, $size = 255 ) {
}

public function rgb( $r = null, $g = null, $b = null ) {
if ( $r === null || $g === null || $b === null ) {
throw new Less_Exception_Compiler( "rgb expects three parameters" );
$color = $this->rgba( $r, $g, $b, 1.0 );
if ( $color ) {
$color->value = 'rgb';
return $color;
}
return $this->rgba( $r, $g, $b, 1.0 );
}

public function rgba( $r = null, $g = null, $b = null, $a = null ) {
$rgb = [ $r, $g, $b ];
$rgb = array_map( [ __CLASS__, 'scaled' ], $rgb );
try {
if ( $r instanceof Less_Tree_Color ) {
if ( $g ) {
$a = self::number( $g );
} else {
$a = $r->alpha;
}
$color = new Less_Tree_Color( $r->rgb, $a );
$color->value = 'rgba';
return $color;
}
$rgb = [ $r, $g, $b ];
$rgb = array_map( [ __CLASS__, 'scaled' ], $rgb );

$a = self::number( $a );
return new Less_Tree_Color( $rgb, $a );
$a = self::number( $a );
$color = new Less_Tree_Color( $rgb, $a );
$color->value = 'rgba';
return $color;
} catch ( Exception $e ) {
// Pass through native CSS color functions, e.g. rgba(0, 0, 0, var(--opacity)).
// Backported from wikimedia/less.php 5.5.0 (T405815).
}
}

public function hsl( $h, $s, $l ) {
return $this->hsla( $h, $s, $l, 1.0 );
$color = $this->hsla( $h, $s, $l, 1.0 );
if ( $color ) {
$color->value = 'hsl';
return $color;
}
}

public function hsla( $h, $s, $l, $a ) {
$h = fmod( self::number( $h ), 360 ) / 360; // Classic % operator will change float to int
$s = self::clamp( self::number( $s ) );
$l = self::clamp( self::number( $l ) );
$a = self::clamp( self::number( $a ) );
public function hsla( $h = null, $s = null, $l = null, $a = null ) {
try {
if ( $h instanceof Less_Tree_Color ) {
if ( $s ) {
$a = self::number( $s );
} else {
$a = $h->alpha;
}
$color = new Less_Tree_Color( $h->rgb, $a );
$color->value = 'hsla';
return $color;
}
$h = fmod( self::number( $h ), 360 ) / 360; // Classic % operator will change float to int
$s = self::clamp( self::number( $s ) );
$l = self::clamp( self::number( $l ) );
$a = self::clamp( self::number( $a ) );

$m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;
$m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;

$m1 = $l * 2 - $m2;
$m1 = $l * 2 - $m2;

return $this->rgba(
self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255,
self::hsla_hue( $h, $m1, $m2 ) * 255,
self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255,
$a
);
return $this->rgba(
self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255,
self::hsla_hue( $h, $m1, $m2 ) * 255,
self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255,
$a
);
} catch ( Exception $e ) {
// Pass through native CSS color functions with CSS variables.
}
}

/**
Expand Down
26 changes: 23 additions & 3 deletions less/4.1.1/lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1734,9 +1734,29 @@ private function parseElement() {
if ( $e === null ) {
$this->save();
if ( $this->MatchChar( '(' ) ) {
if ( ( $v = $this->parseSelector() ) && $this->MatchChar( ')' ) ) {
$e = new Less_Tree_Paren( $v );
$this->forget();
$v = $this->parseSelector();
if ( $v ) {
// Support comma-separated selector lists inside parentheses,
// for pseudo-classes like :is(), :not(), :where(), :has().
// Backported from Less.js 4.2 (less.js#4290), elabx/less.php#1.
$selectors = [];
while ( $this->MatchChar( ',' ) ) {
$selectors[] = $v;
$selectors[] = new Less_Tree_Anonymous( ',' );
$v = $this->parseSelector();
}

if ( $v && $this->MatchChar( ')' ) ) {
if ( $selectors ) {
$selectors[] = $v;
$e = new Less_Tree_Paren( new Less_Tree_Expression( $selectors, true ) );
} else {
$e = new Less_Tree_Paren( $v );
}
$this->forget();
} else {
$this->restore();
}
} else {
$this->restore();
}
Expand Down
79 changes: 55 additions & 24 deletions less/5.4.0/lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,74 @@ private static function _scaled( $n, $size = 255 ) {
}

public function rgb( $r = null, $g = null, $b = null ) {
if ( $r === null || $g === null || $b === null ) {
throw new Less_Exception_Compiler( "rgb expects three parameters" );
$color = $this->rgba( $r, $g, $b, 1.0 );
if ( $color ) {
$color->value = 'rgb';
return $color;
}
return $this->rgba( $r, $g, $b, 1.0 );
}

public function rgba( $r = null, $g = null, $b = null, $a = null ) {
$rgb = [
self::_scaled( $r ),
self::_scaled( $g ),
self::_scaled( $b )
];
try {
if ( $r instanceof Less_Tree_Color ) {
if ( $g ) {
$a = self::_number( $g );
} else {
$a = $r->alpha;
}
return new Less_Tree_Color( $r->rgb, $a, 'rgba' );
}
$rgb = [
self::_scaled( $r ),
self::_scaled( $g ),
self::_scaled( $b )
];

$a = self::_number( $a );
return new Less_Tree_Color( $rgb, $a );
$a = self::_number( $a );
return new Less_Tree_Color( $rgb, $a, 'rgba' );
} catch ( Exception $e ) {
// Pass through native CSS color functions, e.g. rgba(0, 0, 0, var(--opacity)).
// Backported from wikimedia/less.php 5.5.0 (T405815).
}
}

public function hsl( $h, $s, $l ) {
return $this->hsla( $h, $s, $l, 1.0 );
$color = $this->hsla( $h, $s, $l, 1.0 );
if ( $color ) {
$color->value = 'hsl';
return $color;
}
}

public function hsla( $h, $s, $l, $a ) {
$h = fmod( self::_number( $h ), 360 ) / 360; // Classic % operator will change float to int
$s = self::_clamp( self::_number( $s ) );
$l = self::_clamp( self::_number( $l ) );
$a = self::_clamp( self::_number( $a ) );
public function hsla( $h = null, $s = null, $l = null, $a = null ) {
try {
if ( $h instanceof Less_Tree_Color ) {
if ( $s ) {
$a = self::_number( $s );
} else {
$a = $h->alpha;
}
return new Less_Tree_Color( $h->rgb, $a, 'hsla' );
}
// NOTE: Avoid % operator which would change float to int
$h = fmod( self::_number( $h ), 360 ) / 360;
$s = self::_clamp( self::_number( $s ) );
$l = self::_clamp( self::_number( $l ) );
$a = self::_clamp( self::_number( $a ) );

$m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;
$m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;

$m1 = $l * 2 - $m2;
$m1 = $l * 2 - $m2;

return $this->rgba(
self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255,
self::hsla_hue( $h, $m1, $m2 ) * 255,
self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255,
$a
);
return $this->rgba(
self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255,
self::hsla_hue( $h, $m1, $m2 ) * 255,
self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255,
$a
);
} catch ( Exception $e ) {
// Pass through native CSS color functions with CSS variables.
}
}

/**
Expand Down
25 changes: 22 additions & 3 deletions less/5.4.0/lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2195,9 +2195,28 @@ private function parseElement() {
$this->save();
if ( $this->matchChar( '(' ) ) {
$v = $this->parseSelector();
if ( $v && $this->matchChar( ')' ) ) {
$e = new Less_Tree_Paren( $v );
$this->forget();
if ( $v ) {
// Support comma-separated selector lists inside parentheses,
// for pseudo-classes like :is(), :not(), :where(), :has().
// Backported from Less.js 4.2 (less.js#4290), elabx/less.php#1.
$selectors = [];
while ( $this->matchChar( ',' ) ) {
$selectors[] = $v;
$selectors[] = new Less_Tree_Anonymous( ',' );
$v = $this->parseSelector();
}

if ( $v && $this->matchChar( ')' ) ) {
if ( $selectors ) {
$selectors[] = $v;
$e = new Less_Tree_Paren( new Less_Tree_Expression( $selectors, true ) );
} else {
$e = new Less_Tree_Paren( $v );
}
$this->forget();
} else {
$this->restore();
}
} else {
$this->restore();
}
Expand Down
Loading