Skip to content

Commit f158bd9

Browse files
committed
Fix assets
1 parent c78fc16 commit f158bd9

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/codegen/Codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ export class Codegen {
210210
*/
211211
async getTree(): Promise<NodeTree> {
212212
if (!this.tree) {
213-
console.log('buildTree', this.node)
214213
this.tree = await this.buildTree(this.node)
215214
}
216215
return this.tree

src/codegen/utils/check-asset-node.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function isAnimationTarget(node: SceneNode): boolean {
2121
return false
2222
}
2323

24-
export function checkAssetNode(node: SceneNode): 'svg' | 'png' | null {
24+
export function checkAssetNode(
25+
node: SceneNode,
26+
nested = false,
27+
): 'svg' | 'png' | null {
2528
if (node.type === 'TEXT' || node.type === 'COMPONENT_SET') return null
2629
// if node is an animation target (has keyframes), it should not be treated as an asset
2730
if (isAnimationTarget(node)) return null
@@ -56,10 +59,17 @@ export function checkAssetNode(node: SceneNode): 'svg' | 'png' | null {
5659
: node.fills.every(
5760
(fill: Paint) => fill.visible && fill.type === 'SOLID',
5861
)
59-
? null
62+
? nested
63+
? 'svg'
64+
: null
6065
: 'svg'
6166
: null
62-
: null
67+
: nested &&
68+
'fills' in node &&
69+
Array.isArray(node.fills) &&
70+
node.fills.every((fill) => fill.visible && fill.type === 'SOLID')
71+
? 'svg'
72+
: null
6373
}
6474
const { children } = node
6575
if (children.length === 1) {
@@ -75,15 +85,15 @@ export function checkAssetNode(node: SceneNode): 'svg' | 'png' | null {
7585
: true))
7686
)
7787
return null
78-
return checkAssetNode(children[0])
88+
return checkAssetNode(children[0], true)
7989
}
8090
const fillterdChildren = children.filter((child) => child.visible)
8191

8292
// return children.every((child) => child.visible && checkAssetNode(child))
8393
// ? 'svg'
8494
// : null
8595
return fillterdChildren.every((child) => {
86-
const result = checkAssetNode(child)
96+
const result = checkAssetNode(child, true)
8797
if (result === null) return false
8898
return result === 'svg'
8999
})

0 commit comments

Comments
 (0)