material 3.5.3 → 3.5.4

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 (463) hide show
  1. package/dist/components/badge/api.js +156 -156
  2. package/dist/components/badge/badge.js +9 -9
  3. package/dist/components/badge/config.js +43 -43
  4. package/dist/components/badge/constants.js +13 -13
  5. package/dist/components/badge/features.js +75 -75
  6. package/dist/components/bottom-app-bar/bottom-app-bar.js +98 -98
  7. package/dist/components/bottom-app-bar/config.js +5 -5
  8. package/dist/components/bottom-app-bar/constants.js +8 -8
  9. package/dist/components/bottom-sheet/api.js +52 -52
  10. package/dist/components/bottom-sheet/bottom-sheet.js +9 -9
  11. package/dist/components/bottom-sheet/config.js +17 -17
  12. package/dist/components/bottom-sheet/constants.js +24 -24
  13. package/dist/components/bottom-sheet/features/drag.js +91 -91
  14. package/dist/components/bottom-sheet/features/state.js +148 -148
  15. package/dist/components/bottom-sheet/features/structure.js +85 -85
  16. package/dist/components/button/api.js +265 -265
  17. package/dist/components/button/button.js +15 -15
  18. package/dist/components/button/config.js +39 -39
  19. package/dist/components/button/constants.js +21 -21
  20. package/dist/components/button/features/progress.js +167 -167
  21. package/dist/components/button/features/toggle.js +31 -31
  22. package/dist/components/button-group/button-group.js +389 -389
  23. package/dist/components/button-group/config.js +106 -106
  24. package/dist/components/button-group/constants.js +62 -62
  25. package/dist/components/card/api.js +88 -88
  26. package/dist/components/card/card.js +11 -11
  27. package/dist/components/card/config.js +131 -131
  28. package/dist/components/card/constants.js +39 -39
  29. package/dist/components/card/content.js +175 -175
  30. package/dist/components/carousel/api.js +49 -49
  31. package/dist/components/carousel/arrangement.js +51 -51
  32. package/dist/components/carousel/carousel.js +2 -2
  33. package/dist/components/carousel/config.js +31 -31
  34. package/dist/components/carousel/constants.js +17 -17
  35. package/dist/components/carousel/features/scroll.js +469 -469
  36. package/dist/components/carousel/features/slides.js +125 -125
  37. package/dist/components/carousel/keylines.js +244 -244
  38. package/dist/components/carousel/strategy.js +185 -185
  39. package/dist/components/checkbox/api.js +87 -87
  40. package/dist/components/checkbox/checkbox.js +55 -55
  41. package/dist/components/checkbox/config.js +44 -44
  42. package/dist/components/checkbox/constants.js +10 -10
  43. package/dist/components/chips/api.js +157 -157
  44. package/dist/components/chips/chip/chip.js +275 -275
  45. package/dist/components/chips/chips.js +25 -25
  46. package/dist/components/chips/config.js +73 -73
  47. package/dist/components/chips/constants.js +2 -2
  48. package/dist/components/chips/features/chip-items.js +15 -15
  49. package/dist/components/chips/features/container.js +39 -39
  50. package/dist/components/chips/features/controller.js +317 -317
  51. package/dist/components/chips/features/dom.js +52 -52
  52. package/dist/components/datepicker/api.js +6 -6
  53. package/dist/components/datepicker/config.js +3 -3
  54. package/dist/components/datepicker/constants.js +39 -39
  55. package/dist/components/datepicker/datepicker.js +675 -675
  56. package/dist/components/datepicker/render.js +153 -153
  57. package/dist/components/datepicker/types.js +6 -6
  58. package/dist/components/datepicker/utils.js +157 -157
  59. package/dist/components/dialog/api.js +109 -109
  60. package/dist/components/dialog/config.js +29 -29
  61. package/dist/components/dialog/constants.js +35 -35
  62. package/dist/components/dialog/dialog.js +16 -16
  63. package/dist/components/dialog/features.js +739 -739
  64. package/dist/components/divider/config.js +4 -4
  65. package/dist/components/divider/constants.js +10 -10
  66. package/dist/components/divider/divider.js +6 -6
  67. package/dist/components/divider/features.js +72 -72
  68. package/dist/components/drawer/api.js +73 -73
  69. package/dist/components/drawer/config.js +61 -61
  70. package/dist/components/drawer/constants.js +32 -32
  71. package/dist/components/drawer/drawer.js +38 -38
  72. package/dist/components/drawer/features/headline.js +34 -34
  73. package/dist/components/drawer/features/items.js +203 -203
  74. package/dist/components/drawer/features/state.js +206 -206
  75. package/dist/components/extended-fab/api.js +92 -92
  76. package/dist/components/extended-fab/config.js +65 -65
  77. package/dist/components/extended-fab/constants.js +30 -30
  78. package/dist/components/extended-fab/extended-fab.js +51 -51
  79. package/dist/components/fab/api.js +65 -65
  80. package/dist/components/fab/config.js +46 -46
  81. package/dist/components/fab/constants.js +25 -25
  82. package/dist/components/fab/fab.js +9 -9
  83. package/dist/components/fab-menu/config.js +9 -9
  84. package/dist/components/fab-menu/constants.js +15 -15
  85. package/dist/components/fab-menu/fab-menu.js +310 -310
  86. package/dist/components/fab-menu/stagger.js +18 -18
  87. package/dist/components/icon-button/api.js +195 -195
  88. package/dist/components/icon-button/config.js +79 -79
  89. package/dist/components/icon-button/constants.js +43 -43
  90. package/dist/components/icon-button/features/toggle.js +116 -116
  91. package/dist/components/icon-button/icon-button.js +15 -15
  92. package/dist/components/list/api.js +55 -55
  93. package/dist/components/list/config.js +56 -56
  94. package/dist/components/list/constants.js +25 -25
  95. package/dist/components/list/features/anatomy.js +41 -41
  96. package/dist/components/list/features/renderer.js +136 -136
  97. package/dist/components/list/features/selection.js +118 -118
  98. package/dist/components/list/list.js +9 -9
  99. package/dist/components/loading-indicator/api.js +117 -117
  100. package/dist/components/loading-indicator/config.js +13 -13
  101. package/dist/components/loading-indicator/constants.js +23 -23
  102. package/dist/components/loading-indicator/features/motion.js +33 -33
  103. package/dist/components/loading-indicator/features/renderer.js +121 -121
  104. package/dist/components/loading-indicator/loading-indicator.js +8 -8
  105. package/dist/components/menu/api.js +76 -76
  106. package/dist/components/menu/config.js +73 -73
  107. package/dist/components/menu/constants.js +45 -45
  108. package/dist/components/menu/features/controller.js +507 -507
  109. package/dist/components/menu/features/keyboard.js +292 -292
  110. package/dist/components/menu/features/layer.js +13 -13
  111. package/dist/components/menu/features/loader.js +61 -61
  112. package/dist/components/menu/features/opener.js +288 -288
  113. package/dist/components/menu/features/position.js +279 -279
  114. package/dist/components/menu/features/registry.js +7 -7
  115. package/dist/components/menu/features/submenu.js +386 -386
  116. package/dist/components/menu/features/tasks.js +45 -45
  117. package/dist/components/menu/menu.js +16 -16
  118. package/dist/components/menu/on-demand.js +138 -138
  119. package/dist/components/navigation-bar/navigation-bar.js +144 -144
  120. package/dist/components/navigation-rail/config.js +11 -11
  121. package/dist/components/navigation-rail/constants.js +8 -8
  122. package/dist/components/navigation-rail/navigation-rail.js +237 -237
  123. package/dist/components/progress/api.js +207 -207
  124. package/dist/components/progress/config.js +137 -137
  125. package/dist/components/progress/constants.js +88 -88
  126. package/dist/components/progress/features/canvas.js +291 -291
  127. package/dist/components/progress/features/circular.js +69 -69
  128. package/dist/components/progress/features/colors.js +41 -41
  129. package/dist/components/progress/features/linear.js +96 -96
  130. package/dist/components/progress/features/motion.js +87 -87
  131. package/dist/components/progress/features/state.js +35 -35
  132. package/dist/components/progress/progress.js +11 -11
  133. package/dist/components/radios/api.js +54 -54
  134. package/dist/components/radios/config.js +19 -19
  135. package/dist/components/radios/constants.js +10 -10
  136. package/dist/components/radios/radio.js +161 -161
  137. package/dist/components/radios/radios.js +12 -12
  138. package/dist/components/search/api.js +116 -116
  139. package/dist/components/search/config.js +66 -66
  140. package/dist/components/search/constants.js +75 -75
  141. package/dist/components/search/features/input.js +238 -238
  142. package/dist/components/search/features/states.js +279 -279
  143. package/dist/components/search/features/structure.js +212 -212
  144. package/dist/components/search/features/suggestions.js +234 -234
  145. package/dist/components/search/search.js +30 -30
  146. package/dist/components/select/api.js +92 -92
  147. package/dist/components/select/config.js +46 -46
  148. package/dist/components/select/constants.js +39 -39
  149. package/dist/components/select/features.js +485 -485
  150. package/dist/components/select/select.js +17 -17
  151. package/dist/components/side-sheet/api.js +46 -46
  152. package/dist/components/side-sheet/config.js +19 -19
  153. package/dist/components/side-sheet/constants.js +22 -22
  154. package/dist/components/side-sheet/features/state.js +132 -132
  155. package/dist/components/side-sheet/features/structure.js +89 -89
  156. package/dist/components/side-sheet/side-sheet.js +8 -8
  157. package/dist/components/slider/config.js +54 -54
  158. package/dist/components/slider/constants.js +54 -54
  159. package/dist/components/slider/features/axis.js +14 -14
  160. package/dist/components/slider/features/controller.js +944 -944
  161. package/dist/components/slider/features/dom.js +104 -104
  162. package/dist/components/slider/features/states.js +83 -83
  163. package/dist/components/slider/slider.js +16 -16
  164. package/dist/components/snackbar/api.js +199 -199
  165. package/dist/components/snackbar/config.js +24 -24
  166. package/dist/components/snackbar/constants.js +41 -41
  167. package/dist/components/snackbar/features.js +115 -115
  168. package/dist/components/snackbar/layer.js +72 -72
  169. package/dist/components/snackbar/position.js +20 -20
  170. package/dist/components/snackbar/queue.js +89 -89
  171. package/dist/components/snackbar/snackbar.js +12 -12
  172. package/dist/components/split-button/api.js +137 -137
  173. package/dist/components/split-button/config.js +11 -11
  174. package/dist/components/split-button/constants.js +24 -24
  175. package/dist/components/split-button/features/buttons.js +35 -35
  176. package/dist/components/split-button/features/menu.js +12 -12
  177. package/dist/components/split-button/split-button.js +11 -11
  178. package/dist/components/switch/api.js +101 -101
  179. package/dist/components/switch/config.js +20 -20
  180. package/dist/components/switch/constants.js +29 -29
  181. package/dist/components/switch/features.js +123 -123
  182. package/dist/components/switch/switch.js +13 -13
  183. package/dist/components/tabs/api.js +104 -104
  184. package/dist/components/tabs/config.js +20 -20
  185. package/dist/components/tabs/constants.js +40 -40
  186. package/dist/components/tabs/features.js +159 -159
  187. package/dist/components/tabs/indicator.js +151 -151
  188. package/dist/components/tabs/responsive.js +59 -59
  189. package/dist/components/tabs/tab.js +218 -218
  190. package/dist/components/tabs/tabs.js +27 -27
  191. package/dist/components/tabs/utils.js +121 -121
  192. package/dist/components/text-field/api.js +212 -212
  193. package/dist/components/text-field/config.js +30 -30
  194. package/dist/components/text-field/constants.js +54 -54
  195. package/dist/components/text-field/features/counter.js +51 -51
  196. package/dist/components/text-field/features/density.js +36 -36
  197. package/dist/components/text-field/features/error.js +55 -55
  198. package/dist/components/text-field/features/field.js +30 -30
  199. package/dist/components/text-field/features/leading-icon.js +52 -52
  200. package/dist/components/text-field/features/placement.js +146 -146
  201. package/dist/components/text-field/features/prefix-text.js +48 -48
  202. package/dist/components/text-field/features/required.js +48 -48
  203. package/dist/components/text-field/features/suffix-text.js +48 -48
  204. package/dist/components/text-field/features/supporting-text.js +85 -85
  205. package/dist/components/text-field/features/trailing-icon.js +88 -88
  206. package/dist/components/text-field/text-field.js +11 -11
  207. package/dist/components/timepicker/api.js +275 -275
  208. package/dist/components/timepicker/config.js +31 -31
  209. package/dist/components/timepicker/constants.js +52 -52
  210. package/dist/components/timepicker/dial.js +164 -164
  211. package/dist/components/timepicker/render.js +400 -400
  212. package/dist/components/timepicker/timepicker.js +40 -40
  213. package/dist/components/timepicker/types.js +8 -8
  214. package/dist/components/timepicker/utils.js +67 -67
  215. package/dist/components/toolbar/config.js +35 -35
  216. package/dist/components/toolbar/constants.js +17 -17
  217. package/dist/components/toolbar/toolbar.js +188 -188
  218. package/dist/components/tooltip/api.js +309 -309
  219. package/dist/components/tooltip/config.js +32 -32
  220. package/dist/components/tooltip/constants.js +38 -38
  221. package/dist/components/tooltip/tooltip.js +20 -20
  222. package/dist/components/tooltip/types.js +15 -15
  223. package/dist/components/top-app-bar/config.js +5 -5
  224. package/dist/components/top-app-bar/constants.js +25 -25
  225. package/dist/components/top-app-bar/top-app-bar.js +158 -158
  226. package/dist/core/canvas/animation.js +30 -30
  227. package/dist/core/canvas/drawing.js +52 -52
  228. package/dist/core/canvas/resize.js +47 -47
  229. package/dist/core/canvas/utils.js +101 -101
  230. package/dist/core/compose/base.js +5 -5
  231. package/dist/core/compose/cleanup.js +47 -47
  232. package/dist/core/compose/component.js +132 -132
  233. package/dist/core/compose/features/badge.js +56 -56
  234. package/dist/core/compose/features/checkable.js +37 -37
  235. package/dist/core/compose/features/constants.js +1 -1
  236. package/dist/core/compose/features/debounce.js +39 -39
  237. package/dist/core/compose/features/disabled.js +61 -61
  238. package/dist/core/compose/features/events.js +19 -19
  239. package/dist/core/compose/features/icon.js +66 -66
  240. package/dist/core/compose/features/input.js +63 -63
  241. package/dist/core/compose/features/lifecycle.js +71 -71
  242. package/dist/core/compose/features/position.js +31 -31
  243. package/dist/core/compose/features/ripple.js +76 -76
  244. package/dist/core/compose/features/size.js +5 -5
  245. package/dist/core/compose/features/style.js +7 -7
  246. package/dist/core/compose/features/text.js +49 -49
  247. package/dist/core/compose/features/textinput.js +164 -164
  248. package/dist/core/compose/features/textlabel.js +47 -47
  249. package/dist/core/compose/features/throttle.js +39 -39
  250. package/dist/core/compose/features/track.js +24 -24
  251. package/dist/core/compose/features/variant.js +5 -5
  252. package/dist/core/compose/features/withEvents.js +48 -48
  253. package/dist/core/compose/pipe.js +4 -4
  254. package/dist/core/compose/utils/type-guards.js +6 -6
  255. package/dist/core/config/component.js +54 -54
  256. package/dist/core/config/global.js +6 -6
  257. package/dist/core/config.js +9 -9
  258. package/dist/core/dom/attributes.js +38 -38
  259. package/dist/core/dom/classes.js +74 -74
  260. package/dist/core/dom/create.js +133 -133
  261. package/dist/core/dom/direction.js +28 -28
  262. package/dist/core/dom/events.js +80 -80
  263. package/dist/core/dom/focus.js +38 -38
  264. package/dist/core/dom/form-value.js +10 -10
  265. package/dist/core/dom/html.js +7 -7
  266. package/dist/core/dom/layer.js +134 -134
  267. package/dist/core/dom/roving.js +69 -69
  268. package/dist/core/dom/utils.js +38 -38
  269. package/dist/core/navigation/destinations.js +103 -103
  270. package/dist/core/navigation/ripple.js +39 -39
  271. package/dist/core/shapes/cubic.js +55 -55
  272. package/dist/core/shapes/material.js +164 -164
  273. package/dist/core/shapes/polygon.js +198 -198
  274. package/dist/core/state/emitter.js +29 -29
  275. package/dist/core/state/events.js +30 -30
  276. package/dist/core/state/store.js +55 -55
  277. package/dist/core/theme/tokens.js +28 -28
  278. package/dist/core/utils/attributes.js +8 -8
  279. package/dist/core/utils/background.js +29 -29
  280. package/dist/core/utils/color.js +21 -21
  281. package/dist/core/utils/mobile.js +28 -28
  282. package/dist/core/utils/object.js +17 -17
  283. package/dist/core/utils/performance.js +111 -111
  284. package/dist/core/utils/theme.js +49 -49
  285. package/dist/core/utils/url.js +0 -0
  286. package/dist/core/utils/warn.js +14 -14
  287. package/dist/elements/adapter.js +51 -51
  288. package/dist/elements/badge.js +23 -23
  289. package/dist/elements/bottom-app-bar.js +32 -32
  290. package/dist/elements/bottom-sheet.js +81 -81
  291. package/dist/elements/button-group.js +151 -151
  292. package/dist/elements/button.js +40 -40
  293. package/dist/elements/card.js +89 -89
  294. package/dist/elements/carousel.js +101 -101
  295. package/dist/elements/checkbox.js +44 -44
  296. package/dist/elements/chips.js +185 -185
  297. package/dist/elements/datepicker.js +101 -101
  298. package/dist/elements/define.js +571 -571
  299. package/dist/elements/dialog.js +134 -134
  300. package/dist/elements/divider.js +16 -16
  301. package/dist/elements/drawer.js +118 -118
  302. package/dist/elements/extended-fab.js +29 -29
  303. package/dist/elements/fab-menu.js +58 -58
  304. package/dist/elements/fab.js +18 -18
  305. package/dist/elements/form-button.js +14 -14
  306. package/dist/elements/icon-button.js +42 -42
  307. package/dist/elements/index.js +87 -87
  308. package/dist/elements/lifecycle.js +8 -8
  309. package/dist/elements/list.js +162 -162
  310. package/dist/elements/loading-indicator.js +19 -19
  311. package/dist/elements/menu.js +169 -169
  312. package/dist/elements/navigation-bar.js +58 -58
  313. package/dist/elements/navigation-rail.js +110 -110
  314. package/dist/elements/preupgrade/badge.css +1 -1
  315. package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
  316. package/dist/elements/preupgrade/bottom-sheet.css +1 -1
  317. package/dist/elements/preupgrade/button-group.css +1 -1
  318. package/dist/elements/preupgrade/button.css +1 -1
  319. package/dist/elements/preupgrade/card.css +1 -1
  320. package/dist/elements/preupgrade/carousel.css +1 -1
  321. package/dist/elements/preupgrade/checkbox.css +1 -1
  322. package/dist/elements/preupgrade/chips.css +1 -1
  323. package/dist/elements/preupgrade/datepicker.css +1 -1
  324. package/dist/elements/preupgrade/dialog.css +1 -1
  325. package/dist/elements/preupgrade/divider.css +1 -1
  326. package/dist/elements/preupgrade/drawer.css +1 -1
  327. package/dist/elements/preupgrade/extended-fab.css +1 -1
  328. package/dist/elements/preupgrade/fab-menu.css +1 -1
  329. package/dist/elements/preupgrade/fab.css +1 -1
  330. package/dist/elements/preupgrade/icon-button.css +1 -1
  331. package/dist/elements/preupgrade/list.css +1 -1
  332. package/dist/elements/preupgrade/loading-indicator.css +1 -1
  333. package/dist/elements/preupgrade/menu.css +1 -1
  334. package/dist/elements/preupgrade/navigation-bar.css +1 -1
  335. package/dist/elements/preupgrade/navigation-rail.css +1 -1
  336. package/dist/elements/preupgrade/progress.css +1 -1
  337. package/dist/elements/preupgrade/radios.css +1 -1
  338. package/dist/elements/preupgrade/search.css +1 -1
  339. package/dist/elements/preupgrade/select.css +1 -1
  340. package/dist/elements/preupgrade/side-sheet.css +1 -1
  341. package/dist/elements/preupgrade/slider.css +1 -1
  342. package/dist/elements/preupgrade/snackbar.css +1 -1
  343. package/dist/elements/preupgrade/split-button.css +1 -1
  344. package/dist/elements/preupgrade/switch.css +1 -1
  345. package/dist/elements/preupgrade/tabs.css +1 -1
  346. package/dist/elements/preupgrade/text-field.css +1 -1
  347. package/dist/elements/preupgrade/timepicker.css +1 -1
  348. package/dist/elements/preupgrade/toolbar.css +1 -1
  349. package/dist/elements/preupgrade/tooltip.css +1 -1
  350. package/dist/elements/preupgrade/top-app-bar.css +1 -1
  351. package/dist/elements/preupgrade.css +1 -1
  352. package/dist/elements/preupgrade.js +0 -1
  353. package/dist/elements/progress.js +32 -32
  354. package/dist/elements/radios.js +105 -105
  355. package/dist/elements/search.js +189 -189
  356. package/dist/elements/select.js +124 -124
  357. package/dist/elements/sheet.js +49 -49
  358. package/dist/elements/side-sheet.js +53 -53
  359. package/dist/elements/slider.js +117 -117
  360. package/dist/elements/snackbar.js +45 -45
  361. package/dist/elements/split-button.js +82 -82
  362. package/dist/elements/styles.js +27 -27
  363. package/dist/elements/switch.js +43 -43
  364. package/dist/elements/tabs.js +96 -96
  365. package/dist/elements/text-field.js +117 -117
  366. package/dist/elements/timepicker.js +142 -142
  367. package/dist/elements/toolbar.js +63 -63
  368. package/dist/elements/tooltip.js +111 -111
  369. package/dist/elements/top-app-bar.js +75 -75
  370. package/dist/package.json +1 -1
  371. package/dist/react/create.js +113 -113
  372. package/dist/react/shadow.js +8 -8
  373. package/dist/solid/create.js +122 -122
  374. package/dist/solid/shadow.js +6 -6
  375. package/dist/ssr/react.js +2 -310
  376. package/dist/ssr/solid.js +1 -16
  377. package/dist/ssr/svelte.js +1 -73
  378. package/dist/ssr/vue.js +1 -71
  379. package/dist/styles/badge.css +1 -1
  380. package/dist/styles/base.css +1 -1
  381. package/dist/styles/bottom-app-bar.css +1 -1
  382. package/dist/styles/bottom-sheet.css +1 -1
  383. package/dist/styles/button-group.css +1 -1
  384. package/dist/styles/button.css +1 -1
  385. package/dist/styles/card.css +1 -1
  386. package/dist/styles/carousel.css +1 -1
  387. package/dist/styles/checkbox.css +1 -1
  388. package/dist/styles/chips.css +1 -1
  389. package/dist/styles/contrast.css +1 -1
  390. package/dist/styles/datepicker.css +1 -1
  391. package/dist/styles/dialog.css +1 -1
  392. package/dist/styles/divider.css +1 -1
  393. package/dist/styles/drawer.css +1 -1
  394. package/dist/styles/extended-fab.css +1 -1
  395. package/dist/styles/fab-menu.css +1 -1
  396. package/dist/styles/fab.css +1 -1
  397. package/dist/styles/icon-button.css +1 -1
  398. package/dist/styles/list.css +1 -1
  399. package/dist/styles/loading-indicator.css +1 -1
  400. package/dist/styles/menu.css +1 -1
  401. package/dist/styles/navigation-bar.css +1 -1
  402. package/dist/styles/navigation-rail.css +1 -1
  403. package/dist/styles/progress.css +1 -1
  404. package/dist/styles/radios.css +1 -1
  405. package/dist/styles/search.css +1 -1
  406. package/dist/styles/select.css +1 -1
  407. package/dist/styles/side-sheet.css +1 -1
  408. package/dist/styles/slider.css +1 -1
  409. package/dist/styles/snackbar.css +1 -1
  410. package/dist/styles/split-button.css +1 -1
  411. package/dist/styles/switch.css +1 -1
  412. package/dist/styles/tabs.css +1 -1
  413. package/dist/styles/text-field.css +1 -1
  414. package/dist/styles/timepicker.css +1 -1
  415. package/dist/styles/toolbar.css +1 -1
  416. package/dist/styles/tooltip.css +1 -1
  417. package/dist/styles/top-app-bar.css +1 -1
  418. package/dist/styles/typography.css +1 -1
  419. package/dist/styles/utilities.css +1 -1
  420. package/dist/styles.css +1 -1
  421. package/dist/themes/autumn-contrast.css +1 -1
  422. package/dist/themes/autumn.css +1 -1
  423. package/dist/themes/baseline-contrast.css +1 -1
  424. package/dist/themes/baseline.css +1 -1
  425. package/dist/themes/brownbeige-contrast.css +1 -1
  426. package/dist/themes/brownbeige.css +1 -1
  427. package/dist/themes/content-contrast.css +1 -1
  428. package/dist/themes/content.css +1 -1
  429. package/dist/themes/desert-contrast.css +1 -1
  430. package/dist/themes/desert.css +1 -1
  431. package/dist/themes/expressive-contrast.css +1 -1
  432. package/dist/themes/expressive.css +1 -1
  433. package/dist/themes/fidelity-contrast.css +1 -1
  434. package/dist/themes/fidelity.css +1 -1
  435. package/dist/themes/forest-contrast.css +1 -1
  436. package/dist/themes/forest.css +1 -1
  437. package/dist/themes/fruit-salad-contrast.css +1 -1
  438. package/dist/themes/fruit-salad.css +1 -1
  439. package/dist/themes/highcontrast-contrast.css +1 -1
  440. package/dist/themes/highcontrast.css +1 -1
  441. package/dist/themes/monochrome-contrast.css +1 -1
  442. package/dist/themes/monochrome.css +1 -1
  443. package/dist/themes/neutral-contrast.css +1 -1
  444. package/dist/themes/neutral.css +1 -1
  445. package/dist/themes/ocean-contrast.css +1 -1
  446. package/dist/themes/ocean.css +1 -1
  447. package/dist/themes/rainbow-contrast.css +1 -1
  448. package/dist/themes/rainbow.css +1 -1
  449. package/dist/themes/sageivory-contrast.css +1 -1
  450. package/dist/themes/sageivory.css +1 -1
  451. package/dist/themes/spring-contrast.css +1 -1
  452. package/dist/themes/spring.css +1 -1
  453. package/dist/themes/summer-contrast.css +1 -1
  454. package/dist/themes/summer.css +1 -1
  455. package/dist/themes/sunset-contrast.css +1 -1
  456. package/dist/themes/sunset.css +1 -1
  457. package/dist/themes/tealcaramel-contrast.css +1 -1
  458. package/dist/themes/tealcaramel.css +1 -1
  459. package/dist/themes/vibrant-contrast.css +1 -1
  460. package/dist/themes/vibrant.css +1 -1
  461. package/dist/vue/create.js +123 -123
  462. package/dist/vue/shadow.js +6 -6
  463. package/package.json +1 -1
