Fix canvas formatting persistence and editor interactions

This commit is contained in:
2026-11-26 16:18:46 +08:00
parent a78869dba4
commit a7b37ee7d4
16 changed files with 262 additions and 57 deletions
+12 -5
View File
@@ -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) {
+4
View File
@@ -32,6 +32,10 @@ final class Licenses
'url' => 'https://jquery.com/', 'file' => $root . '/public/assets/jquery-LICENSE.txt'],
'toast-ui-editor' => ['name' => 'TOAST UI Editor', 'version' => self::declaredVersion($editor, '~@version\h+' . $version . '~'), 'license' => 'MIT',
'url' => 'https://github.com/nhn/tui.editor', 'file' => $root . '/public/assets/vendor/toastui/LICENSE'],
'codemirror' => ['name' => 'CodeMirror', 'version' => '5.65.21', 'license' => 'MIT',
'url' => 'https://github.com/codemirror/codemirror5', 'file' => $root . '/public/assets/vendor/codemirror/LICENSE'],
'js-beautify' => ['name' => 'JS Beautifier', 'version' => '1.15.4', 'license' => 'MIT',
'url' => 'https://github.com/beautifier/js-beautify', 'file' => $root . '/public/assets/vendor/js-beautify/LICENSE'],
'geist' => ['name' => 'Geist', 'license' => 'OFL-1.1',
'url' => 'https://github.com/vercel/geist-font', 'file' => $root . '/public/assets/geist-OFL.txt'],
'dompurify' => ['name' => 'DOMPurify', 'version' => self::declaredVersion($editor, '~@license DOMPurify\h+' . $version . '~'), 'license' => 'Apache-2.0 / MPL-2.0',