Skip to content

Commit

Permalink
feat: add rfShrink()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Nov 30, 2022
1 parent ece0a4a commit 6ea9cb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
32 changes: 28 additions & 4 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function getModuleInfo()
{
return [
'title' => 'RockFrontend',
'version' => '2.8.6',
'version' => '2.9.0',
'summary' => 'Module for easy frontend development',
'autoload' => true,
'singular' => true,
Expand Down Expand Up @@ -993,6 +993,25 @@ public function initPostCSS()
}, $markup);
});

// rfShrink() postCSS replacer
$data->set("rfShrink(", function ($markup) {
return preg_replace_callback("/rfShrink\((.*?),(.*?)(,(.*?))?(,(.*?))?\)/", function ($match) {
// bd($match);
if (count($match) < 3) return false;
try {
$data = [
'min' => $match[2],
'max' => $match[1],
];
if (count($match) > 4) $data['growMin'] = $match[4];
if (count($match) > 6) $data['growMax'] = $match[6];
return $this->rfGrow($data, true);
} catch (\Throwable $th) {
return $th->getMessage();
}
}, $markup);
});

// convert pxrem to px
// font-size: 20pxrem; --> font-size: 1.25rem;
$data->set("pxrem", function ($markup) {
Expand All @@ -1006,7 +1025,7 @@ public function initPostCSS()
$this->postCSS = $data;
}

public function rfGrow($_data): string
public function rfGrow($_data, $shrink = false): string
{
$data = new WireData();
$data->setArray([
Expand Down Expand Up @@ -1038,8 +1057,13 @@ public function rfGrow($_data): string
// return $min;

$percent = "((100vw - {$growMin}px) / ($growMax - $growMin))";
$grow = "$min * $scale + $diff * $scale * $percent";
return "clamp($min * $scale, $grow, $max * $scale)";
if ($shrink) {
$grow = "$max - $diff * $percent";
return "clamp($min, $grow, $max)";
} else {
$grow = "$min * $scale + $diff * $scale * $percent";
return "clamp($min * $scale, $grow, $max * $scale)";
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.8.6"
}

0 comments on commit 6ea9cb9

Please sign in to comment.