@@ -8,35 +8,35 @@ import { setFormValue } from "../../../core/dom/form-value.js";
8
8
  import { activeElementOf } from "../../../core/dom/focus.js";
9
9
  import { arrowSign, bubbleTransform, getAxis, handleTransform, isRtl, lengthOf, offsetAlong, } from "./axis.js";
10
10
  const getTrackHeight = (size) => {
11
- if (typeof size === "number") {
12
- return Math.max(size, SLIDER_SIZES.XS);
13
- }
14
- if (typeof size === "string" && size in SLIDER_SIZES) {
15
- return SLIDER_SIZES[size];
16
- }
17
- return SLIDER_SIZES.XS;
11
+ if (typeof size === "number") {
12
+ return Math.max(size, SLIDER_SIZES.XS);
13
+ }
14
+ if (typeof size === "string" && size in SLIDER_SIZES) {
15
+ return SLIDER_SIZES[size];
16
+ }
17
+ return SLIDER_SIZES.XS;
18
18
  };
19
19
  const getHandleHeight = (size) => {
20
- const trackHeight = getTrackHeight(size);
21
- if (trackHeight <= SLIDER_SIZES.S) {
22
- return SLIDER_MEASUREMENTS.SMALL_HANDLE_HEIGHT;
23
- }
24
- return trackHeight + SLIDER_MEASUREMENTS.HANDLE_HEIGHT_OFFSET;
20
+ const trackHeight = getTrackHeight(size);
21
+ if (trackHeight <= SLIDER_SIZES.S) {
22
+ return SLIDER_MEASUREMENTS.SMALL_HANDLE_HEIGHT;
23
+ }
24
+ return trackHeight + SLIDER_MEASUREMENTS.HANDLE_HEIGHT_OFFSET;
25
25
  };
