From 6514cb323a1250405093a3e8773a1a82984555a8 Mon Sep 17 00:00:00 2001 From: ArrayIterator <37867551+ArrayIterator@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:31:49 +0700 Subject: [PATCH 1/5] Update BaseKernel.php --- src/HttpKernel/BaseKernel.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/HttpKernel/BaseKernel.php b/src/HttpKernel/BaseKernel.php index 2226d9e..3d4dd20 100644 --- a/src/HttpKernel/BaseKernel.php +++ b/src/HttpKernel/BaseKernel.php @@ -24,6 +24,7 @@ use ArrayAccess\TrayDigita\L10n\Translations\Adapter\Gettext\PoMoAdapter; use ArrayAccess\TrayDigita\L10n\Translations\Adapter\Json\JsonAdapter; use ArrayAccess\TrayDigita\L10n\Translations\Interfaces\TranslatorInterface; +use ArrayAccess\TrayDigita\Middleware\ErrorMiddleware; use ArrayAccess\TrayDigita\Middleware\RoutingMiddleware; use ArrayAccess\TrayDigita\PossibleRoot; use ArrayAccess\TrayDigita\Util\Filter\Consolidation; @@ -837,6 +838,14 @@ final public function init() : static } catch (Throwable) { $debugMiddleware = new DebuggingMiddleware($container); } + try { + $errorMiddleware = ContainerHelper::resolveCallable( + ErrorMiddleware::class, + $container + ); + } catch (Throwable) { + $errorMiddleware = new ErrorMiddleware($container); + } // @dispatch(kernel.initConfig) $manager->dispatch('kernel.initConfig', $this); } finally { @@ -876,8 +885,8 @@ final public function init() : static KernelCommandLoader::register($this); // registering debug middleware at the first middleware - $httpKernel->addMiddleware($debugMiddleware); - + $httpKernel->addDeferredMiddleware($debugMiddleware); + $httpKernel->addDeferredMiddleware($errorMiddleware); return $this; } From 834d0895134a4e50917311f3cc7674721b139650 Mon Sep 17 00:00:00 2001 From: ArrayIterator <37867551+ArrayIterator@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:31:58 +0700 Subject: [PATCH 2/5] Update DebuggingMiddleware.php --- .../Middlewares/DebuggingMiddleware.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Benchmark/Middlewares/DebuggingMiddleware.php b/src/Benchmark/Middlewares/DebuggingMiddleware.php index 076b944..54f7dad 100644 --- a/src/Benchmark/Middlewares/DebuggingMiddleware.php +++ b/src/Benchmark/Middlewares/DebuggingMiddleware.php @@ -31,20 +31,32 @@ class DebuggingMiddleware extends AbstractMiddleware { - protected int $priority = PHP_INT_MIN; + protected int $priority = PHP_INT_MAX; use StreamFactoryTrait, TranslatorTrait; + /** + * @var bool registered + */ private bool $registered = false; + /** + * @var bool darkMode + */ private bool $darkMode = false; + /** + * @var ?float + */ /** * @var ?float */ private ?float $requestFloat = null; + /** + * @inheritdoc + */ protected function doProcess( ServerRequestInterface $request ): ServerRequestInterface { @@ -126,7 +138,7 @@ private function renderDebugBar($response) : mixed // if profiler disabled, stop here! $profiler = ContainerHelper::use(ProfilerInterface::class, $container); $waterfall = ContainerHelper::use(Waterfall::class, $container); - if (!$profiler?->isEnable() || ! $waterfall || !DataType::isHtmlContentType($response)) { + if (!$profiler?->isEnable() || ! $waterfall || $response->getHeaderLine('Content-Type') !== '' && !DataType::isHtmlContentType($response)) { return $response; } @@ -155,7 +167,7 @@ private function renderDebugBar($response) : mixed // get origin performance $performanceOrigin = microtime(true) - $startTime; - $memoryOrigin = Consolidation::sizeFormat(memory_get_usage(), 3); + $memoryOrigin = Consolidation::sizeFormat(memory_get_usage()); // start $body = (string) $response->getBody(); @@ -216,7 +228,7 @@ static function ($match) use ($waterfall, $darkMode) { $this->translateContext('rendered time', 'benchmark'), $profiler->convertMicrotime($performanceEnd), $this->translateContext('memory usage', 'benchmark'), - Consolidation::sizeFormat(memory_get_usage(), 3), + Consolidation::sizeFormat(memory_get_usage()), ) ) ); @@ -270,9 +282,9 @@ private function printPerformance(ResponseInterface $response): ResponseInterfac 4 ), $this->translateContext('peak memory usage', 'benchmark'), - Consolidation::sizeFormat(memory_get_peak_usage(), 3), + Consolidation::sizeFormat(memory_get_peak_usage()), $this->translateContext('memory usage', 'benchmark'), - Consolidation::sizeFormat(memory_get_usage(), 3) + Consolidation::sizeFormat(memory_get_usage()) ) ); $response->getBody()->write($str); @@ -315,8 +327,8 @@ private function printJsonPerformance($data) (microtime(true) * 1000 - $startTime * 1000), 4 ), - 'peak_memory' => Consolidation::sizeFormat(memory_get_peak_usage(), 3), - 'used_memory' => Consolidation::sizeFormat(memory_get_usage(), 3) + 'peak_memory' => Consolidation::sizeFormat(memory_get_peak_usage()), + 'used_memory' => Consolidation::sizeFormat(memory_get_usage()) ]; return $data; } From 923c27bcf67ad995d7e0a02619719bddd0dad137 Mon Sep 17 00:00:00 2001 From: ArrayIterator <37867551+ArrayIterator@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:34:40 +0700 Subject: [PATCH 3/5] Update DebuggingMiddleware.php --- src/Benchmark/Middlewares/DebuggingMiddleware.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Benchmark/Middlewares/DebuggingMiddleware.php b/src/Benchmark/Middlewares/DebuggingMiddleware.php index 54f7dad..468bdcf 100644 --- a/src/Benchmark/Middlewares/DebuggingMiddleware.php +++ b/src/Benchmark/Middlewares/DebuggingMiddleware.php @@ -27,7 +27,6 @@ use function sprintf; use function str_contains; use const PHP_INT_MAX; -use const PHP_INT_MIN; class DebuggingMiddleware extends AbstractMiddleware { @@ -138,7 +137,9 @@ private function renderDebugBar($response) : mixed // if profiler disabled, stop here! $profiler = ContainerHelper::use(ProfilerInterface::class, $container); $waterfall = ContainerHelper::use(Waterfall::class, $container); - if (!$profiler?->isEnable() || ! $waterfall || $response->getHeaderLine('Content-Type') !== '' && !DataType::isHtmlContentType($response)) { + if (!$profiler?->isEnable() || ! $waterfall + || $response->getHeaderLine('Content-Type') !== '' && !DataType::isHtmlContentType($response) + ) { return $response; } From 87a04113918697e5f754f806b1135511038469a9 Mon Sep 17 00:00:00 2001 From: ArrayIterator <37867551+ArrayIterator@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:50:14 +0700 Subject: [PATCH 4/5] Update Waterfall.php --- src/Benchmark/Waterfall.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Benchmark/Waterfall.php b/src/Benchmark/Waterfall.php index d926647..8b6fc09 100644 --- a/src/Benchmark/Waterfall.php +++ b/src/Benchmark/Waterfall.php @@ -1208,12 +1208,13 @@ private function renderCSS(bool $darkMode) : string --waterfall-toolbar-bg: #fafafa; } .{$this->prefix}section-wrapper { + scroll-behavior: smooth; position: fixed; z-index: 2147483647; left:0; right:0; bottom:0; - font-weight: lighter; + font-weight: 250; margin: 0; padding: 0; border: 0; @@ -1449,6 +1450,10 @@ private function renderCSS(bool $darkMode) : string position: relative; z-index: 900; overflow: auto; + scrollbar-width: thin; + scroll-behavior: smooth; + /* make smooth */ + scrollbar-color: rgba(0,0,0,.1) transparent; } .{$this->prefix}section-wrapper .{$this->prefix}hidden { display: none !important; From ad22fcccf4e6f73c71660ea18313db30fe71e697 Mon Sep 17 00:00:00 2001 From: ArrayIterator <37867551+ArrayIterator@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:24:52 +0700 Subject: [PATCH 5/5] Update HtmlTraceAbleErrorRenderer.php --- .../HtmlTraceAbleErrorRenderer.php | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/View/ErrorRenderer/HtmlTraceAbleErrorRenderer.php b/src/View/ErrorRenderer/HtmlTraceAbleErrorRenderer.php index 1adfbc6..b132c3d 100644 --- a/src/View/ErrorRenderer/HtmlTraceAbleErrorRenderer.php +++ b/src/View/ErrorRenderer/HtmlTraceAbleErrorRenderer.php @@ -373,7 +373,7 @@ private function exceptionDetail(Throwable $exception): string $exception->getLine() ); $mainErrorInfo .= sprintf( - "
Message: %s
\n", + "
Message: %s
\n", htmlentities($message) ); $mainErrorInfo .= '

