11import { CloudinaryImage } from "@cloudinary/url-gen/assets/CloudinaryImage" ;
2- import { Plugin , HtmlPluginState } from "../types.js" ;
2+ import { Plugin , HtmlPluginState , AnalyticsOptions } from "../types.js" ;
33import { scale } from "@cloudinary/url-gen/actions/resize" ;
44import debounce from 'lodash.debounce' ;
55import { isNum } from '../utils/isNum.js' ;
66import { isBrowser } from "../utils/isBrowser.js" ;
77import { Action } from "@cloudinary/url-gen/internal/Action" ;
88import { isImage } from "../utils/isImage.js" ;
9+ import { getAnalyticsOptions } from '../utils/analytics'
910
1011/**
1112 * @namespace
@@ -26,8 +27,9 @@ export function responsive({steps}:{steps?: number | number[]}={}): Plugin{
2627 * @param element {HTMLImageElement} The image element
2728 * @param responsiveImage {CloudinaryImage}
2829 * @param htmlPluginState {HtmlPluginState} holds cleanup callbacks and event subscriptions
30+ * @param analyticsOptions {AnalyticsOptions} analytics options for the url to be created
2931 */
30- function responsivePlugin ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage , htmlPluginState ?: HtmlPluginState ) : Promise < void | string > | boolean {
32+ function responsivePlugin ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage , htmlPluginState ?: HtmlPluginState , analyticsOptions ?: AnalyticsOptions ) : Promise < void | string > | boolean {
3133
3234 if ( ! isBrowser ( ) ) return true ;
3335
@@ -42,12 +44,12 @@ function responsivePlugin(steps?: number | number[], element?:HTMLImageElement,
4244 // Use a tagged generic action that can be later searched and replaced.
4345 responsiveImage . addAction ( new Action ( ) . setActionTag ( 'responsive' ) ) ;
4446 // Immediately run the resize plugin, ensuring that first render gets a responsive image.
45- onResize ( steps , element , responsiveImage ) ;
47+ onResize ( steps , element , responsiveImage , analyticsOptions ) ;
4648
4749 let resizeRef : any ;
4850 htmlPluginState . pluginEventSubscription . push ( ( ) => {
4951 window . addEventListener ( 'resize' , resizeRef = debounce ( ( ) => {
50- onResize ( steps , element , responsiveImage ) ;
52+ onResize ( steps , element , responsiveImage , analyticsOptions ) ;
5153 } , 100 ) ) ;
5254 } ) ;
5355 resolve ( ) ;
@@ -60,10 +62,11 @@ function responsivePlugin(steps?: number | number[], element?:HTMLImageElement,
6062 * | number[] A set of image sizes in pixels.
6163 * @param element {HTMLImageElement} The image element
6264 * @param responsiveImage {CloudinaryImage}
65+ * @param analyticsOptions {AnalyticsOptions} analytics options for the url to be created
6366 */
64- function onResize ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage ) {
67+ function onResize ( steps ?: number | number [ ] , element ?:HTMLImageElement , responsiveImage ?: CloudinaryImage , analyticsOptions ?: AnalyticsOptions ) {
6568 updateByContainerWidth ( steps , element , responsiveImage ) ;
66- element . src = responsiveImage . toURL ( ) ;
69+ element . src = responsiveImage . toURL ( getAnalyticsOptions ( analyticsOptions ) ) ;
6770}
6871
6972/**
0 commit comments