Skip to content

Commit f6fc2c8

Browse files
razhwojtekmaj
authored andcommitted
Update .textLayer CSS to match PDF.js 5.4.296 (#2077)
See https://github.com/mozilla/pdf.js/blob/v5.4.296/web/text_layer_builder.css Closes #2064
1 parent 2d545e6 commit f6fc2c8

1 file changed

Lines changed: 53 additions & 17 deletions

File tree

packages/react-pdf/src/Page/TextLayer.css

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@
1515

1616
:root {
1717
--react-pdf-text-layer: 1;
18-
--highlight-bg-color: rgba(180, 0, 170, 1);
19-
--highlight-selected-bg-color: rgba(0, 100, 0, 1);
20-
}
21-
22-
@media screen and (forced-colors: active) {
23-
:root {
24-
--highlight-bg-color: Highlight;
25-
--highlight-selected-bg-color: ButtonText;
26-
}
2718
}
2819

2920
[data-main-rotation='90'] {
@@ -37,15 +28,27 @@
3728
}
3829

3930
.textLayer {
31+
color-scheme: only light;
32+
4033
position: absolute;
4134
text-align: initial;
4235
inset: 0;
43-
overflow: hidden;
36+
overflow: clip;
37+
opacity: 1;
4438
line-height: 1;
4539
text-size-adjust: none;
4640
forced-color-adjust: none;
4741
transform-origin: 0 0;
48-
z-index: 2;
42+
caret-color: CanvasText;
43+
z-index: 0;
44+
45+
/* We multiply the font size by --min-font-size, and then scale the text
46+
* elements by 1/--min-font-size. This allows us to effectively ignore the
47+
* minimum font size enforced by the browser, so that the text layer <span>s
48+
* can always match the size of the text in the canvas. */
49+
--min-font-size: 1;
50+
--text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
51+
--min-font-size-inv: calc(1 / var(--min-font-size));
4952
}
5053

5154
.textLayer :is(span, br) {
@@ -57,20 +60,47 @@
5760
transform-origin: 0 0;
5861
}
5962

60-
/* Only necessary in Google Chrome, see issue 14205, and most unfortunately
61-
* the problem doesn't show up in "text" reference tests. */
62-
.textLayer span.markedContent {
63-
top: 0;
64-
height: 0;
63+
.textLayer > :not(.markedContent),
64+
.textLayer .markedContent span:not(.markedContent) {
65+
z-index: 1;
66+
67+
--font-height: 0; /* set by text_layer.js */
68+
font-size: calc(var(--text-scale-factor) * var(--font-height));
69+
70+
--scale-x: 1;
71+
--rotate: 0deg;
72+
transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
73+
}
74+
75+
.textLayer .markedContent {
76+
display: contents;
77+
}
78+
79+
.textLayer span[role='img'] {
80+
user-select: none;
81+
cursor: default;
6582
}
6683

6784
.textLayer .highlight {
85+
--highlight-bg-color: rgb(180 0 170 / 0.25);
86+
--highlight-selected-bg-color: rgb(0 100 0 / 0.25);
87+
--highlight-backdrop-filter: none;
88+
--highlight-selected-backdrop-filter: none;
89+
6890
margin: -1px;
6991
padding: 1px;
7092
background-color: var(--highlight-bg-color);
93+
backdrop-filter: var(--highlight-backdrop-filter);
7194
border-radius: 4px;
7295
}
7396

97+
@media screen and (forced-colors: active) {
98+
.textLayer .highlight {
99+
--highlight-bg-color: Highlight;
100+
--highlight-selected-bg-color: ButtonText;
101+
}
102+
}
103+
74104
.textLayer .highlight.appended {
75105
position: initial;
76106
}
@@ -89,6 +119,12 @@
89119

90120
.textLayer .highlight.selected {
91121
background-color: var(--highlight-selected-bg-color);
122+
backdrop-filter: var(--highlight-selected-backdrop-filter);
123+
}
124+
125+
.textLayer ::selection {
126+
background: rgba(0 0 255 / 0.25);
127+
background: color-mix(in srgb, AccentColor, transparent 75%);
92128
}
93129

94130
/* Avoids https://github.com/mozilla/pdf.js/issues/13840 in Chrome */
@@ -100,7 +136,7 @@
100136
display: block;
101137
position: absolute;
102138
inset: 100% 0 0;
103-
z-index: -1;
139+
z-index: 0;
104140
cursor: default;
105141
user-select: none;
106142
}

0 commit comments

Comments
 (0)