Skip to content

Commit df5d7a9

Browse files
committed
Fix Image display
1 parent 33aaafc commit df5d7a9

4 files changed

Lines changed: 16 additions & 31 deletions

File tree

src/code-impl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export function extractImports(
2828
}
2929
}
3030

31-
// keyframes 함수 체크
32-
if (/keyframes\s*\(|keyframes`/.test(allCode)) {
31+
if (/\bkeyframes\s*(\(|`)/.test(allCode)) {
3332
imports.add('keyframes')
3433
}
3534

src/codegen/Codegen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class Codegen {
188188
props.bg = maskColor
189189
delete props.src
190190
}
191+
props.display = 'initial'
191192
}
192193
return {
193194
component: 'src' in props ? 'Image' : 'Box',

src/codegen/props/auto-layout.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { addPx } from '../utils/add-px'
2+
import { checkAssetNode } from '../utils/check-asset-node'
23

34
export function getAutoLayoutProps(
45
node: SceneNode,
56
): Record<string, boolean | string | number | undefined | null> | undefined {
67
if (
78
!('inferredAutoLayout' in node) ||
89
!node.inferredAutoLayout ||
9-
node.inferredAutoLayout.layoutMode === 'NONE'
10+
node.inferredAutoLayout.layoutMode === 'NONE' ||
11+
checkAssetNode(node)
1012
)
1113
return
1214
const { layoutMode } = node.inferredAutoLayout

src/codegen/responsive/ResponsiveCodegen.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Codegen } from '../Codegen'
22
import { renderComponent, renderNode } from '../render'
33
import type { NodeTree, Props } from '../types'
44
import {
5-
BREAKPOINT_INDEX,
65
type BreakpointKey,
76
getBreakpointByWidth,
87
mergePropsToResponsive,
@@ -212,34 +211,18 @@ export class ResponsiveCodegen {
212211
}
213212

214213
if (childByBreakpoint.size > 0) {
215-
// Add display:none props when a child exists only at specific breakpoints
216-
// Find the smallest breakpoint where child exists
217-
const sortedPresentBreakpoints = [...presentBreakpoints].sort(
218-
(a, b) => BREAKPOINT_INDEX[a] - BREAKPOINT_INDEX[b],
219-
)
220-
const smallestPresentBp = sortedPresentBreakpoints[0]
221-
const smallestPresentIdx = BREAKPOINT_INDEX[smallestPresentBp]
222-
223-
// Find the smallest breakpoint in the section
224-
const sortedSectionBreakpoints = [...treesByBreakpoint.keys()].sort(
225-
(a, b) => BREAKPOINT_INDEX[a] - BREAKPOINT_INDEX[b],
226-
)
227-
const smallestSectionBp = sortedSectionBreakpoints[0]
228-
const smallestSectionIdx = BREAKPOINT_INDEX[smallestSectionBp]
229-
230-
// If child's smallest breakpoint is larger than section's smallest,
231-
// we need to add display:none for the smaller breakpoints
232-
if (smallestPresentIdx > smallestSectionIdx) {
233-
// Add display:none for all breakpoints smaller than where child exists
234-
for (const bp of treesByBreakpoint.keys()) {
235-
if (!presentBreakpoints.has(bp)) {
236-
const firstChildTree = [...childByBreakpoint.values()][0]
237-
const hiddenTree: NodeTree = {
238-
...firstChildTree,
239-
props: { ...firstChildTree.props, display: 'none' },
240-
}
241-
childByBreakpoint.set(bp, hiddenTree)
214+
// Add display:none props for breakpoints where child doesn't exist
215+
// This handles both:
216+
// 1. Child exists only in mobile (needs display:none in pc)
217+
// 2. Child exists only in pc (needs display:none in mobile)
218+
for (const bp of treesByBreakpoint.keys()) {
219+
if (!presentBreakpoints.has(bp)) {
220+
const firstChildTree = [...childByBreakpoint.values()][0]
221+
const hiddenTree: NodeTree = {
222+
...firstChildTree,
223+
props: { ...firstChildTree.props, display: 'none' },
242224
}
225+
childByBreakpoint.set(bp, hiddenTree)
243226
}
244227
}
245228

0 commit comments

Comments
 (0)