1+ /*! show-js-error | © 2023 Denis Seleznev | MIT License | https://github.com/hcodes/show-js-error/ */
12function getScreenSize ( ) {
23 return [ screen . width , screen . height , screen . colorDepth ] . join ( '×' ) ;
34}
45function getScreenOrientation ( ) {
56 return typeof screen . orientation === 'string' ? screen . orientation : screen . orientation . type ;
67}
78function copyTextToClipboard ( text ) {
8- var textarea = document . createElement ( 'textarea' ) ;
9+ const textarea = document . createElement ( 'textarea' ) ;
910 textarea . value = text ;
1011 document . body . appendChild ( textarea ) ;
1112 try {
@@ -17,6 +18,12 @@ function copyTextToClipboard(text) {
1718 }
1819 document . body . removeChild ( textarea ) ;
1920}
21+ function injectStyle ( style ) {
22+ const styleNode = document . createElement ( 'style' ) ;
23+ document . body . appendChild ( styleNode ) ;
24+ styleNode . textContent = style ;
25+ return styleNode ;
26+ }
2027
2128function createElem ( data ) {
2229 const elem = document . createElement ( data . tag || 'div' ) ;
@@ -78,6 +85,7 @@ function getFilenameWithPosition(error) {
7885 return text ;
7986}
8087
88+ const STYLE = '.show-js-error{background:#ffc1cc;bottom:15px;color:#000;font-family:Arial,sans-serif;font-size:13px;left:15px;max-width:90vw;min-width:15em;opacity:1;position:fixed;transition:opacity .2s ease-out;transition-delay:0s;visibility:visible;z-index:10000000}.show-js-error_size_big{transform:scale(2) translate(25%,-25%)}.show-js-error_hidden{opacity:0;transition:opacity .3s,visibility 0s linear .3s;visibility:hidden}.show-js-error__title{background:#f66;color:#fff;font-weight:700;padding:4px 30px 4px 7px}.show-js-error__title_no-errors{background:#6b6}.show-js-error__message{cursor:pointer;display:inline}.show-js-error__message:before{background-color:#eee;border-radius:10px;content:"+";display:inline-block;font-size:10px;height:10px;line-height:10px;margin-bottom:2px;margin-right:5px;text-align:center;vertical-align:middle;width:10px}.show-js-error__body_detailed .show-js-error__message:before{content:"-"}.show-js-error__body_no-stack .show-js-error__message:before{display:none}.show-js-error__body_detailed .show-js-error__filename{display:block}.show-js-error__body_no-stack .show-js-error__filename{display:none}.show-js-error__close{color:#fff;cursor:pointer;font-size:20px;line-height:20px;padding:3px;position:absolute;right:2px;top:0}.show-js-error__body{line-height:19px;padding:5px 8px}.show-js-error__body_hidden{display:none}.show-js-error__filename{background:#ffe1ec;border:1px solid #faa;display:none;margin:3px 0 3px -2px;max-height:15em;overflow-y:auto;padding:5px;white-space:pre-wrap}.show-js-error__actions{border-top:1px solid #faa;margin-top:5px;padding:5px 0 3px}.show-js-error__actions_hidden{display:none}.show-js-error__arrows{margin-left:8px;white-space:nowrap}.show-js-error__arrows_hidden{display:none}.show-js-error__copy,.show-js-error__next,.show-js-error__num,.show-js-error__prev,.show-js-error__report{font-size:12px}.show-js-error__report_hidden{display:none}.show-js-error__next{margin-left:1px}.show-js-error__num{margin-left:5px;margin-right:5px}.show-js-error__copy,.show-js-error__report{margin-right:3px}.show-js-error input{padding:1px 2px}.show-js-error a,.show-js-error a:visited{color:#000;text-decoration:underline}.show-js-error a:hover{text-decoration:underline}' ;
8189class ShowJSError {
8290 constructor ( ) {
8391 this . elems = { } ;
@@ -88,7 +96,8 @@ class ShowJSError {
8896 errorBuffer : [ ] ,
8997 } ;
9098 this . onerror = ( event ) => {
91- const error = event . error ;
99+ const error = event . error ? event . error : event ;
100+ console . log ( 1 , event ) ;
92101 this . pushError ( {
93102 title : 'JavaScript Error' ,
94103 message : error . message ,
@@ -120,6 +129,7 @@ class ShowJSError {
120129 this . appendToBody = ( ) => {
121130 document . removeEventListener ( 'DOMContentLoaded' , this . appendToBody , false ) ;
122131 if ( this . elems . container ) {
132+ this . styleNode = injectStyle ( STYLE ) ;
123133 document . body . appendChild ( this . elems . container ) ;
124134 }
125135 } ;
@@ -129,6 +139,7 @@ class ShowJSError {
129139 document . addEventListener ( 'securitypolicyviolation' , this . onsecuritypolicyviolation , false ) ;
130140 }
131141 destruct ( ) {
142+ var _a ;
132143 window . removeEventListener ( 'error' , this . onerror , false ) ;
133144 window . removeEventListener ( 'unhandledrejection' , this . onunhandledrejection , false ) ;
134145 document . removeEventListener ( 'securitypolicyviolation' , this . onsecuritypolicyviolation , false ) ;
@@ -138,6 +149,10 @@ class ShowJSError {
138149 }
139150 this . state . errorBuffer = [ ] ;
140151 this . elems = { } ;
152+ if ( this . styleNode ) {
153+ ( _a = this . styleNode . parentNode ) === null || _a === void 0 ? void 0 : _a . removeChild ( this . styleNode ) ;
154+ this . styleNode = undefined ;
155+ }
141156 }
142157 setSettings ( settings ) {
143158 this . settings = this . prepareSettings ( settings ) ;
@@ -168,6 +183,7 @@ class ShowJSError {
168183 hide ( ) {
169184 if ( this . elems . container ) {
170185 this . elems . container . className = buildElemClass ( '' , {
186+ size : this . settings . size ,
171187 hidden : true
172188 } ) ;
173189 }
@@ -190,6 +206,7 @@ class ShowJSError {
190206 prepareSettings ( rawSettings ) {
191207 const settings = rawSettings || { } ;
192208 return {
209+ size : settings . size || 'normal' ,
193210 reportUrl : settings . reportUrl || '' ,
194211 templateDetailedMessage : settings . templateDetailedMessage || '' ,
195212 } ;
@@ -201,7 +218,9 @@ class ShowJSError {
201218 }
202219 appendUI ( ) {
203220 const container = document . createElement ( 'div' ) ;
204- container . className = buildElemClass ( '' ) ;
221+ container . className = buildElemClass ( '' , {
222+ size : this . settings . size ,
223+ } ) ;
205224 this . elems . container = container ;
206225 this . elems . close = createElem ( {
207226 name : 'close' ,
@@ -241,6 +260,7 @@ class ShowJSError {
241260 this . createActions ( body ) ;
242261 if ( document . body ) {
243262 document . body . appendChild ( container ) ;
263+ this . styleNode = injectStyle ( STYLE ) ;
244264 }
245265 else {
246266 document . addEventListener ( 'DOMContentLoaded' , this . appendToBody , false ) ;
@@ -349,7 +369,9 @@ class ShowJSError {
349369 }
350370 showUI ( ) {
351371 if ( this . elems . container ) {
352- this . elems . container . className = buildElemClass ( '' ) ;
372+ this . elems . container . className = buildElemClass ( '' , {
373+ size : this . settings . size ,
374+ } ) ;
353375 }
354376 }
355377 hasStack ( ) {
@@ -431,4 +453,7 @@ class ShowJSError {
431453 }
432454}
433455
434- export { ShowJSError } ;
456+ const showJSError = new ShowJSError ( ) ;
457+ window . showJSError = showJSError ;
458+
459+ export { showJSError } ;
0 commit comments