0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/utils/calculateLinearGradient.ts

24 lines
670 B
TypeScript
Raw Normal View History

2024-04-15 02:48:03 -05:00
import { applyMatrixToPoint } from '@plugin/utils/applyMatrixToPoint';
import { matrixInvert } from '@plugin/utils/matrixInvert';
export const calculateLinearGradient = (shapeWidth: number, shapeHeight: number, t: Transform) => {
const transform = t.length === 2 ? [...t, [0, 0, 1]] : [...t];
const mxInv = matrixInvert(transform);
if (!mxInv) {
return {
start: [0, 0],
end: [0, 0]
};
}
const startEnd = [
[0, 0.5],
[1, 0.5]
].map(p => applyMatrixToPoint(mxInv, p));
return {
start: [startEnd[0][0] * shapeWidth, startEnd[0][1] * shapeHeight],
end: [startEnd[1][0] * shapeWidth, startEnd[1][1] * shapeHeight]
};
};