Release LaySite 1.4.0 canvas editing and layers
This commit is contained in:
@@ -8,7 +8,7 @@ use RuntimeException;
|
||||
|
||||
final class CanvasStyle
|
||||
{
|
||||
public const PAGE = ['hero', 'heading', 'accent', 'lead', 'image', 'actions', 'navigation'];
|
||||
public const PAGE = ['hero', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs'];
|
||||
public const SECTION = ['section', 'title', 'lead', 'body'];
|
||||
|
||||
private const PROPERTIES = [
|
||||
@@ -40,13 +40,34 @@ final class CanvasStyle
|
||||
|
||||
public static function normalize(mixed $input, array $roles): array
|
||||
{
|
||||
if (!is_array($input) || count($input) > count($roles) + 28) {
|
||||
if (!is_array($input) || count($input) > count($roles) + 50) {
|
||||
throw new RuntimeException('画布样式无效。');
|
||||
}
|
||||
$styles = [];
|
||||
foreach ($input as $role => $style) {
|
||||
if ($roles === self::PAGE && $role === 'breadcrumbLinks') {
|
||||
if (!is_string($style)) {
|
||||
throw new RuntimeException('面包屑无效。');
|
||||
}
|
||||
$styles[$role] = SiteDesign::linkText(SiteDesign::parseLinks($style));
|
||||
continue;
|
||||
}
|
||||
if ($roles === self::PAGE && $role === 'heroEyebrow') {
|
||||
if (!is_string($style) || mb_strlen($style) > 100) {
|
||||
throw new RuntimeException('首屏眉题过长。');
|
||||
}
|
||||
$styles[$role] = $style;
|
||||
continue;
|
||||
}
|
||||
if ($roles === self::PAGE && $role === 'heroHtml') {
|
||||
if (!is_string($style) || strlen($style) > 300000) {
|
||||
throw new RuntimeException('首屏 HTML 无效或过长。');
|
||||
}
|
||||
$styles[$role] = Html::sanitize($style);
|
||||
continue;
|
||||
}
|
||||
if ((!in_array($role, $roles, true) && !($roles === self::PAGE && is_string($role)
|
||||
&& preg_match('/^(?:action-[0-7]|nav-(?:[0-9]|1[0-9]))$/D', $role))) || !is_array($style)) {
|
||||
&& preg_match('/^(?:action-[0-7]|(?:nav|crumb)-(?:[0-9]|1[0-9]))$/D', $role))) || !is_array($style)) {
|
||||
throw new RuntimeException('画布样式无效。');
|
||||
}
|
||||
$classes = self::classList($style['classes'] ?? '');
|
||||
@@ -85,6 +106,10 @@ final class CanvasStyle
|
||||
[$property, $size] = array_pad(explode('-', $token, 2), 2, '');
|
||||
if (isset(self::TYPOGRAPHY[$token])) {
|
||||
$classes[$property] = $class;
|
||||
} elseif ($property === 'color' && ($size === 'theme' || preg_match('/^[a-f0-9]{6}$/D', $size))) {
|
||||
$classes[$property] = $class;
|
||||
} elseif (!$textOnly && $property === 'display' && in_array($size, ['block', 'inline', 'inline-block'], true)) {
|
||||
$classes[$property] = $class;
|
||||
} elseif ((!$textOnly || $property === 'size') && isset(self::PROPERTIES[$property])
|
||||
&& preg_match('/^(?:0|-?[1-9]\d{0,2})$/D', $size)) {
|
||||
[, $min, $max] = self::PROPERTIES[$property];
|
||||
@@ -131,6 +156,17 @@ final class CanvasStyle
|
||||
return $markup;
|
||||
}
|
||||
|
||||
public static function colorRules(string $markup): string
|
||||
{
|
||||
preg_match_all('/\bstudio-style-color-([a-f0-9]{6})(?![\w-])/', $markup, $matches);
|
||||
$css = '';
|
||||
foreach (array_unique($matches[1]) as $hex) {
|
||||
$css .= ".studio-style-color-{$hex}{color:#{$hex}!important}\n";
|
||||
}
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
public static function stylesheet(): string
|
||||
{
|
||||
$css = '';
|
||||
@@ -139,6 +175,9 @@ final class CanvasStyle
|
||||
$css .= '.' . self::PREFIX . "$key-$value{{$property}:{$value}px!important}\n";
|
||||
}
|
||||
}
|
||||
for ($width = 10; $width <= 100; $width++) {
|
||||
$css .= ".studio-media-{$width}{--studio-media-factor:calc({$width} / 100)}\n";
|
||||
}
|
||||
foreach (self::TYPOGRAPHY as $key => $value) {
|
||||
$css .= '.' . self::PREFIX . "$key{{$value}!important}\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user