forked from laysense/laysite
Fix canvas formatting persistence and editor interactions
This commit is contained in:
@@ -9,6 +9,7 @@ use RuntimeException;
|
||||
final class CanvasStyle
|
||||
{
|
||||
public const PAGE = ['hero', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs'];
|
||||
public const MIN_MEDIA_SCALE = 1;
|
||||
public const SECTION = ['section', 'title', 'lead', 'body'];
|
||||
|
||||
private const PROPERTIES = [
|
||||
@@ -82,7 +83,7 @@ final class CanvasStyle
|
||||
|| ($textLength += strlen($run[0])) > 2400 || !mb_check_encoding($run[0], 'UTF-8')) {
|
||||
throw new RuntimeException('文字格式无效。');
|
||||
}
|
||||
$cleanRuns[] = [$run[0], self::classList($run[1], textOnly: true)];
|
||||
$cleanRuns[] = [self::lineBreaks($run[0]), self::classList($run[1], textOnly: true)];
|
||||
}
|
||||
if ($classes !== '' || $cleanRuns !== []) {
|
||||
$styles[$role] = ['classes' => $classes, 'runs' => $cleanRuns];
|
||||
@@ -141,15 +142,21 @@ final class CanvasStyle
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function lineBreaks(string $text): string
|
||||
{
|
||||
return str_replace(["\r\n", "\r"], "\n", $text);
|
||||
}
|
||||
|
||||
public static function text(array $styles, string $role, string $plain): string
|
||||
{
|
||||
$plain = self::lineBreaks($plain);
|
||||
$runs = $styles[$role]['runs'] ?? [];
|
||||
if ($runs === [] || trim(implode('', array_column($runs, 0))) !== $plain) {
|
||||
return str_replace(["\r\n", "\r", "\n"], '<br>', View::escape($plain));
|
||||
if ($runs === [] || self::lineBreaks(trim(implode('', array_column($runs, 0)))) !== $plain) {
|
||||
return str_replace("\n", '<br>', View::escape($plain));
|
||||
}
|
||||
$markup = '';
|
||||
foreach ($runs as [$text, $class]) {
|
||||
$escaped = str_replace("\n", '<br>', View::escape($text));
|
||||
$escaped = str_replace("\n", '<br>', View::escape(self::lineBreaks($text)));
|
||||
$markup .= $class === '' ? $escaped : '<span class="' . View::escape($class) . '">' . $escaped . '</span>';
|
||||
}
|
||||
|
||||
@@ -175,7 +182,7 @@ final class CanvasStyle
|
||||
$css .= '.' . self::PREFIX . "$key-$value{{$property}:{$value}px!important}\n";
|
||||
}
|
||||
}
|
||||
for ($width = 10; $width <= 100; $width++) {
|
||||
for ($width = self::MIN_MEDIA_SCALE; $width <= 100; $width++) {
|
||||
$css .= ".studio-media-{$width}{--studio-media-factor:calc({$width} / 100)}\n";
|
||||
}
|
||||
foreach (self::TYPOGRAPHY as $key => $value) {
|
||||
|
||||
Reference in New Issue
Block a user