'; @@ -569,6 +569,14 @@ private function exceptionDetail(Throwable $exception): string display: flex; flex-direction: column; justify-content: flex-start; + scroll-behavior: smooth; + scrollbar-width: thin; + scrollbar-color: rgba(255, 255, 255, .3) transparent; +} + +.current-message > code { + word-wrap:break-word; + white-space: normal } .tab-info { @@ -744,6 +752,7 @@ private function exceptionDetail(Throwable $exception): string min-height: 100%; outline: none; box-shadow: none; + flex: 0 0 auto; /* margin-right: 1em; */ } @@ -882,13 +891,39 @@ private function exceptionDetail(Throwable $exception): string navigator.clipboard.writeText(content); }); e.addEventListener('keydown', function(e) { - if (/^(Backspace|Delete)/i.test(e.code)) { - e.preventDefault(); - return false; - } if (e.code === 'Escape') { window.getSelection()?.removeAllRanges(); + return; + } + // if cut just select current select range + if (e.code === 'KeyX' && (e.ctrlKey || e.metaKey)) { + const selection = window.getSelection(); + if (selection) { + const range = selection.getRangeAt(0); + const content = range.cloneContents(); + const div = document.createElement('div'); + div.appendChild(content); + const text = div.textContent; + try { + navigator.clipboard.writeText(text).catch(() => null); + } catch (err) { + // pass + } + return; + } + return; + } + if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Tab'].includes(e.code) + || ( + (e.ctrlKey || e.metaKey) && ( + ['KeyA', 'KeyC', 'KeyV', 'KeyX', 'KeyR'].includes(e.code) + ) + ) + ) { + return; } + e.preventDefault(); + return false; }); }); let navTabs = document.querySelectorAll('.trace-tab-nav');