@@ -8,8 +8,6 @@ class CapsuleIcon extends LitElement {
88
99 constructor ( ) {
1010 super ( ) ;
11- this . _iconCache = new Map ( ) ;
12- this . _loadingIcons = new Map ( ) ;
1311 this . size = '1em' ;
1412 }
1513
@@ -42,29 +40,12 @@ class CapsuleIcon extends LitElement {
4240 return ;
4341 }
4442
45- if ( this . _iconCache . has ( this . name ) ) {
46- const cached = this . _iconCache . get ( this . name ) ;
47- this . _renderIcon ( cached ) ;
48- return ;
49- }
50-
51- if ( this . _loadingIcons . has ( this . name ) ) {
52- await this . _loadingIcons . get ( this . name ) ;
53- return ;
54- }
55-
56- const loadPromise = this . _fetchIcon ( this . name ) ;
57- this . _loadingIcons . set ( this . name , loadPromise ) ;
58-
5943 try {
60- const iconData = await loadPromise ;
61- this . _iconCache . set ( this . name , iconData ) ;
44+ const iconData = await this . _fetchIcon ( this . name ) ;
6245 this . _renderIcon ( iconData ) ;
6346 } catch ( error ) {
6447 console . error ( `Failed to load icon: ${ this . name } ` , error ) ;
6548 this . innerHTML = '' ;
66- } finally {
67- this . _loadingIcons . delete ( this . name ) ;
6849 }
6950 }
7051
@@ -95,14 +76,21 @@ class CapsuleIcon extends LitElement {
9576
9677 async _fetchIcon ( iconName ) {
9778 const url = `https://api.iconify.design/${ iconName } .svg` ;
79+ return await this . _fetchAndParseSvg ( url ) ;
80+ }
81+
82+ async _fetchAndParseSvg ( url ) {
9883 const response = await fetch ( url ) ;
9984
10085 if ( ! response . ok ) {
10186 throw new Error ( `Failed to fetch icon: ${ response . statusText } ` ) ;
10287 }
10388
10489 const svgText = await response . text ( ) ;
90+ return this . _parseSvg ( svgText ) ;
91+ }
10592
93+ _parseSvg ( svgText ) {
10694 const parser = new DOMParser ( ) ;
10795 const doc = parser . parseFromString ( svgText , 'image/svg+xml' ) ;
10896 const svg = doc . querySelector ( 'svg' ) ;
0 commit comments