import { PropertyTypes } from "../../../../core/types"; import { CollapsedDelta } from "../../../lossless"; import { ResolverPlugin } from "../plugin"; type MaxPluginState = { max?: number; }; /** * Numeric max plugin * * Tracks the maximum numeric value */ export class MaxPlugin implements ResolverPlugin { readonly name = 'max'; readonly dependencies = [] as const; initialize(): MaxPluginState { return { max: undefined }; } update( currentState: MaxPluginState, newValue: PropertyTypes, _delta: CollapsedDelta, _dependencies: Record = {} ): MaxPluginState { const numValue = typeof newValue === 'number' ? newValue : parseFloat(String(newValue)); if (!isNaN(numValue) && (currentState.max === undefined || numValue > currentState.max)) { return { max: numValue }; } return currentState; } resolve( state: MaxPluginState, _dependencies: Record = {} ): PropertyTypes | undefined { return state.max; } }