@@ -14,11 +14,22 @@ const loadImage = async (pathOrUrl) => new Promise((resolve) => fabric.util.load
1414
1515function getZoomParams ( { progress, zoomDirection, zoomAmount } ) {
1616 let scaleFactor = 1 ;
17+ if ( zoomDirection === 'left' || zoomDirection === 'right' ) return 1.3 ;
1718 if ( zoomDirection === 'in' ) scaleFactor = ( 1 + zoomAmount * progress ) ;
1819 else if ( zoomDirection === 'out' ) scaleFactor = ( 1 + zoomAmount * ( 1 - progress ) ) ;
1920 return scaleFactor ;
2021}
2122
23+ function getTranslationParams ( { progress, zoomDirection, zoomAmount } ) {
24+ let translation = 0 ;
25+ const range = zoomAmount * 1000 ;
26+
27+ if ( zoomDirection === 'right' ) translation = ( progress ) * range - range / 2 ;
28+ else if ( zoomDirection === 'left' ) translation = ( 100 - progress * 100 ) * range - range / 2 ;
29+
30+ return translation ;
31+ }
32+
2233export async function imageFrameSource ( { verbose, params, width, height } ) {
2334 const { path, zoomDirection = 'in' , zoomAmount = 0.1 , resizeMode = 'contain-blur' } = params ;
2435
@@ -46,10 +57,13 @@ export async function imageFrameSource({ verbose, params, width, height }) {
4657 const img = createImg ( ) ;
4758
4859 const scaleFactor = getZoomParams ( { progress, zoomDirection, zoomAmount } ) ;
60+ const translationParams = getTranslationParams ( { progress, zoomDirection, zoomAmount } ) ;
4961
5062 const ratioW = width / img . width ;
5163 const ratioH = height / img . height ;
5264
65+ img . left = width / 2 + translationParams ;
66+
5367 if ( [ 'contain' , 'contain-blur' ] . includes ( resizeMode ) ) {
5468 if ( ratioW > ratioH ) {
5569 img . scaleToHeight ( height * scaleFactor ) ;
@@ -230,6 +244,9 @@ export async function imageOverlayFrameSource({ params, width, height }) {
230244 async function onRender ( progress , canvas ) {
231245 const scaleFactor = getZoomParams ( { progress, zoomDirection, zoomAmount } ) ;
232246
247+ const translationParams = getTranslationParams ( { progress, zoomDirection, zoomAmount } ) ;
248+ img . left = width / 2 + translationParams ;
249+
233250 if ( relWidth != null ) {
234251 img . scaleToWidth ( relWidth * width * scaleFactor ) ;
235252 } else if ( relHeight != null ) {
@@ -257,6 +274,8 @@ export async function titleFrameSource({ width, height, params }) {
257274
258275 const scaleFactor = getZoomParams ( { progress, zoomDirection, zoomAmount } ) ;
259276
277+ const translationParams = getTranslationParams ( { progress, zoomDirection, zoomAmount } ) ;
278+
260279 const textBox = new fabric . Textbox ( text , {
261280 fill : textColor ,
262281 fontFamily,
@@ -273,7 +292,7 @@ export async function titleFrameSource({ width, height, params }) {
273292 textImage . set ( {
274293 originX,
275294 originY,
276- left,
295+ left : left + translationParams ,
277296 top,
278297 scaleX : scaleFactor ,
279298 scaleY : scaleFactor ,
0 commit comments