Skip to content

Commit 3b646a4

Browse files
committed
Fix animation
1 parent 2fdd2f6 commit 3b646a4

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

src/codegen/Codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export class Codegen {
8282
const assetNode = checkAssetNode(node)
8383
if (assetNode) {
8484
const props = await getProps(node)
85-
console.log('props', props)
8685
props.src = `/${assetNode === 'svg' ? 'icons' : 'images'}/${node.name}.${assetNode}`
8786
if (assetNode === 'svg') {
8887
const maskColor = await checkSameColor(node)

src/codegen/props/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { getVisibilityProps } from './visibility'
2222
export async function getProps(
2323
node: SceneNode,
2424
): Promise<Record<string, unknown>> {
25-
console.log('getProps', getLayoutProps(node))
2625
return {
2726
...getAutoLayoutProps(node),
2827
...getMinMaxProps(node),

src/codegen/props/position.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { addPx } from '../utils/add-px'
2+
import { checkAssetNode } from '../utils/check-asset-node'
23
import { isPageRoot } from '../utils/is-page-root'
34

45
export function isFreelayout(node: BaseNode & ChildrenMixin) {
@@ -105,6 +106,7 @@ export function getPositionProps(
105106
}
106107
if (
107108
'children' in node &&
109+
!checkAssetNode(node) &&
108110
(node.children.some(
109111
(child) =>
110112
'layoutPositioning' in child && child.layoutPositioning === 'ABSOLUTE',

src/codegen/props/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { canBeAbsolute } from './position'
44
export function getTransformProps(
55
node: SceneNode,
66
): Record<string, boolean | string | number | undefined | null> | undefined {
7-
if ('rotation' in node && node.rotation !== 0)
7+
if ('rotation' in node && Math.abs(node.rotation) > 0.01)
88
return {
99
transform: `rotate(${fmtPct(-node.rotation)}deg)`,
1010
transformOrigin: canBeAbsolute(node) ? 'top left' : undefined,

src/codegen/responsive/ResponsiveCodegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export class ResponsiveCodegen {
5757
const tree = await codegen.getTree()
5858
breakpointTrees.set(bp, tree)
5959
}
60-
console.log('breakpointTrees', breakpointTrees)
6160

6261
// Merge trees and generate code.
6362
return this.generateMergedCode(breakpointTrees, 0)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
function hasSmartAnimateReaction(node: BaseNode | null): boolean {
2+
if (!node || node.type === 'DOCUMENT' || node.type === 'PAGE') return false
3+
if (
4+
'reactions' in node &&
5+
node.reactions?.some((reaction) =>
6+
reaction.actions?.some(
7+
(action) =>
8+
action.type === 'NODE' && action.transition?.type === 'SMART_ANIMATE',
9+
),
10+
)
11+
)
12+
return true
13+
return false
14+
}
15+
16+
function isAnimationTarget(node: SceneNode): boolean {
17+
// Check if node itself has SMART_ANIMATE
18+
if (hasSmartAnimateReaction(node)) return true
19+
// Check if parent has SMART_ANIMATE (node is animation target as child)
20+
if (node.parent && hasSmartAnimateReaction(node.parent)) return true
21+
return false
22+
}
23+
124
export function checkAssetNode(node: SceneNode): 'svg' | 'png' | null {
225
if (node.type === 'TEXT' || node.type === 'COMPONENT_SET') return null
26+
// if node is an animation target (has keyframes), it should not be treated as an asset
27+
if (isAnimationTarget(node)) return null
328
// vector must be svg
429
if (['VECTOR', 'STAR', 'POLYGON'].includes(node.type)) return 'svg'
530
// ellipse with inner radius must be svg

0 commit comments

Comments
 (0)