import type { Opts, RoArray, RoNeTuple, RoPair, Brand } from "@xlabs-xyz/const-utils"; import { Rational, Rationalish } from "./rational.js"; export type SymbolSpec = Readonly<{ symbol: string; plural?: string; position?: "postfix" | "prefix"; spacing?: "spaced" | "compact"; }>; export type DecimalSpec = { readonly oom: N; readonly scale?: never; }; export type ScaleSpec = { readonly oom?: never; readonly scale: N; }; export type Unit = SymbolSpec & { readonly scale: Rational; readonly oom?: number; }; export type SystemInfo = { name: N; symbols: U; decimal: D; }; export type StandardInfo = { system: SY; unit: SU; }; export type ValidStandardInfo = Y extends SystemInfo ? StandardInfo : never; export type Kind = ValidStandardInfo, H extends U | undefined = U | undefined, A extends U | undefined = U | undefined> = Readonly<{ name: N; units: KindUnits; standard: S; systems: KindSystems; } & ([ U | undefined ] extends [H] ? { human?: U; } : [H] extends [U] ? { human: H; } : unknown) & ([ U | undefined ] extends [A] ? { atomic?: U; } : [A] extends [U] ? { atomic: A; } : unknown)>; export type KindWithHuman = ValidStandardInfo, H extends U = U, A extends U | undefined = U | undefined> = Kind; export type KindWithAtomic = ValidStandardInfo, H extends U | undefined = U | undefined, A extends U = U> = Kind; export type KindWithHumanAndAtomic = ValidStandardInfo, H extends U = U, A extends U = U> = Kind; export type DecimalKind = ValidStandardInfo, H extends U = U, A extends U = U> = Brand, "decimalHuman" | "decimalAtomic">; export type SymbolsOf = Extract | "standard" | (K["human"] extends string ? "human" : never) | (K["atomic"] extends string ? "atomic" : never); export type DecimalSymbolsOf = DecimalUnitSymbols | DecimalMetaSymbolOf; export type GetUnitSymbol> = M extends "standard" ? K["standard"]["unit"] : M extends "human" ? K["human"] : M extends "atomic" ? K["atomic"] : M; export declare function sameKind(a: Kind, b: Kind): boolean; export declare function getUnit>(kind: K, unitSymbol: S): Unit; export declare function getDecimals(kind: K, ...args: K extends DecimalKind ? [opts?: GetDecimalsOpts] : [opts: GetDecimalsOpts]): number; type MetaBrandTags = [ H, "human" ] | [A, "atomic"] | [S, "standard"] extends infer M ? M extends [DecimalSymbolsOfSystem>, SystemInfoOf>, MetaSymbols] ? `decimal${Capitalize}` : "" : never; export declare function kind(name: N, unitsInput: I, opts?: Opts<{ human: H & UnitSymbolsOf>; atomic: A & UnitSymbolsOf>; }>): Brand>, N, SystemInfoOf, StandardInfoOf, H & UnitSymbolsOf> extends never ? undefined : H & UnitSymbolsOf>, A & UnitSymbolsOf> extends never ? undefined : A & UnitSymbolsOf>>, MetaBrandTags["unit"], I>>; export declare const powerOfTen: (oom: number) => Rational; export declare function identifyKind(kinds: RoArray, str: string, allowAmbiguous?: A): A extends true ? K[] : K | undefined; type UnitBaseSpec = { readonly symbols: RoNeTuple; }; type UnitSpec = UnitBaseSpec & (F extends true ? D extends true ? Partial> : Partial> : D extends true ? DecimalSpec : ScaleSpec); type KindUnitsSpec = D extends any ? F extends true ? readonly [UnitSpec, ...UnitSpec[]] : RoNeTuple> : never; type KindUnits = { readonly [K in U]?: Unit; }; type KindSystems = { readonly [Sys in Y as Sys["name"]]: Readonly<{ symbols: RoArray; decimal: Sys["decimal"]; }>; }; type UnitSymbolsOf> = U[number]["symbols"][number] extends infer S ? S extends SymbolSpec ? S["symbol"] | Extract : never : never; type SystemEntry = KindUnitsSpec> = RoPair; type SystemsSpec = readonly [SystemEntry, ...SystemEntry[]]; type KindUnitsInput = KindUnitsSpec | SystemsSpec; type IsSystemDecimal> = Spec[0] extends DecimalSpec ? true : Spec[0] extends ScaleSpec ? false : Spec extends readonly [unknown] | readonly [unknown, DecimalSpec, ...unknown[]] ? true : false; type SystemInfoOf = I extends SystemsSpec ? { [K in keyof I & `${number}`]: I[K] extends SystemEntry ? SystemInfo, IsSystemDecimal> : never; }[keyof I & `${number}`] : I extends KindUnitsSpec ? SystemInfo<"default", UnitSymbolsOf, IsSystemDecimal> : never; type UnitsSpecOf = I extends SystemsSpec ? I[number][1] : I; type StandardSystemOf = I extends SystemsSpec ? I[0][0] : "default"; type StandardUnitOf = I extends SystemsSpec ? I[0][1][0]["symbols"][0]["symbol"] : I extends KindUnitsSpec ? I[0]["symbols"][0]["symbol"] : never; type StandardInfoOf = StandardInfo, StandardUnitOf> extends infer S extends ValidStandardInfo> ? S : never; type MetaSymbols = "standard" | "human" | "atomic"; type DecimalMetaSymbolOf = M extends MetaSymbols ? K extends Brand}`> ? M : never : never; type DecimalSymbolsOfSystem = Y extends { symbols: infer Syms extends U; decimal: true; } ? Syms : never; type DecimalUnitSymbols = K extends Kind ? DecimalSymbolsOfSystem : never; type GetDecimalsOptsImpl = DecimalSymbolsOf extends infer D ? ((M extends "human" ? "of" : "in") extends infer P extends string ? { [_ in P]: D; } : never) extends infer R ? M extends D ? Opts : R : never : never; type GetDecimalsOpts = GetDecimalsOptsImpl & GetDecimalsOptsImpl; export {}; //# sourceMappingURL=kind.d.ts.map