-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wip * refactor strokes * fix * fix * fix * refactor * more refactor * add changeset and fix issue fix line node * refactor * continue the refactor * refactor fills * fix * wip * try another approach * refactor * refactor * more refactor * refactor * wip * wip * minor improvements * minor fixes * refactor --------- Co-authored-by: Jordi Sala Morales <[email protected]>
- Loading branch information
1 parent
a734c8a
commit cc5553c
Showing
15 changed files
with
274 additions
and
137 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": patch | ||
--- | ||
|
||
Arrows on complex svgs are now better represented inside Penpot |
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,5 @@ | ||
--- | ||
"penpot-exporter": patch | ||
--- | ||
|
||
Fix line node svg path |
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,30 +1,69 @@ | ||
import { translateStrokes } from '@plugin/translators'; | ||
import { Command } from 'svg-path-parser'; | ||
|
||
import { translateStrokeCap, translateStrokes } from '@plugin/translators'; | ||
|
||
import { ShapeAttributes } from '@ui/lib/types/shapes/shape'; | ||
import { Stroke } from '@ui/lib/types/utils/stroke'; | ||
|
||
const isVectorLike = (node: GeometryMixin | VectorLikeMixin): node is VectorLikeMixin => { | ||
return 'vectorNetwork' in node; | ||
}; | ||
|
||
const isIndividualStrokes = ( | ||
node: GeometryMixin | IndividualStrokesMixin | ||
): node is IndividualStrokesMixin => { | ||
return 'strokeTopWeight' in node; | ||
}; | ||
|
||
const hasFillGeometry = (node: GeometryMixin): boolean => { | ||
return node.fillGeometry.length > 0; | ||
}; | ||
|
||
export const transformStrokes = async ( | ||
node: GeometryMixin | (GeometryMixin & IndividualStrokesMixin) | ||
): Promise<Partial<ShapeAttributes>> => { | ||
const vectorNetwork = isVectorLike(node) ? node.vectorNetwork : undefined; | ||
|
||
const strokeCaps = (stroke: Stroke) => { | ||
if (!hasFillGeometry(node) && vectorNetwork && vectorNetwork.vertices.length > 0) { | ||
stroke.strokeCapStart = translateStrokeCap(vectorNetwork.vertices[0]); | ||
stroke.strokeCapEnd = translateStrokeCap( | ||
vectorNetwork.vertices[vectorNetwork.vertices.length - 1] | ||
); | ||
} | ||
|
||
return stroke; | ||
}; | ||
|
||
return { | ||
strokes: await translateStrokes( | ||
node, | ||
hasFillGeometry(node), | ||
isVectorLike(node) ? node.vectorNetwork : undefined, | ||
isIndividualStrokes(node) ? node : undefined | ||
) | ||
strokes: await translateStrokes(node, strokeCaps) | ||
}; | ||
}; | ||
|
||
export const transformStrokesFromVector = async ( | ||
node: VectorNode, | ||
vector: Command[], | ||
vectorRegion: VectorRegion | undefined | ||
): Promise<Partial<ShapeAttributes>> => { | ||
const strokeCaps = (stroke: Stroke) => { | ||
if (vectorRegion !== undefined) return stroke; | ||
|
||
const startVertex = findVertex(node.vectorNetwork.vertices, vector[0]); | ||
const endVertex = findVertex(node.vectorNetwork.vertices, vector[vector.length - 1]); | ||
|
||
if (!startVertex || !endVertex) return stroke; | ||
|
||
stroke.strokeCapStart = translateStrokeCap(startVertex); | ||
stroke.strokeCapEnd = translateStrokeCap(endVertex); | ||
|
||
return stroke; | ||
}; | ||
|
||
return { | ||
strokes: await translateStrokes(node, strokeCaps) | ||
}; | ||
}; | ||
|
||
const findVertex = ( | ||
vertexs: readonly VectorVertex[], | ||
command: Command | ||
): VectorVertex | undefined => { | ||
if (command.command !== 'moveto' && command.command !== 'lineto' && command.command !== 'curveto') | ||
return; | ||
|
||
return vertexs.find(vertex => vertex.x === command.x && vertex.y === command.y); | ||
}; |
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
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.