26
26
  const TRACK_STEPS = { 8: "small", 12: "medium", 16: "large", 28: "extra-large" };
27
27
  const getExternalTrackRadius = (size) => {
28
- const trackHeight = getTrackHeight(size);
29
- if (trackHeight <= SLIDER_SIZES.S)
30
- return 8;
31
- if (trackHeight <= SLIDER_SIZES.M)
32
- return 12;
33
- if (trackHeight <= SLIDER_SIZES.L)
34
- return 16;
35
- return 28;
28
+ const trackHeight = getTrackHeight(size);
29
+ if (trackHeight <= SLIDER_SIZES.S)
30
+ return 8;
31
+ if (trackHeight <= SLIDER_SIZES.M)
32
+ return 12;
33
+ if (trackHeight <= SLIDER_SIZES.L)
34
+ return 16;
35
+ return 28;
36
36
  };
37
37
  const trackPositionCss = (fraction, inset) => inset
38
- ? `calc(${fraction * 100}% + ${inset * (1 - 2 * fraction)}px)`
39
- : `${fraction * 100}%`;
38
+ ? `calc(${fraction * 100}% + ${inset * (1 - 2 * fraction)}px)`
39
+ : `${fraction * 100}%`;
40
40
  const A0 = { f: 0, p: 0 };
41
41
  const A1 = { f: 1, p: 0 };
42
42
  const ap = (f, p) => ({ f, p });
@@ -45,935 +45,935 @@ const sub = (a, b) => ap(a.f - b.f, a.p - b.p);
45
45
  const px = (p) => ap(0, p);
46
46
  const fractionOf = (value, min, max) => min === max ? 0 : Math.min(1, Math.max(0, (value - min) / (max - min)));
47
47
  const alongCss = (a, unit = "%") => {
48
- const pct = Math.round(a.f * 1e8) / 1e6;
49
- const p = Math.round(a.p * 1e6) / 1e6;
50
- if (pct === 0)
51
- return `${p}px`;
52
- if (p === 0)
53
- return `${pct}${unit}`;
54
- return `calc(${pct}${unit} ${p < 0 ? "-" : "+"} ${Math.abs(p)}px)`;
48
+ const pct = Math.round(a.f * 1e8) / 1e6;
49
+ const p = Math.round(a.p * 1e6) / 1e6;
50
+ if (pct === 0)
51
+ return `${p}px`;
52
+ if (p === 0)
53
+ return `${pct}${unit}`;
54
+ return `calc(${pct}${unit} ${p < 0 ? "-" : "+"} ${Math.abs(p)}px)`;
55
55
  };
56
56
  const INSET_ICON_PADDING = 10;
57
57
  const HANDLE_WIDTH = 4;
58
58
  const NARROW_HANDLE_WIDTH = 2;
