7
7
stripAnsi
8
8
} from './utils' ;
9
9
10
- const base = '/' ;
11
-
12
10
// set :host styles to make playwright detect the element as visible
13
11
const template = /*html*/ `
14
12
<style>
@@ -130,8 +128,7 @@ code {
130
128
131
129
kbd {
132
130
line-height: 1.5;
133
- font-family: ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono',
134
- 'Courier New', monospace;
131
+ font-family: ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
135
132
font-size: 0.75rem;
136
133
font-weight: 700;
137
134
background-color: rgb(38, 40, 44);
@@ -141,8 +138,8 @@ kbd {
141
138
border-width: 0.0625rem 0.0625rem 0.1875rem;
142
139
border-style: solid;
143
140
border-color: rgb(54, 57, 64);
144
- border-image: initial;
145
141
}
142
+
146
143
.message-container {
147
144
padding: 10px 10px;
148
145
}
@@ -155,24 +152,6 @@ kbd {
155
152
margin: 10px 0;
156
153
}
157
154
158
-
159
-
160
- kbd {
161
- line-height: 1.5;
162
- font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
163
- font-size: 0.75rem;
164
- font-weight: 700;
165
- background-color: rgb(38, 40, 44);
166
- color: rgb(166, 167, 171);
167
- padding: 0.15rem 0.3rem;
168
- border-radius: 0.25rem;
169
- border-width: 0.0625rem 0.0625rem 0.1875rem;
170
- border-style: solid;
171
- border-color: rgb(54, 57, 64);
172
- border-image: initial;
173
- }
174
-
175
-
176
155
.code-block-wrapper {
177
156
background-color: #282c34; /* Atom One Dark 背景色 */
178
157
border-radius: 6px;
@@ -562,11 +541,7 @@ pre::-webkit-scrollbar-thumb:hover {
562
541
</div>
563
542
` ;
564
543
565
- const errorAlert = (
566
- message : string ,
567
- description : string ,
568
- _type : string
569
- ) => /*html*/ `
544
+ const errorAlert = ( message : string , description : string ) => /*html*/ `
570
545
<div class="alert alert-error">
571
546
<span class="alert-icon">
572
547
<svg viewBox="64 64 896 896" focusable="false" data-icon="close-circle" width="1.2em" height="1.2em" fill="currentColor" aria-hidden="true">
@@ -580,20 +555,17 @@ const errorAlert = (
580
555
</div>
581
556
` ;
582
557
583
- const warnAlert = ( description : string , type = 'warn' ) => /*html*/ `
584
- <div class="alert alert-${ type } ">
558
+ const warnAlert = ( description : string ) => /*html*/ `
559
+ <div class="alert alert-warn ">
585
560
<span class="alert-icon">
586
- ${ getAlertIcon ( type ) }
561
+ ${ getAlertIcon ( 'warn' ) }
587
562
</span>
588
563
<div class="alert-content">
589
564
<div class="alert-description">${ description . replace ( / \n / g, '<br>' ) } </div>
590
565
</div>
591
566
</div>
592
567
` ;
593
568
594
- const fileRE = / (?: [ a - z A - Z ] : \\ | \/ ) .* ?: \d + : \d + / g;
595
- // const codeframeRE = /^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm;
596
-
597
569
// Allow `ErrorOverlay` to extend `HTMLElement` even in environments where
598
570
// `HTMLElement` was not originally defined.
599
571
const { HTMLElement = class { } as typeof globalThis . HTMLElement } = globalThis ;
@@ -627,66 +599,6 @@ export class ErrorOverlay extends HTMLElement {
627
599
document . addEventListener ( 'keydown' , this . closeOnEsc ) ;
628
600
}
629
601
630
- text ( selector : string , text : string , linkFiles = false ) : void {
631
- const el = this . root . querySelector ( selector ) ! ;
632
- if ( ! linkFiles ) {
633
- el . textContent = text ;
634
- } else {
635
- let curIndex = 0 ;
636
- let match : RegExpExecArray | null ;
637
- fileRE . lastIndex = 0 ;
638
- while ( ( match = fileRE . exec ( text ) ) ) {
639
- const { 0 : file , index } = match ;
640
- if ( index != null ) {
641
- const frag = text . slice ( curIndex , index ) ;
642
- el . appendChild ( document . createTextNode ( frag ) ) ;
643
- const link = document . createElement ( 'a' ) ;
644
- link . textContent = file ;
645
- link . className = 'file-link' ;
646
- link . onclick = ( ) => {
647
- fetch (
648
- new URL (
649
- `${ base } __open-in-editor?file=${ encodeURIComponent ( file ) } ` ,
650
- // import.meta.url
651
- window . location . href
652
- )
653
- ) ;
654
- } ;
655
- el . appendChild ( link ) ;
656
- curIndex += frag . length + file . length ;
657
- }
658
- }
659
- }
660
- }
661
-
662
- setMessageText ( element : HTMLElement , text : string , linkFiles : boolean ) {
663
- if ( ! linkFiles ) {
664
- element . textContent = text ;
665
- } else {
666
- element . innerHTML = '' ;
667
- let lastIndex = 0 ;
668
- text . replace ( fileRE , ( file , index ) => {
669
- if ( index > lastIndex ) {
670
- element . appendChild (
671
- document . createTextNode ( text . substring ( lastIndex , index ) )
672
- ) ;
673
- }
674
- const link = document . createElement ( 'a' ) ;
675
- link . textContent = file ;
676
- link . className = 'file-link' ;
677
- link . onclick = ( ) => {
678
- fetch ( `${ base } __open-in-editor?file=${ encodeURIComponent ( file ) } ` ) ;
679
- } ;
680
- element . appendChild ( link ) ;
681
- lastIndex = index + file . length ;
682
- return file ;
683
- } ) ;
684
- if ( lastIndex < text . length ) {
685
- element . appendChild ( document . createTextNode ( text . substring ( lastIndex ) ) ) ;
686
- }
687
- }
688
- }
689
-
690
602
highlightCode ( code : string , language = 'javascript' ) {
691
603
return Prism . highlight ( code , Prism . languages [ language ] , language ) ;
692
604
}
@@ -740,22 +652,16 @@ export class ErrorOverlay extends HTMLElement {
740
652
msg = parseIfJSON ( msg ) ;
741
653
742
654
if ( msg . type ) {
743
- const TypeError = document . createElement ( 'span' ) ;
744
- TypeError . className = 'type-error' ;
745
- TypeError . textContent = msg . type ;
655
+ const typeError = document . createElement ( 'span' ) ;
656
+ typeError . className = 'type-error' ;
657
+ typeError . textContent = msg . type ;
746
658
const TypeCodeError = document . createElement ( 'div' ) ;
747
- TypeCodeError . innerHTML = errorAlert ( msg . type , msg . id , msg . type ) ;
659
+ TypeCodeError . innerHTML = errorAlert ( msg . type , msg . id ) ;
748
660
messageElement . appendChild ( TypeCodeError ) ;
749
661
}
750
662
751
- // if (msg.plugin) {
752
- // const pluginElement = document.createElement('span');
753
- // pluginElement.className = 'plugin';
754
- // pluginElement.textContent = `[plugin:${msg.plugin}] `;
755
- // messageElement.appendChild(pluginElement);
756
- // }
757
-
758
663
const messageBody = document . createElement ( 'div' ) ;
664
+
759
665
messageBody . className = 'message' ;
760
666
761
667
const splitMessage = splitErrorMessage ( msg ) ;
@@ -880,13 +786,6 @@ export class ErrorOverlay extends HTMLElement {
880
786
messageContainer . appendChild ( messageElement ) ;
881
787
}
882
788
883
- // if (msg.stack) {
884
- // const stack = document.createElement('pre');
885
- // stack.className = 'stack';
886
- // this.setMessageText(stack, msg.stack, links);
887
- // messageElement.appendChild(stack);
888
- // }
889
-
890
789
if ( msg . cause ) {
891
790
const causeElement = document . createElement ( 'div' ) ;
892
791
causeElement . innerHTML = warnAlert ( msg . cause ) ;
0 commit comments