-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
168 lines (137 loc) · 4.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var React = require('react')
var ReactDOM = require('react-dom')
var createReactClass = require('create-react-class')
var RedBox = require('redbox-react').default
var styles = require('redbox-react/lib/style').default
// Custom styles to imitate the Windows BSOD
styles.redbox = {
transform: 'translateZ(0)', // Trigger super fast GPU rendering mode
boxSizing: 'border-box',
fontFamily: 'PerfectDOSVGA, sans-serif',
padding: '1% 4%',
color: 'white',
zIndex: '9998',
textAlign: 'left',
fontSize: '16px',
lineHeight: '1.2',
}
styles.stack.fontFamily = "'PerfectDOSVGA', monospace"
styles.file.fontSize = '16px'
var overlayStyles = {
// Make this a rounded-corner transparent box
position: 'fixed',
boxSizing: 'content-box', // So we can size just the content, excluding the border
width: '100%', // Set the content size to fill the screen
height: '100vh',
// Curved edges roughly like what a CRT looked like
borderRadius: '5% / 50%',
// Inner shadow to give a slight rounded effect
boxShadow: 'rgba(255, 255, 255, 0.2) 2em 7em 10em -1em inset,' +
'rgba(0, 0, 0, 0.2) -20px -7em 10em -1em inset,' +
// makes the black outline of the "CRT", leaving the box to be transparent
'rgba(0, 0, 0, 1) 0 0 0 10vw',
// Give it that old school CRT pixelated feel
// Thanks to http://codepen.io/lbebber/pen/XJRdrV
background: 'linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06))',
backgroundSize: '100% 2px, 3px 100%',
// Make sure it's on top
zIndex: 9999,
// But doesn't capture the mouse
pointerEvents: 'none',
}
var BSODError = createReactClass({
propTypes: RedBox.propTypes,
render: function render() {
return React.createElement(
'div',
{style: overlayStyles},
React.createElement(
'style',
{dangerouslySetInnerHTML: {__html:
/**
* http://www.dafont.com/perfect-dos-vga-437.font
* by Zeh Fernando
*/
'@font-face {' +
' font-family: PerfectDOSVGA;' +
' src: url("https://unpkg.com/react-bsod/static/perfect-dos-vga-437.ttf");' +
' font-weight: 400;' +
'}' +
'.redbox-target:before {' +
' content: "A problem has been detected and React has been shut down to prevent damage to your computer.";' +
' margin-bottom: 2em;' +
'}' +
'.redbox-target:after {' +
' content: "Technical information: \\A\\A *** STOP: 0x000000005 (0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000)";' +
' margin-top: 2em;' +
'}' +
'.redbox-target:before,' +
'.redbox-target:after {' +
' white-space: pre;' +
' display: block;' +
'}' +
// Override any applied styles to ensure our component displays
// correctly
'body, html {' +
' padding: 0 !important;' +
' margin: 0 !important;' +
'}' +
'body {' +
' background: rgb(0, 0, 160);' +
'}' +
'body > .bsod-hidden {' +
' display: none !important;' +
'}'
}}
),
React.createElement(
RedBox,
{
style: styles,
error: this.props.error,
filename: this.props.filename,
editorScheme: this.props.editorScheme,
useLines: this.props.useLines,
useColumns: this.props.useColumns,
className: 'redbox-target'
}
)
)
}
})
var BSOD = createReactClass({
propTypes: BSODError.propTypes,
componentDidMount: function componentDidMount() {
// Hide any other elements so we're guaranteed to be the only thing on the
// page
this.otherBodyEls = Array.prototype.slice.apply(document.querySelectorAll('body > *'))
this.otherBodyEls.forEach(function(el) {
el.className += ' bsod-hidden'
})
this.el = document.createElement('div')
document.body.appendChild(this.el)
this.renderBSODError()
},
componentDidUpdate: function componentDidUpdate() {
this.renderBSODError()
},
componentWillUnmount: function componentWillUnmount() {
ReactDOM.unmountComponentAtNode(this.el)
document.body.removeChild(this.el)
this.el = null
// Un-hide any other elements
this.otherBodyEls.forEach(function(el) {
el.className = el.className.replace(
new RegExp('\\s?\\bbsod-hidden\\b', 'g'),
''
)
})
},
renderBSODError: function renderBSODError() {
ReactDOM.render(React.createElement(BSODError, this.props), this.el)
},
render: function render() {
return null
}
})
module.exports = BSOD