59
59
  export const withTracks = (config) => (component) => {
60
- const container = component.container;
61
- const element = (className, parent) => {
62
- const node = document.createElement("div");
63
- node.className = component.getClass(className);
64
- parent.append(node);
65
- return node;
66
- };
67
- let axis = getAxis(config);
68
- const opposite = { left: "right", right: "left", top: "bottom", bottom: "top" };
69
- const at = (node, position) => {
70
- node.style[opposite[axis.start]] = "";
71
- node.style[axis.start] = position;
72
- };
73
- const visual = element("slider__visual", container);
74
- visual.setAttribute("aria-hidden", "true");
75
- const track = element("slider__track", visual);
76
- const segments = Array.from({ length: 3 }, () => element("slider__segment", track));
77
- const ticks = [element("slider__ticks", visual), element("slider__ticks", visual)];
78
- ticks[1].classList.add(component.getClass("slider__ticks--active"));
79
- const dots = [element("slider__dot", visual), element("slider__dot", visual)];
80
- dots[0].classList.add(component.getClass("slider__dot--start"));
81
- const insetIcon = element("slider__inset-icon", visual);
82
- insetIcon.hidden = true;
83
- let insetMarkup = { icon: config.insetIcon ?? "", atMin: config.insetIconAtMin ?? "" };
84
- let shownMarkup = null;
85
- let destroyed = false;
86
- let size = config.size ?? "XS";
87
- let state = {
88
- value: config.value ?? 0, secondValue: config.secondValue ?? null,
89
- min: config.min ?? 0, max: config.max ?? 100, step: config.step ?? 1,
90
- };
91
- const narrowed = (which) => {
92
- const handle = which === "first" ? component.handle : component.secondHandle;
93
- const pressed = !!state.pressed && (state.activeHandle === which || (!config.range && which === "first"));
94
- return pressed || !!handle?.classList.contains(component.getClass("slider__handle--focused"));
95
- };
96
- const render = (next) => {
97
- if (destroyed)
98
- return;
99
- if (next)
100
- state = { ...next };
101
- axis = getAxis(config, isRtl(component.element));
102
- const width = lengthOf(container.getBoundingClientRect(), axis) || 0;
103
- const corner = getExternalTrackRadius(size);
104
- const inset = config.ticks ? corner : 0;
105
- const fraction = (value) => fractionOf(value, state.min, state.max);
106
- const atValue = (value) => {
107
- const f = fraction(value);
108
- return ap(f, inset * (1 - 2 * f));
109
- };
110
- const cmp = (a, b) => width > 0 ? a.f * width + a.p - (b.f * width + b.p) : (a.f - b.f) || (a.p - b.p);
111
- const gapOf = (which) => px((narrowed(which) ? NARROW_HANDLE_WIDTH : HANDLE_WIDTH) / 2 + SLIDER_MEASUREMENTS.HANDLE_GAP);
112
- const firstGap = gapOf("first");
113
- const secondGap = gapOf("second");
114
- const first = atValue(state.value);
115
- const second = atValue(state.secondValue ?? state.max);
116
- let parts;
117
- let activeStart, activeEnd;
118
- if (config.centered) {
119
- const zero = atValue(Math.min(state.max, Math.max(state.min, 0)));
120
- if (cmp(first, zero) >= 0) {
121
- activeStart = zero;
122
- activeEnd = first;
123
- parts = [[A0, sub(zero, firstGap), false], [zero, sub(first, firstGap), true], [add(first, firstGap), A1, false]];
124
- }
125
- else {
126
- activeStart = first;
127
- activeEnd = zero;
128
- parts = [[A0, sub(first, firstGap), false], [add(first, firstGap), zero, true], [add(zero, firstGap), A1, false]];
129
- }
130
- }
131
- else if (config.range && state.secondValue !== null) {
132
- const lowIsFirst = cmp(first, second) <= 0;
133
- const low = lowIsFirst ? first : second;
134
- const high = lowIsFirst ? second : first;
135
- const lowGap = lowIsFirst ? firstGap : secondGap;
136
- const highGap = lowIsFirst ? secondGap : firstGap;
137
- activeStart = low;
138
- activeEnd = high;
139
- parts = [[A0, sub(low, lowGap), false], [add(low, lowGap), sub(high, highGap), true], [add(high, highGap), A1, false]];
140
- }
141
- else {
142
- activeStart = A0;
143
- activeEnd = first;
144
- parts = [[A0, A0, false], [A0, sub(first, firstGap), true], [add(first, firstGap), A1, false]];
145
- }
146
- const standard = !config.centered && !(config.range && state.secondValue !== null);
147
- const short = (len) => width > 0 ? len.f * width + len.p <= corner : len.f < 0 || (len.f === 0 && len.p <= corner);
148
- parts.forEach((part, index) => {
149
- const meetsEnd = index !== 1 || standard;
150
- if (meetsEnd && short(sub(part[1], part[0])))
151
- part[1] = part[0];
152
- });
153
- segments.forEach((segment, index) => {
154
- const [start, end, active] = parts[index] ?? [A0, A0, false];
155
- const len = sub(end, start);
156
- const drawn = (width > 0 ? len.f * width + len.p < 0 : len.f < 0 || (len.f === 0 && len.p < 0)) ? A0 : len;
157
- at(segment, alongCss(start));
158
- segment.style[axis.size] = alongCss(drawn);
159
- segment.classList.toggle(component.getClass("slider__segment--active"), active);
160
- });
161
- dots[0].hidden = !!config.ticks || standard || cmp(parts[0][1], parts[0][0]) <= 0;
162
- dots[1].hidden = !!config.ticks || cmp(parts[2][1], parts[2][0]) <= 0;
163
- at(dots[0], alongCss(px(corner - 2)));
164
- at(dots[1], alongCss(ap(1, -(corner + 2))));
165
- placeInsetIcon(parts, width);
166
- const discrete = !!config.ticks && state.step > 0 && state.max > state.min;
167
- ticks.forEach(tick => { tick.hidden = !discrete; });
168
- if (discrete) {
169
- const stepF = state.step / (state.max - state.min);
170
- const repeat = `max(0.01px, ${alongCss(ap(stepF, -2 * inset * stepF))})`;
171
- const offset = alongCss(ap(-stepF / 2, inset * (1 + stepF)), axis.vertical ? "cqh" : "cqw");
172
- const last = atValue(state.min + Math.floor((state.max - state.min) / state.step) * state.step);
173
- const holes = [[sub(first, firstGap), add(first, firstGap)]];
174
- if (config.range && state.secondValue !== null)
175
- holes.push([sub(second, secondGap), add(second, secondGap)]);
176
- const mask = (intervals) => {
177
- const merged = [];
178
- for (const [start, end] of [...intervals].sort((a, b) => cmp(a[0], b[0]))) {
179
- const previous = merged[merged.length - 1];
180
- if (previous && cmp(start, previous[1]) <= 0) {
181
- if (cmp(end, previous[1]) > 0)
182
- previous[1] = end;
183
- }
184
- else
185
- merged.push([start, end]);
186
- }
187
- const stops = merged.flatMap(([start, end]) => [`black ${alongCss(start)}`, `transparent ${alongCss(start)}`, `transparent ${alongCss(end)}`, `black ${alongCss(end)}`]);
188
- const direction = { left: "to right", right: "to left", top: "to bottom", bottom: "to top" }[axis.start];
189
- return stops.length ? `linear-gradient(${direction}, black 0px, ${stops.join(",")}, black 100%)` : "none";
190
- };
191
- ticks.forEach((tick, index) => {
192
- tick.style.backgroundSize = axis.vertical ? `100% ${repeat}` : `${repeat} 100%`;
193
- tick.style.backgroundPosition = axis.vertical
194
- ? `center ${axis.start} ${offset}`
195
- : `${axis.start} ${offset} center`;
196
- tick.style.maskImage = mask(index === 0 ? [...holes, [sub(activeStart, px(2)), add(activeEnd, px(2))]] : holes);
197
- });
198
- const clip = (fromStart, fromEnd) => ({
199
- left: `inset(0 ${fromEnd} 0 ${fromStart})`,
200
- right: `inset(0 ${fromStart} 0 ${fromEnd})`,
201
- top: `inset(${fromStart} 0 ${fromEnd} 0)`,
202
- bottom: `inset(${fromEnd} 0 ${fromStart} 0)`,
203
- })[axis.start];
204
- const fromEnd = (edge) => `max(0px, calc(100% - ${alongCss(edge)}))`;
205
- ticks[0].style.clipPath = clip("0px", fromEnd(add(last, px(2))));
206
- ticks[1].style.clipPath = clip(`max(0px, ${alongCss(sub(activeStart, px(2)))})`, `max(0px, calc(100% - min(${alongCss(add(last, px(2)))}, ${alongCss(add(activeEnd, px(2)))})))`);
207
- }
208
- };
209
- function placeInsetIcon(parts, width) {
210
- const trackHeight = getTrackHeight(size);
211
- const eligible = !config.range && !config.centered && trackHeight >= SLIDER_SIZES.M;
212
- const markup = state.value <= state.min && insetMarkup.atMin ? insetMarkup.atMin : insetMarkup.icon;
213
- const iconSize = trackHeight >= SLIDER_SIZES.XL ? 32 : 24;
214
- const room = iconSize + 2 * INSET_ICON_PADDING;
215
- const fits = (len) => width > 0 ? len.f * width + len.p >= room : len.f > 0 || (len.f === 0 && len.p >= room);
216
- const onActive = fits(sub(parts[1][1], parts[1][0]));
217
- const onInactive = !onActive && fits(sub(parts[2][1], parts[2][0]));
218
- insetIcon.hidden = !eligible || !markup || (!onActive && !onInactive);
219
- if (insetIcon.hidden)
220
- return;
221
- if (markup !== shownMarkup) {
222
- setHTML(insetIcon, markup);
223
- shownMarkup = markup;
224
- }
225
- insetIcon.style.width = insetIcon.style.height = `${iconSize}px`;
226
- at(insetIcon, alongCss(add(onActive ? parts[1][0] : parts[2][0], px(INSET_ICON_PADDING))));
227
- insetIcon.classList.toggle(component.getClass("slider__inset-icon--inactive"), onInactive);
228
- }
229
- component.setInsetIcon = (icon, atMin = "") => {
230
- if (destroyed)
231
- return;
232
- insetMarkup = { icon, atMin };
233
- render();
234
- };
235
- const setSize = (next) => {
236
- if (destroyed)
237
- return;
238
- const previous = sliderSizeClass(size), current = sliderSizeClass(next);
239
- if (previous)
240
- component.element.classList.remove(previous);
241
- if (current)
242
- component.element.classList.add(current);
243
- size = next;
244
- const handleHeight = getHandleHeight(size);
245
- container.style[axis.cross] = `${Math.max(handleHeight, SLIDER_MEASUREMENTS.MIN_HEIGHT)}px`;
246
- track.style[axis.cross] = `${getTrackHeight(size)}px`;
247
- track.style.borderRadius = cornerToken(TRACK_STEPS[getExternalTrackRadius(size)], getExternalTrackRadius(size), PREFIX);
248
- for (const handle of [component.handle, component.secondHandle]) {
249
- if (handle)
250
- handle.style[axis.cross] = `${handleHeight}px`;
251
- }
252
- component.element.style.setProperty(`--${PREFIX}-slider-handle-height`, `${handleHeight}px`);
253
- render();
254
- };
255
- component.renderTracks = render;
256
- component.setSize = setSize;
257
- component.getSize = () => size;
258
- const setColor = component.appearance.setColor;
259
- component.appearance.setColor = (color) => {
260
- if (destroyed)
261
- return;
262
- setColor.call(component.appearance, color);
263
- config.color = color;
264
- };
265
- setSize(size);
266
- const resize = () => {
267
- if (!destroyed)
268
- render();
269
- };
270
- const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
271
- if (observer)
272
- observer.observe(container);
273
- else
274
- window.addEventListener("resize", resize);
275
- const destroy = component.lifecycle.destroy;
276
- component.lifecycle.destroy = () => {
277
- if (destroyed)
278
- return;
279
- destroyed = true;
280
- observer?.disconnect();
281
- if (!observer)
282
- window.removeEventListener("resize", resize);
283
- destroy.call(component.lifecycle);
284
- };
285
- return component;
60
+ const container = component.container;
61
+ const element = (className, parent) => {
62
+ const node = document.createElement("div");
63
+ node.className = component.getClass(className);
64
+ parent.append(node);
65
+ return node;
66
+ };
67
+ let axis = getAxis(config);
68
+ const opposite = { left: "right", right: "left", top: "bottom", bottom: "top" };
69
+ const at = (node, position) => {
70
+ node.style[opposite[axis.start]] = "";
71
+ node.style[axis.start] = position;
72
+ };
73
+ const visual = element("slider__visual", container);
74
+ visual.setAttribute("aria-hidden", "true");
75
+ const track = element("slider__track", visual);
76
+ const segments = Array.from({ length: 3 }, () => element("slider__segment", track));
77
+ const ticks = [element("slider__ticks", visual), element("slider__ticks", visual)];
78
+ ticks[1].classList.add(component.getClass("slider__ticks--active"));
79
+ const dots = [element("slider__dot", visual), element("slider__dot", visual)];
80
+ dots[0].classList.add(component.getClass("slider__dot--start"));
81
+ const insetIcon = element("slider__inset-icon", visual);
82
+ insetIcon.hidden = true;
83
+ let insetMarkup = { icon: config.insetIcon ?? "", atMin: config.insetIconAtMin ?? "" };
84
+ let shownMarkup = null;
85
+ let destroyed = false;
86
+ let size = config.size ?? "XS";
87
+ let state = {
88
+ value: config.value ?? 0, secondValue: config.secondValue ?? null,
89
+ min: config.min ?? 0, max: config.max ?? 100, step: config.step ?? 1,
90
+ };
91
+ const narrowed = (which) => {
92
+ const handle = which === "first" ? component.handle : component.secondHandle;
93
+ const pressed = !!state.pressed && (state.activeHandle === which || (!config.range && which === "first"));
94
+ return pressed || !!handle?.classList.contains(component.getClass("slider__handle--focused"));
95
+ };
96
+ const render = (next) => {
97
+ if (destroyed)
98
+ return;
99
+ if (next)
100
+ state = { ...next };
101
+ axis = getAxis(config, isRtl(component.element));
102
+ const width = lengthOf(container.getBoundingClientRect(), axis) || 0;
103
+ const corner = getExternalTrackRadius(size);
104
+ const inset = config.ticks ? corner : 0;
105
+ const fraction = (value) => fractionOf(value, state.min, state.max);
106
+ const atValue = (value) => {
107
+ const f = fraction(value);
108
+ return ap(f, inset * (1 - 2 * f));
109
+ };
110
+ const cmp = (a, b) => width > 0 ? a.f * width + a.p - (b.f * width + b.p) : (a.f - b.f) || (a.p - b.p);
111
+ const gapOf = (which) => px((narrowed(which) ? NARROW_HANDLE_WIDTH : HANDLE_WIDTH) / 2 + SLIDER_MEASUREMENTS.HANDLE_GAP);
112
+ const firstGap = gapOf("first");
113
+ const secondGap = gapOf("second");
114
+ const first = atValue(state.value);
115
+ const second = atValue(state.secondValue ?? state.max);
116
+ let parts;
117
+ let activeStart, activeEnd;
118
+ if (config.centered) {
119
+ const zero = atValue(Math.min(state.max, Math.max(state.min, 0)));
120
+ if (cmp(first, zero) >= 0) {
121
+ activeStart = zero;
122
+ activeEnd = first;
123
+ parts = [[A0, sub(zero, firstGap), false], [zero, sub(first, firstGap), true], [add(first, firstGap), A1, false]];
124
+ }
125
+ else {
126
+ activeStart = first;
127
+ activeEnd = zero;
128
+ parts = [[A0, sub(first, firstGap), false], [add(first, firstGap), zero, true], [add(zero, firstGap), A1, false]];
129
+ }
130
+ }
131
+ else if (config.range && state.secondValue !== null) {
132
+ const lowIsFirst = cmp(first, second) <= 0;
133
+ const low = lowIsFirst ? first : second;
134
+ const high = lowIsFirst ? second : first;
135
+ const lowGap = lowIsFirst ? firstGap : secondGap;
136
+ const highGap = lowIsFirst ? secondGap : firstGap;
137
+ activeStart = low;
138
+ activeEnd = high;
139
+ parts = [[A0, sub(low, lowGap), false], [add(low, lowGap), sub(high, highGap), true], [add(high, highGap), A1, false]];
140
+ }
141
+ else {
142
+ activeStart = A0;
143
+ activeEnd = first;
144
+ parts = [[A0, A0, false], [A0, sub(first, firstGap), true], [add(first, firstGap), A1, false]];
145
+ }
146
+ const standard = !config.centered && !(config.range && state.secondValue !== null);
147
+ const short = (len) => width > 0 ? len.f * width + len.p <= corner : len.f < 0 || (len.f === 0 && len.p <= corner);
148
+ parts.forEach((part, index) => {
149
+ const meetsEnd = index !== 1 || standard;
150
+ if (meetsEnd && short(sub(part[1], part[0])))
151
+ part[1] = part[0];
152
+ });
153
+ segments.forEach((segment, index) => {
154
+ const [start, end, active] = parts[index] ?? [A0, A0, false];
155
+ const len = sub(end, start);
156
+ const drawn = (width > 0 ? len.f * width + len.p < 0 : len.f < 0 || (len.f === 0 && len.p < 0)) ? A0 : len;
157
+ at(segment, alongCss(start));
158
+ segment.style[axis.size] = alongCss(drawn);
159
+ segment.classList.toggle(component.getClass("slider__segment--active"), active);
160
+ });
161
+ dots[0].hidden = !!config.ticks || standard || cmp(parts[0][1], parts[0][0]) <= 0;
162
+ dots[1].hidden = !!config.ticks || cmp(parts[2][1], parts[2][0]) <= 0;
163
+ at(dots[0], alongCss(px(corner - 2)));
164
+ at(dots[1], alongCss(ap(1, -(corner + 2))));
165
+ placeInsetIcon(parts, width);
166
+ const discrete = !!config.ticks && state.step > 0 && state.max > state.min;
167
+ ticks.forEach(tick => { tick.hidden = !discrete; });
168
+ if (discrete) {
169
+ const stepF = state.step / (state.max - state.min);
170
+ const repeat = `max(0.01px, ${alongCss(ap(stepF, -2 * inset * stepF))})`;
171
+ const offset = alongCss(ap(-stepF / 2, inset * (1 + stepF)), axis.vertical ? "cqh" : "cqw");
172
+ const last = atValue(state.min + Math.floor((state.max - state.min) / state.step) * state.step);
173
+ const holes = [[sub(first, firstGap), add(first, firstGap)]];
174
+ if (config.range && state.secondValue !== null)
175
+ holes.push([sub(second, secondGap), add(second, secondGap)]);
176
+ const mask = (intervals) => {
177
+ const merged = [];
178
+ for (const [start, end] of [...intervals].sort((a, b) => cmp(a[0], b[0]))) {
179
+ const previous = merged[merged.length - 1];
180
+ if (previous && cmp(start, previous[1]) <= 0) {
181
+ if (cmp(end, previous[1]) > 0)
182
+ previous[1] = end;
183
+ }
184
+ else
185
+ merged.push([start, end]);
186
+ }
187
+ const stops = merged.flatMap(([start, end]) => [`black ${alongCss(start)}`, `transparent ${alongCss(start)}`, `transparent ${alongCss(end)}`, `black ${alongCss(end)}`]);
188
+ const direction = { left: "to right", right: "to left", top: "to bottom", bottom: "to top" }[axis.start];
189
+ return stops.length ? `linear-gradient(${direction}, black 0px, ${stops.join(",")}, black 100%)` : "none";
190
+ };
191
+ ticks.forEach((tick, index) => {
192
+ tick.style.backgroundSize = axis.vertical ? `100% ${repeat}` : `${repeat} 100%`;
193
+ tick.style.backgroundPosition = axis.vertical
194
+ ? `center ${axis.start} ${offset}`
195
+ : `${axis.start} ${offset} center`;
196
+ tick.style.maskImage = mask(index === 0 ? [...holes, [sub(activeStart, px(2)), add(activeEnd, px(2))]] : holes);
197
+ });
198
+ const clip = (fromStart, fromEnd) => ({
199
+ left: `inset(0 ${fromEnd} 0 ${fromStart})`,
200
+ right: `inset(0 ${fromStart} 0 ${fromEnd})`,
201
+ top: `inset(${fromStart} 0 ${fromEnd} 0)`,
202
+ bottom: `inset(${fromEnd} 0 ${fromStart} 0)`,
203
+ })[axis.start];
204
+ const fromEnd = (edge) => `max(0px, calc(100% - ${alongCss(edge)}))`;
205
+ ticks[0].style.clipPath = clip("0px", fromEnd(add(last, px(2))));
206
+ ticks[1].style.clipPath = clip(`max(0px, ${alongCss(sub(activeStart, px(2)))})`, `max(0px, calc(100% - min(${alongCss(add(last, px(2)))}, ${alongCss(add(activeEnd, px(2)))})))`);
207
+ }
208
+ };
209
+ function placeInsetIcon(parts, width) {
210
+ const trackHeight = getTrackHeight(size);
211
+ const eligible = !config.range && !config.centered && trackHeight >= SLIDER_SIZES.M;
212
+ const markup = state.value <= state.min && insetMarkup.atMin ? insetMarkup.atMin : insetMarkup.icon;
213
+ const iconSize = trackHeight >= SLIDER_SIZES.XL ? 32 : 24;
214
+ const room = iconSize + 2 * INSET_ICON_PADDING;
215
+ const fits = (len) => width > 0 ? len.f * width + len.p >= room : len.f > 0 || (len.f === 0 && len.p >= room);
216
+ const onActive = fits(sub(parts[1][1], parts[1][0]));
217
+ const onInactive = !onActive && fits(sub(parts[2][1], parts[2][0]));
218
+ insetIcon.hidden = !eligible || !markup || (!onActive && !onInactive);
219
+ if (insetIcon.hidden)
220
+ return;
221
+ if (markup !== shownMarkup) {
222
+ setHTML(insetIcon, markup);
223
+ shownMarkup = markup;
224
+ }
225
+ insetIcon.style.width = insetIcon.style.height = `${iconSize}px`;
226
+ at(insetIcon, alongCss(add(onActive ? parts[1][0] : parts[2][0], px(INSET_ICON_PADDING))));
227
+ insetIcon.classList.toggle(component.getClass("slider__inset-icon--inactive"), onInactive);
228
+ }
229
+ component.setInsetIcon = (icon, atMin = "") => {
230
+ if (destroyed)
231
+ return;
232
+ insetMarkup = { icon, atMin };
233
+ render();
234
+ };
235
+ const setSize = (next) => {
236
+ if (destroyed)
237
+ return;
238
+ const previous = sliderSizeClass(size), current = sliderSizeClass(next);
239
+ if (previous)
240
+ component.element.classList.remove(previous);
241
+ if (current)
242
+ component.element.classList.add(current);
243
+ size = next;
244
+ const handleHeight = getHandleHeight(size);
245
+ container.style[axis.cross] = `${Math.max(handleHeight, SLIDER_MEASUREMENTS.MIN_HEIGHT)}px`;
246
+ track.style[axis.cross] = `${getTrackHeight(size)}px`;
247
+ track.style.borderRadius = cornerToken(TRACK_STEPS[getExternalTrackRadius(size)], getExternalTrackRadius(size), PREFIX);
248
+ for (const handle of [component.handle, component.secondHandle]) {
249
+ if (handle)
250
+ handle.style[axis.cross] = `${handleHeight}px`;
251
+ }
252
+ component.element.style.setProperty(`--${PREFIX}-slider-handle-height`, `${handleHeight}px`);
253
+ render();
254
+ };
255
+ component.renderTracks = render;
256
+ component.setSize = setSize;
257
+ component.getSize = () => size;
258
+ const setColor = component.appearance.setColor;
259
+ component.appearance.setColor = (color) => {
260
+ if (destroyed)
261
+ return;
262
+ setColor.call(component.appearance, color);
263
+ config.color = color;
264
+ };
265
+ setSize(size);
266
+ const resize = () => {
267
+ if (!destroyed)
268
+ render();
269
+ };
270
+ const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
271
+ if (observer)
272
+ observer.observe(container);
273
+ else
274
+ window.addEventListener("resize", resize);
275
+ const destroy = component.lifecycle.destroy;
276
+ component.lifecycle.destroy = () => {
277
+ if (destroyed)
278
+ return;
279
+ destroyed = true;
280
+ observer?.disconnect();
281
+ if (!observer)
282
+ window.removeEventListener("resize", resize);
283
+ destroy.call(component.lifecycle);
284
+ };
285
+ return component;
286
286
  };
