mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): upgrade modular dashboard UI, 6-segment context meter, and consumption analytics
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @fileoverview Dynamic SVG icon component and incremental icon patcher.
|
||||
*/
|
||||
|
||||
import { SVG_ICON_DEFS } from './svgRegistry.js';
|
||||
|
||||
export const SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
export function createSvgIcon(name, { size = 14, className = '' } = {}) {
|
||||
const svg = document.createElementNS(SVG_NS, 'svg');
|
||||
svg.setAttribute('viewBox', '0 0 16 16');
|
||||
svg.setAttribute('width', String(size));
|
||||
svg.setAttribute('height', String(size));
|
||||
svg.setAttribute('fill', 'none');
|
||||
svg.setAttribute('stroke', 'currentColor');
|
||||
svg.setAttribute('stroke-width', '1.5');
|
||||
svg.setAttribute('stroke-linecap', 'round');
|
||||
svg.setAttribute('stroke-linejoin', 'round');
|
||||
svg.setAttribute('aria-hidden', 'true');
|
||||
if (className) {
|
||||
svg.setAttribute('class', `svg-icon ${className}`.trim());
|
||||
} else {
|
||||
svg.setAttribute('class', 'svg-icon');
|
||||
}
|
||||
patchSvgIcon(svg, name);
|
||||
return svg;
|
||||
}
|
||||
|
||||
export function patchSvgIcon(svgEl, name) {
|
||||
if (!svgEl || svgEl.dataset?.iconName === name) return false;
|
||||
if (svgEl.dataset) {
|
||||
svgEl.dataset.iconName = name;
|
||||
}
|
||||
while (svgEl.firstChild) {
|
||||
svgEl.removeChild(svgEl.firstChild);
|
||||
}
|
||||
const shapes = SVG_ICON_DEFS[name] || SVG_ICON_DEFS.dot;
|
||||
for (const shape of shapes) {
|
||||
const child = document.createElementNS(SVG_NS, shape.tag);
|
||||
for (const [k, v] of Object.entries(shape.attrs)) {
|
||||
child.setAttribute(k, v);
|
||||
}
|
||||
svgEl.appendChild(child);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user