flet-box 0.0.0-stage → 1.0.2

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 (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -2
  3. package/bin/cli.js +394 -0
  4. package/bin/commands/buildAndroid.js +200 -0
  5. package/bin/commands/buildIOS.js +237 -0
  6. package/bin/commands/create.js +406 -0
  7. package/bin/commands/createBundle.js +375 -0
  8. package/bin/commands/createComponent.js +115 -0
  9. package/bin/commands/createScreen.js +161 -0
  10. package/bin/commands/killServer.js +107 -0
  11. package/bin/commands/package.js +131 -0
  12. package/bin/commands/release.js +189 -0
  13. package/bin/commands/runBundle.js +62 -0
  14. package/bin/commands/runCloudflare.js +89 -0
  15. package/bin/commands/runNative.js +109 -0
  16. package/bin/commands/runServer.js +390 -0
  17. package/bin/ota/loader.js +361 -0
  18. package/bin/utils/bundleConfig.js +178 -0
  19. package/bin/utils/capacitor.js +137 -0
  20. package/bin/utils/colors.js +215 -0
  21. package/bin/utils/helpers.js +80 -0
  22. package/bin/utils/spinner.js +96 -0
  23. package/bin/utils/templates.js +1824 -0
  24. package/bin/utils/version.js +108 -0
  25. package/package.json +58 -4
  26. package/src/animations/AnimatedBox.js +607 -0
  27. package/src/animations/AnimatedText.js +105 -0
  28. package/src/animations/MatrixRain.js +220 -0
  29. package/src/animations/ParallaxBox.js +369 -0
  30. package/src/animations/animate.js +332 -0
  31. package/src/animations/index.js +25 -0
  32. package/src/app.js +41 -0
  33. package/src/assets/icon-1024-maskable.png +0 -0
  34. package/src/assets/icon-192-maskable.png +0 -0
  35. package/src/assets/icon-192.png +0 -0
  36. package/src/assets/icon-512-maskable.png +0 -0
  37. package/src/assets/icon-512.png +0 -0
  38. package/src/assets/logo.png +0 -0
  39. package/src/core/App.js +44 -0
  40. package/src/core/hmr-client.js +142 -0
  41. package/src/core/index.js +34 -0
  42. package/src/core/pwa.js +100 -0
  43. package/src/core/runApp.js +430 -0
  44. package/src/create-index.sh +237 -0
  45. package/src/fonts/MaterialIcons-Regular.woff2 +0 -0
  46. package/src/fonts/icons.css +23 -0
  47. package/src/index.d.ts +1930 -0
  48. package/src/index.js +288 -0
  49. package/src/navigations/AdaptiveScaffold.js +149 -0
  50. package/src/navigations/AppBar.js +331 -0
  51. package/src/navigations/BottomNavigation.js +298 -0
  52. package/src/navigations/CollapsibleSideBar.js +139 -0
  53. package/src/navigations/Drawer.js +333 -0
  54. package/src/navigations/DrawerItem.js +260 -0
  55. package/src/navigations/Router.js +475 -0
  56. package/src/navigations/Scaffold.js +537 -0
  57. package/src/navigations/Tabs.js +384 -0
  58. package/src/navigations/index.js +57 -0
  59. package/src/services/RamStore.js +213 -0
  60. package/src/services/Session.js +310 -0
  61. package/src/services/Storage.js +309 -0
  62. package/src/services/http.js +350 -0
  63. package/src/services/index.js +57 -0
  64. package/src/tools/animation.js +42 -0
  65. package/src/tools/array.js +95 -0
  66. package/src/tools/border.js +28 -0
  67. package/src/tools/clipboard.js +104 -0
  68. package/src/tools/color.js +329 -0
  69. package/src/tools/createList.js +215 -0
  70. package/src/tools/delay.js +55 -0
  71. package/src/tools/device.js +138 -0
  72. package/src/tools/dict.js +297 -0
  73. package/src/tools/dimensions.js +118 -0
  74. package/src/tools/filter.js +41 -0
  75. package/src/tools/flex.js +26 -0
  76. package/src/tools/gradient.js +34 -0
  77. package/src/tools/grid.js +57 -0
  78. package/src/tools/index.js +38 -0
  79. package/src/tools/mapList.js +107 -0
  80. package/src/tools/margin.js +93 -0
  81. package/src/tools/memo.js +60 -0
  82. package/src/tools/os.js +104 -0
  83. package/src/tools/padding.js +93 -0
  84. package/src/tools/print.js +69 -0
  85. package/src/tools/random.js +299 -0
  86. package/src/tools/ref.js +70 -0
  87. package/src/tools/rgba.js +4 -0
  88. package/src/tools/shadow.js +23 -0
  89. package/src/tools/string.js +85 -0
  90. package/src/tools/time.js +674 -0
  91. package/src/tools/transform.js +68 -0
  92. package/src/tools/transition.js +48 -0
  93. package/src/tools/useState.js +268 -0
  94. package/src/tools/uuid.js +42 -0
  95. package/src/utils/TextInputValidator.js +256 -0
  96. package/src/utils/composeUpdate.js +65 -0
  97. package/src/utils/getWidgetProps.js +35 -0
  98. package/src/utils/index.js +76 -0
  99. package/src/utils/markdownParser.js +368 -0
  100. package/src/utils/mediaTime.js +79 -0
  101. package/src/utils/navigation.js +263 -0
  102. package/src/utils/scriptInjector.js +73 -0
  103. package/src/utils/stackPosition.js +31 -0
  104. package/src/utils/stopWebRefresh.js +77 -0
  105. package/src/utils/styleInjector.js +38 -0
  106. package/src/utils/syntaxHighlight.js +339 -0
  107. package/src/utils/themes.js +347 -0
  108. package/src/utils/units.js +87 -0
  109. package/src/utils/visualEffects.js +169 -0
  110. package/src/widget-factory/addChildren.js +114 -0
  111. package/src/widget-factory/assignProps.js +256 -0
  112. package/src/widget-factory/createWidget.js +28 -0
  113. package/src/widget-factory/effects.js +132 -0
  114. package/src/widget-factory/index.js +7 -0
  115. package/src/widget-factory/lifecycle.js +210 -0
  116. package/src/widget-factory/makeParentable.js +89 -0
  117. package/src/widget-factory/pixTool.js +40 -0
  118. package/src/widget-factory/processProps.js +122 -0
  119. package/src/widget-factory/reactivity.js +98 -0
  120. package/src/widget-factory/remTool.js +34 -0
  121. package/src/widget-factory/stackPosition.js +87 -0
  122. package/src/widget-factory/stringTool.js +26 -0
  123. package/src/widget-factory/tools.js +249 -0
  124. package/src/widget-factory/translateProps.js +1049 -0
  125. package/src/widget-factory/warnings.js +284 -0
  126. package/src/widget-factory/widgetFactory.js +200 -0
  127. package/src/widgets/Accordion.js +562 -0
  128. package/src/widgets/AdMob.js +315 -0
  129. package/src/widgets/AdSense.js +268 -0
  130. package/src/widgets/AlertDialog.js +162 -0
  131. package/src/widgets/Audio.js +311 -0
  132. package/src/widgets/Avatar.js +210 -0
  133. package/src/widgets/Badge.js +189 -0
  134. package/src/widgets/BottomSheet.js +287 -0
  135. package/src/widgets/Button.js +247 -0
  136. package/src/widgets/Card.js +33 -0
  137. package/src/widgets/Carousel.js +301 -0
  138. package/src/widgets/Chart.js +632 -0
  139. package/src/widgets/Checkbox.js +106 -0
  140. package/src/widgets/Chip.js +153 -0
  141. package/src/widgets/CircularBar.js +352 -0
  142. package/src/widgets/CircularChart.js +549 -0
  143. package/src/widgets/CodeViewer.js +236 -0
  144. package/src/widgets/Column.js +29 -0
  145. package/src/widgets/Container.js +31 -0
  146. package/src/widgets/DataTable.js +257 -0
  147. package/src/widgets/Divider.js +93 -0
  148. package/src/widgets/DraggBox.js +115 -0
  149. package/src/widgets/Dropdown.js +505 -0
  150. package/src/widgets/DroppBox.js +180 -0
  151. package/src/widgets/FloatingActionButton.js +91 -0
  152. package/src/widgets/GridView.js +20 -0
  153. package/src/widgets/Icon.js +33 -0
  154. package/src/widgets/Image.js +15 -0
  155. package/src/widgets/Input.js +565 -0
  156. package/src/widgets/Inspector.js +254 -0
  157. package/src/widgets/InstallButton.js +110 -0
  158. package/src/widgets/ListTile.js +224 -0
  159. package/src/widgets/ListView.js +503 -0
  160. package/src/widgets/Markdown.js +1236 -0
  161. package/src/widgets/Modal.js +496 -0
  162. package/src/widgets/Pagination.js +195 -0
  163. package/src/widgets/ProgressBar.js +178 -0
  164. package/src/widgets/QRCode.js +467 -0
  165. package/src/widgets/Radio.js +132 -0
  166. package/src/widgets/Rating.js +261 -0
  167. package/src/widgets/Row.js +29 -0
  168. package/src/widgets/Skeleton.js +243 -0
  169. package/src/widgets/Slider.js +527 -0
  170. package/src/widgets/SnackBar.js +227 -0
  171. package/src/widgets/Stack.js +29 -0
  172. package/src/widgets/Stepper.js +296 -0
  173. package/src/widgets/Switch.js +102 -0
  174. package/src/widgets/Text.js +98 -0
  175. package/src/widgets/Tooltip.js +267 -0
  176. package/src/widgets/TreeView.js +370 -0
  177. package/src/widgets/Video.js +92 -0
  178. package/src/widgets/index.js +52 -0
@@ -0,0 +1,527 @@
1
+ /**
2
+ * @file Slider.js
3
+ * @description Range slider with drag/track input, custom `update` compositor and
4
+ * idempotent `onUnmount` cleanup.
5
+ */
6
+ import { WidgetFactory } from "../widget-factory/index.js";
7
+ import { colors } from "../utils/themes.js";
8
+ import { composeUpdate } from "../utils/composeUpdate.js";
9
+ import { injectKeyframes } from "../utils/styleInjector.js";
10
+
11
+ /**
12
+ * Props owned by the Slider's closure state. Routed to the widget's `update`
13
+ * and never to the factory's (see `composeUpdate`).
14
+ */
15
+ const SLIDER_PROP_KEYS = [
16
+ "value", "min", "max", "step", "disabled",
17
+ "width", "height", "thumbSize",
18
+ "color", "trackColor", "thumbColor", "orientation", "inverted",
19
+ "showValue", "valuePrefix", "valueSuffix", "showMarks", "marks",
20
+ "striped", "animatedStripes", "stripeColor", "glow",
21
+ "onChanged", "onPress", "onChangeEnd",
22
+ ];
23
+
24
+ export const Slider = (props) => {
25
+ let {
26
+ // Basic values
27
+ value = 0,
28
+ min = 0,
29
+ max = 100,
30
+ step = 1,
31
+ disabled = false,
32
+ // Appearance
33
+ width = "100%",
34
+ height = 4,
35
+ thumbSize = 20,
36
+ color = colors.primary,
37
+ trackColor = colors.border,
38
+ thumbColor = "#fff",
39
+ orientation = "horizontal",
40
+ inverted = false,
41
+ // Text and marks
42
+ showValue = false,
43
+ valuePrefix = "",
44
+ valueSuffix = "",
45
+ showMarks = false,
46
+ marks = [], // ← implemented
47
+ // Visual effects
48
+ striped = true,
49
+ animatedStripes = false,
50
+ stripeColor = "rgba(255,255,255,0.25)",
51
+ glow = false,
52
+ // Events
53
+ onChanged,
54
+ /** @deprecated Use onPress instead */
55
+ onPress: onPressProp,
56
+ onChangeEnd,
57
+ // Rest
58
+ ...rest
59
+ } = props;
60
+
61
+ // onPress is the canonical callback name; onChanged is kept as a deprecated alias
62
+ const effectiveOnChange = onPressProp || onChanged;
63
+
64
+ // Internal state
65
+ let currentValue = Math.min(Math.max(value, min), max);
66
+ let currentMin = min;
67
+ let currentMax = max;
68
+ let currentStep = step;
69
+
70
+ // Percentage (0..1) always in positive direction (not inverted)
71
+ let rawPercent = (currentValue - currentMin) / (currentMax - currentMin);
72
+ let displayPercent = inverted ? 1 - rawPercent : rawPercent;
73
+
74
+ let isHorizontal = orientation === "horizontal";
75
+ let trackSizePx = isHorizontal ? height : width;
76
+ let trackLengthPx =
77
+ typeof trackSizePx === "number" ? `${trackSizePx}px` : trackSizePx;
78
+ let thumbSizeNum = typeof thumbSize === "number" ? thumbSize : 20;
79
+
80
+ injectKeyframes(
81
+ "slider-stripes",
82
+ "0% { background-position: 0 0; } 100% { background-position: 20px 0; }",
83
+ );
84
+ injectKeyframes(
85
+ "slider-glow",
86
+ "0% { filter: brightness(1); } 50% { filter: brightness(1.2); box-shadow: 0 0 8px currentColor; } 100% { filter: brightness(1); }",
87
+ );
88
+
89
+ // Main container
90
+ const container = WidgetFactory({
91
+ tag: "div",
92
+ widgetName: "Slider",
93
+ width: isHorizontal ? width : "auto",
94
+ height: !isHorizontal ? width : "auto",
95
+ opacity: disabled ? 0.5 : 1,
96
+ ...rest,
97
+ });
98
+
99
+ // ---------- Value display ----------
100
+ let valueDisplay = null;
101
+ if (showValue) {
102
+ valueDisplay = WidgetFactory({
103
+ tag: "div",
104
+ textContent: `${valuePrefix}${currentValue}${valueSuffix}`,
105
+ fontSize: "14px",
106
+ color: colors.textSecondary,
107
+ textAlign: "center",
108
+ marginBottom: isHorizontal ? "4px" : "0",
109
+ marginRight: !isHorizontal ? "4px" : "0",
110
+ });
111
+ container.appendChild(valueDisplay);
112
+ }
113
+
114
+ // ---------- Wrapper (ensures fixed height/width) ----------
115
+ const wrapper = WidgetFactory({
116
+ tag: "div",
117
+ position: "relative",
118
+ ...(isHorizontal
119
+ ? {
120
+ width: "100%",
121
+ height: trackLengthPx,
122
+ display: "flex",
123
+ alignItems: "center",
124
+ }
125
+ : {
126
+ height: "100%", // for vertical, the wrapper takes the full height
127
+ display: "flex",
128
+ justifyContent: "center",
129
+ }),
130
+ });
131
+ container.appendChild(wrapper);
132
+
133
+ // ---------- Track (background) ----------
134
+ const track = WidgetFactory({
135
+ tag: "div",
136
+ position: "relative",
137
+ ...(isHorizontal
138
+ ? {
139
+ width: "100%",
140
+ height: trackLengthPx,
141
+ }
142
+ : {
143
+ width: trackLengthPx,
144
+ height: "100%",
145
+ }),
146
+ backgroundColor: trackColor,
147
+ borderRadius: trackLengthPx,
148
+ cursor: disabled ? "not-allowed" : "pointer",
149
+ });
150
+ wrapper.appendChild(track);
151
+
152
+ // ---------- Fill (progress) ----------
153
+ const fill = WidgetFactory({
154
+ tag: "div",
155
+ position: "absolute",
156
+ backgroundColor: color,
157
+ borderRadius: trackLengthPx,
158
+ transition: disabled ? "none" : "width 0.1s ease, height 0.1s ease",
159
+ ...(isHorizontal
160
+ ? {
161
+ width: `${displayPercent * 100}%`,
162
+ height: "100%",
163
+ left: 0,
164
+ top: 0,
165
+ }
166
+ : {
167
+ height: `${displayPercent * 100}%`,
168
+ width: "100%",
169
+ bottom: 0,
170
+ left: 0,
171
+ }),
172
+ });
173
+
174
+ if (striped) {
175
+ fill.style.backgroundImage = `repeating-linear-gradient(45deg, ${stripeColor} 0px, ${stripeColor} 8px, transparent 8px, transparent 16px)`;
176
+ fill.style.backgroundSize = "16px 16px";
177
+ if (animatedStripes)
178
+ fill.style.animation = "slider-stripes 0.5s linear infinite";
179
+ }
180
+ if (glow) fill.style.animation = "slider-glow 1.5s ease-in-out infinite";
181
+ track.appendChild(fill);
182
+
183
+ // ---------- Thumb (knob) ----------
184
+ const thumb = WidgetFactory({
185
+ tag: "div",
186
+ position: "absolute",
187
+ width: `${thumbSizeNum}px`,
188
+ height: `${thumbSizeNum}px`,
189
+ backgroundColor: thumbColor,
190
+ borderRadius: "50%",
191
+ boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
192
+ cursor: disabled ? "not-allowed" : "grab",
193
+ zIndex: 2,
194
+ boxSizing: "border-box",
195
+ pointerEvents: "auto",
196
+ ...(isHorizontal
197
+ ? {
198
+ top: "50%",
199
+ transform: "translateY(-50%)",
200
+ }
201
+ : {
202
+ left: "50%",
203
+ transform: "translateX(-50%)",
204
+ }),
205
+ });
206
+ wrapper.appendChild(thumb);
207
+
208
+ // ---------- Marks ----------
209
+ let marksContainer = null;
210
+ if (showMarks) {
211
+ marksContainer = WidgetFactory({
212
+ tag: "div",
213
+ position: "absolute",
214
+ ...(isHorizontal
215
+ ? {
216
+ left: 0,
217
+ right: 0,
218
+ top: "50%",
219
+ transform: "translateY(-50%)",
220
+ height: "100%",
221
+ pointerEvents: "none",
222
+ }
223
+ : {
224
+ top: 0,
225
+ bottom: 0,
226
+ left: "50%",
227
+ transform: "translateX(-50%)",
228
+ width: "100%",
229
+ pointerEvents: "none",
230
+ }),
231
+ });
232
+ wrapper.appendChild(marksContainer);
233
+ renderMarks();
234
+ }
235
+
236
+ // ---------- Helper functions ----------
237
+ function renderMarks() {
238
+ if (!marksContainer) return;
239
+ // Clear previous marks
240
+ while (marksContainer.firstChild)
241
+ marksContainer.removeChild(marksContainer.firstChild);
242
+
243
+ const markValues = marks.length ? marks : generateDefaultMarks();
244
+ for (const mark of markValues) {
245
+ const markValue = typeof mark === "number" ? mark : mark.value;
246
+ if (markValue < currentMin || markValue > currentMax) continue;
247
+
248
+ const percent = (markValue - currentMin) / (currentMax - currentMin);
249
+ const posPercent = inverted ? 1 - percent : percent;
250
+
251
+ let markElement = WidgetFactory({
252
+ tag: "div",
253
+ position: "absolute",
254
+ ...(isHorizontal
255
+ ? {
256
+ left: `${posPercent * 100}%`,
257
+ // transform: 'translateX(-50%)',
258
+ top: "50%",
259
+ transform: "translate(-50%, -50%)",
260
+ }
261
+ : {
262
+ bottom: `${posPercent * 100}%`,
263
+ transform: "translate(-50%, 50%)",
264
+ left: "50%",
265
+ }),
266
+ width: mark.size || 4,
267
+ height: mark.size || 4,
268
+ backgroundColor: mark.color || colors.textSecondary,
269
+ borderRadius: "50%",
270
+ cursor: "pointer",
271
+ });
272
+ if (mark.label) {
273
+ const label = WidgetFactory({
274
+ tag: "span",
275
+ textContent: mark.label,
276
+ fontSize: "10px",
277
+ color: colors.textSecondary,
278
+ position: "absolute",
279
+ ...(isHorizontal
280
+ ? {
281
+ top: "100%",
282
+ left: "50%",
283
+ transform: "translateX(-50%)",
284
+ marginTop: "4px",
285
+ }
286
+ : {
287
+ left: "100%",
288
+ top: "50%",
289
+ transform: "translateY(-50%)",
290
+ marginLeft: "4px",
291
+ }),
292
+ whiteSpace: "nowrap",
293
+ });
294
+ markElement.appendChild(label);
295
+ }
296
+ marksContainer.appendChild(markElement);
297
+ }
298
+ }
299
+
300
+ function generateDefaultMarks() {
301
+ const stepMark = (currentMax - currentMin) / 4;
302
+ const marksList = [];
303
+ for (let i = currentMin; i <= currentMax + 0.1; i += stepMark) {
304
+ marksList.push(Math.round(i));
305
+ }
306
+ return marksList;
307
+ }
308
+
309
+ // Update the position of the fill and thumb
310
+ function updateUI() {
311
+ rawPercent = (currentValue - currentMin) / (currentMax - currentMin);
312
+ displayPercent = inverted ? 1 - rawPercent : rawPercent;
313
+
314
+ if (isHorizontal) {
315
+ fill.style.width = `${displayPercent * 100}%`;
316
+ } else {
317
+ fill.style.height = `${displayPercent * 100}%`;
318
+ }
319
+ updateThumbPosition();
320
+ if (valueDisplay) {
321
+ valueDisplay.textContent = `${valuePrefix}${currentValue}${valueSuffix}`;
322
+ }
323
+ if (showMarks && marksContainer) {
324
+ renderMarks();
325
+ }
326
+ }
327
+
328
+ function updateThumbPosition() {
329
+ if (!track || !thumb) return;
330
+ const trackRect = track.getBoundingClientRect();
331
+ if (trackRect.width === 0 && trackRect.height === 0) {
332
+ requestAnimationFrame(updateThumbPosition);
333
+ return;
334
+ }
335
+ if (isHorizontal) {
336
+ const left = displayPercent * trackRect.width;
337
+ thumb.style.left = `${left - thumbSizeNum / 2}px`;
338
+ thumb.style.top = "50%";
339
+ thumb.style.transform = "translateY(-50%)";
340
+ } else {
341
+ const bottom = displayPercent * trackRect.height;
342
+ thumb.style.bottom = `${bottom - thumbSizeNum / 2}px`;
343
+ thumb.style.left = "50%";
344
+ thumb.style.transform = "translateX(-50%)";
345
+ }
346
+ }
347
+
348
+ function calcValueFromEvent(clientX, clientY) {
349
+ const rect = track.getBoundingClientRect();
350
+ let percent;
351
+ if (isHorizontal) {
352
+ let x = clientX - rect.left;
353
+ percent = Math.min(Math.max(x / rect.width, 0), 1);
354
+ } else {
355
+ let y = rect.bottom - clientY;
356
+ percent = Math.min(Math.max(y / rect.height, 0), 1);
357
+ }
358
+ if (inverted) percent = 1 - percent;
359
+ let raw = currentMin + percent * (currentMax - currentMin);
360
+ let stepped = Math.round(raw / currentStep) * currentStep;
361
+ return Math.min(Math.max(stepped, currentMin), currentMax);
362
+ }
363
+
364
+ function setValue(newVal, triggerChange = true, triggerEnd = false) {
365
+ if (disabled) return;
366
+ let clamped = Math.min(Math.max(newVal, currentMin), currentMax);
367
+ if (clamped === currentValue) return;
368
+ currentValue = clamped;
369
+ updateUI();
370
+ if (triggerChange && effectiveOnChange) effectiveOnChange(currentValue);
371
+ if (triggerEnd && onChangeEnd) onChangeEnd(currentValue);
372
+ }
373
+
374
+ // ---------- Drag events ----------
375
+ let dragging = false;
376
+ let currentPointerId = null;
377
+ let hasMoved = false;
378
+
379
+ const onMove = (e) => {
380
+ if (!dragging) return;
381
+ e.preventDefault();
382
+ let clientX, clientY;
383
+ if (e.clientX !== undefined) {
384
+ clientX = e.clientX;
385
+ clientY = e.clientY;
386
+ } else if (e.touches && e.touches[0]) {
387
+ clientX = e.touches[0].clientX;
388
+ clientY = e.touches[0].clientY;
389
+ } else return;
390
+ const newValue = calcValueFromEvent(clientX, clientY);
391
+ setValue(newValue, true, false);
392
+ hasMoved = true;
393
+ };
394
+
395
+ const onEnd = () => {
396
+ if (!dragging) return;
397
+ dragging = false;
398
+ if (currentPointerId !== null) {
399
+ thumb.releasePointerCapture(currentPointerId);
400
+ currentPointerId = null;
401
+ }
402
+ if (hasMoved && onChangeEnd) onChangeEnd(currentValue);
403
+ hasMoved = false;
404
+ document.removeEventListener("mousemove", onMove);
405
+ document.removeEventListener("mouseup", onEnd);
406
+ document.removeEventListener("touchmove", onMove);
407
+ document.removeEventListener("touchend", onEnd);
408
+ thumb.style.cursor = "grab";
409
+ if (wrapper.style) wrapper.style.touchAction = "";
410
+ };
411
+
412
+ const onStart = (e) => {
413
+ if (disabled) return;
414
+ e.preventDefault();
415
+ dragging = true;
416
+ hasMoved = false;
417
+ thumb.style.cursor = "grabbing";
418
+ if (e.pointerId !== undefined) {
419
+ currentPointerId = e.pointerId;
420
+ thumb.setPointerCapture(currentPointerId);
421
+ }
422
+ if (wrapper.style) wrapper.style.touchAction = "none";
423
+
424
+ let clientX, clientY;
425
+ if (e.clientX !== undefined) {
426
+ clientX = e.clientX;
427
+ clientY = e.clientY;
428
+ } else if (e.touches && e.touches[0]) {
429
+ clientX = e.touches[0].clientX;
430
+ clientY = e.touches[0].clientY;
431
+ } else return;
432
+
433
+ const newValue = calcValueFromEvent(clientX, clientY);
434
+ setValue(newValue, true, false);
435
+
436
+ document.addEventListener("mousemove", onMove);
437
+ document.addEventListener("mouseup", onEnd);
438
+ document.addEventListener("touchmove", onMove);
439
+ document.addEventListener("touchend", onEnd);
440
+ };
441
+
442
+ track.addEventListener("mousedown", onStart);
443
+ track.addEventListener("touchstart", onStart);
444
+ thumb.addEventListener("mousedown", onStart);
445
+ thumb.addEventListener("touchstart", onStart);
446
+
447
+ // ---------- ResizeObserver to reposition thumb ----------
448
+ let resizeObserver = null;
449
+ if (typeof ResizeObserver !== "undefined") {
450
+ resizeObserver = new ResizeObserver(() => {
451
+ updateThumbPosition();
452
+ });
453
+ resizeObserver.observe(track);
454
+ } else {
455
+ window.addEventListener("resize", updateThumbPosition);
456
+ }
457
+
458
+ // ---------- Public API and reactivity ----------
459
+ const update = (newProps) => {
460
+ let needsUpdate = false;
461
+ if (newProps.min !== undefined && newProps.min !== currentMin) {
462
+ currentMin = newProps.min;
463
+ needsUpdate = true;
464
+ }
465
+ if (newProps.max !== undefined && newProps.max !== currentMax) {
466
+ currentMax = newProps.max;
467
+ needsUpdate = true;
468
+ }
469
+ if (newProps.step !== undefined && newProps.step !== currentStep) {
470
+ currentStep = newProps.step;
471
+ needsUpdate = true;
472
+ }
473
+ if (newProps.value !== undefined && newProps.value !== currentValue) {
474
+ currentValue = Math.min(Math.max(newProps.value, currentMin), currentMax);
475
+ needsUpdate = true;
476
+ }
477
+ if (needsUpdate) {
478
+ updateUI();
479
+ if (effectiveOnChange) effectiveOnChange(currentValue);
480
+ }
481
+ };
482
+
483
+ Object.defineProperty(container, "value", {
484
+ get: () => currentValue,
485
+ set: (v) => setValue(v, true, false),
486
+ });
487
+ Object.defineProperty(container, "min", {
488
+ get: () => currentMin,
489
+ set: (v) => update({ min: v }),
490
+ });
491
+ Object.defineProperty(container, "max", {
492
+ get: () => currentMax,
493
+ set: (v) => update({ max: v }),
494
+ });
495
+ Object.defineProperty(container, "step", {
496
+ get: () => currentStep,
497
+ set: (v) => update({ step: v }),
498
+ });
499
+
500
+ container.setValue = (v) => setValue(v, true, false);
501
+ container.getValue = () => currentValue;
502
+ composeUpdate(container, SLIDER_PROP_KEYS, update);
503
+
504
+ // ---------- Cleanup ----------
505
+ const cleanup = () => {
506
+ if (resizeObserver) {
507
+ resizeObserver.disconnect();
508
+ } else {
509
+ window.removeEventListener("resize", updateThumbPosition);
510
+ }
511
+ track.removeEventListener("mousedown", onStart);
512
+ track.removeEventListener("touchstart", onStart);
513
+ thumb.removeEventListener("mousedown", onStart);
514
+ thumb.removeEventListener("touchstart", onStart);
515
+ document.removeEventListener("mousemove", onMove);
516
+ document.removeEventListener("mouseup", onEnd);
517
+ document.removeEventListener("touchmove", onMove);
518
+ document.removeEventListener("touchend", onEnd);
519
+ };
520
+ container.onUnmount(cleanup);
521
+
522
+ // Initialize position
523
+ setTimeout(() => updateThumbPosition(), 0);
524
+ return container;
525
+ };
526
+
527
+ export default Slider;