3
3
4
4
import ansiHTML from "ansi-html-community" ;
5
5
import { encode } from "html-entities" ;
6
+ import {
7
+ containerStyle ,
8
+ dismissButtonStyle ,
9
+ headerStyle ,
10
+ iframeStyle ,
11
+ msgStyles ,
12
+ msgTextStyle ,
13
+ msgTypeStyle ,
14
+ } from "./overlay/styles.js" ;
6
15
7
16
const colors = {
8
17
reset : [ "transparent" , "transparent" ] ,
@@ -28,6 +37,17 @@ let overlayTrustedTypesPolicy;
28
37
29
38
ansiHTML . setColors ( colors ) ;
30
39
40
+ /**
41
+ *
42
+ * @param {HTMLElement } element
43
+ * @param {CSSStyleDeclaration } style
44
+ */
45
+ function applyStyle ( element , style ) {
46
+ Object . keys ( style ) . forEach ( ( prop ) => {
47
+ element . style [ prop ] = style [ prop ] ;
48
+ } ) ;
49
+ }
50
+
31
51
/**
32
52
* @param {string | null } trustedTypesPolicyName
33
53
*/
@@ -45,64 +65,35 @@ function createContainer(trustedTypesPolicyName) {
45
65
iframeContainerElement = document . createElement ( "iframe" ) ;
46
66
iframeContainerElement . id = "webpack-dev-server-client-overlay" ;
47
67
iframeContainerElement . src = "about:blank" ;
48
- iframeContainerElement . style . position = "fixed" ;
49
- iframeContainerElement . style . left = 0 ;
50
- iframeContainerElement . style . top = 0 ;
51
- iframeContainerElement . style . right = 0 ;
52
- iframeContainerElement . style . bottom = 0 ;
53
- iframeContainerElement . style . width = "100vw" ;
54
- iframeContainerElement . style . height = "100vh" ;
55
- iframeContainerElement . style . border = "none" ;
56
- iframeContainerElement . style . zIndex = 9999999999 ;
68
+ applyStyle ( iframeContainerElement , iframeStyle ) ;
57
69
iframeContainerElement . onload = ( ) => {
58
70
containerElement =
59
71
/** @type {Document } */
60
72
(
61
73
/** @type {HTMLIFrameElement } */
62
74
( iframeContainerElement ) . contentDocument
63
75
) . createElement ( "div" ) ;
76
+
64
77
containerElement . id = "webpack-dev-server-client-overlay-div" ;
65
- containerElement . style . position = "fixed" ;
66
- containerElement . style . boxSizing = "border-box" ;
67
- containerElement . style . left = 0 ;
68
- containerElement . style . top = 0 ;
69
- containerElement . style . right = 0 ;
70
- containerElement . style . bottom = 0 ;
71
- containerElement . style . width = "100vw" ;
72
- containerElement . style . height = "100vh" ;
73
- containerElement . style . backgroundColor = "rgba(0, 0, 0, 0.85)" ;
74
- containerElement . style . color = "#E8E8E8" ;
75
- containerElement . style . fontFamily = "Menlo, Consolas, monospace" ;
76
- containerElement . style . fontSize = "large" ;
77
- containerElement . style . padding = "2rem" ;
78
- containerElement . style . lineHeight = "1.2" ;
79
- containerElement . style . whiteSpace = "pre-wrap" ;
80
- containerElement . style . overflow = "auto" ;
81
-
82
- const headerElement = document . createElement ( "span" ) ;
78
+ applyStyle ( containerElement , containerStyle ) ;
79
+
80
+ const headerElement = document . createElement ( "div" ) ;
83
81
84
82
headerElement . innerText = "Compiled with problems:" ;
83
+ applyStyle ( headerElement , headerStyle ) ;
85
84
86
85
const closeButtonElement = document . createElement ( "button" ) ;
87
86
88
- closeButtonElement . innerText = "X" ;
89
- closeButtonElement . style . background = "transparent" ;
90
- closeButtonElement . style . border = "none" ;
91
- closeButtonElement . style . fontSize = "20px" ;
92
- closeButtonElement . style . fontWeight = "bold" ;
93
- closeButtonElement . style . color = "white" ;
94
- closeButtonElement . style . cursor = "pointer" ;
95
- closeButtonElement . style . cssFloat = "right" ;
96
- // @ts -ignore
97
- closeButtonElement . style . styleFloat = "right" ;
87
+ applyStyle ( closeButtonElement , dismissButtonStyle ) ;
88
+
89
+ closeButtonElement . innerText = "×" ;
90
+ closeButtonElement . ariaLabel = "Dismiss" ;
98
91
closeButtonElement . addEventListener ( "click" , ( ) => {
99
92
hide ( ) ;
100
93
} ) ;
101
94
102
95
containerElement . appendChild ( headerElement ) ;
103
96
containerElement . appendChild ( closeButtonElement ) ;
104
- containerElement . appendChild ( document . createElement ( "br" ) ) ;
105
- containerElement . appendChild ( document . createElement ( "br" ) ) ;
106
97
107
98
/** @type {Document } */
108
99
(
@@ -200,26 +191,29 @@ function show(type, messages, trustedTypesPolicyName) {
200
191
ensureOverlayExists ( ( ) => {
201
192
messages . forEach ( ( message ) => {
202
193
const entryElement = document . createElement ( "div" ) ;
203
- const typeElement = document . createElement ( "span" ) ;
194
+ const msgStyle = type === "warning" ? msgStyles . warning : msgStyles . error ;
195
+ applyStyle ( entryElement , {
196
+ ...msgStyle ,
197
+ padding : "1rem 1rem 1.5rem 1rem" ,
198
+ } ) ;
199
+
200
+ const typeElement = document . createElement ( "div" ) ;
204
201
const { header, body } = formatProblem ( type , message ) ;
205
202
206
203
typeElement . innerText = header ;
207
- typeElement . style . color = `# ${ colors . red } ` ;
204
+ applyStyle ( typeElement , msgTypeStyle ) ;
208
205
209
206
// Make it look similar to our terminal.
210
207
const text = ansiHTML ( encode ( body ) ) ;
211
208
const messageTextNode = document . createElement ( "div" ) ;
209
+ applyStyle ( messageTextNode , msgTextStyle ) ;
212
210
213
211
messageTextNode . innerHTML = overlayTrustedTypesPolicy
214
212
? overlayTrustedTypesPolicy . createHTML ( text )
215
213
: text ;
216
214
217
215
entryElement . appendChild ( typeElement ) ;
218
- entryElement . appendChild ( document . createElement ( "br" ) ) ;
219
- entryElement . appendChild ( document . createElement ( "br" ) ) ;
220
216
entryElement . appendChild ( messageTextNode ) ;
221
- entryElement . appendChild ( document . createElement ( "br" ) ) ;
222
- entryElement . appendChild ( document . createElement ( "br" ) ) ;
223
217
224
218
/** @type {HTMLDivElement } */
225
219
( containerElement ) . appendChild ( entryElement ) ;
0 commit comments