import*as StringUtilities from"./string-utilities.js";import{localize}from"./UIString.js";export const clamp=(t,i,o)=>{let r=t;return t<i?r=i:t>o&&(r=o),r};export const mod=(t,i)=>(t%i+i)%i;export const bytesToString=t=>{if(t<1e3)return StringUtilities.vsprintf(localize("%.0f\xa0B"),[t]);const i=t/1e3;if(i<100)return StringUtilities.vsprintf(localize("%.1f\xa0kB"),[i]);if(i<1e3)return StringUtilities.vsprintf(localize("%.0f\xa0kB"),[i]);const o=i/1e3;return o<100?StringUtilities.vsprintf(localize("%.1f\xa0MB"),[o]):StringUtilities.vsprintf(localize("%.0f\xa0MB"),[o])};export const toFixedIfFloating=t=>{if(!t||Number.isNaN(Number(t)))return t;const i=Number(t);return i%1?i.toFixed(3):String(i)};export const floor=(t,i=0)=>{const o=Math.pow(10,i);return Math.floor(t*o)/o};export const greatestCommonDivisor=(t,i)=>{for(t=Math.round(t),i=Math.round(i);0!==i;){const o=i;i=t%i,t=o}return t};const commonRatios=new Map([["8\u22365","16\u223610"]]);export const aspectRatio=(t,i)=>{const o=greatestCommonDivisor(t,i);0!==o&&(t/=o,i/=o);const r=`${t}\u2236${i}`;return commonRatios.get(r)||r};