@@ -17,7 +17,7 @@ import {getAnalyticsOptions} from "../utils/analytics";
1717 * @example <caption>NOTE: The following is in React. For further examples, see the Packages tab.</caption>
1818 * <AdvancedImage cldImg={img} plugins={[responsive({steps: [800, 1000, 1400]})]} />
1919 */
20- export function responsive ( { steps} : { steps ?: number | number [ ] } = { } ) : Plugin {
20+ export function responsive ( { steps} :{ steps ?: number | number [ ] } = { } ) : Plugin {
2121 return responsivePlugin . bind ( null , steps ) ;
2222}
2323
@@ -29,14 +29,14 @@ export function responsive({steps}: { steps?: number | number[] } = {}): Plugin
2929 * @param htmlPluginState {HtmlPluginState} holds cleanup callbacks and event subscriptions
3030 * @param analyticsOptions {AnalyticsOptions} analytics options for the url to be created
3131 */
32- function responsivePlugin ( steps ?: number | number [ ] , element ?: HTMLImageElement , responsiveImage ?: CloudinaryImage , htmlPluginState ?: HtmlPluginState , analyticsOptions ?: AnalyticsOptions ) : Promise < void | string > | boolean {
32+ function responsivePlugin ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage , htmlPluginState ?: HtmlPluginState , analyticsOptions ?: AnalyticsOptions ) : Promise < void | string > | boolean {
3333
34- if ( ! isBrowser ( ) ) return true ;
34+ if ( ! isBrowser ( ) ) return true ;
3535
36- if ( ! isImage ( element ) ) return ;
36+ if ( ! isImage ( element ) ) return ;
3737
38- return new Promise ( ( resolve ) => {
39- htmlPluginState . cleanupCallbacks . push ( ( ) => {
38+ return new Promise ( ( resolve ) => {
39+ htmlPluginState . cleanupCallbacks . push ( ( ) => {
4040 window . removeEventListener ( "resize" , resizeRef ) ;
4141 resolve ( 'canceled' ) ;
4242 } ) ;
@@ -47,8 +47,8 @@ function responsivePlugin(steps?: number | number[], element?: HTMLImageElement,
4747 onResize ( steps , element , responsiveImage , analyticsOptions ) ;
4848
4949 let resizeRef : any ;
50- htmlPluginState . pluginEventSubscription . push ( ( ) => {
51- window . addEventListener ( 'resize' , resizeRef = debounce ( ( ) => {
50+ htmlPluginState . pluginEventSubscription . push ( ( ) => {
51+ window . addEventListener ( 'resize' , resizeRef = debounce ( ( ) => {
5252 onResize ( steps , element , responsiveImage , analyticsOptions ) ;
5353 } , 100 ) ) ;
5454 } ) ;
@@ -64,7 +64,7 @@ function responsivePlugin(steps?: number | number[], element?: HTMLImageElement,
6464 * @param responsiveImage {CloudinaryImage}
6565 * @param analyticsOptions {AnalyticsOptions} analytics options for the url to be created
6666 */
67- function onResize ( steps ?: number | number [ ] , element ?: HTMLImageElement , responsiveImage ?: CloudinaryImage , analyticsOptions ?: AnalyticsOptions ) {
67+ function onResize ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage , analyticsOptions ?: AnalyticsOptions ) {
6868 updateByContainerWidth ( steps , element , responsiveImage ) ;
6969 element . src = responsiveImage . toURL ( getAnalyticsOptions ( analyticsOptions ) ) ;
7070}
@@ -76,24 +76,24 @@ function onResize(steps?: number | number[], element?: HTMLImageElement, respons
7676 * @param element {HTMLImageElement} The image element
7777 * @param responsiveImage {CloudinaryImage}
7878 */
79- function updateByContainerWidth ( steps ?: number | number [ ] , element ?: HTMLImageElement , responsiveImage ?: CloudinaryImage ) {
79+ function updateByContainerWidth ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage ) {
8080 // Default value for responsiveImgWidth, used when no steps are passed.
8181 let responsiveImgWidth = element . parentElement . clientWidth ;
8282
83- if ( isNum ( steps ) ) {
83+ if ( isNum ( steps ) ) {
8484 const WIDTH_INTERVALS = steps as number ;
8585 // We need to force the container width to be intervals of max width.
86- responsiveImgWidth = Math . ceil ( responsiveImgWidth / WIDTH_INTERVALS ) * WIDTH_INTERVALS ;
86+ responsiveImgWidth = Math . ceil ( responsiveImgWidth / WIDTH_INTERVALS ) * WIDTH_INTERVALS ;
8787
88- } else if ( Array . isArray ( steps ) ) {
89- responsiveImgWidth = steps . reduce ( ( prev , curr ) => {
88+ } else if ( Array . isArray ( steps ) ) {
89+ responsiveImgWidth = steps . reduce ( ( prev , curr ) => {
9090 return ( Math . abs ( curr - responsiveImgWidth ) < Math . abs ( prev - responsiveImgWidth ) ? curr : prev ) ;
9191 } ) ;
9292 }
9393
9494 responsiveImage . transformation . actions . forEach ( ( action , index ) => {
9595 if ( action instanceof Action && action . getActionTag ( ) === 'responsive' ) {
96- responsiveImage . transformation . actions [ index ] = scale ( responsiveImgWidth ) . setActionTag ( 'responsive' ) ;
96+ responsiveImage . transformation . actions [ index ] = scale ( responsiveImgWidth ) . setActionTag ( 'responsive' ) ;
9797 }
9898 } ) ;
9999}
0 commit comments