Skip to content
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

Partial PR of blendmode value #193

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/extractor/extractColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import config from '@config/config'
const transparentFill: fillValuesType = {
fill: {
value: { r: 0, g: 0, b: 0, a: 0 },
type: 'color'
type: 'color',
blendMode: 'normal'
}
}

Expand Down Expand Up @@ -59,7 +60,8 @@ const extractFills = (paint): fillValuesType | gradientValuesType => {
return {
fill: {
value: convertPaintToRgba(paint),
type: 'color' as PropertyType
type: 'color' as PropertyType,
blendMode: paint.blendMode?.toLowerCase() || 'normal'
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/transformer/standardTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ const typographyValueTransformer = ({ name, values }) => ({

const colorValueTransformer = ({ fill }): StandardTokenDataInterface => ({
type: 'color' as StandardTokenTypes,
value: rgbaObjectToHex8(fill.value)
value: rgbaObjectToHex8(fill.value),
blendMode: fill.blendMode?.toLowerCase() || 'normal'
})

const gradientValueTransformer = ({ gradientType, rotation, stops, opacity }): StandardTokenDataInterface => ({
Expand All @@ -164,7 +165,8 @@ const fillValueTransformer = (token): StandardTokenDataInterface | StandardToken
if (token.extensions && token.extensions[config.key.extensionPluginData] && token.extensions[config.key.extensionPluginData].alias) {
return {
type: Object.hasOwnProperty.call(token.values[0], 'fill') ? 'color' : 'custom-gradient',
value: `{${token.extensions[config.key.extensionPluginData].alias}}`
value: `{${token.extensions[config.key.extensionPluginData].alias}}`,
blendMode: token.values[0]?.fill?.blendMode?.toLowerCase() || 'normal'
}
}
// no alias, use value
Expand Down
1 change: 1 addition & 0 deletions tests/integration/data/original.variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
--color-colors-ref-blue: #044aff; /* Some other description */
--color-colors-special-characters: #40df50; /* Emoji */
--color-colors-special-characters-nderung: #3456af;
--color-invalid-empty: rgba(0, 0, 0, 0);
--grid-multiple-0-pattern: columns;
--grid-multiple-0-section-size: 1;
--grid-multiple-0-gutter-size: 20;
Expand Down
1 change: 1 addition & 0 deletions tests/integration/data/standard.variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
--color-colors-ref-blue: rgb(4, 74, 255); /* Some other description */
--color-colors-special-characters: rgb(64, 223, 80); /* Emoji */
--color-colors-special-characters-nderung: rgb(52, 86, 175);
--color-invalid-empty: rgba(0, 0, 0, 0);
--grid-multiple-0: [object Object];
--grid-multiple-1: [object Object];
--grid-multiple-2: [object Object];
Expand Down
16 changes: 11 additions & 5 deletions tests/unit/data/extractedFigmaTokens.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ export const extractedFigmaTokens = {
{
fill: {
value: { r: 255, g: 230, b: 0, a: 1 },
type: 'color'
type: 'color',
blendMode: 'NORMAL'
}
}
],
Expand All @@ -594,6 +595,7 @@ export const extractedFigmaTokens = {
category: 'color' as tokenCategoryType,
exportKey: 'color' as tokenExportKeyType,
description: 'a color token',
blendMode: 'NORMAL',
values: [
{
fill: {
Expand All @@ -618,13 +620,15 @@ export const extractedFigmaTokens = {
{
fill: {
value: { r: 255, g: 230, b: 0, a: 1 },
type: 'color'
type: 'color',
blendMode: 'NORMAL'
}
},
{
fill: {
value: { r: 0, g: 100, b: 255, a: 0.5 },
type: 'color'
type: 'color',
blendMode: 'NORMAL'
}
}
],
Expand Down Expand Up @@ -730,7 +734,8 @@ export const extractedFigmaTokens = {
{
fill: {
value: { r: 0, g: 100, b: 255, a: 0.5 },
type: 'color'
type: 'color',
blendMode: 'normal'
}
}
],
Expand All @@ -749,7 +754,8 @@ export const extractedFigmaTokens = {
{
fill: {
value: { r: 255, g: 230, b: 0, a: 1 },
type: 'color'
type: 'color',
blendMode: 'normal'
}
},
{
Expand Down
14 changes: 10 additions & 4 deletions tests/unit/data/transformedStandardTokens.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export const transformedStandardTokens = {
description: 'a color token',
type: 'color',
value: '#ffe600ff',
blendMode: 'normal',
extensions: {
'org.lukasoppermann.figmaDesignTokens': {
exportKey: 'color'
Expand All @@ -343,6 +344,7 @@ export const transformedStandardTokens = {
description: 'a color token',
type: 'color',
value: '{{color}}',
blendMode: 'normal',
extensions: {
'org.lukasoppermann.figmaDesignTokens': {
exportKey: 'color',
Expand All @@ -360,11 +362,13 @@ export const transformedStandardTokens = {
description: 'a multi color token',
0: {
type: 'color',
value: '#ffe600ff'
value: '#ffe600ff',
blendMode: 'normal'
},
1: {
type: 'color',
value: '#0064ff80'
value: '#0064ff80',
blendMode: 'normal'
}
},
/**
Expand Down Expand Up @@ -394,7 +398,8 @@ export const transformedStandardTokens = {
},
1: {
value: '#0064ff80',
type: 'color'
type: 'color',
blendMode: 'normal'
}
},
colorAndGradient: {
Expand All @@ -407,7 +412,8 @@ export const transformedStandardTokens = {
description: 'a color and gradient token',
0: {
value: '#ffe600ff',
type: 'color'
type: 'color',
blendMode: 'normal'
},
1: {
type: 'custom-gradient',
Expand Down
24 changes: 16 additions & 8 deletions tests/unit/extractColors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('extracting color fills', () => {
b: 186,
g: 26,
r: 255
}
},
blendMode: 'normal'
}
}]
},
Expand All @@ -47,7 +48,8 @@ describe('extracting color fills', () => {
b: 186,
g: 26,
r: 255
}
},
blendMode: 'normal'
}
}]
},
Expand All @@ -70,7 +72,8 @@ describe('extracting color fills', () => {
b: 0,
g: 0,
r: 0
}
},
blendMode: 'normal'
}
}]
},
Expand All @@ -93,7 +96,8 @@ describe('extracting color fills', () => {
b: 255,
g: 255,
r: 255
}
},
blendMode: 'normal'
}
}]
},
Expand All @@ -116,7 +120,8 @@ describe('extracting color fills', () => {
b: 186,
g: 26,
r: 255
}
},
blendMode: 'normal'
}
}, {
gradientType: {
Expand Down Expand Up @@ -234,7 +239,8 @@ describe('extracting color fills', () => {
b: 230,
g: 128,
r: 51
}
},
blendMode: 'normal'
}
}
]
Expand Down Expand Up @@ -262,7 +268,8 @@ describe('extracting color fills', () => {
b: 186,
g: 26,
r: 255
}
},
blendMode: 'normal'
}
}]
},
Expand All @@ -286,7 +293,8 @@ describe('extracting color fills', () => {
b: 186,
g: 26,
r: 255
}
},
blendMode: 'normal'
}
}]
}
Expand Down
5 changes: 3 additions & 2 deletions types/propertyObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { extractedGridValues } from './extractedData'
import { StandardTokenExtensionsInterface } from './standardToken'
import { tokenCategoryType } from './tokenCategory'
import { tokenExportKeyType } from './tokenExportKey'
import { ColorRgba, GradientType, GridAlignment, GridPattern, NumericUnitTypes, StrokeAlign, StrokeJoin, StrokeCap, TextCase, TextDecoration, UnitTypePixel, EffectType, PropertyType, UnitTypeSeconds } from './valueTypes'
import { ColorRgba, BlendType, GradientType, GridAlignment, GridPattern, NumericUnitTypes, StrokeAlign, StrokeJoin, StrokeCap, TextCase, TextDecoration, UnitTypePixel, EffectType, PropertyType, UnitTypeSeconds } from './valueTypes'

export type propertyObject = {
name: string,
Expand Down Expand Up @@ -68,7 +68,8 @@ export type fontPropertyInterface = propertyObject & {
export type fillValuesType = {
fill: {
value: ColorRgba,
type: PropertyType
type: PropertyType,
blendMode: BlendType
}
}

Expand Down
3 changes: 3 additions & 0 deletions types/standardToken.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { BlendType } from './valueTypes'

export type customTokenTypes = 'custom-spacing' |
'custom-radius' |
'custom-fontStyle' |
Expand Down Expand Up @@ -48,6 +50,7 @@ export type StandardTokenDataInterface = {
description?: string,
value: StandardTokenValueType | StandardCompositeTokenValueType,
type: StandardTokenTypes,
blendMode?: BlendType,
extensions?: StandardTokenExtensionsInterface
}

Expand Down
2 changes: 2 additions & 0 deletions types/valueTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type ColorRgba = {
a: number
}

export type BlendType = 'normal' | 'darken' | 'multiply' | 'color_burn' | 'lighten' | 'screen' | 'color_dodge' | 'overlay' | 'soft_light' | 'hard_light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity'

export type GradientType = 'linear' | 'radial' | 'angular' | 'diamond'

export type UnitTypeDegree = 'degree'
Expand Down