287
287
  const clientXOf = (e) => "touches" in e ? e.touches[0].clientX : e.clientX;
288
288
  const clientYOf = (e) => "touches" in e ? e.touches[0].clientY : e.clientY;
289
289
  export const withController = (config, getComponent) => (component) => {
290
- const max = config.max !== undefined ? config.max : 100;
291
- const state = {
292
- value: config.value !== undefined ? config.value : 0,
293
- secondValue: config.secondValue !== undefined
294
- ? config.secondValue
295
- : config.range
296
- ? max
297
- : null,
298
- min: config.min !== undefined ? config.min : 0,
299
- max,
300
- step: config.step !== undefined ? config.step : 1,
301
- dragging: false,
302
- pressed: false,
303
- activeHandle: null,
304
- activeBubble: null,
305
- valueHideTimer: null,
306
- };
307
- const emitEvent = (eventName, originalEvent = null) => {
308
- const eventData = {
309
- slider: getComponent(),
310
- value: state.value,
311
- secondValue: state.secondValue,
312
- originalEvent,
313
- preventDefault: () => {
314
- eventData.defaultPrevented = true;
315
- },
316
- defaultPrevented: false,
317
- };
318
- component.emit(eventName, eventData);
319
- return eventData;
320
- };
321
- const axisNow = () => getAxis(config, isRtl(component.element));
322
- const inset = () => config.ticks ? getExternalTrackRadius(component.getSize?.() ?? config.size) : 0;
323
- const visualPosition = (value) => trackPositionCss(fractionOf(value, state.min, state.max), inset());
324
- const getValueFromPosition = (position) => {
325
- const { handle, container } = component;
326
- if (!handle || !container)
327
- return state.min;
328
- try {
329
- const containerRect = container.getBoundingClientRect();
330
- const range = state.max - state.min;
331
- const edge = inset();
332
- const axis = axisNow();
333
- const span = lengthOf(containerRect, axis) - 2 * edge;
334
- const along = offsetAlong(position, containerRect, axis) - edge;
335
- const fraction = span > 0 ? Math.max(0, Math.min(1, along / span)) : 0;
336
- return state.min + fraction * range;
337
- }
338
- catch (error) {
339
- console.warn("Error calculating value from position:", error);
340
- return state.min;
341
- }
342
- };
343
- const roundToStep = (value) => {
344
- const step = state.step;
345
- if (!step || step <= 0)
346
- return value;
347
- const steps = Math.round((value - state.min) / step);
348
- return state.min + steps * step;
349
- };
350
- const clamp = (value, min = state.min, max = state.max) => Math.min(Math.max(value, min), max);
351
- const updateHandlePositions = () => {
352
- const { handle, container, valueBubble, secondHandle, secondValueBubble } = component;
353
- if (!handle || !container)
354
- return;
355
- const axis = axisNow();
356
- const place = (element, value, transform) => {
357
- if (axis.vertical)
358
- element.style.left = "";
359
- if (axis.start === "right")
360
- element.style.left = "auto";
361
- if (axis.start === "left")
362
- element.style.right = "";
363
- element.style[axis.start] = visualPosition(value);
364
- element.style.transform = transform;
365
- };
366
- place(handle, state.value, handleTransform(axis));
367
- if (valueBubble)
368
- place(valueBubble, state.value, bubbleTransform(axis));
369
- if (config.range && secondHandle && state.secondValue !== null) {
370
- place(secondHandle, state.secondValue, handleTransform(axis));
371
- if (secondValueBubble)
372
- place(secondValueBubble, state.secondValue, bubbleTransform(axis));
373
- }
374
- updateHandleAria(handle, state.value);
375
- if (config.range && secondHandle && state.secondValue !== null) {
376
- updateHandleAria(secondHandle, state.secondValue);
377
- handle.setAttribute("aria-valuemax", String(state.secondValue));
378
- secondHandle.setAttribute("aria-valuemin", String(state.value));
379
- }
380
- };
381
- const updateHandleAria = (handleElement, value) => {
382
- handleElement.setAttribute("aria-valuenow", String(value));
383
- if (config.valueFormatter &&
384
- config.valueFormatter !== defaultConfig.valueFormatter) {
385
- handleElement.setAttribute("aria-valuetext", config.valueFormatter(value));
386
- }
387
- };
388
- const updateValueBubbles = () => {
389
- const { valueBubble, secondValueBubble } = component;
390
- if (!valueBubble)
391
- return;
392
- const formatter = config.valueFormatter || ((value) => value.toString());
393
- valueBubble.textContent = formatter(state.value);
394
- if (config.range && secondValueBubble && state.secondValue !== null) {
395
- secondValueBubble.textContent = formatter(state.secondValue);
396
- }
397
- };
398
- const showValueBubble = (bubbleElement, show) => {
399
- if (!bubbleElement || !config.showValue)
400
- return;
401
- const bubbleClass = component.getClass("slider__value");
402
- bubbleElement.classList[show ? "add" : "remove"](`${bubbleClass}--visible`);
403
- };
404
- const SETTLE_MS = 450;
405
- let rendered = null;
406
- let settleTimer = null;
407
- const settle = () => {
408
- const settling = component.getClass("slider--settling");
409
- const changed = rendered !== null &&
410
- (rendered.value !== state.value || rendered.secondValue !== state.secondValue);
411
- rendered = { value: state.value, secondValue: state.secondValue };
412
- if (state.dragging) {
413
- if (settleTimer !== null)
414
- clearTimeout(settleTimer);
415
- settleTimer = null;
416
- component.element.classList.remove(settling);
417
- return;
418
- }
419
- if (!changed)
420
- return;
421
- component.element.classList.add(settling);
422
- if (settleTimer !== null)
423
- clearTimeout(settleTimer);
424
- settleTimer = setTimeout(() => {
425
- settleTimer = null;
426
- component.element.classList.remove(settling);
427
- }, SETTLE_MS);
428
- };
429
- const render = () => {
430
- try {
431
- settle();
432
- updateHandlePositions();
433
- updateValueBubbles();
434
- if (component.formFields) {
435
- setFormValue(component.formFields[0], String(state.value));
436
- if (state.secondValue !== null) {
437
- setFormValue(component.formFields[1], String(state.secondValue));
438
- }
439
- }
440
- if (component.renderTracks) {
441
- component.renderTracks(state);
442
- }
443
- }
444
- catch (error) {
445
- console.warn("Error rendering UI:", error);
446
- }
447
- };
448
- const pointerOf = config.orientation === "vertical" ? clientYOf : clientXOf;
449
- const rangeBounds = (isSecondHandle) => !config.range || state.secondValue === null
450
- ? [state.min, state.max]
451
- : isSecondHandle
452
- ? [state.value, state.max]
453
- : [state.min, state.secondValue];
454
- const { container, handle, valueBubble, secondHandle, secondValueBubble } = component;
455
- const handleFor = (second) => (second ? secondHandle : handle) ?? null;
456
- const bubbleFor = (second) => (second ? secondValueBubble : valueBubble) ?? null;
457
- const disabled = () => !!component.disabled?.isDisabled();
458
- let hasActualDragStarted = false;
459
- let initialX = 0;
460
- const DRAG_THRESHOLD = 3;
461
- let lastFocusedHandle = null;
462
- const clearBubbleHideTimer = () => {
463
- if (state.valueHideTimer) {
464
- clearTimeout(state.valueHideTimer);
465
- state.valueHideTimer = null;
466
- }
467
- };
468
- const hideAllBubbles = () => {
469
- clearBubbleHideTimer();
470
- if (valueBubble)
471
- showValueBubble(valueBubble, false);
472
- if (secondValueBubble)
473
- showValueBubble(secondValueBubble, false);
474
- };
475
- const showActiveBubble = (bubble) => {
476
- hideAllBubbles();
477
- if (bubble && config.showValue)
478
- showValueBubble(bubble, true);
479
- };
480
- const hideActiveBubble = (bubble, delay = 0) => {
481
- clearBubbleHideTimer();
482
- if (!bubble || !config.showValue)
483
- return;
484
- if (delay > 0) {
485
- state.valueHideTimer = setTimeout(() => {
486
- showValueBubble(bubble, false);
487
- }, delay);
488
- }
489
- else {
490
- showValueBubble(bubble, false);
491
- }
492
- };
493
- const clearKeyboardFocus = () => {
494
- if (handle)
495
- handle.classList.remove(`${component.getClass("slider__handle")}--focused`);
496
- if (secondHandle)
497
- secondHandle.classList.remove(`${component.getClass("slider__handle")}--focused`);
498
- try {
499
- const focusClass = component.getClass("slider__handle--focused");
500
- component.element
501
- .querySelectorAll(`.${focusClass}`)
502
- .forEach((el) => {
503
- el.classList.remove(focusClass);
504
- });
505
- const active = activeElementOf(component.element);
506
- if (active &&
507
- component.element.contains(active) &&
508
- active.classList.contains(component.getClass("slider__handle"))) {
509
- active.blur();
510
- }
511
- }
512
- catch (error) {
513
- console.warn("Error clearing keyboard focus:", error);
514
- }
515
- };
516
- const followPointer = () => {
517
- document.addEventListener("mousemove", handleMouseMove);
518
- document.addEventListener("mouseup", handleMouseUp);
519
- document.addEventListener("touchmove", handleMouseMove, { passive: false });
520
- document.addEventListener("touchend", handleMouseUp);
521
- };
522
- const stopFollowing = () => {
523
- document.removeEventListener("mousemove", handleMouseMove);
524
- document.removeEventListener("mouseup", handleMouseUp);
525
- document.removeEventListener("touchmove", handleMouseMove);
526
- document.removeEventListener("touchend", handleMouseUp);
527
- };
528
- const handleHandleMouseDown = (e, isSecondHandle = false) => {
529
- if (disabled()) {
530
- return;
531
- }
532
- if (e.type === "mousedown") {
533
- e.preventDefault();
534
- }
535
- e.stopPropagation();
536
- hideAllBubbles();
537
- clearKeyboardFocus();
538
- initialX = pointerOf(e);
539
- state.dragging = false;
540
- state.pressed = true;
541
- hasActualDragStarted = false;
542
- state.activeHandle = isSecondHandle ? "second" : "first";
543
- state.activeBubble = bubbleFor(isSecondHandle);
544
- showActiveBubble(state.activeBubble);
545
- followPointer();
546
- render();
547
- emitEvent(SLIDER_EVENTS.START, e);
548
- };
549
- const handleTrackMouseDown = (e) => {
550
- if (disabled() || !container) {
551
- return;
552
- }
553
- if (e.type === "mousedown") {
554
- e.preventDefault();
555
- }
556
- hideAllBubbles();
557
- clearKeyboardFocus();
558
- let isSecondHandle = false;
559
- try {
560
- const position = pointerOf(e);
561
- let newValue = getValueFromPosition(position);
562
- if (config.snapToSteps && state.step > 0)
563
- newValue = roundToStep(newValue);
564
- newValue = clamp(newValue, state.min, state.max);
565
- if (config.range && state.secondValue !== null) {
566
- const distToFirst = Math.abs(newValue - state.value);
567
- const distToSecond = Math.abs(newValue - state.secondValue);
568
- isSecondHandle = distToSecond < distToFirst;
569
- isSecondHandle
570
- ? (state.secondValue = newValue)
571
- : (state.value = newValue);
572
- }
573
- else {
574
- state.value = newValue;
575
- }
576
- render();
577
- emitEvent(SLIDER_EVENTS.INPUT, e);
578
- }
579
- catch (error) {
580
- console.warn("Error handling track click:", error);
581
- }
582
- state.activeHandle = isSecondHandle ? "second" : "first";
583
- state.activeBubble = bubbleFor(isSecondHandle);
584
- initialX = pointerOf(e);
585
- if (config.centered && !config.range) {
586
- showActiveBubble(state.activeBubble);
587
- followPointer();
588
- state.pressed = false;
589
- emitEvent(SLIDER_EVENTS.START, e);
590
- }
591
- else {
592
- state.dragging = false;
593
- state.pressed = false;
594
- hasActualDragStarted = false;
595
- showActiveBubble(state.activeBubble);
596
- followPointer();
597
- render();
598
- emitEvent(SLIDER_EVENTS.START, e);
599
- }
600
- };
601
- const handleMouseMove = (e) => {
602
- if (!state.activeHandle || !container)
603
- return;
604
- e.preventDefault();
605
- try {
606
- const currentX = pointerOf(e);
607
- if (!hasActualDragStarted &&
608
- Math.abs(currentX - initialX) >= DRAG_THRESHOLD) {
609
- hasActualDragStarted = true;
610
- state.dragging = true;
611
- component.element.classList.add(`${component.getClass("slider")}--dragging`);
612
- }
613
- let newValue = getValueFromPosition(currentX);
614
- if (config.snapToSteps && state.step > 0)
615
- newValue = roundToStep(newValue);
616
- newValue = clamp(newValue, state.min, state.max);
617
- const isSecondHandle = state.activeHandle === "second";
618
- if (config.range && state.secondValue !== null) {
619
- const [low, high] = rangeBounds(isSecondHandle);
620
- const clamped = Math.min(high, Math.max(low, newValue));
621
- if (isSecondHandle)
622
- state.secondValue = clamped;
623
- else
624
- state.value = clamped;
625
- }
626
- else {
627
- state.value = newValue;
628
- }
629
- render();
630
- emitEvent(SLIDER_EVENTS.INPUT, e);
631
- }
632
- catch (error) {
633
- console.warn("Error during slider drag:", error);
634
- }
635
- };
636
- const handleMouseUp = (e) => {
637
- if (!state.activeHandle)
638
- return;
639
- e.preventDefault();
640
- state.dragging = false;
641
- state.pressed = false;
642
- hasActualDragStarted = false;
643
- component.element.classList.remove(`${component.getClass("slider")}--dragging`);
644
- hideActiveBubble(state.activeBubble, 1000);
645
- stopFollowing();
646
- state.activeHandle = null;
647
- render();
648
- emitEvent(SLIDER_EVENTS.CHANGE, e);
649
- emitEvent(SLIDER_EVENTS.END, e);
650
- };
651
- const handleKeyDown = (e, isSecondHandle = false) => {
652
- if (disabled())
653
- return;
654
- const step = state.step || 1;
655
- let newValue = isSecondHandle ? state.secondValue : state.value;
656
- if (newValue === null)
657
- return;
658
- const stepSize = e.shiftKey ? step * 10 : step;
659
- if (e.key === "Tab")
660
- return;
661
- const axis = getAxis(config, isRtl(component.element));
662
- const sign = arrowSign(axis);
663
- const intervals = Math.max(1, Math.floor((state.max - state.min) / step));
664
- const page = Math.min(10, Math.max(1, Math.floor(intervals / 10))) * step;
665
- const along = axis.vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowRight", "ArrowLeft"];
666
- let target;
667
- if (e.key === along[0])
668
- target = newValue + sign * stepSize;
669
- else if (e.key === along[1])
670
- target = newValue - sign * stepSize;
671
- else if (e.key === "ArrowUp" || e.key === "ArrowRight")
672
- target = newValue + stepSize;
673
- else if (e.key === "ArrowDown" || e.key === "ArrowLeft")
674
- target = newValue - stepSize;
675
- else if (e.key === "PageUp")
676
- target = newValue + (axis.vertical ? sign : 1) * page;
677
- else if (e.key === "PageDown")
678
- target = newValue - (axis.vertical ? sign : 1) * page;
679
- else if (e.key === "Home")
680
- target = state.min;
681
- else if (e.key === "End")
682
- target = state.max;
683
- else
684
- return;
685
- e.preventDefault();
686
- const [low, high] = rangeBounds(isSecondHandle);
687
- newValue = Math.min(high, Math.max(low, target));
688
- state.activeBubble = bubbleFor(isSecondHandle);
689
- showActiveBubble(state.activeBubble);
690
- if (isSecondHandle) {
691
- state.secondValue = newValue;
692
- }
693
- else {
694
- state.value = newValue;
695
- }
696
- render();
697
- emitEvent(SLIDER_EVENTS.INPUT, e);
698
- emitEvent(SLIDER_EVENTS.CHANGE, e);
699
- };
700
- const handleFocus = (e, isSecondHandle = false) => {
701
- if (disabled())
702
- return;
703
- const currentHandle = handleFor(isSecondHandle);
704
- if (lastFocusedHandle && lastFocusedHandle !== currentHandle) {
705
- hideAllBubbles();
706
- }
707
- if (!currentHandle)
708
- return;
709
- lastFocusedHandle = currentHandle;
710
- currentHandle.classList.add(`${component.getClass("slider__handle")}--focused`);
711
- showActiveBubble(bubbleFor(isSecondHandle));
712
- state.activeBubble = bubbleFor(isSecondHandle);
713
- render();
714
- emitEvent(SLIDER_EVENTS.FOCUS, e);
715
- };
716
- const handleBlur = (e, isSecondHandle = false) => {
717
- const handleElement = handleFor(isSecondHandle);
718
- if (!handleElement)
719
- return;
720
- handleElement.classList.remove(`${component.getClass("slider__handle")}--focused`);
721
- render();
722
- const relatedTarget = e.relatedTarget;
723
- const otherHandle = handleFor(!isSecondHandle);
724
- if (!relatedTarget || relatedTarget !== otherHandle) {
725
- hideActiveBubble(bubbleFor(isSecondHandle), 200);
726
- }
727
- emitEvent(SLIDER_EVENTS.BLUR, e);
728
- };
729
- const listenersFor = (isSecondHandle) => ({
730
- press: (e) => handleHandleMouseDown(e, isSecondHandle),
731
- keydown: (e) => handleKeyDown(e, isSecondHandle),
732
- focus: (e) => handleFocus(e, isSecondHandle),
733
- blur: (e) => handleBlur(e, isSecondHandle),
734
- });
735
- const handleListeners = listenersFor(false);
736
- const secondHandleListeners = listenersFor(true);
737
- const attach = (element, listeners) => {
738
- element.addEventListener("mousedown", listeners.press);
739
- element.addEventListener("touchstart", listeners.press, { passive: true });
740
- element.addEventListener("keydown", listeners.keydown);
741
- element.addEventListener("focus", listeners.focus);
742
- element.addEventListener("blur", listeners.blur);
743
- };
744
- const detach = (element, listeners) => {
745
- element.removeEventListener("mousedown", listeners.press);
746
- element.removeEventListener("touchstart", listeners.press);
747
- element.removeEventListener("keydown", listeners.keydown);
748
- element.removeEventListener("focus", listeners.focus);
749
- element.removeEventListener("blur", listeners.blur);
750
- };
751
- const setupEventListeners = () => {
752
- if (!handle || !container) {
753
- console.warn("Cannot set up event listeners: missing container or handle");
754
- return;
755
- }
756
- container.addEventListener("mousedown", handleTrackMouseDown);
757
- container.addEventListener("touchstart", handleTrackMouseDown, {
758
- passive: true,
759
- });
760
- attach(handle, handleListeners);
761
- if (config.range && secondHandle)
762
- attach(secondHandle, secondHandleListeners);
763
- };
764
- const cleanupEventListeners = () => {
765
- if (container) {
766
- container.removeEventListener("mousedown", handleTrackMouseDown);
767
- container.removeEventListener("touchstart", handleTrackMouseDown);
768
- }
769
- if (handle)
770
- detach(handle, handleListeners);
771
- if (config.range && secondHandle)
772
- detach(secondHandle, secondHandleListeners);
773
- stopFollowing();
774
- };
775
- const initController = () => {
776
- try {
777
- if (!handle) {
778
- console.warn("Cannot initialize slider controller: missing required handle component");
779
- return;
780
- }
781
- handle.setAttribute("aria-valuemin", String(state.min));
782
- handle.setAttribute("aria-valuemax", String(state.max));
783
- handle.setAttribute("aria-valuenow", String(state.value));
784
- if (config.range && secondHandle && state.secondValue !== null) {
785
- secondHandle.setAttribute("aria-valuemin", String(state.min));
786
- secondHandle.setAttribute("aria-valuemax", String(state.max));
787
- secondHandle.setAttribute("aria-valuenow", String(state.secondValue));
788
- }
789
- setupEventListeners();
790
- render();
791
- }
792
- catch (error) {
793
- console.error("Error initializing slider controller:", error);
794
- }
795
- };
796
- initController();
797
- const layout = typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => updateHandlePositions()) : null;
798
- layout?.observe(component.element);
799
- if (component.lifecycle) {
800
- const originalDestroy = component.lifecycle.destroy || (() => { });
801
- component.lifecycle.destroy = () => {
802
- layout?.disconnect();
803
- if (settleTimer !== null)
804
- clearTimeout(settleTimer);
805
- if (state.valueHideTimer !== null)
806
- clearTimeout(state.valueHideTimer);
807
- cleanupEventListeners();
808
- originalDestroy.call(component.lifecycle);
809
- };
810
- }
811
- const api = {
812
- element: component.element,
813
- setValue(value, triggerEvent = false) {
814
- const ceiling = config.range && state.secondValue !== null ? state.secondValue : state.max;
815
- const newValue = clamp(roundToStep(clamp(value, state.min, state.max)), state.min, ceiling);
816
- state.value = newValue;
817
- render();
818
- if (triggerEvent) {
819
- emitEvent(SLIDER_EVENTS.CHANGE);
820
- }
821
- return this;
822
- },
823
- getValue() {
824
- return state.value;
825
- },
826
- setSecondValue(value, triggerEvent = false) {
827
- if (!config.range)
828
- return this;
829
- const newValue = clamp(roundToStep(clamp(value, state.min, state.max)), state.value, state.max);
830
- state.secondValue = newValue;
831
- render();
832
- if (triggerEvent) {
833
- emitEvent(SLIDER_EVENTS.CHANGE);
834
- }
835
- return this;
836
- },
837
- getSecondValue() {
838
- return config.range ? state.secondValue : null;
839
- },
840
- setMin(min) {
841
- state.min = min;
842
- if (handle) {
843
- handle.setAttribute("aria-valuemin", String(min));
844
- }
845
- if (config.range && secondHandle) {
846
- secondHandle.setAttribute("aria-valuemin", String(min));
847
- }
848
- if (state.value < min)
849
- state.value = min;
850
- if (config.range &&
851
- state.secondValue !== null &&
852
- state.secondValue < min) {
853
- state.secondValue = min;
854
- }
855
- render();
856
- return this;
857
- },
858
- getMin() {
859
- return state.min;
860
- },
861
- setMax(max) {
862
- state.max = max;
863
- if (handle) {
864
- handle.setAttribute("aria-valuemax", String(max));
865
- }
866
- if (config.range && secondHandle) {
867
- secondHandle.setAttribute("aria-valuemax", String(max));
868
- }
869
- if (state.value > max)
870
- state.value = max;
871
- if (config.range &&
872
- state.secondValue !== null &&
873
- state.secondValue > max) {
874
- state.secondValue = max;
875
- }
876
- render();
877
- return this;
878
- },
879
- getMax() {
880
- return state.max;
881
- },
882
- setStep(step) {
883
- state.step = step;
884
- render();
885
- component.element.classList[step > 0 ? "add" : "remove"](`${component.getClass("slider")}--discrete`);
886
- return this;
887
- },
888
- getStep() {
889
- return state.step;
890
- },
891
- enable() {
892
- component.disabled?.enable();
893
- return this;
894
- },
895
- disable() {
896
- component.disabled?.disable();
897
- return this;
898
- },
899
- isDisabled() {
900
- return component.disabled?.isDisabled() ?? false;
901
- },
902
- setColor(color) {
903
- component.appearance.setColor(color);
904
- return this;
905
- },
906
- getColor() {
907
- return component.appearance.getColor();
908
- },
909
- setSize(size) {
910
- component.setSize?.(size);
911
- return this;
912
- },
913
- getSize() {
914
- return component.getSize?.() ?? "XS";
915
- },
916
- showTicks(show) {
917
- component.appearance.showTicks(show);
918
- return this;
919
- },
920
- showCurrentValue(show) {
921
- component.appearance.showCurrentValue(show);
922
- return this;
923
- },
924
- setLabel(text) {
925
- component.label?.setText(text);
926
- return this;
927
- },
928
- getLabel() {
929
- return component.label?.getText() ?? "";
930
- },
931
- setInsetIcon(icon, atMin) {
932
- component.setInsetIcon?.(icon, atMin);
933
- return this;
934
- },
935
- setIcon(iconHtml) {
936
- component.icon?.setIcon(iconHtml);
937
- return this;
938
- },
939
- getIcon() {
940
- return component.icon?.getIcon() ?? "";
941
- },
942
- on(event, handler) {
943
- component.on?.(event, handler);
944
- return this;
945
- },
946
- off(event, handler) {
947
- component.off?.(event, handler);
948
- return this;
949
- },
950
- destroy() {
951
- component.lifecycle?.destroy?.();
952
- },
953
- };
954
- const slider = {
955
- setValue: api.setValue,
956
- getValue: api.getValue,
957
- setSecondValue: api.setSecondValue,
958
- getSecondValue: api.getSecondValue,
959
- setMin: api.setMin,
960
- getMin: api.getMin,
961
- setMax: api.setMax,
962
- getMax: api.getMax,
963
- setStep: api.setStep,
964
- getStep: api.getStep,
965
- regenerateTicks() {
966
- render();
967
- return this;
968
- },
969
- updateUi() {
970
- render();
971
- return this;
972
- },
973
- };
974
- return {
975
- ...component,
976
- ...api,
977
- slider,
978
- };
290
+ const max = config.max !== undefined ? config.max : 100;
291
+ const state = {
292
+ value: config.value !== undefined ? config.value : 0,
293
+ secondValue: config.secondValue !== undefined
294
+ ? config.secondValue
295
+ : config.range
296
+ ? max
297
+ : null,
298
+ min: config.min !== undefined ? config.min : 0,
299
+ max,
300
+ step: config.step !== undefined ? config.step : 1,
301
+ dragging: false,
302
+ pressed: false,
303
+ activeHandle: null,
304
+ activeBubble: null,
305
+ valueHideTimer: null,
306
+ };
307
+ const emitEvent = (eventName, originalEvent = null) => {
308
+ const eventData = {
309
+ slider: getComponent(),
310
+ value: state.value,
311
+ secondValue: state.secondValue,
312
+ originalEvent,
313
+ preventDefault: () => {
314
+ eventData.defaultPrevented = true;
315
+ },
316
+ defaultPrevented: false,
317
+ };
318
+ component.emit(eventName, eventData);
319
+ return eventData;
320
+ };
321
+ const axisNow = () => getAxis(config, isRtl(component.element));
322
+ const inset = () => config.ticks ? getExternalTrackRadius(component.getSize?.() ?? config.size) : 0;
323
+ const visualPosition = (value) => trackPositionCss(fractionOf(value, state.min, state.max), inset());
324
+ const getValueFromPosition = (position) => {
325
+ const { handle, container } = component;
326
+ if (!handle || !container)
327
+ return state.min;
328
+ try {
329
+ const containerRect = container.getBoundingClientRect();
330
+ const range = state.max - state.min;
331
+ const edge = inset();
332
+ const axis = axisNow();
333
+ const span = lengthOf(containerRect, axis) - 2 * edge;
334
+ const along = offsetAlong(position, containerRect, axis) - edge;
335
+ const fraction = span > 0 ? Math.max(0, Math.min(1, along / span)) : 0;
336
+ return state.min + fraction * range;
337
+ }
338
+ catch (error) {
339
+ console.warn("Error calculating value from position:", error);
340
+ return state.min;
341
+ }
342
+ };
343
+ const roundToStep = (value) => {
344
+ const step = state.step;
345
+ if (!step || step <= 0)
346
+ return value;
347
+ const steps = Math.round((value - state.min) / step);
348
+ return state.min + steps * step;
349
+ };
350
+ const clamp = (value, min = state.min, max = state.max) => Math.min(Math.max(value, min), max);
351
+ const updateHandlePositions = () => {
352
+ const { handle, container, valueBubble, secondHandle, secondValueBubble } = component;
353
+ if (!handle || !container)
354
+ return;
355
+ const axis = axisNow();
356
+ const place = (element, value, transform) => {
357
+ if (axis.vertical)
358
+ element.style.left = "";
359
+ if (axis.start === "right")
360
+ element.style.left = "auto";
361
+ if (axis.start === "left")
362
+ element.style.right = "";
363
+ element.style[axis.start] = visualPosition(value);
364
+ element.style.transform = transform;
365
+ };
366
+ place(handle, state.value, handleTransform(axis));
367
+ if (valueBubble)
368
+ place(valueBubble, state.value, bubbleTransform(axis));
369
+ if (config.range && secondHandle && state.secondValue !== null) {
370
+ place(secondHandle, state.secondValue, handleTransform(axis));
371
+ if (secondValueBubble)
372
+ place(secondValueBubble, state.secondValue, bubbleTransform(axis));
373
+ }
374
+ updateHandleAria(handle, state.value);
375
+ if (config.range && secondHandle && state.secondValue !== null) {
376
+ updateHandleAria(secondHandle, state.secondValue);
377
+ handle.setAttribute("aria-valuemax", String(state.secondValue));
378
+ secondHandle.setAttribute("aria-valuemin", String(state.value));
379
+ }
380
+ };
381
+ const updateHandleAria = (handleElement, value) => {
382
+ handleElement.setAttribute("aria-valuenow", String(value));
383
+ if (config.valueFormatter &&
384
+ config.valueFormatter !== defaultConfig.valueFormatter) {
385
+ handleElement.setAttribute("aria-valuetext", config.valueFormatter(value));
386
+ }
387
+ };
388
+ const updateValueBubbles = () => {
389
+ const { valueBubble, secondValueBubble } = component;
390
+ if (!valueBubble)
391
+ return;
392
+ const formatter = config.valueFormatter || ((value) => value.toString());
393
+ valueBubble.textContent = formatter(state.value);
394
+ if (config.range && secondValueBubble && state.secondValue !== null) {
395
+ secondValueBubble.textContent = formatter(state.secondValue);
396
+ }
397
+ };
398
+ const showValueBubble = (bubbleElement, show) => {
399
+ if (!bubbleElement || !config.showValue)
400
+ return;
401
+ const bubbleClass = component.getClass("slider__value");
402
+ bubbleElement.classList[show ? "add" : "remove"](`${bubbleClass}--visible`);
403
+ };
404
+ const SETTLE_MS = 450;
405
+ let rendered = null;
406
+ let settleTimer = null;
407
+ const settle = () => {
408
+ const settling = component.getClass("slider--settling");
409
+ const changed = rendered !== null &&
410
+ (rendered.value !== state.value || rendered.secondValue !== state.secondValue);
411
+ rendered = { value: state.value, secondValue: state.secondValue };
412
+ if (state.dragging) {
413
+ if (settleTimer !== null)
414
+ clearTimeout(settleTimer);
415
+ settleTimer = null;
416
+ component.element.classList.remove(settling);
417
+ return;
418
+ }
419
+ if (!changed)
420
+ return;
421
+ component.element.classList.add(settling);
422
+ if (settleTimer !== null)
423
+ clearTimeout(settleTimer);
424
+ settleTimer = setTimeout(() => {
425
+ settleTimer = null;
426
+ component.element.classList.remove(settling);
427
+ }, SETTLE_MS);
428
+ };
429
+ const render = () => {
430
+ try {
431
+ settle();
432
+ updateHandlePositions();
433
+ updateValueBubbles();
434
+ if (component.formFields) {
435
+ setFormValue(component.formFields[0], String(state.value));
436
+ if (state.secondValue !== null) {
437
+ setFormValue(component.formFields[1], String(state.secondValue));
438
+ }
439
+ }
440
+ if (component.renderTracks) {
441
+ component.renderTracks(state);
442
+ }
443
+ }
444
+ catch (error) {
445
+ console.warn("Error rendering UI:", error);
446
+ }
447
+ };
448
+ const pointerOf = config.orientation === "vertical" ? clientYOf : clientXOf;
449
+ const rangeBounds = (isSecondHandle) => !config.range || state.secondValue === null
450
+ ? [state.min, state.max]
451
+ : isSecondHandle
452
+ ? [state.value, state.max]
453
+ : [state.min, state.secondValue];
454
+ const { container, handle, valueBubble, secondHandle, secondValueBubble } = component;
455
+ const handleFor = (second) => (second ? secondHandle : handle) ?? null;
456
+ const bubbleFor = (second) => (second ? secondValueBubble : valueBubble) ?? null;
457
+ const disabled = () => !!component.disabled?.isDisabled();
458
+ let hasActualDragStarted = false;
459
+ let initialX = 0;
460
+ const DRAG_THRESHOLD = 3;
461
+ let lastFocusedHandle = null;
462
+ const clearBubbleHideTimer = () => {
463
+ if (state.valueHideTimer) {
464
+ clearTimeout(state.valueHideTimer);
465
+ state.valueHideTimer = null;
466
+ }
467
+ };
468
+ const hideAllBubbles = () => {
469
+ clearBubbleHideTimer();
470
+ if (valueBubble)
471
+ showValueBubble(valueBubble, false);
472
+ if (secondValueBubble)
473
+ showValueBubble(secondValueBubble, false);
474
+ };
475
+ const showActiveBubble = (bubble) => {
476
+ hideAllBubbles();
477
+ if (bubble && config.showValue)
478
+ showValueBubble(bubble, true);
479
+ };
480
+ const hideActiveBubble = (bubble, delay = 0) => {
481
+ clearBubbleHideTimer();
482
+ if (!bubble || !config.showValue)
483
+ return;
484
+ if (delay > 0) {
485
+ state.valueHideTimer = setTimeout(() => {
486
+ showValueBubble(bubble, false);
487
+ }, delay);
488
+ }
489
+ else {
490
+ showValueBubble(bubble, false);
491
+ }
492
+ };
493
+ const clearKeyboardFocus = () => {
494
+ if (handle)
495
+ handle.classList.remove(`${component.getClass("slider__handle")}--focused`);
496
+ if (secondHandle)
497
+ secondHandle.classList.remove(`${component.getClass("slider__handle")}--focused`);
498
+ try {
499
+ const focusClass = component.getClass("slider__handle--focused");
500
+ component.element
501
+ .querySelectorAll(`.${focusClass}`)
502
+ .forEach((el) => {
503
+ el.classList.remove(focusClass);
504
+ });
505
+ const active = activeElementOf(component.element);
506
+ if (active &&
507
+ component.element.contains(active) &&
508
+ active.classList.contains(component.getClass("slider__handle"))) {
509
+ active.blur();
510
+ }
511
+ }
512
+ catch (error) {
513
+ console.warn("Error clearing keyboard focus:", error);
514
+ }
515
+ };
516
+ const followPointer = () => {
517
+ document.addEventListener("mousemove", handleMouseMove);
518
+ document.addEventListener("mouseup", handleMouseUp);
519
+ document.addEventListener("touchmove", handleMouseMove, { passive: false });
520
+ document.addEventListener("touchend", handleMouseUp);
521
+ };
522
+ const stopFollowing = () => {
523
+ document.removeEventListener("mousemove", handleMouseMove);
524
+ document.removeEventListener("mouseup", handleMouseUp);
525
+ document.removeEventListener("touchmove", handleMouseMove);
526
+ document.removeEventListener("touchend", handleMouseUp);
527
+ };
528
+ const handleHandleMouseDown = (e, isSecondHandle = false) => {
529
+ if (disabled()) {
530
+ return;
531
+ }
532
+ if (e.type === "mousedown") {
533
+ e.preventDefault();
534
+ }
535
+ e.stopPropagation();
536
+ hideAllBubbles();
537
+ clearKeyboardFocus();
538
+ initialX = pointerOf(e);
539
+ state.dragging = false;
540
+ state.pressed = true;
541
+ hasActualDragStarted = false;
542
+ state.activeHandle = isSecondHandle ? "second" : "first";
543
+ state.activeBubble = bubbleFor(isSecondHandle);
544
+ showActiveBubble(state.activeBubble);
545
+ followPointer();
546
+ render();
547
+ emitEvent(SLIDER_EVENTS.START, e);
548
+ };
549
+ const handleTrackMouseDown = (e) => {
550
+ if (disabled() || !container) {
551
+ return;
552
+ }
553
+ if (e.type === "mousedown") {
554
+ e.preventDefault();
555
+ }
556
+ hideAllBubbles();
557
+ clearKeyboardFocus();
558
+ let isSecondHandle = false;
559
+ try {
560
+ const position = pointerOf(e);
561
+ let newValue = getValueFromPosition(position);
562
+ if (config.snapToSteps && state.step > 0)
563
+ newValue = roundToStep(newValue);
564
+ newValue = clamp(newValue, state.min, state.max);
565
+ if (config.range && state.secondValue !== null) {
566
+ const distToFirst = Math.abs(newValue - state.value);
567
+ const distToSecond = Math.abs(newValue - state.secondValue);
568
+ isSecondHandle = distToSecond < distToFirst;
569
+ isSecondHandle
570
+ ? (state.secondValue = newValue)
571
+ : (state.value = newValue);
572
+ }
573
+ else {
574
+ state.value = newValue;
575
+ }
576
+ render();
577
+ emitEvent(SLIDER_EVENTS.INPUT, e);
578
+ }
579
+ catch (error) {
580
+ console.warn("Error handling track click:", error);
581
+ }
582
+ state.activeHandle = isSecondHandle ? "second" : "first";
583
+ state.activeBubble = bubbleFor(isSecondHandle);
584
+ initialX = pointerOf(e);
585
+ if (config.centered && !config.range) {
586
+ showActiveBubble(state.activeBubble);
587
+ followPointer();
588
+ state.pressed = false;
589
+ emitEvent(SLIDER_EVENTS.START, e);
590
+ }
591
+ else {
592
+ state.dragging = false;
593
+ state.pressed = false;
594
+ hasActualDragStarted = false;
595
+ showActiveBubble(state.activeBubble);
596
+ followPointer();
597
+ render();
598
+ emitEvent(SLIDER_EVENTS.START, e);
599
+ }
600
+ };
601
+ const handleMouseMove = (e) => {
602
+ if (!state.activeHandle || !container)
603
+ return;
604
+ e.preventDefault();
605
+ try {
606
+ const currentX = pointerOf(e);
607
+ if (!hasActualDragStarted &&
608
+ Math.abs(currentX - initialX) >= DRAG_THRESHOLD) {
609
+ hasActualDragStarted = true;
610
+ state.dragging = true;
611
+ component.element.classList.add(`${component.getClass("slider")}--dragging`);
612
+ }
613
+ let newValue = getValueFromPosition(currentX);
614
+ if (config.snapToSteps && state.step > 0)
615
+ newValue = roundToStep(newValue);
616
+ newValue = clamp(newValue, state.min, state.max);
617
+ const isSecondHandle = state.activeHandle === "second";
618
+ if (config.range && state.secondValue !== null) {
619
+ const [low, high] = rangeBounds(isSecondHandle);
620
+ const clamped = Math.min(high, Math.max(low, newValue));
621
+ if (isSecondHandle)
622
+ state.secondValue = clamped;
623
+ else
624
+ state.value = clamped;
625
+ }
626
+ else {
627
+ state.value = newValue;
628
+ }
629
+ render();
630
+ emitEvent(SLIDER_EVENTS.INPUT, e);
631
+ }
632
+ catch (error) {
633
+ console.warn("Error during slider drag:", error);
634
+ }
635
+ };
636
+ const handleMouseUp = (e) => {
637
+ if (!state.activeHandle)
638
+ return;
639
+ e.preventDefault();
640
+ state.dragging = false;
641
+ state.pressed = false;
642
+ hasActualDragStarted = false;
643
+ component.element.classList.remove(`${component.getClass("slider")}--dragging`);
644
+ hideActiveBubble(state.activeBubble, 1000);
645
+ stopFollowing();
646
+ state.activeHandle = null;
647
+ render();
648
+ emitEvent(SLIDER_EVENTS.CHANGE, e);
649
+ emitEvent(SLIDER_EVENTS.END, e);
650
+ };
651
+ const handleKeyDown = (e, isSecondHandle = false) => {
652
+ if (disabled())
653
+ return;
654
+ const step = state.step || 1;
655
+ let newValue = isSecondHandle ? state.secondValue : state.value;
656
+ if (newValue === null)
657
+ return;
658
+ const stepSize = e.shiftKey ? step * 10 : step;
659
+ if (e.key === "Tab")
660
+ return;
661
+ const axis = getAxis(config, isRtl(component.element));
662
+ const sign = arrowSign(axis);
663
+ const intervals = Math.max(1, Math.floor((state.max - state.min) / step));
664
+ const page = Math.min(10, Math.max(1, Math.floor(intervals / 10))) * step;
665
+ const along = axis.vertical ? ["ArrowUp", "ArrowDown"] : ["ArrowRight", "ArrowLeft"];
666
+ let target;
667
+ if (e.key === along[0])
668
+ target = newValue + sign * stepSize;
669
+ else if (e.key === along[1])
670
+ target = newValue - sign * stepSize;
671
+ else if (e.key === "ArrowUp" || e.key === "ArrowRight")
672
+ target = newValue + stepSize;
673
+ else if (e.key === "ArrowDown" || e.key === "ArrowLeft")
674
+ target = newValue - stepSize;
675
+ else if (e.key === "PageUp")
676
+ target = newValue + (axis.vertical ? sign : 1) * page;
677
+ else if (e.key === "PageDown")
678
+ target = newValue - (axis.vertical ? sign : 1) * page;
679
+ else if (e.key === "Home")
680
+ target = state.min;
681
+ else if (e.key === "End")
682
+ target = state.max;
683
+ else
684
+ return;
685
+ e.preventDefault();
686
+ const [low, high] = rangeBounds(isSecondHandle);
687
+ newValue = Math.min(high, Math.max(low, target));
688
+ state.activeBubble = bubbleFor(isSecondHandle);
689
+ showActiveBubble(state.activeBubble);
690
+ if (isSecondHandle) {
691
+ state.secondValue = newValue;
692
+ }
693
+ else {
694
+ state.value = newValue;
695
+ }
696
+ render();
697
+ emitEvent(SLIDER_EVENTS.INPUT, e);
698
+ emitEvent(SLIDER_EVENTS.CHANGE, e);
699
+ };
700
+ const handleFocus = (e, isSecondHandle = false) => {
701
+ if (disabled())
702
+ return;
703
+ const currentHandle = handleFor(isSecondHandle);
704
+ if (lastFocusedHandle && lastFocusedHandle !== currentHandle) {
705
+ hideAllBubbles();
706
+ }
707
+ if (!currentHandle)
708
+ return;
709
+ lastFocusedHandle = currentHandle;
710
+ currentHandle.classList.add(`${component.getClass("slider__handle")}--focused`);
711
+ showActiveBubble(bubbleFor(isSecondHandle));
712
+ state.activeBubble = bubbleFor(isSecondHandle);
713
+ render();
714
+ emitEvent(SLIDER_EVENTS.FOCUS, e);
715
+ };
716
+ const handleBlur = (e, isSecondHandle = false) => {
717
+ const handleElement = handleFor(isSecondHandle);
718
+ if (!handleElement)
719
+ return;
720
+ handleElement.classList.remove(`${component.getClass("slider__handle")}--focused`);
721
+ render();
722
+ const relatedTarget = e.relatedTarget;
723
+ const otherHandle = handleFor(!isSecondHandle);
724
+ if (!relatedTarget || relatedTarget !== otherHandle) {
725
+ hideActiveBubble(bubbleFor(isSecondHandle), 200);
726
+ }
727
+ emitEvent(SLIDER_EVENTS.BLUR, e);
728
+ };
729
+ const listenersFor = (isSecondHandle) => ({
730
+ press: (e) => handleHandleMouseDown(e, isSecondHandle),
731
+ keydown: (e) => handleKeyDown(e, isSecondHandle),
732
+ focus: (e) => handleFocus(e, isSecondHandle),
733
+ blur: (e) => handleBlur(e, isSecondHandle),
734
+ });
735
+ const handleListeners = listenersFor(false);
736
+ const secondHandleListeners = listenersFor(true);
737
+ const attach = (element, listeners) => {
738
+ element.addEventListener("mousedown", listeners.press);
739
+ element.addEventListener("touchstart", listeners.press, { passive: true });
740
+ element.addEventListener("keydown", listeners.keydown);
741
+ element.addEventListener("focus", listeners.focus);
742
+ element.addEventListener("blur", listeners.blur);
743
+ };
744
+ const detach = (element, listeners) => {
745
+ element.removeEventListener("mousedown", listeners.press);
746
+ element.removeEventListener("touchstart", listeners.press);
747
+ element.removeEventListener("keydown", listeners.keydown);
748
+ element.removeEventListener("focus", listeners.focus);
749
+ element.removeEventListener("blur", listeners.blur);
750
+ };
751
+ const setupEventListeners = () => {
752
+ if (!handle || !container) {
753
+ console.warn("Cannot set up event listeners: missing container or handle");
754
+ return;
755
+ }
756
+ container.addEventListener("mousedown", handleTrackMouseDown);
757
+ container.addEventListener("touchstart", handleTrackMouseDown, {
758
+ passive: true,
759
+ });
760
+ attach(handle, handleListeners);
761
+ if (config.range && secondHandle)
762
+ attach(secondHandle, secondHandleListeners);
763
+ };
764
+ const cleanupEventListeners = () => {
765
+ if (container) {
766
+ container.removeEventListener("mousedown", handleTrackMouseDown);
767
+ container.removeEventListener("touchstart", handleTrackMouseDown);
768
+ }
769
+ if (handle)
770
+ detach(handle, handleListeners);
771
+ if (config.range && secondHandle)
772
+ detach(secondHandle, secondHandleListeners);
773
+ stopFollowing();
774
+ };
775
+ const initController = () => {
776
+ try {
777
+ if (!handle) {
778
+ console.warn("Cannot initialize slider controller: missing required handle component");
779
+ return;
780
+ }
781
+ handle.setAttribute("aria-valuemin", String(state.min));
782
+ handle.setAttribute("aria-valuemax", String(state.max));
783
+ handle.setAttribute("aria-valuenow", String(state.value));
784
+ if (config.range && secondHandle && state.secondValue !== null) {
785
+ secondHandle.setAttribute("aria-valuemin", String(state.min));
786
+ secondHandle.setAttribute("aria-valuemax", String(state.max));
787
+ secondHandle.setAttribute("aria-valuenow", String(state.secondValue));
788
+ }
789
+ setupEventListeners();
790
+ render();
791
+ }
792
+ catch (error) {
793
+ console.error("Error initializing slider controller:", error);
794
+ }
795
+ };
796
+ initController();
797
+ const layout = typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => updateHandlePositions()) : null;
798
+ layout?.observe(component.element);
799
+ if (component.lifecycle) {
800
+ const originalDestroy = component.lifecycle.destroy || (() => { });
801
+ component.lifecycle.destroy = () => {
802
+ layout?.disconnect();
803
+ if (settleTimer !== null)
804
+ clearTimeout(settleTimer);
805
+ if (state.valueHideTimer !== null)
806
+ clearTimeout(state.valueHideTimer);
807
+ cleanupEventListeners();
808
+ originalDestroy.call(component.lifecycle);
809
+ };
810
+ }
811
+ const api = {
812
+ element: component.element,
813
+ setValue(value, triggerEvent = false) {
814
+ const ceiling = config.range && state.secondValue !== null ? state.secondValue : state.max;
815
+ const newValue = clamp(roundToStep(clamp(value, state.min, state.max)), state.min, ceiling);
816
+ state.value = newValue;
817
+ render();
818
+ if (triggerEvent) {
819
+ emitEvent(SLIDER_EVENTS.CHANGE);
820
+ }
821
+ return this;
822
+ },
823
+ getValue() {
824
+ return state.value;
825
+ },
826
+ setSecondValue(value, triggerEvent = false) {
827
+ if (!config.range)
828
+ return this;
829
+ const newValue = clamp(roundToStep(clamp(value, state.min, state.max)), state.value, state.max);
830
+ state.secondValue = newValue;
831
+ render();
832
+ if (triggerEvent) {
833
+ emitEvent(SLIDER_EVENTS.CHANGE);
834
+ }
835
+ return this;
836
+ },
837
+ getSecondValue() {
838
+ return config.range ? state.secondValue : null;
839
+ },
840
+ setMin(min) {
841
+ state.min = min;
842
+ if (handle) {
843
+ handle.setAttribute("aria-valuemin", String(min));
844
+ }
845
+ if (config.range && secondHandle) {
846
+ secondHandle.setAttribute("aria-valuemin", String(min));
847
+ }
848
+ if (state.value < min)
849
+ state.value = min;
850
+ if (config.range &&
851
+ state.secondValue !== null &&
852
+ state.secondValue < min) {
853
+ state.secondValue = min;
854
+ }
855
+ render();
856
+ return this;
857
+ },
858
+ getMin() {
859
+ return state.min;
860
+ },
861
+ setMax(max) {
862
+ state.max = max;
863
+ if (handle) {
864
+ handle.setAttribute("aria-valuemax", String(max));
865
+ }
866
+ if (config.range && secondHandle) {
867
+ secondHandle.setAttribute("aria-valuemax", String(max));
868
+ }
869
+ if (state.value > max)
870
+ state.value = max;
871
+ if (config.range &&
872
+ state.secondValue !== null &&
873
+ state.secondValue > max) {
874
+ state.secondValue = max;
875
+ }
876
+ render();
877
+ return this;
878
+ },
879
+ getMax() {
880
+ return state.max;
881
+ },
882
+ setStep(step) {
883
+ state.step = step;
884
+ render();
885
+ component.element.classList[step > 0 ? "add" : "remove"](`${component.getClass("slider")}--discrete`);
886
+ return this;
887
+ },
888
+ getStep() {
889
+ return state.step;
890
+ },
891
+ enable() {
892
+ component.disabled?.enable();
893
+ return this;
894
+ },
895
+ disable() {
896
+ component.disabled?.disable();
897
+ return this;
898
+ },
899
+ isDisabled() {
900
+ return component.disabled?.isDisabled() ?? false;
901
+ },
902
+ setColor(color) {
903
+ component.appearance.setColor(color);
904
+ return this;
905
+ },
906
+ getColor() {
907
+ return component.appearance.getColor();
908
+ },
909
+ setSize(size) {
910
+ component.setSize?.(size);
911
+ return this;
912
+ },
913
+ getSize() {
914
+ return component.getSize?.() ?? "XS";
915
+ },
916
+ showTicks(show) {
917
+ component.appearance.showTicks(show);
918
+ return this;
919
+ },
920
+ showCurrentValue(show) {
921
+ component.appearance.showCurrentValue(show);
922
+ return this;
923
+ },
924
+ setLabel(text) {
925
+ component.label?.setText(text);
926
+ return this;
927
+ },
928
+ getLabel() {
929
+ return component.label?.getText() ?? "";
930
+ },
931
+ setInsetIcon(icon, atMin) {
932
+ component.setInsetIcon?.(icon, atMin);
933
+ return this;
934
+ },
935
+ setIcon(iconHtml) {
936
+ component.icon?.setIcon(iconHtml);
937
+ return this;
938
+ },
939
+ getIcon() {
940
+ return component.icon?.getIcon() ?? "";
941
+ },
942
+ on(event, handler) {
943
+ component.on?.(event, handler);
944
+ return this;
945
+ },
946
+ off(event, handler) {
947
+ component.off?.(event, handler);
948
+ return this;
949
+ },
950
+ destroy() {
951
+ component.lifecycle?.destroy?.();
952
+ },
953
+ };
954
+ const slider = {
955
+ setValue: api.setValue,
956
+ getValue: api.getValue,
957
+ setSecondValue: api.setSecondValue,
958
+ getSecondValue: api.getSecondValue,
959
+ setMin: api.setMin,
960
+ getMin: api.getMin,
961
+ setMax: api.setMax,
962
+ getMax: api.getMax,
963
+ setStep: api.setStep,
964
+ getStep: api.getStep,
965
+ regenerateTicks() {
966
+ render();
967
+ return this;
968
+ },
969
+ updateUi() {
970
+ render();
971
+ return this;
972
+ },
973
+ };
974
+ return {
975
+ ...component,
976
+ ...api,
977
+ slider,
978
+ };
979
979
  };