Skip to content

Commit a562ba9

Browse files
committed
style: fix ESLint issues - remove unused imports and replace any types with proper typing
1 parent 686d05b commit a562ba9

4 files changed

Lines changed: 120 additions & 19 deletions

File tree

lib/svg/generator.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
sanitizeRadius,
1212
sanitizeGoogleFontUrl,
1313
getLuminance,
14-
normalizeHexColor,
1514
parseGradientStops,
1615
getGradientCoordinates,
1716
} from './sanitizer';
@@ -158,15 +157,16 @@ function renderHeader(
158157

159158
/**
160159
* Generates custom SVG gradient definitions from gradient_stops and gradient_dir parameters.
161-
* Returns a string of linearGradient elements for each intensity level (1-4).
162-
* If custom stops are invalid or insufficient, returns an empty string (fallback to default behavior).
160+
* Returns an object with gradient SVG elements and the gradient ID (or empty string if invalid).
161+
* If custom stops are invalid or insufficient, returns { gradients: '', gradientId: '' }.
162+
* Also stores the gradient ID on the params object for tower rendering to use.
163163
*/
164-
function generateCustomGradients(params: BadgeParams, bgHex: string): string {
164+
function generateCustomGradients(params: BadgeParams): { gradients: string; gradientId: string } {
165165
const stops = parseGradientStops(params.gradient_stops);
166166

167167
// Require at least 2 valid colors for custom gradient
168168
if (stops.length < 2) {
169-
return '';
169+
return { gradients: '', gradientId: '' };
170170
}
171171

172172
const coords = getGradientCoordinates(params.gradient_dir);
@@ -207,10 +207,10 @@ ${stopElements}
207207
</linearGradient>`;
208208
}
209209

210-
// Store the gradient ID in a temporary attribute so tower rendering can use it
211-
(params as any).__customGradientId = gradientId;
210+
// Store the gradient ID on params for tower rendering to use
211+
params.__customGradientId = gradientId;
212212

213-
return gradients;
213+
return { gradients, gradientId };
214214
}
215215

216216
function renderDefs(sf: number, params: BadgeParams): string {
@@ -219,15 +219,15 @@ function renderDefs(sf: number, params: BadgeParams): string {
219219
let gradients = '';
220220
if (params.gradient) {
221221
// Try to use custom gradient if gradient_stops is provided
222-
const bgStr = params.bg || '0d1117';
223-
const bgHex = bgStr.startsWith('#') ? bgStr : `#${bgStr}`;
224-
225-
const customGradients = generateCustomGradients(params, bgHex);
226-
if (customGradients) {
222+
const result = generateCustomGradients(params);
223+
if (result.gradientId) {
227224
// Custom gradient stops were valid and used
228-
gradients = customGradients;
225+
gradients = result.gradients;
229226
} else {
230227
// Fallback to default gradient behavior
228+
const bgStr = params.bg || '0d1117';
229+
const bgHex = bgStr.startsWith('#') ? bgStr : `#${bgStr}`;
230+
231231
if (params.autoTheme) {
232232
for (let i = 0; i < 4; i++) {
233233
const level = i + 1;
@@ -245,7 +245,9 @@ function renderDefs(sf: number, params: BadgeParams): string {
245245
const c = accent[idx] || accent[accent.length - 1] || '00ffaa';
246246
return c.startsWith('#') ? c : `#${c}`;
247247
})
248-
: [0, 1, 2, 3].map(() => (String(accent).startsWith('#') ? String(accent) : `#${accent}`));
248+
: [0, 1, 2, 3].map(() =>
249+
String(accent).startsWith('#') ? String(accent) : `#${accent}`
250+
);
249251

250252
colors.forEach((c, idx) => {
251253
const level = idx + 1;
@@ -405,7 +407,7 @@ function renderTowers(
405407

406408
if (!isGhost && t.intensityLevel > 0 && params.gradient === true) {
407409
// Use custom gradient ID if available, otherwise use default gradient ID
408-
const customGradId = (params as any).__customGradientId;
410+
const customGradId = params.__customGradientId;
409411
const gradId = customGradId
410412
? `${customGradId}-level-${t.intensityLevel}`
411413
: `tower-grad-level-${t.intensityLevel}`;

lib/svg/sanitizer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ export function parseGradientStops(input?: string): string[] {
167167
* Returns {x1, y1, x2, y2} as percentage strings suitable for SVG linearGradient attributes.
168168
* Defaults to 'vertical' if direction is invalid.
169169
*/
170-
export function getGradientCoordinates(
171-
dir?: string
172-
): { x1: string; y1: string; x2: string; y2: string } {
170+
export function getGradientCoordinates(dir?: string): {
171+
x1: string;
172+
y1: string;
173+
x2: string;
174+
y2: string;
175+
} {
173176
const direction = (dir || 'vertical').toLowerCase().trim();
174177

175178
switch (direction) {

0 commit comments

Comments
 (0)