Skip to content

Commit

Permalink
chore: refactor figma plugin (#2275)
Browse files Browse the repository at this point in the history
resolves #2630

---------

Co-authored-by: barsnes <[email protected]>
Co-authored-by: Michael Marszalek <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent b16971c commit 47f7e1c
Show file tree
Hide file tree
Showing 48 changed files with 3,825 additions and 481 deletions.
21 changes: 17 additions & 4 deletions packages/cli/src/colors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,19 @@ export const HSLToHex = (h: number, s: number, l: number) => {
* Converts a HEX color '#xxxxxx' into an array of RGB values '[R, G, B]'
*
* @param hex A hex color string
* @param type The type of RGB values to return
* @returns RGB values in an array
*/
export const hexToRgb = (hex: string) => {
export const hexToRgb = (hex: string, type: '255' | '1' = '255') => {
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, (m, r: string, g: string, b: string) => r + r + g + g + b + b);

const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
r: type === '255' ? parseInt(result[1], 16) : parseInt(result[1], 16) / 255,
g: type === '255' ? parseInt(result[2], 16) : parseInt(result[2], 16) / 255,
b: type === '255' ? parseInt(result[3], 16) : parseInt(result[3], 16) / 255,
}
: null;
};
Expand Down Expand Up @@ -382,3 +383,15 @@ export const convertToHex = (color?: string): CssColor => {
}
return chroma(color).hex() as CssColor;
};

export const rgbToHex = (rgb: { r: number; g: number; b: number }) => {
return (
'#' +
[rgb.r, rgb.g, rgb.b]
.map((x) => {
const hex = Math.round(x * 255).toString(16);
return hex.length === 1 ? '0' + hex : hex;
})
.join('')
);
};
9 changes: 0 additions & 9 deletions plugins/figma-plugin/src/common/types.ts

This file was deleted.

68 changes: 0 additions & 68 deletions plugins/figma-plugin/src/plugin/plugin.ts

This file was deleted.

59 changes: 0 additions & 59 deletions plugins/figma-plugin/src/ui/App.css

This file was deleted.

48 changes: 0 additions & 48 deletions plugins/figma-plugin/src/ui/app.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions plugins/figma-plugin/src/ui/components/Footer/Footer.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions plugins/figma-plugin/src/ui/components/Toast/Toast.css

This file was deleted.

43 changes: 0 additions & 43 deletions plugins/figma-plugin/src/ui/components/Toast/Toast.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/figma-plugin/src/ui/index.html

This file was deleted.

Loading

0 comments on commit 47f7e1c

Please sign in to comment.