{"version":3,"names":["clamp","value","min","max","Math","decimalNumberRegex","RegExp","decimalPlaces","match","parseInt","length","getDecimals","parseFloat","toString","split","remap","fromMin","fromMax","toMin","toMax","closeToRangeEdge","range","threshold"],"sources":["src/utils/math.ts"],"sourcesContent":["export const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(value, max));\n\nconst decimalNumberRegex = new RegExp(/(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/);\n\n/**\n * Returns the quantity of real decimal places for a number, which excludes trailing zeros.\n *\n * Adapted from {@link https://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number}.\n *\n * @param decimal - decimal value\n * @param value\n * @returns {number} the amount of decimal places in a number\n */\nexport const decimalPlaces = (value: number | string): number => {\n const match = (\"\" + value).match(decimalNumberRegex);\n if (!match || parseInt(match[1]) === 0) {\n return 0;\n }\n return Math.max(\n 0,\n // Number of digits right of decimal point.\n (match[1] ? match[1].length : 0) -\n // Adjust for scientific notation.\n (match[2] ? +match[2] : 0),\n );\n};\n\nexport function getDecimals(value: number): number {\n if (decimalPlaces(value) > 0 && value > 0) {\n return parseFloat(`0.${value.toString().split(\".\")[1]}`);\n }\n return value;\n}\n\nexport function remap(value: number, fromMin: number, fromMax: number, toMin: number, toMax: number): number {\n return ((value - fromMin) * (toMax - toMin)) / (fromMax - fromMin) + toMin;\n}\n\n/**\n * Helper to determine if a value is close to the edge of a range within a threshold.\n *\n * @param value\n * @param range\n * @param threshold\n * @returns -1 if close to lower edge, 1 if close to upper edge, 0 otherwise.\n */\nexport function closeToRangeEdge(value: number, range: number, threshold: number): number {\n return value < threshold ? -1 : value > range - threshold ? 1 : 0;\n}\n"],"mappings":";;;;;MAAaA,EAAQ,CAACC,EAAeC,EAAaC,IAAwBC,KAAKD,IAAID,EAAKE,KAAKF,IAAID,EAAOE,IAExG,MAAME,EAAqB,IAAIC,OAAO,oC,MAWzBC,EAAiBN,IAC5B,MAAMO,GAAS,GAAKP,GAAOO,MAAMH,GACjC,IAAKG,GAASC,SAASD,EAAM,MAAQ,EAAG,CACtC,OAAO,C,CAET,OAAOJ,KAAKD,IACV,GAECK,EAAM,GAAKA,EAAM,GAAGE,OAAS,IAE3BF,EAAM,IAAMA,EAAM,GAAK,GAC3B,E,SAGaG,EAAYV,GAC1B,GAAIM,EAAcN,GAAS,GAAKA,EAAQ,EAAG,CACzC,OAAOW,WAAW,KAAKX,EAAMY,WAAWC,MAAM,KAAK,K,CAErD,OAAOb,CACT,C,SAEgBc,EAAMd,EAAee,EAAiBC,EAAiBC,EAAeC,GACpF,OAASlB,EAAQe,IAAYG,EAAQD,IAAWD,EAAUD,GAAWE,CACvE,C,SAUgBE,EAAiBnB,EAAeoB,EAAeC,GAC7D,OAAOrB,EAAQqB,GAAa,EAAIrB,EAAQoB,EAAQC,EAAY,EAAI,CAClE,Q","ignoreList":[]}