@@ -16,7 +16,8 @@ import {
1616 collectCustomPropsFromCSS ,
1717 buildSeedCustomPropsRule ,
1818 markSlottedSubtree ,
19- rasterizeIframe
19+ rasterizeIframe ,
20+ getUnscaledDimensions
2021} from '../utils/clone.helpers.js'
2122
2223// helper implementations moved to ../utils/clone.helpers.js
@@ -101,17 +102,18 @@ export async function deepClone(node, sessionCache, options) {
101102
102103 // Fallback actual (placeholder o spacer)
103104 if ( options . placeholders ) {
105+ const { width, height } = getUnscaledDimensions ( node )
104106 const fallback = document . createElement ( 'div' )
105107 fallback . style . cssText =
106- `width:${ node . offsetWidth } px;height:${ node . offsetHeight } px;` +
108+ `width:${ width } px;height:${ height } px;` +
107109 'background-image:repeating-linear-gradient(45deg,#ddd,#ddd 5px,#f9f9f9 5px,#f9f9f9 10px);' +
108110 'display:flex;align-items:center;justify-content:center;font-size:12px;color:#555;border:1px solid #aaa;'
109111 inlineAllStyles ( node , fallback , sessionCache , options )
110112 return fallback
111113 } else {
112- const rect = node . getBoundingClientRect ( )
114+ const { width , height } = getUnscaledDimensions ( node )
113115 const spacer = document . createElement ( 'div' )
114- spacer . style . cssText = `display:inline-block;width:${ rect . width } px;height:${ rect . height } px;visibility:hidden;`
116+ spacer . style . cssText = `display:inline-block;width:${ width } px;height:${ height } px;visibility:hidden;`
115117 inlineAllStyles ( node , spacer , sessionCache , options )
116118 return spacer
117119 }
@@ -165,12 +167,10 @@ export async function deepClone(node, sessionCache, options) {
165167 img . width = node . width
166168 img . height = node . height
167169
168- // conservar caja CSS para no romper layout
169- try {
170- const cs = getComputedStyle ( node )
171- if ( cs . width ) img . style . width = cs . width
172- if ( cs . height ) img . style . height = cs . height
173- } catch { }
170+ // conservar caja CSS para no romper layout usando dimensiones pre-transform
171+ const { width, height } = getUnscaledDimensions ( node )
172+ if ( width > 0 ) img . style . width = `${ width } px`
173+ if ( height > 0 ) img . style . height = `${ height } px`
174174
175175 sessionCache . nodeMap . set ( img , node )
176176 inlineAllStyles ( node , img , sessionCache , options )
@@ -184,22 +184,11 @@ export async function deepClone(node, sessionCache, options) {
184184 sessionCache . nodeMap . set ( clone , node )
185185 if ( node . tagName === 'IMG' ) {
186186 freezeImgSrcset ( node , clone )
187- // Record original image dimensions for fallback usage when inlining fails
187+ // Record original image dimensions (pre-transform) for fallback usage when inlining fails
188188 try {
189- const rect = node . getBoundingClientRect ( )
190- let w = Math . round ( rect . width || 0 )
191- let h = Math . round ( rect . height || 0 )
192- if ( ! w || ! h ) {
193- const computed = window . getComputedStyle ( node )
194- const cssW = parseFloat ( computed . width ) || 0
195- const cssH = parseFloat ( computed . height ) || 0
196- const attrW = parseInt ( node . getAttribute ( 'width' ) || '' , 10 ) || 0
197- const attrH = parseInt ( node . getAttribute ( 'height' ) || '' , 10 ) || 0
198- const propW = node . width || node . naturalWidth || 0
199- const propH = node . height || node . naturalHeight || 0
200- w = Math . round ( w || cssW || attrW || propW || 0 )
201- h = Math . round ( h || cssH || attrH || propH || 0 )
202- }
189+ const { width, height } = getUnscaledDimensions ( node )
190+ const w = Math . round ( width || 0 )
191+ const h = Math . round ( height || 0 )
203192 if ( w ) clone . dataset . snapdomWidth = String ( w )
204193 if ( h ) clone . dataset . snapdomHeight = String ( h )
205194 } catch { }
0 commit comments