vgapp 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +58 -35
  2. package/agents.md +2 -2
  3. package/app/modules/base-module.js +87 -10
  4. package/app/modules/vgalert/js/vgalert.js +3 -3
  5. package/app/modules/vgdynamictable/index.js +5 -0
  6. package/app/modules/vgdynamictable/js/editable.js +438 -0
  7. package/app/modules/vgdynamictable/js/expandable.js +248 -0
  8. package/app/modules/vgdynamictable/js/filters.js +450 -0
  9. package/app/modules/vgdynamictable/js/fixed.js +566 -0
  10. package/app/modules/vgdynamictable/js/options.js +646 -0
  11. package/app/modules/vgdynamictable/js/pagination.js +623 -0
  12. package/app/modules/vgdynamictable/js/search.js +82 -0
  13. package/app/modules/vgdynamictable/js/skeleton.js +136 -0
  14. package/app/modules/vgdynamictable/js/sortable.js +442 -0
  15. package/app/modules/vgdynamictable/js/summary-footer.js +284 -0
  16. package/app/modules/vgdynamictable/js/table-remote.js +821 -0
  17. package/app/modules/vgdynamictable/js/table-state.js +243 -0
  18. package/app/modules/vgdynamictable/js/table-url-state.js +444 -0
  19. package/app/modules/vgdynamictable/js/utils/common.js +48 -0
  20. package/app/modules/vgdynamictable/js/vgdynamictable.js +3829 -0
  21. package/app/modules/vgdynamictable/js/viewport.js +322 -0
  22. package/app/modules/vgdynamictable/readme.md +251 -0
  23. package/app/modules/vgdynamictable/scss/_actions.scss +193 -0
  24. package/app/modules/vgdynamictable/scss/_pagination.scss +183 -0
  25. package/app/modules/vgdynamictable/scss/_skeleton.scss +60 -0
  26. package/app/modules/vgdynamictable/scss/_sortable.scss +63 -0
  27. package/app/modules/vgdynamictable/scss/_table.scss +157 -0
  28. package/app/modules/vgdynamictable/scss/_variables.scss +130 -0
  29. package/app/modules/vgdynamictable/scss/vgdynamictable.scss +267 -0
  30. package/app/modules/vgrangeslider/index.js +3 -0
  31. package/app/modules/vgrangeslider/js/skins.js +222 -0
  32. package/app/modules/vgrangeslider/js/vgrangeslider.js +704 -0
  33. package/app/modules/vgrangeslider/readme.md +523 -0
  34. package/app/modules/vgrangeslider/scss/_variables.scss +53 -0
  35. package/app/modules/vgrangeslider/scss/vgrangeslider.scss +240 -0
  36. package/app/utils/js/components/ajax.js +116 -7
  37. package/build/vgapp.css +2 -3246
  38. package/build/vgapp.css.map +1 -1
  39. package/build/vgapp.js +2 -30
  40. package/index.js +2 -0
  41. package/index.scss +6 -0
  42. package/package.json +1 -1
