var MAX_IMAGE_WIDTH=3840;function tryParseUrl(i){try{return new URL(i)}catch(i){return null}}function optimizeCloudinaryUrl(i,r){if(!i)return i;var t=tryParseUrl(i);if(!t)return i;if(t.hostname!=="res.cloudinary.com")return i;var n=t.pathname.split("/");var o=n.indexOf("upload");if(o===-1||n[o-1]!=="image"){return i}var u=n[o+1]||"";var e=u.split(",");if(e.some((function(i){return i.startsWith("f_")||i.startsWith("q_")}))){return i}var a=[];if(r===null||r===void 0?void 0:r.width){a.push("w_"+r.width)}if(r===null||r===void 0?void 0:r.height){a.push("h_"+r.height)}if(!(r===null||r===void 0?void 0:r.width)&&!(r===null||r===void 0?void 0:r.height)){a.push("c_limit","w_"+MAX_IMAGE_WIDTH)}a.push("f_auto","q_auto");n.splice(o+1,0,a.join(","));t.pathname=n.join("/");return t.toString()}export{optimizeCloudinaryUrl as o};