UNPKG

6.06 kBTypeScriptView Raw
1interface CssClasses {
2 target: string;
3 base: string;
4 origin: string;
5 handle: string;
6 handleLower: string;
7 handleUpper: string;
8 touchArea: string;
9 horizontal: string;
10 vertical: string;
11 background: string;
12 connect: string;
13 connects: string;
14 ltr: string;
15 rtl: string;
16 textDirectionLtr: string;
17 textDirectionRtl: string;
18 draggable: string;
19 drag: string;
20 tap: string;
21 active: string;
22 tooltip: string;
23 pips: string;
24 pipsHorizontal: string;
25 pipsVertical: string;
26 marker: string;
27 markerHorizontal: string;
28 markerVertical: string;
29 markerNormal: string;
30 markerLarge: string;
31 markerSub: string;
32 value: string;
33 valueHorizontal: string;
34 valueVertical: string;
35 valueNormal: string;
36 valueLarge: string;
37 valueSub: string;
38}
39export interface PartialFormatter {
40 to: (value: number) => string | number;
41 from?: (value: string) => number | false;
42}
43export interface Formatter extends PartialFormatter {
44 from: (value: string) => number | false;
45}
46export declare enum PipsMode {
47 Range = "range",
48 Steps = "steps",
49 Positions = "positions",
50 Count = "count",
51 Values = "values"
52}
53export declare enum PipsType {
54 None = -1,
55 NoValue = 0,
56 LargeValue = 1,
57 SmallValue = 2
58}
59declare type WrappedSubRange = [number] | [number, number];
60declare type SubRange = number | WrappedSubRange;
61interface Range {
62 min: SubRange;
63 max: SubRange;
64 [key: `${number}%`]: SubRange;
65}
66interface BasePips {
67 mode: PipsMode;
68 density?: number;
69 filter?: PipsFilter;
70 format?: PartialFormatter;
71}
72interface PositionsPips extends BasePips {
73 mode: PipsMode.Positions;
74 values: number[];
75 stepped?: boolean;
76}
77interface ValuesPips extends BasePips {
78 mode: PipsMode.Values;
79 values: number[];
80 stepped?: boolean;
81}
82interface CountPips extends BasePips {
83 mode: PipsMode.Count;
84 values: number;
85 stepped?: boolean;
86}
87interface StepsPips extends BasePips {
88 mode: PipsMode.Steps;
89}
90interface RangePips extends BasePips {
91 mode: PipsMode.Range;
92}
93declare type Pips = PositionsPips | ValuesPips | CountPips | StepsPips | RangePips;
94declare type ValueArgument = number | string | null;
95declare type StartValues = ValueArgument | ValueArgument[];
96declare type HandleAttributes = {
97 [key: string]: string;
98};
99interface UpdatableOptions {
100 range?: Range;
101 start?: StartValues;
102 margin?: number;
103 limit?: number;
104 padding?: number | number[];
105 snap?: boolean;
106 step?: number;
107 pips?: Pips;
108 format?: Formatter;
109 tooltips?: boolean | PartialFormatter | (boolean | PartialFormatter)[];
110 animate?: boolean;
111 connect?: "lower" | "upper" | boolean | boolean[];
112}
113export interface Options extends UpdatableOptions {
114 range: Range;
115 orientation?: "vertical" | "horizontal";
116 direction?: "ltr" | "rtl";
117 behaviour?: string;
118 keyboardSupport?: boolean;
119 keyboardPageMultiplier?: number;
120 keyboardMultiplier?: number;
121 keyboardDefaultStep?: number;
122 documentElement?: HTMLElement;
123 cssPrefix?: string;
124 cssClasses?: CssClasses;
125 ariaFormat?: PartialFormatter;
126 animationDuration?: number;
127 handleAttributes?: HandleAttributes[];
128}
129export interface API {
130 destroy: () => void;
131 steps: () => NextStepsForHandle[];
132 on: (eventName: string, callback: EventCallback) => void;
133 off: (eventName: string) => void;
134 get: (unencoded?: boolean) => GetResult;
135 set: (input: ValueArgument | ValueArgument[], fireSetEvent?: boolean, exactInput?: boolean) => void;
136 setHandle: (handleNumber: number, value: ValueArgument, fireSetEvent?: boolean, exactInput?: boolean) => void;
137 reset: (fireSetEvent?: boolean) => void;
138 disable: (handleNumber?: number) => void;
139 enable: (handleNumber?: number) => void;
140 options: Options;
141 updateOptions: (optionsToUpdate: UpdatableOptions, fireSetEvent: boolean) => void;
142 target: HTMLElement;
143 removePips: () => void;
144 removeTooltips: () => void;
145 getPositions: () => number[];
146 getTooltips: () => (HTMLElement | false)[] | null;
147 getOrigins: () => HTMLElement[];
148 pips: (grid: Pips) => HTMLElement;
149}
150interface TargetElement extends HTMLElement {
151 noUiSlider?: API;
152}
153interface NearByStep {
154 startValue: number;
155 step: number | false;
156 highestStep: number;
157}
158interface NearBySteps {
159 stepBefore: NearByStep;
160 thisStep: NearByStep;
161 stepAfter: NearByStep;
162}
163declare type GetResult = number | string | (string | number)[];
164declare type NextStepsForHandle = [number | false | null, number | false | null];
165declare type PipsFilter = (value: number, type: PipsType) => PipsType;
166declare type EventCallback = (this: API, values: (number | string)[], handleNumber: number, unencoded: number[], tap: boolean, locations: number[], slider: API) => void;
167declare class Spectrum {
168 xPct: number[];
169 xVal: number[];
170 xSteps: (number | false)[];
171 xNumSteps: (number | false)[];
172 protected xHighestCompleteStep: number[];
173 protected snap: boolean;
174 constructor(entry: Range, snap: boolean, singleStep: number);
175 getDistance(value: number): number[];
176 getAbsoluteDistance(value: number, distances: number[] | null, direction: boolean): number;
177 toStepping(value: number): number;
178 fromStepping(value: number): number;
179 getStep(value: number): number;
180 getDefaultStep(value: number, isDown: boolean, size: number): number;
181 getNearbySteps(value: number): NearBySteps;
182 countStepDecimals(): number;
183 hasNoSize(): boolean;
184 convert(value: number): number;
185 private handleEntryPoint;
186 private handleStepPoint;
187}
188declare const cssClasses: CssClasses;
189declare function initialize(target: TargetElement, originalOptions: Options): API;
190export { TargetElement as target };
191export { initialize as create };
192export { cssClasses };
193declare const _default: {
194 __spectrum: typeof Spectrum;
195 cssClasses: CssClasses;
196 create: typeof initialize;
197};
198export default _default;