-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: remove unmaintained color2k dependency and replace with local utility #6885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
divyanshu-patil
wants to merge
13
commits into
RocketChat:develop
Choose a base branch
from
divyanshu-patil:refactor/cleanup
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−8
Open
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b2a5d79
chore: replaced transparentize function from color2k to a utility fun…
divyanshu-patil 1930088
docs: typescript intellisence documentation
divyanshu-patil 3ad99cb
chore: added tests
divyanshu-patil ac12beb
cleanup: removed color2k
divyanshu-patil c0dba5a
cleanup: logs
divyanshu-patil eb70a23
test: added failing cases
divyanshu-patil d74bbc5
Merge branch 'develop' into refactor/cleanup
divyanshu-patil e84891c
Merge branch 'develop' into refactor/cleanup
divyanshu-patil a6f93a6
Merge branch 'develop' into refactor/cleanup
divyanshu-patil 063f884
Merge branch 'develop' into refactor/cleanup
divyanshu-patil dd7bbf4
Merge branch 'develop' into refactor/cleanup
divyanshu-patil c72a0bf
refactor: change alpha to target transparency
divyanshu-patil 404ab63
refactor: change alpha to target transparency
divyanshu-patil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import withAlpha from './withAlpha'; | ||
|
|
||
| describe('withAlpha', () => { | ||
| test('rgba to be rgba with updated alpha', () => { | ||
| expect(withAlpha('rgba(255, 0, 0, 0.2)', 0.8)).toBe('rgba(255, 0, 0, 0.8)'); | ||
| }); | ||
|
|
||
| test('rgb to be rgba with updated alpha', () => { | ||
| expect(withAlpha('rgb(255, 0, 0)', 0.8)).toBe('rgba(255, 0, 0, 0.8)'); | ||
| }); | ||
|
|
||
| test('hex #rgb to be hex #rrggbbaa with updated alpha', () => { | ||
| expect(withAlpha('#f00', 0.8)).toBe('#ff0000cc'); | ||
| }); | ||
|
|
||
| test('hex #rrggbb to be hex #rrggbbaa with updated alpha', () => { | ||
| expect(withAlpha('#ff0000', 0.8)).toBe('#ff0000cc'); | ||
| }); | ||
|
|
||
| test('hex #rrggbbaa to be hex #rrggbbaa with updated alpha', () => { | ||
| expect(withAlpha('#ff000022', 0.8)).toBe('#ff0000cc'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Applies an alpha (opacity) value to a color string. | ||
| * | ||
| * Supported formats: | ||
| * - `rgba(r,g,b,a)` → updates alpha | ||
| * - `rgb(r,g,b)` → converted to `rgba` | ||
| * - `#rgb`, `#rrggbb`, `#rrggbbaa` → normalized to `#rrggbbaa` | ||
| * | ||
| * Unsupported formats (returned unchanged): | ||
| * - Named colors (`red`) | ||
| * - `hsl()` / `hsla()` | ||
| * - Invalid color strings | ||
| * | ||
| * @param color Input color string | ||
| * @param alpha Opacity value between `0` and `1` (default: `1`) | ||
| */ | ||
| const withAlpha = (color: string, alpha: number = 1) => { | ||
| if (!color) { | ||
| return color; | ||
| } | ||
|
|
||
| // case rgba | ||
| if (color.startsWith('rgba')) { | ||
| const match = color.match(/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9.]+)\s*\)/); | ||
|
|
||
| if (!match) { | ||
| return color; | ||
| } | ||
|
|
||
| const [, r, g, b] = match; | ||
| return `rgba(${r}, ${g}, ${b}, ${alpha})`; | ||
| } | ||
|
|
||
| // case rgb | ||
| if (color.startsWith('rgb')) { | ||
| const match = color.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/); | ||
|
|
||
| if (!match) { | ||
| return color; | ||
| } | ||
|
|
||
| const [, r, g, b] = match; | ||
| return `rgba(${r}, ${g}, ${b}, ${alpha})`; | ||
| } | ||
|
|
||
| // case hex | ||
| if (color.startsWith('#')) { | ||
| let hex = color.slice(1); | ||
|
|
||
| // #rgb → #rrggbb | ||
| if (hex.length === 3) { | ||
| hex = hex | ||
| .split('') | ||
| .map(c => c + c) | ||
| .join(''); | ||
| } | ||
|
|
||
| if (hex.length === 8) { | ||
| hex = hex.substring(0, 6); | ||
| } | ||
| if (hex.length !== 6) { | ||
| return color; | ||
| } | ||
|
|
||
| const alphaHex = Math.round(alpha * 255) | ||
| .toString(16) | ||
| .padStart(2, '0'); | ||
|
|
||
| return `#${hex}${alphaHex}`; | ||
| } | ||
|
|
||
| // named colors / invalid strings | ||
| return color; | ||
| }; | ||
|
|
||
| export default withAlpha; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7000,11 +7000,6 @@ color-string@^1.9.0: | |
| color-name "^1.0.0" | ||
| simple-swizzle "^0.2.2" | ||
|
|
||
| [email protected]: | ||
| version "1.2.4" | ||
| resolved "https://registry.yarnpkg.com/color2k/-/color2k-1.2.4.tgz#af34950ac58e23cf224a01cb8dd0c9911a79605e" | ||
| integrity sha512-DiwdBwc0BryPFFXoCrW8XQGXl2rEtMToODybxZjKnN5IJXt/tV/FsN02pCK/b7KcWvJEioz3c74lQSmayFvS4Q== | ||
|
|
||
| color@^4.2.3: | ||
| version "4.2.3" | ||
| resolved "https://registry.yarnpkg.com/color/-/color-4.2.3.tgz#d781ecb5e57224ee43ea9627560107c0e0c6463a" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.