import type * as defs from "./FormDefinition"; import type { FormatOptions } from "./numberFormatter"; import type { PropertyConstraints, PropertyConstraintsWithDefault } from "./utils"; /** * Configuration for cleaning up a {@link defs.NumberFormat} used in producing a {@link defs.NumberConstraints}. * * This is a bit meta. * * A `NumberConstraints` is used at runtime to ensure the value that a user entered is valid. * * The `NumberConstraints` is generated from a `NumberFormat` which may only be partially defined, or may have values that are out of range. * * We need to populate and validate the `NumberFormat` first of all before we can generate a valid `NumberConstraints`. */ export interface NumberFormatConfiguration { [key: string]: PropertyConstraints | undefined; lowerBound: PropertyConstraints; precision: PropertyConstraintsWithDefault; step: PropertyConstraintsWithDefault; upperBound: PropertyConstraints; } export declare const defaultNumberFormatConfiguration: NumberFormatConfiguration; /** * Returns constraints to be used to ensure a value is a valid number for a form element. * * Non-numeric or missing values are replaced by defaults. * * The step is sanitized as follows: * 1. If it is not a number it is set to 1. * 2. If it is <= zero it is set to 1. (The @vertigis/react-ui/Slider gets stuck on the minimum value if the step is zero.) * 2. It cannot be greater than the full range. (max-min) * @param numberFormat The formatting options to use, typically configured on a Form Element. * @param partialNumberFormatConfiguration Additional configuration specific to the caller. These are combined with the defaults. * @returns A {@link defs.NumberConstraints} containing values that can be safely used in a component. */ export declare function getNumberConstraints(numberFormat: defs.NumberFormat | undefined, partialNumberFormatConfiguration?: Partial): defs.NumberConstraints; /** * Counts the number of decimal places in the specified number and returns the result. * This uses Intl.NumberFormat rather than number.toString() to ensure that large numbers don't get converted to an exponential format. * * Despite this, it may not be accurate for very large numbers as it seems the decimal places might still be ignored. * e.g. `(10 ** 21.5) + 0.123456789 and `(10 ** 21.5)` both return "3162277660168379400000". * @param value The value to be inspected. * @returns The number of decimal places in `value`. */ export declare function countDecimalsInValue(value: number): number; /** * Determines how many decimal places should be used in presenting values to the user. * * There must be at least enough decimal places for the step size, although there could be more. * @param precision A precision value, likely from element.format.precision. * @param step The step size being used. This must be a validated step size from a NumberConstraints. * @param partialNumberFormatConfiguration Any configuration to normalize the supplied precision. * @returns The number of decimal places to be used to display values. */ export declare function sanitizePrecision(precision: number | undefined, step: number, partialNumberFormatConfiguration?: Partial): number; /** * Combines the provided configuration with the default and returns a new {@link NumberFormatConfiguration}. * @param partialConfiguration Configuration to be added with the defaults. * @returns The full set of constraints to use. */ export declare function getNumberFormatConfiguration(partialConfiguration: Partial | undefined): NumberFormatConfiguration; /** * Compares a value with some constraints and returns an adjusted value that satisfies the constraints. There are three considerations: * 1. The value must be >= `minimum`. Otherwise it is changed to `minimum`. * 2. The value must be <= `maximum`. Otherwise it is changed to `maximum`. * 3. The value must land on a valid step between the bounds. Otherwise it is moved to the nearest step. * This can only be enforced if `minimum` or `maximum` is specified. * * It is assumed that the supplied `numberConstraints` satisfy the following criteria: * * `maximum` must not be less than or equal to `minimum`. * * If `maximum` and `minimum` are both defined: * * `maximum` must be a whole number of steps greater than `minimum`. * * `step` must not be greater than `maximum - minimum`. * @param value The value to be inspected. * @param numberConstraints The constraints to be applied to the value. * @returns A new value which satisfies the constraints. */ export declare function enforceConstraints(value: number, numberConstraints: defs.NumberConstraints): number; /** * Retrieves the effective number slider values after applying various validation checks and bounds. * @param values The initial input values based on which the result is computed. * @param numberConstraints * @returns A sorted numeric array with user entered values, if valid and default values if not. */ export declare function getNumberSliderValues(values: defs.Value | undefined, numberConstraints: defs.NumberConstraints, singleValue?: boolean): number[]; /** * Checks if a form element's value is equal to the supplied value. * @param elementValue The current value of a Form Element. * @param newValue A new value for the Form Element. * @returns True if the element's current value and the new value are equal, false otherwise. */ export declare function areValuesEqual(elementValue: defs.Value | undefined, newValue: defs.NumberRef | undefined): boolean; /** * A mark on the slider. This is a copy of the interface by the same name in @mui/base/useSlider. * We use string rather than React.Node so that we can share this between runtime and designer without discrepancies between the typings. */ interface Mark { label?: string; value: number; } /** * Gets marks to be used with the @vertigis/react-ui/Slider component. * * Returning `true` is a shortcut to tell the Slider to generate its own marks based on the step size. * This is only possible when `showMinMaxLabels` is false, though, as they are also rendered as marks. * When `showMinMaxLabels` and `showTickMarks` are both true, we need to manually generate all of the marks. * @param maximum The highest allowed value. * @param minimum The lowest allowed value. * @param step: The amount of change between values. * @param formatOptions The FormatOptions for formatting text on the labels. * @param showMinMaxLabels True if labels should be included for min and max, false otherwise. * @param showTickMarks True if tick marsks should be shown, false otherwise. * @returns The value for the marks property for the slider. */ export declare function getMarks(maximum: number, minimum: number, step: number, formatOptions: FormatOptions, showMinMaxLabels: boolean, showTickMarks: boolean): boolean | Mark[]; /** * Rounds a value to the specified number of decimals in a way that should avoid rounding errors. * This is based on an example found here: * https://medium.com/swlh/how-to-round-to-a-certain-number-of-decimal-places-in-javascript-ed74c471c1b8 * @param value The value to be rounded. * @param decimalPlaces The number of decimal places to round to. * @returns An accurately rounded value. */ export declare function preciseRound(value: number, decimalPlaces: number): number; /** * Details about a symbol that is used to represent currency or percentage. */ type SymbolInfo = { /** * Whether the symbol should appear at the start (before the value) or end (after it). */ position: "start" | "end"; /** * The symbol to displayed. */ symbol: string; }; export declare function getCurrencySymbolInfo(locale: string, currency: string): SymbolInfo | undefined; export declare function getPercentSymbolInfo(locale: string): SymbolInfo | undefined; export {};