{"version":3,"names":["getDecimalPrecision","num","Math","abs","parts","toExponential","split","mantissaDecimalPart","length","Number","parseInt","decimalPart","toString","roundValueToStep","value","step","min","nearest","round","toFixed","max"],"sources":["round-value-to-step.ts"],"sourcesContent":["/**\n * Returns the number of digits after the decimal point. Handles both the\n * normal decimal notation (`\"0.25\"`) and the exponential notation that JS\n * produces for very small magnitudes (`\"1e-8\"`).\n */\nexport function getDecimalPrecision(num: number): number {\n\tif (num === 0) {\n\t\treturn 0;\n\t}\n\n\t// Very small numbers (|num| < 1) get serialized as \"1e-8\", not \"0.00000001\".\n\tif (Math.abs(num) < 1) {\n\t\tconst parts = num.toExponential().split(\"e-\");\n\t\t// biome-ignore lint/style/noNonNullAssertion: `toExponential` always yields a mantissa\n\t\tconst mantissaDecimalPart = parts[0]!.split(\".\")[1];\n\t\treturn (\n\t\t\t(mantissaDecimalPart ? mantissaDecimalPart.length : 0) +\n\t\t\t// biome-ignore lint/style/noNonNullAssertion: exponential form always has an exponent after \"e-\"\n\t\t\tNumber.parseInt(parts[1]!, 10)\n\t\t);\n\t}\n\n\tconst decimalPart = num.toString().split(\".\")[1];\n\treturn decimalPart ? decimalPart.length : 0;\n}\n\n/**\n * Rounds `value` to the nearest multiple of `step`, offset by `min` — so the\n * quantization grid is always anchored on `min`, not on `0`. The result is\n * then re-quantized via `toFixed(precision)` to trim binary-float drift.\n */\nexport function roundValueToStep(\n\tvalue: number,\n\tstep: number,\n\tmin: number,\n): number {\n\tconst nearest = Math.round((value - min) / step) * step + min;\n\treturn Number(\n\t\tnearest.toFixed(\n\t\t\tMath.max(getDecimalPrecision(step), getDecimalPrecision(min)),\n\t\t),\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAmBA,CAACC,GAAW,EAAU;EACxD,IAAIA,GAAG,KAAK,CAAC,EAAE;IACd,OAAO,CAAC;EACT;;EAEA;EACA,IAAIC,IAAI,CAACC,GAAG,CAACF,GAAG,CAAC,GAAG,CAAC,EAAE;IACtB,MAAMG,KAAK,GAAGH,GAAG,CAACI,aAAa,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAAC;IAC7C;IACA,MAAMC,mBAAmB,GAAGH,KAAK,CAAC,CAAC,CAAC,CAAEE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnD,OACC,CAACC,mBAAmB,GAAGA,mBAAmB,CAACC,MAAM,GAAG,CAAC;IACrD;IACAC,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,EAAG,EAAE,CAAC;EAEhC;EAEA,MAAMO,WAAW,GAAGV,GAAG,CAACW,QAAQ,CAAC,CAAC,CAACN,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EAChD,OAAOK,WAAW,GAAGA,WAAW,CAACH,MAAM,GAAG,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,gBAAgBA,CAC/BC,KAAa,EACbC,IAAY,EACZC,GAAW,EACF;EACT,MAAMC,OAAO,GAAGf,IAAI,CAACgB,KAAK,CAAC,CAACJ,KAAK,GAAGE,GAAG,IAAID,IAAI,CAAC,GAAGA,IAAI,GAAGC,GAAG;EAC7D,OAAOP,MAAM,CACZQ,OAAO,CAACE,OAAO,CACdjB,IAAI,CAACkB,GAAG,CAACpB,mBAAmB,CAACe,IAAI,CAAC,EAAEf,mBAAmB,CAACgB,GAAG,CAAC,CAC7D,CACD,CAAC;AACF","ignoreList":[]}