@@ -0,0 +1,704 @@
1
+ import BaseModule from "../../base-module";
2
+ import EventHandler from "../../../utils/js/dom/event";
3
+ import Selectors from "../../../utils/js/dom/selectors";
4
+ import { mergeDeepObject, normalizeData } from "../../../utils/js/functions";
5
+ import { applyRangeSliderSkin, syncRangeSliderSkin } from "./skins";
6
+
7
+ const NAME = 'rangeslider';
8
+ const NAME_KEY = 'vg.rangeslider';
9
+
10
+ const SELECTOR_DATA_MODULE = '[data-vgrangeslider]';
11
+
12
+ const CLASS_NAME_MODULE = 'vg-range-slider';
13
+ const CLASS_NAME_RANGE = 'is-range';
14
+ const CLASS_NAME_DISABLED = 'disabled';
15
+ const CLASS_NAME_TOOLTIP_HIDDEN = 'is-hidden';
16
+
17
+ const EVENT_KEY_INIT = `${NAME_KEY}.init`;
18
+ const EVENT_KEY_INPUT = `${NAME_KEY}.input`;
19
+ const EVENT_KEY_CHANGE = `${NAME_KEY}.change`;
20
+ const EVENT_KEY_UPDATE = `${NAME_KEY}.update`;
21
+
22
+ const defaultParams = {
23
+ range: false,
24
+ min: 0,
25
+ max: 100,
26
+ step: 1,
27
+ start: null,
28
+ connect: true,
29
+ tooltips: true,
30
+ labels: true,
31
+ separator: ' - ',
32
+ suffix: '',
33
+ prefix: '',
34
+ labelWords: null,
35
+ skin: 'default',
36
+ ruler: {
37
+ count: 6,
38
+ labels: true,
39
+ values: null,
40
+ dimInactive: false,
41
+ },
42
+ status: {
43
+ warningBelow: 60,
44
+ dangerBelow: 30,
45
+ by: 'to',
46
+ },
47
+ name: {
48
+ min: '',
49
+ max: '',
50
+ },
51
+ input: {
52
+ min: null,
53
+ max: null,
54
+ },
55
+ output: {
56
+ target: null,
57
+ min: null,
58
+ max: null,
59
+ },
60
+ disabled: false,
61
+ onInit: null,
62
+ onInput: null,
63
+ onChange: null,
64
+ onUpdate: null,
65
+ formatValue: null,
66
+ };
67
+
68
+ class VGRangeSlider extends BaseModule {
69
+ constructor(element, params = {}) {
70
+ super(element, params);
71
+
72
+ this._sourceInput = this._element.matches('input[type="range"]') ? this._element : null;
73
+ this._params = this._buildParams(params);
74
+ this._isRange = this._resolveRangeMode();
75
+ this._listeners = [];
76
+ this._handleResize = () => this._syncUI();
77
+ this._dom = {
78
+ root: null,
79
+ wrapper: null,
80
+ fill: null,
81
+ inputFrom: null,
82
+ inputTo: null,
83
+ tooltipFrom: null,
84
+ tooltipTo: null,
85
+ tooltipMerged: null,
86
+ labelFrom: null,
87
+ labelTo: null,
88
+ labelSeparator: null,
89
+ hiddenMin: null,
90
+ hiddenMax: null,
91
+ skin: null,
92
+ };
93
+
94
+ this._state = this._buildState();
95
+
96
+ this._render();
97
+ this._bindEvents();
98
+ this._syncUI();
99
+ this._setDisabledState(this._params.disabled);
100
+ this._emit(EVENT_KEY_INIT, 'onInit');
101
+ }
102
+
103
+ static get NAME() {
104
+ return NAME;
105
+ }
106
+
107
+ static get NAME_KEY() {
108
+ return NAME_KEY;
109
+ }
110
+
111
+ static init(element, params = {}) {
112
+ return this.getOrCreateInstance(element, params);
113
+ }
114
+
115
+ getValue() {
116
+ return this._isRange ? [this._state.from, this._state.to] : this._state.from;
117
+ }
118
+
119
+ setValue(value, options = {}) {
120
+ const { silent = false, emit = 'update' } = options;
121
+
122
+ if (this._isRange) {
123
+ const next = Array.isArray(value) ? value : [value, this._state.to];
124
+ const from = this._normalizeValue(next[0], this._state.min);
125
+ const to = this._normalizeValue(next[1], this._state.max);
126
+ this._state.from = Math.min(from, to);
127
+ this._state.to = Math.max(from, to);
128
+ } else {
129
+ this._state.from = this._normalizeValue(value, this._state.min);
130
+ }
131
+
132
+ this._syncUI();
133
+
134
+ if (!silent) {
135
+ this._emit(emit === 'change' ? EVENT_KEY_CHANGE : EVENT_KEY_UPDATE, emit === 'change' ? 'onChange' : 'onUpdate');
136
+ }
137
+ }
138
+
139
+ enable() {
140
+ this._setDisabledState(false);
141
+ }
142
+
143
+ disable() {
144
+ this._setDisabledState(true);
145
+ }
146
+
147
+ dispose() {
148
+ this._listeners.forEach(({ element, type, handler }) => element.removeEventListener(type, handler));
149
+ this._listeners = [];
150
+ window.removeEventListener('resize', this._handleResize);
151
+ super.dispose();
152
+ }
153
+
154
+ _buildParams(params) {
155
+ const merged = this._getParams(this._element, mergeDeepObject(defaultParams, params));
156
+
157
+ if (this._sourceInput) {
158
+ merged.min = this._sourceInput.min !== '' ? normalizeData(this._sourceInput.min) : merged.min;
159
+ merged.max = this._sourceInput.max !== '' ? normalizeData(this._sourceInput.max) : merged.max;
160
+ merged.step = this._sourceInput.step !== '' ? normalizeData(this._sourceInput.step) : merged.step;
161
+ merged.start = this._sourceInput.value !== '' ? normalizeData(this._sourceInput.value) : merged.start;
162
+ merged.name = this._sourceInput.name || merged.name;
163
+ merged.disabled = this._sourceInput.disabled || merged.disabled;
164
+ }
165
+
166
+ if (typeof merged.name === 'string') {
167
+ merged.name = {
168
+ min: merged.name,
169
+ max: merged.name,
170
+ };
171
+ }
172
+
173
+ if (!merged.input || typeof merged.input !== 'object') {
174
+ merged.input = { min: null, max: null };
175
+ }
176
+
177
+ if (typeof merged.output === 'string') {
178
+ merged.output = {
179
+ target: merged.output,
180
+ min: null,
181
+ max: null,
182
+ };
183
+ } else if (!merged.output || typeof merged.output !== 'object') {
184
+ merged.output = {
185
+ target: null,
186
+ min: null,
187
+ max: null,
188
+ };
189
+ } else if (!Object.prototype.hasOwnProperty.call(merged.output, 'target')) {
190
+ merged.output.target = null;
191
+ }
192
+
193
+ if (!merged.labelWords && merged.label && typeof merged.label === 'object' && Object.prototype.hasOwnProperty.call(merged.label, 'words')) {
194
+ merged.labelWords = merged.label.words;
195
+ }
196
+
197
+ if (typeof merged.labelWords === 'string') {
198
+ merged.labelWords = merged.labelWords
199
+ .split(',')
200
+ .map((word) => word.trim())
201
+ .filter(Boolean);
202
+ } else if (!Array.isArray(merged.labelWords)) {
203
+ merged.labelWords = null;
204
+ }
205
+
206
+ return merged;
207
+ }
208
+
209
+ _buildState() {
210
+ const min = Number(normalizeData(this._params.min));
211
+ const max = Math.max(Number(normalizeData(this._params.max)), min);
212
+ const step = Number(normalizeData(this._params.step)) || 1;
213
+ const start = this._resolveStartValues(min, max);
214
+
215
+ return {
216
+ min,
217
+ max: max >= min ? max : min,
218
+ step: step > 0 ? step : 1,
219
+ from: start.from,
220
+ to: start.to,
221
+ };
222
+ }
223
+
224
+ _resolveRangeMode() {
225
+ if (this._sourceInput) return false;
226
+ return normalizeData(this._params.range) === true;
227
+ }
228
+
229
+ _resolveStartValues(min, max) {
230
+ let from = min;
231
+ let to = max;
232
+
233
+ if (this._isRange) {
234
+ const start = Array.isArray(this._params.start) ? this._params.start : [this._params.from, this._params.to];
235
+ from = this._normalizeValue(start[0], min, min, max);
236
+ to = this._normalizeValue(start[1], max, min, max);
237
+ if (from > to) {
238
+ [from, to] = [to, from];
239
+ }
240
+ } else {
241
+ const value = this._params.start ?? this._params.value ?? min;
242
+ from = this._normalizeValue(value, min, min, max);
243
+ to = from;
244
+ }
245
+
246
+ return { from, to };
247
+ }
248
+
249
+ _render() {
250
+ const root = this._sourceInput ? this._renderFromInput() : this._renderFromContainer();
251
+ this._dom.root = root;
252
+ this._dom.wrapper = Selectors.find('.vg-range-slider__wrapper', root);
253
+ this._dom.fill = Selectors.find('.vg-range-slider__fill', root);
254
+ this._dom.inputFrom = Selectors.find('.vg-range-slider__input--from', root);
255
+ this._dom.inputTo = Selectors.find('.vg-range-slider__input--to', root);
256
+ this._dom.tooltipFrom = Selectors.find('.vg-range-slider__tooltip--from', root);
257
+ this._dom.tooltipTo = Selectors.find('.vg-range-slider__tooltip--to', root);
258
+ this._dom.tooltipMerged = Selectors.find('.vg-range-slider__tooltip--merged', root);
259
+ this._dom.labelFrom = Selectors.find('.vg-range-slider__label--from', root);
260
+ this._dom.labelTo = Selectors.find('.vg-range-slider__label--to', root);
261
+ this._dom.labelSeparator = Selectors.find('.vg-range-slider__separator', root);
262
+ this._dom.hiddenMin = root.querySelector('input[data-vgrangeslider-hidden="min"]');
263
+ this._dom.hiddenMax = root.querySelector('input[data-vgrangeslider-hidden="max"]');
264
+ this._dom.skin = applyRangeSliderSkin(root, this._params, this._state, {
265
+ formatValue: (value) => this._formatValue(value),
266
+ toPositionPx: (value) => this._toPositionPx(value),
267
+ });
268
+ }
269
+
270
+ _renderFromInput() {
271
+ const sourceInput = this._sourceInput;
272
+ const root = document.createElement('div');
273
+ root.className = CLASS_NAME_MODULE;
274
+
275
+ const wrapper = document.createElement('div');
276
+ wrapper.className = 'vg-range-slider__wrapper';
277
+
278
+ const track = document.createElement('div');
279
+ track.className = 'vg-range-slider__track';
280
+
281
+ const fill = document.createElement('div');
282
+ fill.className = 'vg-range-slider__fill';
283
+
284
+ const tooltip = this._params.tooltips ? this._createTooltip('from') : null;
285
+ const labels = this._params.labels ? this._createLabels(false) : null;
286
+
287
+ sourceInput.insertAdjacentElement('beforebegin', root);
288
+
289
+ sourceInput.classList.add('vg-range-slider__input', 'vg-range-slider__input--from');
290
+ sourceInput.autocomplete = 'off';
291
+
292
+ track.appendChild(fill);
293
+ wrapper.appendChild(track);
294
+ wrapper.appendChild(sourceInput);
295
+ if (tooltip) wrapper.appendChild(tooltip);
296
+ root.appendChild(wrapper);
297
+ if (labels) root.appendChild(labels);
298
+
299
+ return root;
300
+ }
301
+
302
+ _renderFromContainer() {
303
+ const root = this._element;
304
+ root.classList.add(CLASS_NAME_MODULE);
305
+ if (this._isRange) root.classList.add(CLASS_NAME_RANGE);
306
+
307
+ root.innerHTML = '';
308
+
309
+ const wrapper = document.createElement('div');
310
+ wrapper.className = 'vg-range-slider__wrapper';
311
+
312
+ const track = document.createElement('div');
313
+ track.className = 'vg-range-slider__track';
314
+
315
+ const fill = document.createElement('div');
316
+ fill.className = 'vg-range-slider__fill';
317
+
318
+ track.appendChild(fill);
319
+ wrapper.appendChild(track);
320
+
321
+ const inputFrom = this._createRangeInput('from');
322
+ wrapper.appendChild(inputFrom);
323
+
324
+ if (this._isRange) {
325
+ const inputTo = this._createRangeInput('to');
326
+ wrapper.appendChild(inputTo);
327
+ }
328
+
329
+ if (this._params.tooltips) {
330
+ wrapper.appendChild(this._createTooltip('from'));
331
+ if (this._isRange) wrapper.appendChild(this._createTooltip('to'));
332
+ if (this._isRange) wrapper.appendChild(this._createTooltip('merged'));
333
+ }
334
+
335
+ root.appendChild(wrapper);
336
+
337
+ if (this._params.labels) {
338
+ root.appendChild(this._createLabels(this._isRange));
339
+ }
340
+
341
+ if (this._isRange) {
342
+ this._ensureHiddenInput(root, 'min', this._params.input?.min, this._params.name?.min);
343
+ this._ensureHiddenInput(root, 'max', this._params.input?.max, this._params.name?.max);
344
+ } else if (this._params.name?.min) {
345
+ this._ensureHiddenInput(root, 'min', this._params.input?.min, this._params.name.min);
346
+ }
347
+
348
+ return root;
349
+ }
350
+
351
+ _createRangeInput(type) {
352
+ const input = document.createElement('input');
353
+ input.type = 'range';
354
+ input.className = `vg-range-slider__input vg-range-slider__input--${type}`;
355
+ input.min = String(this._state.min);
356
+ input.max = String(this._state.max);
357
+ input.step = String(this._state.step);
358
+ input.value = String(type === 'to' ? this._state.to : this._state.from);
359
+ input.autocomplete = 'off';
360
+ return input;
361
+ }
362
+
363
+ _createTooltip(type) {
364
+ const tooltip = document.createElement('span');
365
+ tooltip.className = `vg-range-slider__tooltip vg-range-slider__tooltip--${type}`;
366
+ if (type === 'merged') {
367
+ tooltip.classList.add(CLASS_NAME_TOOLTIP_HIDDEN);
368
+ }
369
+ return tooltip;
370
+ }
371
+
372
+ _createLabels(isRange) {
373
+ const labels = document.createElement('div');
374
+ labels.className = 'vg-range-slider__labels';
375
+
376
+ const from = document.createElement('span');
377
+ from.className = 'vg-range-slider__label vg-range-slider__label--from';
378
+ labels.appendChild(from);
379
+
380
+ if (isRange) {
381
+ const separator = document.createElement('span');
382
+ separator.className = 'vg-range-slider__separator';
383
+ separator.textContent = this._params.separator;
384
+ labels.appendChild(separator);
385
+
386
+ const to = document.createElement('span');
387
+ to.className = 'vg-range-slider__label vg-range-slider__label--to';
388
+ labels.appendChild(to);
389
+ }
390
+
391
+ return labels;
392
+ }
393
+
394
+ _ensureHiddenInput(root, role, selector, name) {
395
+ let input = selector ? Selectors.find(selector) : null;
396
+ if (!input) {
397
+ input = document.createElement('input');
398
+ input.type = 'hidden';
399
+ if (name) input.name = name;
400
+ root.appendChild(input);
401
+ }
402
+ input.setAttribute('data-vgrangeslider-hidden', role);
403
+ }
404
+
405
+ _bindEvents() {
406
+ const inputHandler = (type) => (event) => {
407
+ const rawValue = this._normalizeValue(event.target.value, this._state.min);
408
+
409
+ if (this._isRange) {
410
+ if (type === 'from') {
411
+ this._state.from = Math.min(rawValue, this._state.to);
412
+ event.target.value = String(this._state.from);
413
+ } else {
414
+ this._state.to = Math.max(rawValue, this._state.from);
415
+ event.target.value = String(this._state.to);
416
+ }
417
+ } else {
418
+ this._state.from = rawValue;
419
+ }
420
+
421
+ this._syncUI();
422
+ this._emit(EVENT_KEY_INPUT, 'onInput');
423
+ };
424
+
425
+ const changeHandler = () => {
426
+ this._syncUI();
427
+ this._emit(EVENT_KEY_CHANGE, 'onChange');
428
+ };
429
+
430
+ [this._dom.inputFrom, this._dom.inputTo].filter(Boolean).forEach((input) => {
431
+ const type = input.classList.contains('vg-range-slider__input--to') ? 'to' : 'from';
432
+ const onInput = inputHandler(type);
433
+ const onChange = changeHandler;
434
+
435
+ input.addEventListener('input', onInput);
436
+ input.addEventListener('change', onChange);
437
+
438
+ this._listeners.push({ element: input, type: 'input', handler: onInput });
439
+ this._listeners.push({ element: input, type: 'change', handler: onChange });
440
+ });
441
+
442
+ window.addEventListener('resize', this._handleResize);
443
+ }
444
+
445
+ _syncUI() {
446
+ const fromPercent = this._toPercent(this._state.from);
447
+ const toPercent = this._toPercent(this._isRange ? this._state.to : this._state.from);
448
+ const fromPosition = this._toPositionPx(this._state.from);
449
+ const toPosition = this._toPositionPx(this._isRange ? this._state.to : this._state.from);
450
+
451
+ if (this._dom.inputFrom) this._dom.inputFrom.value = String(this._state.from);
452
+ if (this._dom.inputTo) this._dom.inputTo.value = String(this._state.to);
453
+
454
+ if (this._dom.fill) {
455
+ const left = this._isRange ? fromPosition : 0;
456
+ const width = this._isRange ? (toPosition - fromPosition) : toPosition;
457
+ this._dom.fill.style.left = `${Math.max(left, 0)}px`;
458
+ this._dom.fill.style.width = `${Math.max(width, 0)}px`;
459
+ }
460
+
461
+ this._placeTooltip(this._dom.tooltipFrom, fromPosition, this._formatValue(this._state.from));
462
+ this._placeTooltip(this._dom.tooltipTo, toPosition, this._formatValue(this._state.to));
463
+ this._syncTooltips(fromPosition, toPosition);
464
+
465
+ if (this._dom.labelFrom) this._dom.labelFrom.textContent = this._formatValue(this._state.from);
466
+ if (this._dom.labelTo) this._dom.labelTo.textContent = this._formatValue(this._state.to);
467
+ if (this._dom.labelSeparator) this._dom.labelSeparator.hidden = !this._isRange;
468
+
469
+ this._syncTargets();
470
+ syncRangeSliderSkin(this._dom.skin, this._state, {
471
+ isRange: this._isRange,
472
+ params: this._params,
473
+ dom: this._dom,
474
+ });
475
+ }
476
+
477
+ _syncTargets() {
478
+ const values = this.getValue();
479
+ const [from, to] = Array.isArray(values) ? values : [values, values];
480
+
481
+ if (this._dom.hiddenMin) {
482
+ this._dom.hiddenMin.value = String(from);
483
+ }
484
+
485
+ if (this._dom.hiddenMax) {
486
+ this._dom.hiddenMax.value = String(to);
487
+ }
488
+
489
+ this._setText(this._params.output?.target, this._isRange ? `${this._formatValue(from)}${this._params.separator}${this._formatValue(to)}` : this._formatValue(from));
490
+ this._setText(this._params.output?.min, this._formatValue(from));
491
+ this._setText(this._params.output?.max, this._formatValue(to));
492
+ }
493
+
494
+ _setDisabledState(state) {
495
+ this._params.disabled = !!state;
496
+ if (this._dom.root) {
497
+ this._dom.root.classList.toggle(CLASS_NAME_DISABLED, this._params.disabled);
498
+ }
499
+
500
+ [this._dom.inputFrom, this._dom.inputTo].filter(Boolean).forEach((input) => {
501
+ input.disabled = this._params.disabled;
502
+ });
503
+ }
504
+
505
+ _placeTooltip(node, percent, value) {
506
+ if (!node) return;
507
+ node.textContent = value;
508
+ node.style.left = `${percent}px`;
509
+ }
510
+
511
+ _syncTooltips(fromPosition, toPosition) {
512
+ const mergedTooltip = this._dom.tooltipMerged;
513
+ const fromTooltip = this._dom.tooltipFrom;
514
+ const toTooltip = this._dom.tooltipTo;
515
+
516
+ if (!this._isRange || !mergedTooltip || !fromTooltip || !toTooltip) {
517
+ if (fromTooltip) fromTooltip.classList.remove(CLASS_NAME_TOOLTIP_HIDDEN);
518
+ if (toTooltip) toTooltip.classList.remove(CLASS_NAME_TOOLTIP_HIDDEN);
519
+ if (mergedTooltip) mergedTooltip.classList.add(CLASS_NAME_TOOLTIP_HIDDEN);
520
+ return;
521
+ }
522
+
523
+ const gap = 8;
524
+ const fromHalfWidth = fromTooltip.offsetWidth / 2;
525
+ const toHalfWidth = toTooltip.offsetWidth / 2;
526
+ const isIntersected = (toPosition - fromPosition) <= (fromHalfWidth + toHalfWidth + gap);
527
+
528
+ if (!isIntersected) {
529
+ fromTooltip.classList.remove(CLASS_NAME_TOOLTIP_HIDDEN);
530
+ toTooltip.classList.remove(CLASS_NAME_TOOLTIP_HIDDEN);
531
+ mergedTooltip.classList.add(CLASS_NAME_TOOLTIP_HIDDEN);
532
+ return;
533
+ }
534
+
535
+ fromTooltip.classList.add(CLASS_NAME_TOOLTIP_HIDDEN);
536
+ toTooltip.classList.add(CLASS_NAME_TOOLTIP_HIDDEN);
537
+ mergedTooltip.classList.remove(CLASS_NAME_TOOLTIP_HIDDEN);
538
+ mergedTooltip.textContent = `${this._formatValue(this._state.from)}${this._params.separator}${this._formatValue(this._state.to)}`;
539
+ mergedTooltip.style.left = `${(fromPosition + toPosition) / 2}px`;
540
+ }
541
+
542
+ _toPercent(value) {
543
+ const range = this._state.max - this._state.min;
544
+ if (range <= 0) return 0;
545
+ return ((value - this._state.min) / range) * 100;
546
+ }
547
+
548
+ _toPositionPx(value) {
549
+ const wrapper = this._dom?.wrapper;
550
+ const range = this._state.max - this._state.min;
551
+ if (!wrapper || range <= 0) return 0;
552
+
553
+ const percent = (value - this._state.min) / range;
554
+ const styles = getComputedStyle(this._dom.root || wrapper);
555
+ const thumbSize = parseFloat(styles.getPropertyValue('--vg-range-slider-thumb-size')) || 0;
556
+ const width = wrapper.clientWidth || 0;
557
+
558
+ if (width <= 0) return 0;
559
+ if (width <= thumbSize) return width / 2;
560
+
561
+ return (percent * (width - thumbSize)) + (thumbSize / 2);
562
+ }
563
+
564
+ _normalizeValue(value, fallback, min = this._state?.min ?? 0, max = this._state?.max ?? 100) {
565
+ const numeric = Number(normalizeData(value));
566
+ const safeValue = Number.isFinite(numeric) ? numeric : fallback;
567
+ const clamped = Math.min(Math.max(safeValue, min), max);
568
+ const step = this._state?.step || this._params.step || 1;
569
+ const stepped = Math.round((clamped - min) / step) * step + min;
570
+ return Number(stepped.toFixed(5));
571
+ }
572
+
573
+ _formatValue(value) {
574
+ if (typeof this._params.formatValue === 'function') {
575
+ return this._params.formatValue.call(this, value, this._element);
576
+ }
577
+
578
+ const prefix = this._params.prefix == null ? '' : String(this._params.prefix);
579
+ const suffix = this._params.suffix == null ? '' : String(this._params.suffix);
580
+
581
+ return `${prefix}${value}${suffix}`;
582
+ }
583
+
584
+ _getStatusBy() {
585
+ if (typeof this._params?.status?.by !== 'string') {
586
+ return 'to';
587
+ }
588
+
589
+ const by = this._params.status.by.toLowerCase();
590
+ return ['from', 'to', 'avg'].includes(by) ? by : 'to';
591
+ }
592
+
593
+ _getStatusPercentByValue(value) {
594
+ const range = this._state.max - this._state.min;
595
+ if (range <= 0) {
596
+ return 0;
597
+ }
598
+
599
+ return ((value - this._state.min) / range) * 100;
600
+ }
601
+
602
+ _getStatusToneByValue(value) {
603
+ const percent = this._getStatusPercentByValue(value);
604
+ const warningBelow = Number(this._params?.status?.warningBelow);
605
+ const dangerBelow = Number(this._params?.status?.dangerBelow);
606
+ const warningThreshold = Number.isFinite(warningBelow) ? warningBelow : 60;
607
+ const dangerThreshold = Number.isFinite(dangerBelow) ? dangerBelow : 30;
608
+
609
+ if (percent < dangerThreshold) {
610
+ return 'danger';
611
+ }
612
+
613
+ if (percent < warningThreshold) {
614
+ return 'warning';
615
+ }
616
+
617
+ return 'success';
618
+ }
619
+
620
+ _getStatusLabelByTone(tone) {
621
+ if (!Array.isArray(this._params?.labelWords) || this._params.labelWords.length < 3) {
622
+ return null;
623
+ }
624
+
625
+ if (tone === 'danger') {
626
+ return this._params.labelWords[0] || null;
627
+ }
628
+
629
+ if (tone === 'warning') {
630
+ return this._params.labelWords[1] || null;
631
+ }
632
+
633
+ return this._params.labelWords[2] || null;
634
+ }
635
+
636
+ _getStatusDetail() {
637
+ const by = this._getStatusBy();
638
+ const fromValue = this._state.from;
639
+ const toValue = this._state.to;
640
+ const sourceValue = by === 'from'
641
+ ? fromValue
642
+ : by === 'avg'
643
+ ? (fromValue + toValue) / 2
644
+ : toValue;
645
+ const tone = this._getStatusToneByValue(sourceValue);
646
+
647
+ return {
648
+ by,
649
+ sourceValue,
650
+ percent: Number(this._getStatusPercentByValue(sourceValue).toFixed(5)),
651
+ tone,
652
+ label: this._getStatusLabelByTone(tone),
653
+ from: {
654
+ value: fromValue,
655
+ percent: Number(this._getStatusPercentByValue(fromValue).toFixed(5)),
656
+ tone: this._getStatusToneByValue(fromValue),
657
+ label: this._getStatusLabelByTone(this._getStatusToneByValue(fromValue)),
658
+ },
659
+ to: {
660
+ value: toValue,
661
+ percent: Number(this._getStatusPercentByValue(toValue).toFixed(5)),
662
+ tone: this._getStatusToneByValue(toValue),
663
+ label: this._getStatusLabelByTone(this._getStatusToneByValue(toValue)),
664
+ },
665
+ };
666
+ }
667
+
668
+ _emit(eventName, callbackName) {
669
+ const detail = {
670
+ value: this.getValue(),
671
+ from: this._state.from,
672
+ to: this._state.to,
673
+ min: this._state.min,
674
+ max: this._state.max,
675
+ step: this._state.step,
676
+ status: this._getStatusDetail(),
677
+ instance: this,
678
+ };
679
+
680
+ EventHandler.trigger(this._element, eventName, detail);
681
+
682
+ const callback = this._params[callbackName];
683
+ if (typeof callback === 'function') {
684
+ callback.call(this, this._element, detail);
685
+ }
686
+ }
687
+
688
+ _setText(selector, value) {
689
+ if (!selector) return;
690
+ const target = Selectors.find(selector);
691
+ if (target) target.textContent = value;
692
+ }
693
+ }
694
+
695
+ EventHandler.on(document, 'DOMContentLoaded', () => {
696
+ Selectors.findAll(SELECTOR_DATA_MODULE).forEach((element) => {
697
+ if (!element.dataset.vgrangesliderInitialized) {
698
+ VGRangeSlider.getOrCreateInstance(element);
699
+ element.dataset.vgrangesliderInitialized = 'true';
700
+ }
701
+ });
702
+ });
703
+
704
+ export default VGRangeSlider;