Skip to content

Commit e4f2431

Browse files
committed
icon fix
1 parent 0f35af8 commit e4f2431

File tree

11 files changed

+28
-130
lines changed

11 files changed

+28
-130
lines changed

docs/@capsule/components/capsule-icon/capsule-icon.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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');

docs/@capsule/components/capsule-icon/capsule-icon.style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ capsule-icon[size='xl'] {
3939
width: 2rem;
4040
height: 2rem;
4141
}
42-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
import './capsule-icon.js';
2-

docs/@capsule/components/capsule-icon/vscode.data.json

Lines changed: 0 additions & 37 deletions
This file was deleted.

docs/@capsule/global.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
@import url('./components/capsule-icon/capsule-icon.style.css');
12
@import url('./components/capsule-sidebar/capsule-sidebar.style.css');
23
@import url('./components/capsule-radio-group/capsule-radio-group.style.css');
34
@import url('./components/capsule-hover-card/capsule-hover-card.style.css');
45
@import url('./components/capsule-input/capsule-input.style.css');
5-
@import url('./components/capsule-icon/capsule-icon.style.css');
66
@import url('./components/capsule-tour/capsule-tour.style.css');
77
@import url('./components/capsule-circular-progress/capsule-circular-progress.style.css');
88
@import url('./components/capsule-pagination/capsule-pagination.style.css');
@@ -29,7 +29,7 @@
2929
@import url('./components/capsule-breadcrumb/capsule-breadcrumb.style.css');
3030
@import url('./components/capsule-button-group/capsule-button-group.style.css');
3131
@import url('./components/capsule-button/capsule-button.style.css');
32-
/* Shadcn-style theme variables */
32+
3333
:root {
3434
color-scheme: light;
3535

docs/@capsule/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ import './components/capsule-comparison/register.js';
4545
import './components/capsule-pagination/register.js';
4646
import './components/capsule-circular-progress/register.js';
4747
import './components/capsule-tour/register.js';
48-
49-
// Import all modules
50-
import './modules/form/index.js';
5148
import './components/capsule-container/register.js';
52-
import './components/capsule-icon/register.js';
5349
import './components/capsule-input/register.js';
5450
import './components/capsule-hover-card/register.js';
5551
import './components/capsule-radio-group/register.js';
5652
import './components/capsule-sidebar/register.js';
53+
54+
// Import all modules
55+
import './modules/form/index.js';
56+
import './components/capsule-icon/register.js';

src/@template/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/**
22
* @file CapsuleUI Main Entry Point
3-
* @version 1.0.0
4-
* @description Open-source Web Components library.
3+
* @version 1.2.6
4+
* @description Open-source Web Components library.
55
* Copy, paste, and customize - no npm install required.
6-
*
6+
*
77
* @example
88
* // HTML
99
* <script type="module" src="@capsule/index.js"></script>
1010
* <capsule-button>Click</capsule-button>
11-
*
12-
* @see https://capsuleui.dev/docs
11+
*
12+
* @see https://zizigy.github.io/CapsuleUI/
1313
*/
1414

1515
/**
1616
* Auto-registers all CapsuleUI components
1717
* @namespace CapsuleUI
1818
*/
1919

20-
// Import all components
20+
// Import all components

src/templates/Icon/icon.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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');

src/templates/Icon/icon.style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ __PREFIX__-__COMPONENT__[size='xl'] {
3939
width: 2rem;
4040
height: 2rem;
4141
}
42-

src/templates/Icon/register.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
import './__PREFIX__-__COMPONENT__.js';
2-

0 commit comments

Comments
 (0)