material 3.3.1 → 3.3.3

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 (153) hide show
  1. package/README.md +2 -2
  2. package/dist/components/slider/config.js +0 -46
  3. package/dist/components/slider/features/controller.js +805 -171
  4. package/dist/components/slider/features/dom.js +29 -62
  5. package/dist/components/slider/features/index.js +1 -3
  6. package/dist/components/slider/features/states.js +2 -30
  7. package/dist/components/slider/slider.js +3 -6
  8. package/dist/components/slider/types.d.ts +0 -26
  9. package/dist/components/tooltip/api.js +53 -97
  10. package/dist/core/canvas/resize.d.ts +1 -1
  11. package/dist/core/canvas/resize.js +24 -11
  12. package/dist/core/dom/classes.js +17 -118
  13. package/dist/core/dom/create.d.ts +0 -2
  14. package/dist/core/dom/create.js +0 -72
  15. package/dist/core/utils/mobile.js +9 -29
  16. package/dist/elements/css/tooltip.css +1 -1
  17. package/dist/elements/css/tooltip.js +1 -1
  18. package/dist/elements/preupgrade/badge.css +1 -1
  19. package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
  20. package/dist/elements/preupgrade/bottom-sheet.css +1 -1
  21. package/dist/elements/preupgrade/button-group.css +1 -1
  22. package/dist/elements/preupgrade/button.css +1 -1
  23. package/dist/elements/preupgrade/card.css +1 -1
  24. package/dist/elements/preupgrade/carousel.css +1 -1
  25. package/dist/elements/preupgrade/checkbox.css +1 -1
  26. package/dist/elements/preupgrade/chips.css +1 -1
  27. package/dist/elements/preupgrade/datepicker.css +1 -1
  28. package/dist/elements/preupgrade/dialog.css +1 -1
  29. package/dist/elements/preupgrade/divider.css +1 -1
  30. package/dist/elements/preupgrade/drawer.css +1 -1
  31. package/dist/elements/preupgrade/extended-fab.css +1 -1
  32. package/dist/elements/preupgrade/fab-menu.css +1 -1
  33. package/dist/elements/preupgrade/fab.css +1 -1
  34. package/dist/elements/preupgrade/icon-button.css +1 -1
  35. package/dist/elements/preupgrade/list.css +1 -1
  36. package/dist/elements/preupgrade/loading-indicator.css +1 -1
  37. package/dist/elements/preupgrade/menu.css +1 -1
  38. package/dist/elements/preupgrade/navigation-bar.css +1 -1
  39. package/dist/elements/preupgrade/navigation-rail.css +1 -1
  40. package/dist/elements/preupgrade/progress.css +1 -1
  41. package/dist/elements/preupgrade/radios.css +1 -1
  42. package/dist/elements/preupgrade/search.css +1 -1
  43. package/dist/elements/preupgrade/select.css +1 -1
  44. package/dist/elements/preupgrade/side-sheet.css +1 -1
  45. package/dist/elements/preupgrade/slider.css +1 -1
  46. package/dist/elements/preupgrade/snackbar.css +1 -1
  47. package/dist/elements/preupgrade/split-button.css +1 -1
  48. package/dist/elements/preupgrade/switch.css +1 -1
  49. package/dist/elements/preupgrade/tabs.css +1 -1
  50. package/dist/elements/preupgrade/text-field.css +1 -1
  51. package/dist/elements/preupgrade/timepicker.css +1 -1
  52. package/dist/elements/preupgrade/toolbar.css +1 -1
  53. package/dist/elements/preupgrade/tooltip.css +1 -1
  54. package/dist/elements/preupgrade/top-app-bar.css +1 -1
  55. package/dist/elements/preupgrade.css +1 -1
  56. package/dist/package.json +1 -1
  57. package/dist/styles/badge.css +1 -1
  58. package/dist/styles/base.css +1 -1
  59. package/dist/styles/bottom-app-bar.css +1 -1
  60. package/dist/styles/bottom-sheet.css +1 -1
  61. package/dist/styles/button-group.css +1 -1
  62. package/dist/styles/button.css +1 -1
  63. package/dist/styles/card.css +1 -1
  64. package/dist/styles/carousel.css +1 -1
  65. package/dist/styles/checkbox.css +1 -1
  66. package/dist/styles/chips.css +1 -1
  67. package/dist/styles/contrast.css +1 -1
  68. package/dist/styles/datepicker.css +1 -1
  69. package/dist/styles/dialog.css +1 -1
  70. package/dist/styles/divider.css +1 -1
  71. package/dist/styles/drawer.css +1 -1
  72. package/dist/styles/extended-fab.css +1 -1
  73. package/dist/styles/fab-menu.css +1 -1
  74. package/dist/styles/fab.css +1 -1
  75. package/dist/styles/icon-button.css +1 -1
  76. package/dist/styles/list.css +1 -1
  77. package/dist/styles/loading-indicator.css +1 -1
  78. package/dist/styles/menu.css +1 -1
  79. package/dist/styles/navigation-bar.css +1 -1
  80. package/dist/styles/navigation-rail.css +1 -1
  81. package/dist/styles/progress.css +1 -1
  82. package/dist/styles/radios.css +1 -1
  83. package/dist/styles/search.css +1 -1
  84. package/dist/styles/select.css +1 -1
  85. package/dist/styles/side-sheet.css +1 -1
  86. package/dist/styles/slider.css +1 -1
  87. package/dist/styles/snackbar.css +1 -1
  88. package/dist/styles/split-button.css +1 -1
  89. package/dist/styles/switch.css +1 -1
  90. package/dist/styles/tabs.css +1 -1
  91. package/dist/styles/text-field.css +1 -1
  92. package/dist/styles/timepicker.css +1 -1
  93. package/dist/styles/toolbar.css +1 -1
  94. package/dist/styles/tooltip.css +2 -2
  95. package/dist/styles/top-app-bar.css +1 -1
  96. package/dist/styles/typography.css +1 -1
  97. package/dist/styles/utilities.css +1 -1
  98. package/dist/styles.css +2 -2
  99. package/dist/themes/autumn-contrast.css +1 -1
  100. package/dist/themes/autumn.css +1 -1
  101. package/dist/themes/baseline-contrast.css +1 -1
  102. package/dist/themes/baseline.css +1 -1
  103. package/dist/themes/brownbeige-contrast.css +1 -1
  104. package/dist/themes/brownbeige.css +1 -1
  105. package/dist/themes/content-contrast.css +1 -1
  106. package/dist/themes/content.css +1 -1
  107. package/dist/themes/desert-contrast.css +1 -1
  108. package/dist/themes/desert.css +1 -1
  109. package/dist/themes/expressive-contrast.css +1 -1
  110. package/dist/themes/expressive.css +1 -1
  111. package/dist/themes/fidelity-contrast.css +1 -1
  112. package/dist/themes/fidelity.css +1 -1
  113. package/dist/themes/forest-contrast.css +1 -1
  114. package/dist/themes/forest.css +1 -1
  115. package/dist/themes/fruit-salad-contrast.css +1 -1
  116. package/dist/themes/fruit-salad.css +1 -1
  117. package/dist/themes/highcontrast-contrast.css +1 -1
  118. package/dist/themes/highcontrast.css +1 -1
  119. package/dist/themes/monochrome-contrast.css +1 -1
  120. package/dist/themes/monochrome.css +1 -1
  121. package/dist/themes/neutral-contrast.css +1 -1
  122. package/dist/themes/neutral.css +1 -1
  123. package/dist/themes/ocean-contrast.css +1 -1
  124. package/dist/themes/ocean.css +1 -1
  125. package/dist/themes/rainbow-contrast.css +1 -1
  126. package/dist/themes/rainbow.css +1 -1
  127. package/dist/themes/sageivory-contrast.css +1 -1
  128. package/dist/themes/sageivory.css +1 -1
  129. package/dist/themes/spring-contrast.css +1 -1
  130. package/dist/themes/spring.css +1 -1
  131. package/dist/themes/summer-contrast.css +1 -1
  132. package/dist/themes/summer.css +1 -1
  133. package/dist/themes/sunset-contrast.css +1 -1
  134. package/dist/themes/sunset.css +1 -1
  135. package/dist/themes/tealcaramel-contrast.css +1 -1
  136. package/dist/themes/tealcaramel.css +1 -1
  137. package/dist/themes/vibrant-contrast.css +1 -1
  138. package/dist/themes/vibrant.css +1 -1
  139. package/package.json +1 -1
  140. package/src/styles/components/_tooltip.scss +3 -16
  141. package/dist/components/card/features.js +0 -217
  142. package/dist/components/chips/chip/constants.js +0 -18
  143. package/dist/components/chips/chip/index.js +0 -1
  144. package/dist/components/chips/schema.js +0 -46
  145. package/dist/components/progress/features/index.js +0 -4
  146. package/dist/components/progress/features/resize-observer.js +0 -40
  147. package/dist/components/slider/api.js +0 -108
  148. package/dist/components/slider/features/handlers.js +0 -379
  149. package/dist/components/slider/features/range.js +0 -70
  150. package/dist/components/slider/features/tracks.js +0 -287
  151. package/dist/components/tabs/scroll-indicators.js +0 -78
  152. package/dist/components/tabs/state.js +0 -44
  153. package/dist/core/utils/validate.js +0 -114
