UNPKG

4.69 kBTypeScriptView Raw
1import { Value, Mark, MarksProp, ProcessProp, ProcessOption, DotOption } from '../typings';
2export declare const enum ERROR_TYPE {
3 VALUE = 1,
4 INTERVAL = 2,
5 MIN = 3,
6 MAX = 4,
7 ORDER = 5
8}
9declare type ERROR_MESSAGE = {
10 [key in ERROR_TYPE]: string;
11};
12export declare const ERROR_MSG: ERROR_MESSAGE;
13/**
14 * Slider logic control center
15 *
16 * @export
17 * @class Control
18 */
19export default class Control {
20 dotsPos: number[];
21 dotsValue: Value[];
22 data?: Value[];
23 enableCross: boolean;
24 fixed: boolean;
25 max: number;
26 min: number;
27 interval: number;
28 minRange: number;
29 maxRange: number;
30 order: boolean;
31 marks?: MarksProp;
32 included?: boolean;
33 process?: ProcessProp;
34 adsorb?: boolean;
35 dotOptions?: DotOption | DotOption[];
36 onError?: (type: ERROR_TYPE, message: string) => void;
37 constructor(options: {
38 value: Value | Value[];
39 data?: Value[];
40 enableCross: boolean;
41 fixed: boolean;
42 max: number;
43 min: number;
44 interval: number;
45 order: boolean;
46 minRange?: number;
47 maxRange?: number;
48 marks?: MarksProp;
49 included?: boolean;
50 process?: ProcessProp;
51 adsorb?: boolean;
52 dotOptions?: DotOption | DotOption[];
53 onError?: (type: ERROR_TYPE, message: string) => void;
54 });
55 setValue(value: Value | Value[]): void;
56 setDotsValue(value: Value[], syncPos?: boolean): void;
57 setDotsPos(dotsPos: number[]): void;
58 getValueByPos(pos: number): Value;
59 syncDotsPos(): void;
60 /**
61 * Get all the marks
62 *
63 * @readonly
64 * @type {Mark[]}
65 * @memberof Control
66 */
67 get markList(): Mark[];
68 /**
69 * Get the most recent slider index by position
70 *
71 * @param {number} pos
72 * @returns {number}
73 * @memberof Control
74 */
75 getRecentDot(pos: number): number;
76 /**
77 * Get index by value
78 *
79 * @param {Value} value
80 * @returns {number}
81 * @memberof Control
82 */
83 getIndexByValue(value: Value): number;
84 /**
85 * Get value by index
86 *
87 * @param {index} number
88 * @returns {Value}
89 * @memberof Control
90 */
91 getValueByIndex(index: number): Value;
92 /**
93 * Set the position of a single slider
94 *
95 * @param {number} pos
96 * @param {number} index
97 */
98 setDotPos(pos: number, index: number): void;
99 /**
100 * In fixed mode, get the position of all slider changes
101 *
102 * @param {number} changePos Change distance of a single slider
103 * @param {number} index slider index
104 * @returns {DotsPosChangeArray}
105 * @memberof Control
106 */
107 private getFixedChangePosArr;
108 /**
109 * In minRange/maxRange mode, get the position of all slider changes
110 *
111 * @param {number} pos position of a single slider
112 * @param {number} changePos Change distance of a single slider
113 * @param {number} index slider index
114 * @returns {DotsPosChangeArray}
115 * @memberof Control
116 */
117 private getLimitRangeChangePosArr;
118 private isPos;
119 /**
120 * Get a valid position by pos
121 *
122 * @param {number} pos
123 * @param {number} index
124 * @returns {{ pos: number, inRange: boolean }}
125 */
126 getValidPos(pos: number, index: number): {
127 pos: number;
128 inRange: boolean;
129 };
130 /**
131 * Calculate the position of the slider by value
132 *
133 * @param {Value} val
134 * @returns {number}
135 */
136 parseValue(val: Value): number;
137 /**
138 * Calculate the value by position
139 *
140 * @param {number} pos
141 * @returns {Value}
142 * @memberof Control
143 */
144 parsePos(pos: number): Value;
145 /**
146 * Determine if the location is active
147 *
148 * @param {number} pos
149 * @returns {boolean}
150 * @memberof Control
151 */
152 isActiveByPos(pos: number): boolean;
153 /**
154 * Get each value
155 *
156 * @returns {Value[]}
157 * @memberof Control
158 */
159 getValues(): Value[];
160 /**
161 * Calculate the distance of the range
162 * @param range number
163 */
164 getRangeDir(range: number): number;
165 private emitError;
166 get processArray(): ProcessOption;
167 /**
168 * The total number of values
169 *
170 * @type {number}
171 * @memberof Control
172 */
173 get total(): number;
174 get gap(): number;
175 private cacheRangeDir;
176 get minRangeDir(): number;
177 get maxRangeDir(): number;
178 private getDotOption;
179 private getDotRange;
180 /**
181 * Sliding range of each slider
182 *
183 * @type {Array<[number, number]>}
184 * @memberof Control
185 */
186 get valuePosRange(): Array<[number, number]>;
187 get dotsIndex(): number[];
188}
189export {};