-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bitovi/feat/PD-378-appearance
Feat/pd 378 appearance
- Loading branch information
Showing
14 changed files
with
4,670 additions
and
176 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,69 +1,99 @@ | ||
import { StyleProcessor, VariableToken, ProcessedValue } from '../types'; | ||
import { rgbaToString } from '../utils/color.utils'; | ||
import { processGradient } from '../utils/gradient.utils'; | ||
import { normalizeValue } from '../utils/value.utils'; | ||
|
||
export const backgroundProcessor: StyleProcessor = { | ||
property: "background", | ||
bindingKey: "fills", | ||
process: async (variables: VariableToken[], node?: SceneNode): Promise<ProcessedValue | null> => { | ||
if (node && 'fills' in node && Array.isArray(node.fills)) { | ||
const visibleFills = node.fills.filter(fill => fill.visible); | ||
if (!visibleFills.length) return null; | ||
export const backgroundProcessors: StyleProcessor[] = [ | ||
{ | ||
property: "background", | ||
bindingKey: "fills", | ||
process: async (variables: VariableToken[], node?: SceneNode): Promise<ProcessedValue | null> => { | ||
if (node && 'fills' in node && Array.isArray(node.fills)) { | ||
const visibleFills = node.fills.filter(fill => fill.visible); | ||
if (!visibleFills.length) return null; | ||
|
||
const warningsSet = new Set<string>(); | ||
const errorsSet = new Set<string>(); | ||
const warningsSet = new Set<string>(); | ||
const errorsSet = new Set<string>(); | ||
|
||
const backgrounds = await Promise.all(visibleFills.map(async (fill: Paint) => { | ||
if (fill.type === "SOLID") { | ||
const fillVariable = variables.find(v => v.property === 'fills'); | ||
if (fillVariable) { | ||
return { | ||
value: fillVariable.value, | ||
rawValue: fillVariable.rawValue | ||
}; | ||
const backgrounds = await Promise.all(visibleFills.map(async (fill: Paint) => { | ||
if (fill.type === "SOLID") { | ||
const fillVariable = variables.find(v => v.property === 'fills'); | ||
if (fillVariable) { | ||
return { | ||
value: fillVariable.value, | ||
rawValue: fillVariable.rawValue | ||
}; | ||
} | ||
|
||
const { r, g, b } = fill.color; | ||
const a = fill.opacity ?? 1; | ||
const value = rgbaToString(r, g, b, a); | ||
return { value, rawValue: value }; | ||
} | ||
|
||
const { r, g, b } = fill.color; | ||
const a = fill.opacity ?? 1; | ||
const value = rgbaToString(r, g, b, a); | ||
return { value, rawValue: value }; | ||
} | ||
if (fill.type.startsWith('GRADIENT_')) { | ||
const result = processGradient(fill as GradientPaint, node.id); | ||
if (result.warnings) { | ||
result.warnings.forEach(warning => warningsSet.add(warning)); | ||
} | ||
if (result.errors) { | ||
result.errors.forEach(error => errorsSet.add(error)); | ||
} | ||
|
||
if (fill.type.startsWith('GRADIENT_')) { | ||
const result = processGradient(fill as GradientPaint, node.id); | ||
if (result.warnings) { | ||
result.warnings.forEach(warning => warningsSet.add(warning)); | ||
} | ||
if (result.errors) { | ||
result.errors.forEach(error => errorsSet.add(error)); | ||
if (result.value) { | ||
return { | ||
value: result.value, | ||
rawValue: result.value | ||
}; | ||
} | ||
} | ||
|
||
if (result.value) { | ||
return { | ||
value: result.value, | ||
rawValue: result.value | ||
}; | ||
} | ||
} | ||
|
||
return null; | ||
})); | ||
return null; | ||
})); | ||
|
||
const result: ProcessedValue = { | ||
warnings: warningsSet.size > 0 ? Array.from(warningsSet) : undefined, | ||
errors: errorsSet.size > 0 ? Array.from(errorsSet) : undefined, | ||
value: null, | ||
rawValue: null | ||
}; | ||
const result: ProcessedValue = { | ||
warnings: warningsSet.size > 0 ? Array.from(warningsSet) : undefined, | ||
errors: errorsSet.size > 0 ? Array.from(errorsSet) : undefined, | ||
value: null, | ||
rawValue: null | ||
}; | ||
|
||
const validBackgrounds = backgrounds.filter((b): b is NonNullable<typeof b> => b !== null); | ||
if (validBackgrounds.length > 0) { | ||
result.value = validBackgrounds.map(b => b.value).join(', '); | ||
result.rawValue = validBackgrounds.map(b => b.rawValue).join(', '); | ||
const validBackgrounds = backgrounds.filter((b): b is NonNullable<typeof b> => b !== null); | ||
if (validBackgrounds.length > 0) { | ||
result.value = validBackgrounds.map(b => b.value).join(', '); | ||
result.rawValue = validBackgrounds.map(b => b.rawValue).join(', '); | ||
} | ||
|
||
return result; | ||
} | ||
return null; | ||
} | ||
}, | ||
{ | ||
property: "opacity", | ||
bindingKey: "opacity", | ||
process: async (variables: VariableToken[], node?: SceneNode): Promise<ProcessedValue | null> => { | ||
if (node && 'opacity' in node && node.opacity !== 1) { | ||
const opacityVariable = variables.find(v => v.property === 'opacity'); | ||
if (opacityVariable) { | ||
return { | ||
value: opacityVariable.value, | ||
rawValue: opacityVariable.rawValue | ||
}; | ||
} | ||
|
||
return result; | ||
if (typeof node.opacity === 'number') { | ||
const value = normalizeValue({ | ||
propertyName: 'opacity', | ||
value: node.opacity | ||
}); | ||
return { | ||
value, | ||
rawValue: value | ||
}; | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
} | ||
}; | ||
]; |
This file contains 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 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 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
Oops, something went wrong.