Commit 31b409d
authored
feat: add custom gradient_stops and gradient_dir URL parameters (JhaSourav07#2194)
---
## Description
Fixes JhaSourav07#2190
Adds support for custom multi-stop gradients in the Isometric Towers
badge generator through two new URL parameters: `gradient_stops` and
`gradient_dir`. This enables users to customize tower face gradient
colors and direction beyond the default volumetric gradient, while
maintaining 100% backward compatibility.
## Pillar
- [ ] 🎨 Pillar 1 — New Theme Design
- [x] 📐 Pillar 2 — Geometric SVG Improvement
- [ ] 🕐 Pillar 3 — Timezone Logic Optimization
- [ ] 🛠️ Other (Bug fix, refactoring, docs)
## Visual Preview
**Default gradient (backward compatible):**
```
?user=chetan&gradient=true
```
**Custom 3-color gradient (vertical by default):**
```
?user=chetan&gradient=true&gradient_stops=ff6b35,ff007f,7000ff
```
**Custom gradient with horizontal direction:**
```
?user=chetan&gradient=true&gradient_stops=ff6b35,7000ff&gradient_dir=horizontal
```
**Custom gradient with diagonal direction:**
```
?user=chetan&gradient=true&gradient_stops=ff6b35,ff007f,7000ff&gradient_dir=diagonal
```
All examples render with smooth, harmonious gradients on tower faces,
maintaining CommitPulse's premium visual aesthetic.
## Changes
### `types/index.ts`
- Added `gradient_stops?: string` — comma-separated hex colors (e.g.,
`ff6b35,ff007f,7000ff`)
- Added `gradient_dir?: 'vertical' | 'horizontal' | 'diagonal'` —
gradient direction control
### `lib/svg/sanitizer.ts`
- `normalizeHexColor()` — validates and normalizes individual hex colors
(with/without `#` prefix)
- `parseGradientStops()` — parses comma-separated colors, filters
invalid entries safely
- `getGradientCoordinates()` — converts direction strings to SVG
linearGradient coordinates
### `lib/svg/generator.ts`
- `generateCustomGradients()` — creates dynamic SVG `<linearGradient>`
definitions with deterministic IDs, supporting 4 intensity levels
- Updated `renderDefs()` — prioritizes custom gradients with automatic
fallback to default behavior
- Updated tower rendering — uses custom gradient IDs when available
### `lib/svg/generator.additional.test.ts`
- 13 new test cases covering validation, directions, fallback behavior,
and edge cases
## Technical Details
- **Input Validation:** All colors validated using existing hex regex;
invalid stops filtered silently
- **Minimum Requirement:** Requires at least 2 valid colors; fewer
triggers fallback to default gradient
- **Deterministic IDs:** Gradient IDs generated from color stops +
direction using `deterministicRandom()` for consistent output
- **SVG Safety:** Zero raw user input in SVG; all parameters sanitized
before generation
- **Opacity Progression:** Gradients increase opacity with tower
intensity levels (0.4–0.8) for visual depth
- **Top Face Color:** Tower cap color remains controlled by `accent`
parameter, unaffected by `gradient_stops`
## Checklist before requesting a review:
- [x] I have read the CONTRIBUTING.md file.
- [x] I have tested these changes locally and verified all gradient
directions render correctly.
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors.
- [x] I have run `npm run test` and all tests pass locally.
- [x] I have run `npm run test:coverage` and branch coverage is at or
above 70%.
- [x] My commits follow the Conventional Commits format (`feat(svg): add
custom gradient support`).
- [x] I have not added any new URL parameters without documentation
consideration.
- [x] The SVG output matches CommitPulse's "premium quality" aesthetic —
smooth gradients, no raw elements, consistent styling.
- [x] This is a single, atomic commit.
---
This PR adds a powerful customization layer to the isometric tower
rendering engine while keeping the codebase clean, testable, and
backward compatible. Existing badges continue to render identically; new
users can opt into custom gradients for enhanced visual control.5 files changed
Lines changed: 503 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
0 commit comments