@@ -61,15 +61,21 @@ function ITerm2Image(props: ImageProps) {
6161 height : number ;
6262 } | null > ( null ) ;
6363 const shouldCleanupRef = useRef < boolean > ( true ) ;
64+ const {
65+ onSupportDetected,
66+ src,
67+ width : propsWidth ,
68+ height : propsHeight ,
69+ } = props ;
6470
6571 // Detect support and notify parent
6672 useEffect ( ( ) => {
6773 if ( ! terminalCapabilities ) return ;
6874
6975 // ITerm2 rendering requires explicit iTerm2 graphics support
7076 const isSupported = terminalCapabilities . supportsITerm2Graphics ;
71- props . onSupportDetected ?.( isSupported ) ;
72- } , [ terminalCapabilities , props . onSupportDetected ] ) ;
77+ onSupportDetected ?.( isSupported ) ;
78+ } , [ terminalCapabilities , onSupportDetected ] ) ;
7379
7480 // TODO: If we upgrade to Ink 6 we will need to deal with Box background colors when rendering/cleaning up
7581 // const inheritedBackgroundColor = useContext(backgroundContext);
@@ -85,57 +91,61 @@ function ITerm2Image(props: ImageProps) {
8591 * 5. Converts processed image data to ITerm2 format
8692 * 6. Tracks actual size in terminal cells for cleanup purposes
8793 */
88- useEffect ( ( ) => {
89- const generateImageOutput = async ( ) => {
90- if ( ! componentPosition ) return ;
91- if ( ! terminalDimensions ) return ;
94+ useEffect (
95+ ( ) => {
96+ const generateImageOutput = async ( ) => {
97+ if ( ! componentPosition ) return ;
98+ if ( ! terminalDimensions ) return ;
9299
93- const image = await fetchImage ( props . src ) ;
94- if ( ! image ) {
95- setHasError ( true ) ;
96- return ;
97- }
98- setHasError ( false ) ;
100+ const image = await fetchImage ( src ) ;
101+ if ( ! image ) {
102+ setHasError ( true ) ;
103+ return ;
104+ }
105+ setHasError ( false ) ;
99106
100- const metadata = await image . metadata ( ) ;
107+ const metadata = await image . metadata ( ) ;
101108
102- const { width : maxWidth , height : maxHeight } = componentPosition ;
103- const { width, height } = calculateImageSize ( {
104- maxWidth : maxWidth * terminalDimensions . cellWidth ,
105- maxHeight : maxHeight * terminalDimensions . cellHeight ,
106- originalAspectRatio : metadata . width / metadata . height ,
107- specifiedWidth : props . width
108- ? props . width * terminalDimensions . cellWidth
109- : undefined ,
110- specifiedHeight : props . height
111- ? props . height * terminalDimensions . cellHeight
112- : undefined ,
113- } ) ;
109+ const { width : maxWidth , height : maxHeight } = componentPosition ;
110+ const { width, height } = calculateImageSize ( {
111+ maxWidth : maxWidth * terminalDimensions . cellWidth ,
112+ maxHeight : maxHeight * terminalDimensions . cellHeight ,
113+ originalAspectRatio : metadata . width / metadata . height ,
114+ specifiedWidth : propsWidth
115+ ? propsWidth * terminalDimensions . cellWidth
116+ : undefined ,
117+ specifiedHeight : propsHeight
118+ ? propsHeight * terminalDimensions . cellHeight
119+ : undefined ,
120+ } ) ;
114121
115- const resizedImage = await image
116- . png ( ) // iTerm2 expects a FILE, not raw pixel data
117- . toBuffer ( { resolveWithObject : true } ) ;
118- setActualSizeInCells ( {
119- width : Math . ceil (
120- resizedImage . info . width / terminalDimensions . cellWidth ,
121- ) ,
122- height : Math . ceil (
123- resizedImage . info . height / terminalDimensions . cellHeight ,
124- ) ,
125- } ) ;
122+ const resizedImage = await image
123+ . png ( ) // iTerm2 expects a FILE, not raw pixel data
124+ . toBuffer ( { resolveWithObject : true } ) ;
125+ setActualSizeInCells ( {
126+ width : Math . ceil (
127+ resizedImage . info . width / terminalDimensions . cellWidth ,
128+ ) ,
129+ height : Math . ceil (
130+ resizedImage . info . height / terminalDimensions . cellHeight ,
131+ ) ,
132+ } ) ;
126133
127- const output = toITerm2 ( resizedImage , { width, height } ) ;
128- setImageOutput ( output ) ;
129- } ;
130- generateImageOutput ( ) ;
131- } , [
132- props . src ,
133- props . width ,
134- props . height ,
135- componentPosition ?. width ,
136- componentPosition ?. height ,
137- terminalDimensions ,
138- ] ) ;
134+ const output = toITerm2 ( resizedImage , { width, height } ) ;
135+ setImageOutput ( output ) ;
136+ } ;
137+ generateImageOutput ( ) ;
138+ } ,
139+ // eslint-disable-next-line react-hooks/exhaustive-deps
140+ [
141+ src ,
142+ propsWidth ,
143+ propsHeight ,
144+ componentPosition ?. width ,
145+ componentPosition ?. height ,
146+ terminalDimensions ,
147+ ] ,
148+ ) ;
139149
140150 /**
141151 * Critical rendering effect for ITerm2 image display.
0 commit comments