@@ -29,6 +29,7 @@ import {
2929 patchElementInHtml ,
3030 probeElementInSource ,
3131 splitElementInHtml ,
32+ isHTMLElement ,
3233 type PatchOperation ,
3334} from "../helpers/sourceMutation.js" ;
3435import { parseHTML } from "linkedom" ;
@@ -265,7 +266,8 @@ function stripStudioEditsFromTarget(document: Document, selector: string): numbe
265266 try {
266267 for ( const el of document . querySelectorAll ( selector ) ) {
267268 if ( ! el . getAttribute ( "data-hf-studio-path-offset" ) ) continue ;
268- const htmlEl = el as unknown as HTMLElement ;
269+ if ( ! isHTMLElement ( el ) ) continue ;
270+ const htmlEl = el ;
269271 const originalTranslate = el . getAttribute ( "data-hf-studio-original-inline-translate" ) ;
270272 htmlEl . style . removeProperty ( "--hf-studio-offset-x" ) ;
271273 htmlEl . style . removeProperty ( "--hf-studio-offset-y" ) ;
@@ -285,33 +287,29 @@ function stripStudioEditsFromTarget(document: Document, selector: string): numbe
285287 return stripped ;
286288}
287289
288- function bakeVisibilityOnDelete ( document : Document , anim : GsapAnimation ) : void {
289- let finalOpacity : number | string | undefined ;
290- if ( anim . method === "from" ) {
291- return ;
292- }
293- if ( anim . keyframes ) {
294- const kfs = anim . keyframes . keyframes ;
295- for ( let i = kfs . length - 1 ; i >= 0 ; i -- ) {
296- if ( "opacity" in kfs [ i ] ! . properties ) {
297- finalOpacity = kfs [ i ] ! . properties . opacity ;
298- break ;
299- }
300- }
301- } else if ( "opacity" in anim . properties ) {
302- finalOpacity = anim . properties . opacity ;
303- }
304- if ( finalOpacity == null ) {
305- return ;
306- }
307- if ( typeof finalOpacity === "string" && / ^ [ + \- * ] = / . test ( finalOpacity ) ) {
308- return ;
290+ function lastKeyframeOpacity ( kfs : GsapAnimation [ "keyframes" ] ) : number | string | undefined {
291+ if ( ! kfs ) return undefined ;
292+ for ( let i = kfs . keyframes . length - 1 ; i >= 0 ; i -- ) {
293+ if ( "opacity" in kfs . keyframes [ i ] ! . properties ) return kfs . keyframes [ i ] ! . properties . opacity ;
309294 }
310- const numOpacity = Number ( finalOpacity ) ;
311- if ( ! Number . isFinite ( numOpacity ) || numOpacity === 0 ) return ;
295+ return undefined ;
296+ }
297+
298+ function resolveFinalOpacity ( anim : GsapAnimation ) : number | null {
299+ if ( anim . method === "from" ) return null ;
300+ const raw = anim . keyframes ? lastKeyframeOpacity ( anim . keyframes ) : anim . properties . opacity ;
301+ if ( raw == null ) return null ;
302+ if ( typeof raw === "string" && / ^ [ + \- * ] = / . test ( raw ) ) return null ;
303+ const num = Number ( raw ) ;
304+ return Number . isFinite ( num ) && num !== 0 ? num : null ;
305+ }
306+
307+ function bakeVisibilityOnDelete ( document : Document , anim : GsapAnimation ) : void {
308+ const opacity = resolveFinalOpacity ( anim ) ;
309+ if ( opacity === null ) return ;
312310 try {
313311 for ( const el of document . querySelectorAll ( anim . targetSelector ) ) {
314- ( el as unknown as HTMLElement ) . style . setProperty ( "opacity" , String ( numOpacity ) ) ;
312+ if ( isHTMLElement ( el ) ) el . style . setProperty ( "opacity" , String ( opacity ) ) ;
315313 }
316314 } catch {
317315 // Invalid selector — skip silently.
@@ -780,8 +778,9 @@ async function processUploadedFiles(
780778 const ext = dotIdx > 0 ? name . slice ( dotIdx ) : "" ;
781779 const base = dotIdx > 0 ? name . slice ( 0 , dotIdx ) : name ;
782780 let n = 2 ;
783- while ( n < 10000 && existsSync ( resolve ( targetDir , `${ base } (${ n } )${ ext } ` ) ) ) n ++ ;
784- if ( n >= 10000 ) {
781+ const MAX_COPY_INDEX = 10000 ;
782+ while ( n < MAX_COPY_INDEX && existsSync ( resolve ( targetDir , `${ base } (${ n } )${ ext } ` ) ) ) n ++ ;
783+ if ( n >= MAX_COPY_INDEX ) {
785784 skipped . push ( name ) ;
786785 continue ;
787786 }
0 commit comments