-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* path shapes * add polygon node * wip vector * implement translation of commands and paths * vectors and polygon * strokes * star * deformed shapes * simplify star * simplify star * fix transformers --------- Co-authored-by: Alex Sánchez <[email protected]>
- Loading branch information
1 parent
cfbd196
commit 73ccf83
Showing
25 changed files
with
303 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
transformBlend, | ||
transformDimensionAndPosition, | ||
transformSceneNode | ||
} from '@plugin/transformers/partials'; | ||
import { translateFills, translateStrokes, translateVectorPaths } from '@plugin/translators'; | ||
|
||
import { PathShape } from '@ui/lib/types/path/pathShape'; | ||
|
||
export const transformPolygonNode = ( | ||
node: DefaultShapeMixin, | ||
baseX: number, | ||
baseY: number | ||
): PathShape => { | ||
return { | ||
type: 'path', | ||
name: node.name, | ||
content: translateVectorPaths(node.fillGeometry, baseX + node.x, baseY + node.y), | ||
strokes: translateStrokes(node), | ||
fills: translateFills(node.fills, node.width, node.height), | ||
...transformDimensionAndPosition(node, baseX, baseY), | ||
...transformSceneNode(node), | ||
...transformBlend(node) | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
transformBlend, | ||
transformDimensionAndPosition, | ||
transformSceneNode | ||
} from '@plugin/transformers/partials'; | ||
import { translateFills, translateStrokes, translateVectorPaths } from '@plugin/translators'; | ||
|
||
import { PathShape } from '@ui/lib/types/path/pathShape'; | ||
|
||
export const transformVectorNode = (node: VectorNode, baseX: number, baseY: number): PathShape => { | ||
return { | ||
type: 'path', | ||
name: node.name, | ||
fills: node.fillGeometry.length ? translateFills(node.fills, node.width, node.height) : [], | ||
content: translateVectorPaths(node.vectorPaths, baseX + node.x, baseY + node.y), | ||
strokes: translateStrokes(node), | ||
...transformDimensionAndPosition(node, baseX, baseY), | ||
...transformSceneNode(node), | ||
...transformBlend(node) | ||
}; | ||
}; |
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,6 +1,8 @@ | ||
export * from './translateBlendMode'; | ||
export * from './translateFills'; | ||
export * from './translateGradientLinearFill'; | ||
export * from './translateSolidFill'; | ||
export * from './translateStrokes'; | ||
export * from './translateTextDecoration'; | ||
export * from './translateTextTransform'; | ||
export * from './translateBlendMode'; | ||
export * from './translateVectorPaths'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { translateFill } from '@plugin/translators/translateFills'; | ||
|
||
import { Stroke } from '@ui/lib/types/utils/stroke'; | ||
|
||
export const translateStrokes = (node: MinimalStrokesMixin): Stroke[] => { | ||
return node.strokes.map(stroke => { | ||
const fill = translateFill(stroke, 0, 0); | ||
return { | ||
strokeColor: fill?.fillColor, | ||
strokeOpacity: fill?.fillOpacity, | ||
strokeWidth: node.strokeWeight === figma.mixed ? 1 : node.strokeWeight | ||
}; | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import SVGPathCommander from 'svg-path-commander'; | ||
|
||
import { Segment } from '@ui/lib/types/path/PathContent'; | ||
|
||
export const translateVectorPaths = ( | ||
paths: VectorPaths, | ||
baseX: number, | ||
baseY: number | ||
): Segment[] => { | ||
let segments: Segment[] = []; | ||
|
||
for (const path of paths) { | ||
segments = [...segments, ...translateVectorPath(path, baseX, baseY)]; | ||
} | ||
|
||
return segments; | ||
}; | ||
|
||
const translateVectorPath = (path: VectorPath, baseX: number, baseY: number): Segment[] => { | ||
const segments: Segment[] = []; | ||
|
||
const normalizedPath = SVGPathCommander.normalizePath(path.data); | ||
|
||
for (const [command, ...rest] of normalizedPath) { | ||
switch (command) { | ||
case 'M': | ||
segments.push({ | ||
command: 'move-to', | ||
params: { x: (rest[0] ?? 0) + baseX, y: (rest[1] ?? 0) + baseY } | ||
}); | ||
break; | ||
case 'L': | ||
segments.push({ | ||
command: 'line-to', | ||
params: { x: (rest[0] ?? 0) + baseX, y: (rest[1] ?? 0) + baseY } | ||
}); | ||
break; | ||
case 'C': | ||
segments.push({ | ||
command: 'curve-to', | ||
params: { | ||
c1x: (rest[0] ?? 0) + baseX, | ||
c1y: (rest[1] ?? 0) + baseY, | ||
c2x: (rest[2] ?? 0) + baseX, | ||
c2y: (rest[3] ?? 0) + baseY, | ||
x: (rest[4] ?? 0) + baseX, | ||
y: (rest[5] ?? 0) + baseY | ||
} | ||
}); | ||
break; | ||
case 'Z': | ||
segments.push({ | ||
command: 'close-path' | ||
}); | ||
break; | ||
} | ||
} | ||
|
||
return segments; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PenpotFile } from '@ui/lib/penpot'; | ||
import { PATH_TYPE } from '@ui/lib/types/path/pathAttributes'; | ||
import { PathShape } from '@ui/lib/types/path/pathShape'; | ||
import { | ||
translateFillGradients, | ||
translatePathContent, | ||
translateUiBlendMode | ||
} from '@ui/translators'; | ||
|
||
export const createPenpotPath = ( | ||
file: PenpotFile, | ||
{ type, fills, blendMode, content, ...rest }: PathShape | ||
) => { | ||
file.createPath({ | ||
type: PATH_TYPE, | ||
fills: translateFillGradients(fills), | ||
blendMode: translateUiBlendMode(blendMode), | ||
content: translatePathContent(content), | ||
...rest | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export const VECTOR_LINE_TO: unique symbol = Symbol.for('line-to'); | ||
export const VECTOR_CLOSE_PATH: unique symbol = Symbol.for('close-path'); | ||
export const VECTOR_MOVE_TO: unique symbol = Symbol.for('move-to'); | ||
export const VECTOR_CURVE_TO: unique symbol = Symbol.for('curve-to'); | ||
|
||
export type PathContent = Segment[]; | ||
export type Segment = LineTo | ClosePath | MoveTo | CurveTo; | ||
export type Command = | ||
| 'line-to' | ||
| 'close-path' | ||
| 'move-to' | ||
| 'curve-to' | ||
| typeof VECTOR_LINE_TO | ||
| typeof VECTOR_CLOSE_PATH | ||
| typeof VECTOR_MOVE_TO | ||
| typeof VECTOR_CURVE_TO; | ||
|
||
type LineTo = { | ||
command: 'line-to' | typeof VECTOR_LINE_TO; | ||
params: { | ||
x: number; | ||
y: number; | ||
}; | ||
}; | ||
|
||
type ClosePath = { | ||
command: 'close-path' | typeof VECTOR_CLOSE_PATH; | ||
}; | ||
|
||
type MoveTo = { | ||
command: 'move-to' | typeof VECTOR_MOVE_TO; | ||
params: { | ||
x: number; | ||
y: number; | ||
}; | ||
}; | ||
|
||
type CurveTo = { | ||
command: 'curve-to' | typeof VECTOR_CURVE_TO; | ||
params: { | ||
x: number; | ||
y: number; | ||
c1x: number; | ||
c1y: number; | ||
c2x: number; | ||
c2y: number; | ||
}; | ||
}; |
Oops, something went wrong.