@@ -1,108 +0,0 @@
1
- export const withAPI = (options) => (component) => {
2
- return {
3
- ...component,
4
- element: component.element,
5
- setValue(value, triggerEvent = false) {
6
- options.slider.setValue(value, triggerEvent);
7
- return this;
8
- },
9
- getValue() {
10
- return options.slider.getValue();
11
- },
12
- setSecondValue(value, triggerEvent = false) {
13
- options.slider.setSecondValue(value, triggerEvent);
14
- return this;
15
- },
16
- getSecondValue() {
17
- return options.slider.getSecondValue();
18
- },
19
- setMin(min) {
20
- options.slider.setMin(min);
21
- return this;
22
- },
23
- getMin() {
24
- return options.slider.getMin();
25
- },
26
- setMax(max) {
27
- options.slider.setMax(max);
28
- return this;
29
- },
30
- getMax() {
31
- return options.slider.getMax();
32
- },
33
- setStep(step) {
34
- options.slider.setStep(step);
35
- return this;
36
- },
37
- getStep() {
38
- return options.slider.getStep();
39
- },
40
- enable() {
41
- options.disabled.enable();
42
- return this;
43
- },
44
- disable() {
45
- options.disabled.disable();
46
- return this;
47
- },
48
- isDisabled() {
49
- return options.disabled.isDisabled();
50
- },
51
- setColor(color) {
52
- options.appearance.setColor(color);
53
- return this;
54
- },
55
- getColor() {
56
- return options.appearance.getColor();
57
- },
58
- setSize(size) {
59
- options.appearance.setSize(size);
60
- return this;
61
- },
62
- getSize() {
63
- return options.appearance.getSize();
64
- },
65
- showTicks(show) {
66
- options.appearance.showTicks(show);
67
- return this;
68
- },
69
- showCurrentValue(show) {
70
- options.appearance.showCurrentValue(show);
71
- return this;
72
- },
73
- setLabel(text) {
74
- if (options.text?.setText)
75
- options.text.setText(text);
76
- return this;
77
- },
78
- getLabel() {
79
- return options.text?.getText ? options.text.getText() : "";
80
- },
81
- setInsetIcon(icon, atMin) {
82
- options.insetIcon.setInsetIcon(icon, atMin);
83
- return this;
84
- },
85
- setIcon(iconHtml) {
86
- if (options.icon?.setIcon)
87
- options.icon.setIcon(iconHtml);
88
- return this;
89
- },
90
- getIcon() {
91
- return options.icon?.getIcon ? options.icon.getIcon() : "";
92
- },
93
- on(event, handler) {
94
- if (options.events?.on)
95
- options.events.on(event, handler);
96
- return this;
97
- },
98
- off(event, handler) {
99
- if (options.events?.off)
100
- options.events.off(event, handler);
101
- return this;
102
- },
103
- destroy() {
104
- if (options.lifecycle?.destroy)
105
- options.lifecycle.destroy();
106
- },
107
- };
108
- };
@@ -1,379 +0,0 @@
1
- import { SLIDER_EVENTS } from "../types.js";
2
- import { arrowSign, getAxis, isRtl } from "./axis.js";
3
- import { activeElementOf } from "../../../core/dom/focus.js";
4
- const clientXOf = (e) => "touches" in e ? e.touches[0].clientX : e.clientX;
5
- const clientYOf = (e) => "touches" in e ? e.touches[0].clientY : e.clientY;
6
- export const createHandlers = (config, state, uiRenderer, eventHelpers) => {
7
- const components = state.component.components || {};
8
- const component = state.component;
9
- const pointerOf = config.orientation === "vertical" ? clientYOf : clientXOf;
10
- const rangeBounds = (isSecondHandle) => {
11
- if (!config.range || state.secondValue === null)
12
- return [state.min, state.max];
13
- return isSecondHandle ? [state.value, state.max] : [state.min, state.secondValue];
14
- };
15
- const container = component.container || components.container || null;
16
- const handle = component.handle || components.handle || null;
17
- const valueBubble = component.valueBubble || components.valueBubble || null;
18
- const secondHandle = component.secondHandle || components.secondHandle || null;
19
- const secondValueBubble = component.secondValueBubble || components.secondValueBubble || null;
20
- const { getValueFromPosition = () => 0, roundToStep = (value) => value, clamp = (value) => value, showValueBubble = () => { }, render = () => { }, } = uiRenderer;
21
- const { triggerEvent = () => ({ defaultPrevented: false }) } = eventHelpers;
22
- let hasActualDragStarted = false;
23
- let initialX = 0;
24
- const DRAG_THRESHOLD = 3;
25
- let lastFocusedHandle = null;
26
- const clearBubbleHideTimer = () => {
27
- if (state.valueHideTimer) {
28
- clearTimeout(state.valueHideTimer);
29
- state.valueHideTimer = null;
30
- }
31
- };
32
- const hideAllBubbles = () => {
33
- clearBubbleHideTimer();
34
- if (valueBubble)
35
- showValueBubble(valueBubble, false);
36
- if (secondValueBubble)
37
- showValueBubble(secondValueBubble, false);
38
- };
39
- const showActiveBubble = (bubble) => {
40
- hideAllBubbles();
41
- if (bubble && config.showValue)
42
- showValueBubble(bubble, true);
43
- };
44
- const hideActiveBubble = (bubble, delay = 0) => {
45
- clearBubbleHideTimer();
46
- if (!bubble || !config.showValue)
47
- return;
48
- if (delay > 0) {
49
- state.valueHideTimer = setTimeout(() => {
50
- showValueBubble(bubble, false);
51
- }, delay);
52
- }
53
- else {
54
- showValueBubble(bubble, false);
55
- }
56
- };
57
- const clearKeyboardFocus = () => {
58
- if (handle)
59
- handle.classList.remove(`${state.component.getClass("slider__handle")}--focused`);
60
- if (secondHandle)
61
- secondHandle.classList.remove(`${state.component.getClass("slider__handle")}--focused`);
62
- try {
63
- const focusClass = state.component.getClass("slider__handle--focused");
64
- state.component.element
65
- .querySelectorAll(`.${focusClass}`)
66
- .forEach((el) => {
67
- el.classList.remove(focusClass);
68
- });
69
- const active = activeElementOf(state.component.element);
70
- if (active &&
71
- state.component.element.contains(active) &&
72
- active.classList.contains(state.component.getClass("slider__handle"))) {
73
- active.blur();
74
- }
75
- }
76
- catch (error) {
77
- console.warn("Error clearing keyboard focus:", error);
78
- }
79
- };
80
- const handleHandleMouseDown = (e, isSecondHandle = false) => {
81
- if (!state.component ||
82
- (state.component.disabled && state.component.disabled.isDisabled())) {
83
- return;
84
- }
85
- if (e.type === "mousedown") {
86
- e.preventDefault();
87
- }
88
- e.stopPropagation();
89
- hideAllBubbles();
90
- clearKeyboardFocus();
91
- initialX = pointerOf(e);
92
- state.dragging = false;
93
- state.pressed = true;
94
- hasActualDragStarted = false;
95
- state.activeHandle = isSecondHandle ? "second" : "first";
96
- state.activeBubble = isSecondHandle ? secondValueBubble : valueBubble;
97
- showActiveBubble(state.activeBubble);
98
- document.addEventListener("mousemove", handleMouseMove);
99
- document.addEventListener("mouseup", handleMouseUp);
100
- document.addEventListener("touchmove", handleMouseMove, { passive: false });
101
- document.addEventListener("touchend", handleMouseUp);
102
- render();
103
- triggerEvent(SLIDER_EVENTS.START, e);
104
- };
105
- const handleTrackMouseDown = (e) => {
106
- if (!state.component ||
107
- (state.component.disabled && state.component.disabled.isDisabled()) ||
108
- !container) {
109
- return;
110
- }
111
- if (e.type === "mousedown") {
112
- e.preventDefault();
113
- }
114
- hideAllBubbles();
115
- clearKeyboardFocus();
116
- let isSecondHandle = false;
117
- try {
118
- const position = pointerOf(e);
119
- let newValue = getValueFromPosition(position);
120
- if (config.snapToSteps && state.step > 0)
121
- newValue = roundToStep(newValue);
122
- newValue = clamp(newValue, state.min, state.max);
123
- if (config.range && state.secondValue !== null) {
124
- const distToFirst = Math.abs(newValue - state.value);
125
- const distToSecond = Math.abs(newValue - state.secondValue);
126
- isSecondHandle = distToSecond < distToFirst;
127
- isSecondHandle
128
- ? (state.secondValue = newValue)
129
- : (state.value = newValue);
130
- }
131
- else {
132
- if (config.centered &&
133
- state.component.slider &&
134
- state.component.slider.setValue) {
135
- state.component.slider.setValue(newValue, false);
136
- }
137
- else {
138
- state.value = newValue;
139
- }
140
- }
141
- render();
142
- triggerEvent(SLIDER_EVENTS.INPUT, e);
143
- }
144
- catch (error) {
145
- console.warn("Error handling track click:", error);
146
- }
147
- state.activeHandle = isSecondHandle ? "second" : "first";
148
- state.activeBubble = isSecondHandle ? secondValueBubble : valueBubble;
149
- initialX = pointerOf(e);
150
- if (config.centered && !config.range) {
151
- showActiveBubble(state.activeBubble);
152
- document.addEventListener("mousemove", handleMouseMove);
153
- document.addEventListener("mouseup", handleMouseUp);
154
- document.addEventListener("touchmove", handleMouseMove, {
155
- passive: false,
156
- });
157
- document.addEventListener("touchend", handleMouseUp);
158
- state.pressed = false;
159
- triggerEvent(SLIDER_EVENTS.START, e);
160
- }
161
- else {
162
- state.dragging = false;
163
- state.pressed = false;
164
- hasActualDragStarted = false;
165
- showActiveBubble(state.activeBubble);
166
- document.addEventListener("mousemove", handleMouseMove);
167
- document.addEventListener("mouseup", handleMouseUp);
168
- document.addEventListener("touchmove", handleMouseMove, {
169
- passive: false,
170
- });
171
- document.addEventListener("touchend", handleMouseUp);
172
- render();
173
- triggerEvent(SLIDER_EVENTS.START, e);
174
- }
175
- };
176
- const handleMouseMove = (e) => {
177
- if (!state.activeHandle || !container)
178
- return;
179
- e.preventDefault();
180
- try {
181
- const currentX = pointerOf(e);
182
- if (!hasActualDragStarted &&
183
- Math.abs(currentX - initialX) >= DRAG_THRESHOLD) {
184
- hasActualDragStarted = true;
185
- state.dragging = true;
186
- state.component.element.classList.add(`${state.component.getClass("slider")}--dragging`);
187
- }
188
- let newValue = getValueFromPosition(currentX);
189
- if (config.snapToSteps && state.step > 0)
190
- newValue = roundToStep(newValue);
191
- newValue = clamp(newValue, state.min, state.max);
192
- const isSecondHandle = state.activeHandle === "second";
193
- if (config.range && state.secondValue !== null) {
194
- const [low, high] = rangeBounds(isSecondHandle);
195
- const clamped = Math.min(high, Math.max(low, newValue));
196
- if (isSecondHandle)
197
- state.secondValue = clamped;
198
- else
199
- state.value = clamped;
200
- }
201
- else {
202
- if (config.centered) {
203
- state.previousValue = state.value;
204
- }
205
- state.value = newValue;
206
- }
207
- render();
208
- triggerEvent(SLIDER_EVENTS.INPUT, e);
209
- }
210
- catch (error) {
211
- console.warn("Error during slider drag:", error);
212
- }
213
- };
214
- const handleMouseUp = (e) => {
215
- if (!state.activeHandle)
216
- return;
217
- e.preventDefault();
218
- state.dragging = false;
219
- state.pressed = false;
220
- hasActualDragStarted = false;
221
- state.component.element.classList.remove(`${state.component.getClass("slider")}--dragging`);
222
- hideActiveBubble(state.activeBubble, 1000);
223
- document.removeEventListener("mousemove", handleMouseMove);
224
- document.removeEventListener("mouseup", handleMouseUp);
225
- document.removeEventListener("touchmove", handleMouseMove);
226
- document.removeEventListener("touchend", handleMouseUp);
227
- state.activeHandle = null;
228
- render();
229
- triggerEvent(SLIDER_EVENTS.CHANGE, e);
230
- triggerEvent(SLIDER_EVENTS.END, e);
231
- };
232
- const handleKeyDown = (e, isSecondHandle = false) => {
233
- if (state.component.disabled && state.component.disabled.isDisabled())
234
- return;
235
- const step = state.step || 1;
236
- let newValue = isSecondHandle ? state.secondValue : state.value;
237
- if (newValue === null)
238
- return;
239
- const stepSize = e.shiftKey ? step * 10 : step;
240
- if (e.key === "Tab")
241
- return;
242
- const axis = getAxis(config, isRtl(state.component.element));
243
- const sign = arrowSign(axis);
244
- const intervals = Math.max(1, Math.floor((state.max - state.min) / step));
245
- const page = Math.min(10, Math.max(1, Math.floor(intervals / 10))) * step;
246
- const along = axis.vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowRight", "ArrowLeft"];
247
- let target;
248
- if (e.key === along[0])
249
- target = newValue + sign * stepSize;
250
- else if (e.key === along[1])
251
- target = newValue - sign * stepSize;
252
- else if (e.key === "ArrowUp" || e.key === "ArrowRight")
253
- target = newValue + stepSize;
254
- else if (e.key === "ArrowDown" || e.key === "ArrowLeft")
255
- target = newValue - stepSize;
256
- else if (e.key === "PageUp")
257
- target = newValue + (axis.vertical ? sign : 1) * page;
258
- else if (e.key === "PageDown")
259
- target = newValue - (axis.vertical ? sign : 1) * page;
260
- else if (e.key === "Home")
261
- target = state.min;
262
- else if (e.key === "End")
263
- target = state.max;
264
- else
265
- return;
266
- e.preventDefault();
267
- const [low, high] = rangeBounds(isSecondHandle);
268
- newValue = Math.min(high, Math.max(low, target));
269
- state.activeBubble = isSecondHandle ? secondValueBubble : valueBubble;
270
- showActiveBubble(state.activeBubble);
271
- if (isSecondHandle) {
272
- state.secondValue = newValue;
273
- }
274
- else {
275
- if (config.centered) {
276
- state.previousValue = state.value;
277
- }
278
- state.value = newValue;
279
- }
280
- render();
281
- triggerEvent(SLIDER_EVENTS.INPUT, e);
282
- triggerEvent(SLIDER_EVENTS.CHANGE, e);
283
- };
284
- const handleFocus = (e, isSecondHandle = false) => {
285
- if (state.component.disabled && state.component.disabled.isDisabled())
286
- return;
287
- const currentHandle = isSecondHandle ? secondHandle : handle;
288
- if (lastFocusedHandle && lastFocusedHandle !== currentHandle) {
289
- hideAllBubbles();
290
- }
291
- if (!currentHandle)
292
- return;
293
- lastFocusedHandle = currentHandle;
294
- currentHandle.classList.add(`${state.component.getClass("slider__handle")}--focused`);
295
- showActiveBubble(isSecondHandle ? secondValueBubble : valueBubble);
296
- state.activeBubble = isSecondHandle ? secondValueBubble : valueBubble;
297
- render();
298
- triggerEvent(SLIDER_EVENTS.FOCUS, e);
299
- };
300
- const handleBlur = (e, isSecondHandle = false) => {
301
- const handleElement = isSecondHandle ? secondHandle : handle;
302
- if (!handleElement)
303
- return;
304
- handleElement.classList.remove(`${state.component.getClass("slider__handle")}--focused`);
305
- render();
306
- const relatedTarget = e.relatedTarget;
307
- const otherHandle = isSecondHandle ? handle : secondHandle;
308
- if (!relatedTarget || relatedTarget !== otherHandle) {
309
- hideActiveBubble(isSecondHandle ? secondValueBubble : valueBubble, 200);
310
- }
311
- triggerEvent(SLIDER_EVENTS.BLUR, e);
312
- };
313
- const listenersFor = (isSecondHandle) => ({
314
- press: (e) => handleHandleMouseDown(e, isSecondHandle),
315
- keydown: (e) => handleKeyDown(e, isSecondHandle),
316
- focus: (e) => handleFocus(e, isSecondHandle),
317
- blur: (e) => handleBlur(e, isSecondHandle),
318
- });
319
- const handleListeners = listenersFor(false);
320
- const secondHandleListeners = listenersFor(true);
321
- const attach = (element, listeners) => {
322
- element.addEventListener("mousedown", listeners.press);
323
- element.addEventListener("touchstart", listeners.press, { passive: true });
324
- element.addEventListener("keydown", listeners.keydown);
325
- element.addEventListener("focus", listeners.focus);
326
- element.addEventListener("blur", listeners.blur);
327
- };
328
- const detach = (element, listeners) => {
329
- element.removeEventListener("mousedown", listeners.press);
330
- element.removeEventListener("touchstart", listeners.press);
331
- element.removeEventListener("keydown", listeners.keydown);
332
- element.removeEventListener("focus", listeners.focus);
333
- element.removeEventListener("blur", listeners.blur);
334
- };
335
- const setupEventListeners = () => {
336
- if (!handle || !container) {
337
- console.warn("Cannot set up event listeners: missing container or handle");
338
- return;
339
- }
340
- container.addEventListener("mousedown", handleTrackMouseDown);
341
- container.addEventListener("touchstart", handleTrackMouseDown, {
342
- passive: true,
343
- });
344
- attach(handle, handleListeners);
345
- if (config.range && secondHandle)
346
- attach(secondHandle, secondHandleListeners);
347
- };
348
- const cleanupEventListeners = () => {
349
- if (!state.component)
350
- return;
351
- if (container) {
352
- container.removeEventListener("mousedown", handleTrackMouseDown);
353
- container.removeEventListener("touchstart", handleTrackMouseDown);
354
- }
355
- if (handle)
356
- detach(handle, handleListeners);
357
- if (config.range && secondHandle)
358
- detach(secondHandle, secondHandleListeners);
359
- document.removeEventListener("mousemove", handleMouseMove);
360
- document.removeEventListener("mouseup", handleMouseUp);
361
- document.removeEventListener("touchmove", handleMouseMove);
362
- document.removeEventListener("touchend", handleMouseUp);
363
- };
364
- return {
365
- handleHandleMouseDown,
366
- handleTrackMouseDown,
367
- handleMouseMove,
368
- handleMouseUp,
369
- handleKeyDown,
370
- handleFocus,
371
- handleBlur,
372
- setupEventListeners,
373
- cleanupEventListeners,
374
- showActiveBubble,
375
- hideActiveBubble,
376
- hideAllBubbles,
377
- clearKeyboardFocus,
378
- };
379
- };
@@ -1,70 +0,0 @@
1
- import { createElement } from "../../../core/dom/create.js";
2
- export const withRange = (config) => (component) => {
3
- if (!config.range || !config.secondValue || !component.schema) {
4
- return component;
5
- }
6
- try {
7
- const min = config.min || 0;
8
- const max = config.max || 100;
9
- const secondValue = config.secondValue;
10
- const secondValuePercent = ((secondValue - min) / (max - min)) * 100;
11
- const formatter = config.valueFormatter || (val => val.toString());
12
- const isDisabled = config.disabled === true;
13
- const getClass = component.getClass;
14
- const schema = JSON.parse(JSON.stringify(component.schema));
15
- const rootClasses = schema.element.options.className || [];
16
- if (Array.isArray(rootClasses)) {
17
- rootClasses.push(getClass('slider--range'));
18
- }
19
- else {
20
- schema.element.options.className = `${rootClasses} ${getClass('slider--range')}`.trim();
21
- }
22
- const containerChildren = schema.element.children.container.children;
23
- containerChildren.secondHandle = {
24
- name: 'secondHandle',
25
- creator: createElement,
26
- options: {
27
- tag: 'div',
28
- className: getClass('slider__handle'),
29
- attributes: {
30
- role: 'slider',
31
- 'aria-valuemin': String(min),
32
- 'aria-valuemax': String(max),
33
- 'aria-valuenow': String(secondValue),
34
- 'aria-orientation': config.orientation === 'vertical' ? 'vertical' : 'horizontal',
35
- tabindex: isDisabled ? '-1' : '0',
36
- 'aria-disabled': isDisabled ? 'true' : 'false',
37
- 'data-value': String(secondValue),
38
- 'data-handle-index': '1'
39
- },
40
- style: {
41
- left: `${secondValuePercent}%`
42
- }
43
- }
44
- };
45
- containerChildren.secondValueBubble = {
46
- name: 'secondValueBubble',
47
- creator: createElement,
48
- options: {
49
- tag: 'div',
50
- className: getClass('slider__value'),
51
- attributes: {
52
- 'aria-hidden': 'true',
53
- 'data-handle-index': '1'
54
- },
55
- text: formatter(secondValue),
56
- style: {
57
- left: `${secondValuePercent}%`
58
- }
59
- }
60
- };
61
- return {
62
- ...component,
63
- schema
64
- };
65
- }
66
- catch (error) {
67
- console.warn('Error enhancing structure with range functionality:', error);
68
- return component;
69
- }
70
- };