From 525be9afeac29d69c61a260ca0687ab0c0492b16 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 27 Oct 2023 17:38:01 +0200 Subject: [PATCH] Use CSS nesting in the textLayer --- test/text_layer_test.css | 27 ++++---- web/text_layer_builder.css | 136 ++++++++++++++++++------------------- 2 files changed, 80 insertions(+), 83 deletions(-) diff --git a/test/text_layer_test.css b/test/text_layer_test.css index 9f7b0ca5764e2..df0d5859bf1ae 100644 --- a/test/text_layer_test.css +++ b/test/text_layer_test.css @@ -20,18 +20,19 @@ inset: 0; line-height: 1; opacity: 1; -} -.textLayer :is(span, br) { - color: black; - position: absolute; - white-space: pre; - transform-origin: 0% 0%; - border: solid 1px rgb(255 0 0 / 0.5); - background-color: rgb(255 255 32 / 0.1); - box-sizing: border-box; -} -.textLayer .markedContent { - border: none; - background-color: transparent; + :is(span, br) { + color: black; + position: absolute; + white-space: pre; + transform-origin: 0% 0%; + border: solid 1px rgb(255 0 0 / 0.5); + background-color: rgb(255 255 32 / 0.1); + box-sizing: border-box; + } + + .markedContent { + border: none; + background-color: transparent; + } } diff --git a/web/text_layer_builder.css b/web/text_layer_builder.css index 992c888b16291..fca3ac8d7be72 100644 --- a/web/text_layer_builder.css +++ b/web/text_layer_builder.css @@ -13,18 +13,6 @@ * limitations under the License. */ -:root { - --highlight-bg-color: rgb(180 0 170); - --highlight-selected-bg-color: rgb(0 100 0); -} - -@media screen and (forced-colors: active) { - :root { - --highlight-bg-color: Highlight; - --highlight-selected-bg-color: ButtonText; - } -} - .textLayer { position: absolute; text-align: initial; @@ -36,75 +24,83 @@ forced-color-adjust: none; transform-origin: 0 0; z-index: 2; -} -.textLayer :is(span, br) { - color: transparent; - position: absolute; - white-space: pre; - cursor: text; - transform-origin: 0% 0%; -} + :is(span, br) { + color: transparent; + position: absolute; + white-space: pre; + cursor: text; + transform-origin: 0% 0%; + } -/* Only necessary in Google Chrome, see issue 14205, and most unfortunately - * the problem doesn't show up in "text" reference tests. */ -/*#if !MOZCENTRAL*/ -.textLayer span.markedContent { - top: 0; - height: 0; -} -/*#endif*/ + /* Only necessary in Google Chrome, see issue 14205, and most unfortunately + * the problem doesn't show up in "text" reference tests. */ + /*#if !MOZCENTRAL*/ + span.markedContent { + top: 0; + height: 0; + } + /*#endif*/ -.textLayer .highlight { - margin: -1px; - padding: 1px; - background-color: var(--highlight-bg-color); - border-radius: 4px; -} + .highlight { + --highlight-bg-color: rgb(180 0 170); + --highlight-selected-bg-color: rgb(0 100 0); -.textLayer .highlight.appended { - position: initial; -} + @media screen and (forced-colors: active) { + --highlight-bg-color: Highlight; + --highlight-selected-bg-color: ButtonText; + } -.textLayer .highlight.begin { - border-radius: 4px 0 0 4px; -} + margin: -1px; + padding: 1px; + background-color: var(--highlight-bg-color); + border-radius: 4px; -.textLayer .highlight.end { - border-radius: 0 4px 4px 0; -} + &.appended { + position: initial; + } -.textLayer .highlight.middle { - border-radius: 0; -} + &.begin { + border-radius: 4px 0 0 4px; + } -.textLayer .highlight.selected { - background-color: var(--highlight-selected-bg-color); -} + &.end { + border-radius: 0 4px 4px 0; + } + + &.middle { + border-radius: 0; + } + + &.selected { + background-color: var(--highlight-selected-bg-color); + } + } + + ::selection { + /*#if !MOZCENTRAL*/ + background: blue; + /*#endif*/ + background: AccentColor; /* stylelint-disable-line declaration-block-no-duplicate-properties */ + } -.textLayer ::selection { + /* Avoids https://github.com/mozilla/pdf.js/issues/13840 in Chrome */ /*#if !MOZCENTRAL*/ - background: blue; + br::selection { + background: transparent; + } /*#endif*/ - background: AccentColor; /* stylelint-disable-line declaration-block-no-duplicate-properties */ -} -/* Avoids https://github.com/mozilla/pdf.js/issues/13840 in Chrome */ -/*#if !MOZCENTRAL*/ -.textLayer br::selection { - background: transparent; -} -/*#endif*/ + .endOfContent { + display: block; + position: absolute; + inset: 100% 0 0; + z-index: -1; + cursor: default; + user-select: none; -.textLayer .endOfContent { - display: block; - position: absolute; - inset: 100% 0 0; - z-index: -1; - cursor: default; - user-select: none; -} - -.textLayer .endOfContent.active { - top: 0; + &.active { + top: 0; + } + } }