Skip to content

Clean up Gradient and Color classes in TS by removing their methods#3857

Merged
Keavon merged 1 commit intomasterfrom
remove-color-ts-class-methods
Mar 4, 2026
Merged

Clean up Gradient and Color classes in TS by removing their methods#3857
Keavon merged 1 commit intomasterfrom
remove-color-ts-class-methods

Conversation

@Keavon
Copy link
Copy Markdown
Member

@Keavon Keavon commented Mar 4, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the core Color and Gradient classes by extracting their methods into a set of pure utility functions. This change promotes a more functional programming paradigm, enhancing modularity, testability, and potentially improving tree-shaking capabilities by decoupling behavior from data structures. The update ensures that all consuming components are aligned with this new functional approach.

Highlights

  • Refactored Color and Gradient Classes: The Color and Gradient classes in messages.ts have been refactored to remove all their methods. Functionality such as color conversions, comparisons, and gradient manipulations are now provided as standalone utility functions.
  • Introduced Utility Functions: New factory functions (e.g., createColor, createNoneColor, createColorFromHSVA) and utility functions (e.g., colorToHexOptionalAlpha, colorEquals, gradientToLinearGradientCSS) have been added to handle color and gradient operations in a functional style.
  • Updated Component Usage: All Svelte components (ColorPicker.svelte, Document.svelte, ColorInput.svelte, SpectrumInput.svelte, WorkingColorsInput.svelte) that previously used methods on Color or Gradient instances, or instanceof checks, have been updated to utilize the new utility functions and type guards (isColor, isGradient).
Changelog
  • frontend/src/components/floating-menus/ColorPicker.svelte
    • Updated imports to include new color and gradient utility functions and type guards.
    • Replaced direct method calls on Color and Gradient instances with corresponding utility functions.
    • Changed new Color() and instanceof checks to use createColorFromHSVA, createNoneColor, isColor, and isGradient.
  • frontend/src/components/panels/Document.svelte
    • Updated imports for color utility functions and type guards.
    • Replaced Color.toHexOptionalAlpha() with colorToHexOptionalAlpha().
    • Replaced new Color() with createColor() and instanceof Color with isColor().
  • frontend/src/components/widgets/inputs/ColorInput.svelte
    • Updated imports to use new color and gradient utility functions and type guards.
    • Replaced instanceof Gradient and instanceof Color checks with isGradient() and isColor().
    • Replaced value.toLinearGradientCSS() and value.toHexOptionalAlpha() with gradientToLinearGradientCSS() and colorToHexOptionalAlpha().
  • frontend/src/components/widgets/inputs/SpectrumInput.svelte
    • Updated imports to include new color and gradient utility functions.
    • Replaced new Color() with createColor().
    • Replaced gradient and color method calls like .firstColor(), .lastColor(), .toHexOptionalAlpha(), .toLinearGradientCSS(), and .toRgbCSS() with their respective utility functions.
  • frontend/src/components/widgets/inputs/WorkingColorsInput.svelte
    • Updated imports for color utility functions and type guards.
    • Replaced primary.toRgbaCSS() and secondary.toRgbaCSS() with colorToRgbaCSS().
    • Replaced detail instanceof Color checks with isColor(detail).
  • frontend/src/messages.ts
    • Removed all methods from the Gradient class.
    • Removed all methods and constructors from the Color class, making it a pure data interface.
    • Introduced createColor, createNoneColor, and createColorFromHSVA as factory functions for Color objects.
    • Added a comprehensive set of color utility functions: colorFromCSS, colorEquals, colorToHexNoAlpha, colorToHexOptionalAlpha, colorToRgb255, colorToRgbCSS, colorToRgbaCSS, colorToHSVA, colorOpaque, colorLuminance, and colorContrastingColor.
    • Added gradient utility functions: gradientToLinearGradientCSS, gradientFirstColor, and gradientLastColor.
    • Implemented type guards isColor and isGradient for runtime type checking.
    • Updated the ColorInput transformation logic to use the new factory and utility functions for creating and manipulating Color and Gradient objects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Color and Gradient classes by moving their methods to standalone utility functions. This is a good move towards a more functional approach for these data structures. The changes are applied consistently across several Svelte components. I've found one critical issue where a type cast could lead to a runtime crash, and one suggestion for code simplification. Otherwise, the refactoring looks solid.

Comment thread frontend/src/components/widgets/inputs/SpectrumInput.svelte Outdated
Comment thread frontend/src/messages.ts Outdated
@Keavon Keavon force-pushed the remove-color-ts-class-methods branch from 62731e7 to d3b7b7d Compare March 4, 2026 10:12
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

@github-actions github-actions bot temporarily deployed to graphite-dev (Preview) March 4, 2026 10:15 Inactive
@Keavon Keavon force-pushed the remove-color-ts-class-methods branch from d3b7b7d to 3560bb8 Compare March 4, 2026 10:21
@github-actions github-actions bot temporarily deployed to graphite-dev (Preview) March 4, 2026 10:22 Inactive
@github-actions github-actions bot temporarily deployed to graphite-dev (Preview) March 4, 2026 10:28 Inactive
@Keavon Keavon merged commit f00a15a into master Mar 4, 2026
5 checks passed
@Keavon Keavon deleted the remove-color-ts-class-methods branch March 4, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant