@zag-js/slider 0.1.11 → 0.1.12

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 (3) hide show
  1. package/dist/index.js +256 -245
  2. package/dist/index.mjs +256 -245
  3. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -65,9 +65,6 @@ function getDocument(el) {
65
65
  return el;
66
66
  return (el == null ? void 0 : el.ownerDocument) ?? document;
67
67
  }
68
- function getWindow(el) {
69
- return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
70
- }
71
68
  function defineDomHelpers(helpers) {
72
69
  const dom2 = {
73
70
  getRootNode: (ctx) => {
@@ -94,46 +91,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
94
91
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
95
92
  var isLeftClick = (v) => v.button === 0;
96
93
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
97
- function observeAttributes(node, attributes, fn) {
98
- if (!node)
99
- return;
100
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
101
- const win = node.ownerDocument.defaultView || window;
102
- const obs = new win.MutationObserver((changes) => {
103
- for (const change of changes) {
104
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
105
- fn(change);
106
- }
107
- }
108
- });
109
- obs.observe(node, { attributes: true, attributeFilter: attrs });
110
- return () => obs.disconnect();
111
- }
112
- function getClosestForm(el) {
113
- if (isFormElement(el))
114
- return el.form;
115
- else
116
- return el.closest("form");
117
- }
118
- function isFormElement(el) {
119
- return el.matches("textarea, input, select, button");
120
- }
121
- function trackFormReset(el, callback) {
122
- if (!el)
123
- return;
124
- const form = getClosestForm(el);
125
- form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
126
- return () => {
127
- form == null ? void 0 : form.removeEventListener("reset", callback);
128
- };
129
- }
130
- function trackFieldsetDisabled(el, callback) {
131
- const fieldset = el == null ? void 0 : el.closest("fieldset");
132
- if (!fieldset)
133
- return;
134
- callback(fieldset.disabled);
135
- return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
136
- }
137
94
  function getElementOffset(element) {
138
95
  let left = 0;
139
96
  let top = 0;
@@ -172,23 +129,6 @@ function getPointRelativeToNode(point, element) {
172
129
  const y = point.y - offset.top;
173
130
  return { x, y };
174
131
  }
175
- function getDescriptor(el, options) {
176
- const { type, property } = options;
177
- const proto = getWindow(el)[type].prototype;
178
- return Object.getOwnPropertyDescriptor(proto, property) ?? {};
179
- }
180
- function dispatchInputValueEvent(el, value) {
181
- var _a;
182
- if (!el)
183
- return;
184
- const win = getWindow(el);
185
- if (!(el instanceof win.HTMLInputElement))
186
- return;
187
- const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
188
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
189
- const event = new win.Event("input", { bubbles: true });
190
- el.dispatchEvent(event);
191
- }
192
132
  var rtlKeyMap = {
193
133
  ArrowLeft: "ArrowRight",
194
134
  ArrowRight: "ArrowLeft",
@@ -367,7 +307,75 @@ function trackPointerMove(doc, opts) {
367
307
  }
368
308
  onPointerMove(info, event);
369
309
  };
370
- return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
310
+ return callAll(
311
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
312
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
313
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
314
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
315
+ disableTextSelection({ doc })
316
+ );
317
+ }
318
+
319
+ // ../../utilities/form-utils/dist/index.mjs
320
+ function getWindow(el) {
321
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
322
+ }
323
+ function observeAttributes(node, attributes, fn) {
324
+ if (!node)
325
+ return;
326
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
327
+ const win = node.ownerDocument.defaultView || window;
328
+ const obs = new win.MutationObserver((changes) => {
329
+ for (const change of changes) {
330
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
331
+ fn(change);
332
+ }
333
+ }
334
+ });
335
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
336
+ return () => obs.disconnect();
337
+ }
338
+ function getDescriptor(el, options) {
339
+ const { type, property } = options;
340
+ const proto = getWindow(el)[type].prototype;
341
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
342
+ }
343
+ function dispatchInputValueEvent(el, value) {
344
+ var _a;
345
+ if (!el)
346
+ return;
347
+ const win = getWindow(el);
348
+ if (!(el instanceof win.HTMLInputElement))
349
+ return;
350
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
351
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
352
+ const event = new win.Event("input", { bubbles: true });
353
+ el.dispatchEvent(event);
354
+ }
355
+ function getClosestForm(el) {
356
+ if (isFormElement(el))
357
+ return el.form;
358
+ else
359
+ return el.closest("form");
360
+ }
361
+ function isFormElement(el) {
362
+ return el.matches("textarea, input, select, button");
363
+ }
364
+ function trackFormReset(el, callback) {
365
+ if (!el)
366
+ return;
367
+ const form = getClosestForm(el);
368
+ form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
369
+ return () => {
370
+ form == null ? void 0 : form.removeEventListener("reset", callback);
371
+ };
372
+ }
373
+ function trackFieldsetDisabled(el, callback) {
374
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
375
+ if (!fieldset)
376
+ return;
377
+ callback(fieldset.disabled);
378
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
371
379
  }
372
380
 
373
381
  // ../../utilities/number/dist/index.mjs
@@ -830,206 +838,209 @@ function connect(state2, send, normalize) {
830
838
  // src/slider.machine.ts
831
839
  var import_core = require("@zag-js/core");
832
840
  function machine(ctx) {
833
- return (0, import_core.createMachine)({
834
- id: "slider",
835
- initial: "unknown",
836
- context: {
837
- thumbSize: null,
838
- thumbAlignment: "contain",
839
- disabled: false,
840
- threshold: 5,
841
- dir: "ltr",
842
- origin: "start",
843
- orientation: "horizontal",
844
- initialValue: null,
845
- value: 0,
846
- step: 1,
847
- min: 0,
848
- max: 100,
849
- ...ctx
850
- },
851
- computed: {
852
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
853
- isVertical: (ctx2) => ctx2.orientation === "vertical",
854
- isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
855
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
856
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
857
- },
858
- watch: {
859
- value: ["invokeOnChange", "dispatchChangeEvent"]
860
- },
861
- activities: ["trackFormReset", "trackFieldsetDisabled"],
862
- on: {
863
- SET_VALUE: {
864
- actions: "setValue"
865
- },
866
- INCREMENT: {
867
- actions: "increment"
841
+ return (0, import_core.createMachine)(
842
+ {
843
+ id: "slider",
844
+ initial: "unknown",
845
+ context: {
846
+ thumbSize: null,
847
+ thumbAlignment: "contain",
848
+ disabled: false,
849
+ threshold: 5,
850
+ dir: "ltr",
851
+ origin: "start",
852
+ orientation: "horizontal",
853
+ initialValue: null,
854
+ value: 0,
855
+ step: 1,
856
+ min: 0,
857
+ max: 100,
858
+ ...ctx
868
859
  },
869
- DECREMENT: {
870
- actions: "decrement"
871
- }
872
- },
873
- states: {
874
- unknown: {
875
- on: {
876
- SETUP: {
877
- target: "idle",
878
- actions: ["setThumbSize", "checkValue"]
879
- }
880
- }
860
+ computed: {
861
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
862
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
863
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
864
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
865
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
881
866
  },
882
- idle: {
883
- on: {
884
- POINTER_DOWN: {
885
- target: "dragging",
886
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
887
- },
888
- FOCUS: "focus"
889
- }
867
+ watch: {
868
+ value: ["invokeOnChange", "dispatchChangeEvent"]
890
869
  },
891
- focus: {
892
- entry: "focusThumb",
893
- on: {
894
- POINTER_DOWN: {
895
- target: "dragging",
896
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
897
- },
898
- ARROW_LEFT: {
899
- guard: "isHorizontal",
900
- actions: "decrement"
901
- },
902
- ARROW_RIGHT: {
903
- guard: "isHorizontal",
904
- actions: "increment"
905
- },
906
- ARROW_UP: {
907
- guard: "isVertical",
908
- actions: "increment"
909
- },
910
- ARROW_DOWN: {
911
- guard: "isVertical",
912
- actions: "decrement"
913
- },
914
- PAGE_UP: {
915
- actions: "increment"
916
- },
917
- PAGE_DOWN: {
918
- actions: "decrement"
919
- },
920
- HOME: {
921
- actions: "setToMin"
922
- },
923
- END: {
924
- actions: "setToMax"
925
- },
926
- BLUR: "idle"
870
+ activities: ["trackFormReset", "trackFieldsetDisabled"],
871
+ on: {
872
+ SET_VALUE: {
873
+ actions: "setValue"
874
+ },
875
+ INCREMENT: {
876
+ actions: "increment"
877
+ },
878
+ DECREMENT: {
879
+ actions: "decrement"
927
880
  }
928
881
  },
929
- dragging: {
930
- entry: "focusThumb",
931
- activities: "trackPointerMove",
932
- on: {
933
- POINTER_UP: {
934
- target: "focus",
935
- actions: "invokeOnChangeEnd"
936
- },
937
- POINTER_MOVE: {
938
- actions: "setPointerValue"
882
+ states: {
883
+ unknown: {
884
+ on: {
885
+ SETUP: {
886
+ target: "idle",
887
+ actions: ["setThumbSize", "checkValue"]
888
+ }
939
889
  }
940
- }
941
- }
942
- }
943
- }, {
944
- guards: {
945
- isHorizontal: (ctx2) => ctx2.isHorizontal,
946
- isVertical: (ctx2) => ctx2.isVertical
947
- },
948
- activities: {
949
- trackFieldsetDisabled(ctx2) {
950
- return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
951
- if (disabled) {
952
- ctx2.disabled = disabled;
890
+ },
891
+ idle: {
892
+ on: {
893
+ POINTER_DOWN: {
894
+ target: "dragging",
895
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
896
+ },
897
+ FOCUS: "focus"
953
898
  }
954
- });
955
- },
956
- trackFormReset(ctx2) {
957
- return trackFormReset(dom.getInputEl(ctx2), () => {
958
- if (ctx2.initialValue != null) {
959
- ctx2.value = ctx2.initialValue;
899
+ },
900
+ focus: {
901
+ entry: "focusThumb",
902
+ on: {
903
+ POINTER_DOWN: {
904
+ target: "dragging",
905
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
906
+ },
907
+ ARROW_LEFT: {
908
+ guard: "isHorizontal",
909
+ actions: "decrement"
910
+ },
911
+ ARROW_RIGHT: {
912
+ guard: "isHorizontal",
913
+ actions: "increment"
914
+ },
915
+ ARROW_UP: {
916
+ guard: "isVertical",
917
+ actions: "increment"
918
+ },
919
+ ARROW_DOWN: {
920
+ guard: "isVertical",
921
+ actions: "decrement"
922
+ },
923
+ PAGE_UP: {
924
+ actions: "increment"
925
+ },
926
+ PAGE_DOWN: {
927
+ actions: "decrement"
928
+ },
929
+ HOME: {
930
+ actions: "setToMin"
931
+ },
932
+ END: {
933
+ actions: "setToMax"
934
+ },
935
+ BLUR: "idle"
960
936
  }
961
- });
962
- },
963
- trackPointerMove(ctx2, _evt, { send }) {
964
- return trackPointerMove(dom.getDoc(ctx2), {
965
- onPointerMove(info) {
966
- send({ type: "POINTER_MOVE", point: info.point });
967
- },
968
- onPointerUp() {
969
- send("POINTER_UP");
937
+ },
938
+ dragging: {
939
+ entry: "focusThumb",
940
+ activities: "trackPointerMove",
941
+ on: {
942
+ POINTER_UP: {
943
+ target: "focus",
944
+ actions: "invokeOnChangeEnd"
945
+ },
946
+ POINTER_MOVE: {
947
+ actions: "setPointerValue"
948
+ }
970
949
  }
971
- });
950
+ }
972
951
  }
973
952
  },
974
- actions: {
975
- checkValue(ctx2) {
976
- const value = utils.convert(ctx2, ctx2.value);
977
- Object.assign(ctx2, { value, initialValue: value });
978
- },
979
- invokeOnChangeStart(ctx2) {
980
- var _a;
981
- (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
982
- },
983
- invokeOnChangeEnd(ctx2) {
984
- var _a;
985
- (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
953
+ {
954
+ guards: {
955
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
956
+ isVertical: (ctx2) => ctx2.isVertical
986
957
  },
987
- invokeOnChange(ctx2) {
988
- var _a;
989
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
990
- },
991
- dispatchChangeEvent(ctx2) {
992
- dom.dispatchChangeEvent(ctx2);
993
- },
994
- setThumbSize(ctx2) {
995
- if (ctx2.thumbAlignment !== "contain")
996
- return;
997
- raf(() => {
998
- const el = dom.getThumbEl(ctx2);
999
- if (!el)
1000
- return;
1001
- ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
1002
- });
1003
- },
1004
- setPointerValue(ctx2, evt) {
1005
- const value = dom.getValueFromPoint(ctx2, evt.point);
1006
- if (value == null)
1007
- return;
1008
- ctx2.value = utils.clamp(ctx2, value);
958
+ activities: {
959
+ trackFieldsetDisabled(ctx2) {
960
+ return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
961
+ if (disabled) {
962
+ ctx2.disabled = disabled;
963
+ }
964
+ });
965
+ },
966
+ trackFormReset(ctx2) {
967
+ return trackFormReset(dom.getInputEl(ctx2), () => {
968
+ if (ctx2.initialValue != null) {
969
+ ctx2.value = ctx2.initialValue;
970
+ }
971
+ });
972
+ },
973
+ trackPointerMove(ctx2, _evt, { send }) {
974
+ return trackPointerMove(dom.getDoc(ctx2), {
975
+ onPointerMove(info) {
976
+ send({ type: "POINTER_MOVE", point: info.point });
977
+ },
978
+ onPointerUp() {
979
+ send("POINTER_UP");
980
+ }
981
+ });
982
+ }
1009
983
  },
1010
- focusThumb(ctx2) {
1011
- raf(() => {
984
+ actions: {
985
+ checkValue(ctx2) {
986
+ const value = utils.convert(ctx2, ctx2.value);
987
+ Object.assign(ctx2, { value, initialValue: value });
988
+ },
989
+ invokeOnChangeStart(ctx2) {
1012
990
  var _a;
1013
- return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1014
- });
1015
- },
1016
- decrement(ctx2, evt) {
1017
- ctx2.value = utils.decrement(ctx2, evt.step);
1018
- },
1019
- increment(ctx2, evt) {
1020
- ctx2.value = utils.increment(ctx2, evt.step);
1021
- },
1022
- setToMin(ctx2) {
1023
- ctx2.value = ctx2.min;
1024
- },
1025
- setToMax(ctx2) {
1026
- ctx2.value = ctx2.max;
1027
- },
1028
- setValue(ctx2, evt) {
1029
- ctx2.value = utils.convert(ctx2, evt.value);
991
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
992
+ },
993
+ invokeOnChangeEnd(ctx2) {
994
+ var _a;
995
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
996
+ },
997
+ invokeOnChange(ctx2) {
998
+ var _a;
999
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
1000
+ },
1001
+ dispatchChangeEvent(ctx2) {
1002
+ dom.dispatchChangeEvent(ctx2);
1003
+ },
1004
+ setThumbSize(ctx2) {
1005
+ if (ctx2.thumbAlignment !== "contain")
1006
+ return;
1007
+ raf(() => {
1008
+ const el = dom.getThumbEl(ctx2);
1009
+ if (!el)
1010
+ return;
1011
+ ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
1012
+ });
1013
+ },
1014
+ setPointerValue(ctx2, evt) {
1015
+ const value = dom.getValueFromPoint(ctx2, evt.point);
1016
+ if (value == null)
1017
+ return;
1018
+ ctx2.value = utils.clamp(ctx2, value);
1019
+ },
1020
+ focusThumb(ctx2) {
1021
+ raf(() => {
1022
+ var _a;
1023
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1024
+ });
1025
+ },
1026
+ decrement(ctx2, evt) {
1027
+ ctx2.value = utils.decrement(ctx2, evt.step);
1028
+ },
1029
+ increment(ctx2, evt) {
1030
+ ctx2.value = utils.increment(ctx2, evt.step);
1031
+ },
1032
+ setToMin(ctx2) {
1033
+ ctx2.value = ctx2.min;
1034
+ },
1035
+ setToMax(ctx2) {
1036
+ ctx2.value = ctx2.max;
1037
+ },
1038
+ setValue(ctx2, evt) {
1039
+ ctx2.value = utils.convert(ctx2, evt.value);
1040
+ }
1030
1041
  }
1031
1042
  }
1032
- });
1043
+ );
1033
1044
  }
1034
1045
  // Annotate the CommonJS export names for ESM import in node:
1035
1046
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -37,9 +37,6 @@ function getDocument(el) {
37
37
  return el;
38
38
  return (el == null ? void 0 : el.ownerDocument) ?? document;
39
39
  }
40
- function getWindow(el) {
41
- return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
42
- }
43
40
  function defineDomHelpers(helpers) {
44
41
  const dom2 = {
45
42
  getRootNode: (ctx) => {
@@ -66,46 +63,6 @@ var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
66
63
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
67
64
  var isLeftClick = (v) => v.button === 0;
68
65
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
69
- function observeAttributes(node, attributes, fn) {
70
- if (!node)
71
- return;
72
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
73
- const win = node.ownerDocument.defaultView || window;
74
- const obs = new win.MutationObserver((changes) => {
75
- for (const change of changes) {
76
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
77
- fn(change);
78
- }
79
- }
80
- });
81
- obs.observe(node, { attributes: true, attributeFilter: attrs });
82
- return () => obs.disconnect();
83
- }
84
- function getClosestForm(el) {
85
- if (isFormElement(el))
86
- return el.form;
87
- else
88
- return el.closest("form");
89
- }
90
- function isFormElement(el) {
91
- return el.matches("textarea, input, select, button");
92
- }
93
- function trackFormReset(el, callback) {
94
- if (!el)
95
- return;
96
- const form = getClosestForm(el);
97
- form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
98
- return () => {
99
- form == null ? void 0 : form.removeEventListener("reset", callback);
100
- };
101
- }
102
- function trackFieldsetDisabled(el, callback) {
103
- const fieldset = el == null ? void 0 : el.closest("fieldset");
104
- if (!fieldset)
105
- return;
106
- callback(fieldset.disabled);
107
- return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
108
- }
109
66
  function getElementOffset(element) {
110
67
  let left = 0;
111
68
  let top = 0;
@@ -144,23 +101,6 @@ function getPointRelativeToNode(point, element) {
144
101
  const y = point.y - offset.top;
145
102
  return { x, y };
146
103
  }
147
- function getDescriptor(el, options) {
148
- const { type, property } = options;
149
- const proto = getWindow(el)[type].prototype;
150
- return Object.getOwnPropertyDescriptor(proto, property) ?? {};
151
- }
152
- function dispatchInputValueEvent(el, value) {
153
- var _a;
154
- if (!el)
155
- return;
156
- const win = getWindow(el);
157
- if (!(el instanceof win.HTMLInputElement))
158
- return;
159
- const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
160
- (_a = desc.set) == null ? void 0 : _a.call(el, value);
161
- const event = new win.Event("input", { bubbles: true });
162
- el.dispatchEvent(event);
163
- }
164
104
  var rtlKeyMap = {
165
105
  ArrowLeft: "ArrowRight",
166
106
  ArrowRight: "ArrowLeft",
@@ -339,7 +279,75 @@ function trackPointerMove(doc, opts) {
339
279
  }
340
280
  onPointerMove(info, event);
341
281
  };
342
- return callAll(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
282
+ return callAll(
283
+ addPointerEvent(doc, "pointermove", handlePointerMove, false),
284
+ addPointerEvent(doc, "pointerup", onPointerUp, false),
285
+ addPointerEvent(doc, "pointercancel", onPointerUp, false),
286
+ addPointerEvent(doc, "contextmenu", onPointerUp, false),
287
+ disableTextSelection({ doc })
288
+ );
289
+ }
290
+
291
+ // ../../utilities/form-utils/dist/index.mjs
292
+ function getWindow(el) {
293
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
294
+ }
295
+ function observeAttributes(node, attributes, fn) {
296
+ if (!node)
297
+ return;
298
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
299
+ const win = node.ownerDocument.defaultView || window;
300
+ const obs = new win.MutationObserver((changes) => {
301
+ for (const change of changes) {
302
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
303
+ fn(change);
304
+ }
305
+ }
306
+ });
307
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
308
+ return () => obs.disconnect();
309
+ }
310
+ function getDescriptor(el, options) {
311
+ const { type, property } = options;
312
+ const proto = getWindow(el)[type].prototype;
313
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
314
+ }
315
+ function dispatchInputValueEvent(el, value) {
316
+ var _a;
317
+ if (!el)
318
+ return;
319
+ const win = getWindow(el);
320
+ if (!(el instanceof win.HTMLInputElement))
321
+ return;
322
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
323
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
324
+ const event = new win.Event("input", { bubbles: true });
325
+ el.dispatchEvent(event);
326
+ }
327
+ function getClosestForm(el) {
328
+ if (isFormElement(el))
329
+ return el.form;
330
+ else
331
+ return el.closest("form");
332
+ }
333
+ function isFormElement(el) {
334
+ return el.matches("textarea, input, select, button");
335
+ }
336
+ function trackFormReset(el, callback) {
337
+ if (!el)
338
+ return;
339
+ const form = getClosestForm(el);
340
+ form == null ? void 0 : form.addEventListener("reset", callback, { passive: true });
341
+ return () => {
342
+ form == null ? void 0 : form.removeEventListener("reset", callback);
343
+ };
344
+ }
345
+ function trackFieldsetDisabled(el, callback) {
346
+ const fieldset = el == null ? void 0 : el.closest("fieldset");
347
+ if (!fieldset)
348
+ return;
349
+ callback(fieldset.disabled);
350
+ return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled));
343
351
  }
344
352
 
345
353
  // ../../utilities/number/dist/index.mjs
@@ -802,206 +810,209 @@ function connect(state2, send, normalize) {
802
810
  // src/slider.machine.ts
803
811
  import { createMachine } from "@zag-js/core";
804
812
  function machine(ctx) {
805
- return createMachine({
806
- id: "slider",
807
- initial: "unknown",
808
- context: {
809
- thumbSize: null,
810
- thumbAlignment: "contain",
811
- disabled: false,
812
- threshold: 5,
813
- dir: "ltr",
814
- origin: "start",
815
- orientation: "horizontal",
816
- initialValue: null,
817
- value: 0,
818
- step: 1,
819
- min: 0,
820
- max: 100,
821
- ...ctx
822
- },
823
- computed: {
824
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
825
- isVertical: (ctx2) => ctx2.orientation === "vertical",
826
- isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
827
- isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
828
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
829
- },
830
- watch: {
831
- value: ["invokeOnChange", "dispatchChangeEvent"]
832
- },
833
- activities: ["trackFormReset", "trackFieldsetDisabled"],
834
- on: {
835
- SET_VALUE: {
836
- actions: "setValue"
837
- },
838
- INCREMENT: {
839
- actions: "increment"
813
+ return createMachine(
814
+ {
815
+ id: "slider",
816
+ initial: "unknown",
817
+ context: {
818
+ thumbSize: null,
819
+ thumbAlignment: "contain",
820
+ disabled: false,
821
+ threshold: 5,
822
+ dir: "ltr",
823
+ origin: "start",
824
+ orientation: "horizontal",
825
+ initialValue: null,
826
+ value: 0,
827
+ step: 1,
828
+ min: 0,
829
+ max: 100,
830
+ ...ctx
840
831
  },
841
- DECREMENT: {
842
- actions: "decrement"
843
- }
844
- },
845
- states: {
846
- unknown: {
847
- on: {
848
- SETUP: {
849
- target: "idle",
850
- actions: ["setThumbSize", "checkValue"]
851
- }
852
- }
832
+ computed: {
833
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
834
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
835
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
836
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
837
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
853
838
  },
854
- idle: {
855
- on: {
856
- POINTER_DOWN: {
857
- target: "dragging",
858
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
859
- },
860
- FOCUS: "focus"
861
- }
839
+ watch: {
840
+ value: ["invokeOnChange", "dispatchChangeEvent"]
862
841
  },
863
- focus: {
864
- entry: "focusThumb",
865
- on: {
866
- POINTER_DOWN: {
867
- target: "dragging",
868
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
869
- },
870
- ARROW_LEFT: {
871
- guard: "isHorizontal",
872
- actions: "decrement"
873
- },
874
- ARROW_RIGHT: {
875
- guard: "isHorizontal",
876
- actions: "increment"
877
- },
878
- ARROW_UP: {
879
- guard: "isVertical",
880
- actions: "increment"
881
- },
882
- ARROW_DOWN: {
883
- guard: "isVertical",
884
- actions: "decrement"
885
- },
886
- PAGE_UP: {
887
- actions: "increment"
888
- },
889
- PAGE_DOWN: {
890
- actions: "decrement"
891
- },
892
- HOME: {
893
- actions: "setToMin"
894
- },
895
- END: {
896
- actions: "setToMax"
897
- },
898
- BLUR: "idle"
842
+ activities: ["trackFormReset", "trackFieldsetDisabled"],
843
+ on: {
844
+ SET_VALUE: {
845
+ actions: "setValue"
846
+ },
847
+ INCREMENT: {
848
+ actions: "increment"
849
+ },
850
+ DECREMENT: {
851
+ actions: "decrement"
899
852
  }
900
853
  },
901
- dragging: {
902
- entry: "focusThumb",
903
- activities: "trackPointerMove",
904
- on: {
905
- POINTER_UP: {
906
- target: "focus",
907
- actions: "invokeOnChangeEnd"
908
- },
909
- POINTER_MOVE: {
910
- actions: "setPointerValue"
854
+ states: {
855
+ unknown: {
856
+ on: {
857
+ SETUP: {
858
+ target: "idle",
859
+ actions: ["setThumbSize", "checkValue"]
860
+ }
911
861
  }
912
- }
913
- }
914
- }
915
- }, {
916
- guards: {
917
- isHorizontal: (ctx2) => ctx2.isHorizontal,
918
- isVertical: (ctx2) => ctx2.isVertical
919
- },
920
- activities: {
921
- trackFieldsetDisabled(ctx2) {
922
- return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
923
- if (disabled) {
924
- ctx2.disabled = disabled;
862
+ },
863
+ idle: {
864
+ on: {
865
+ POINTER_DOWN: {
866
+ target: "dragging",
867
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
868
+ },
869
+ FOCUS: "focus"
925
870
  }
926
- });
927
- },
928
- trackFormReset(ctx2) {
929
- return trackFormReset(dom.getInputEl(ctx2), () => {
930
- if (ctx2.initialValue != null) {
931
- ctx2.value = ctx2.initialValue;
871
+ },
872
+ focus: {
873
+ entry: "focusThumb",
874
+ on: {
875
+ POINTER_DOWN: {
876
+ target: "dragging",
877
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
878
+ },
879
+ ARROW_LEFT: {
880
+ guard: "isHorizontal",
881
+ actions: "decrement"
882
+ },
883
+ ARROW_RIGHT: {
884
+ guard: "isHorizontal",
885
+ actions: "increment"
886
+ },
887
+ ARROW_UP: {
888
+ guard: "isVertical",
889
+ actions: "increment"
890
+ },
891
+ ARROW_DOWN: {
892
+ guard: "isVertical",
893
+ actions: "decrement"
894
+ },
895
+ PAGE_UP: {
896
+ actions: "increment"
897
+ },
898
+ PAGE_DOWN: {
899
+ actions: "decrement"
900
+ },
901
+ HOME: {
902
+ actions: "setToMin"
903
+ },
904
+ END: {
905
+ actions: "setToMax"
906
+ },
907
+ BLUR: "idle"
932
908
  }
933
- });
934
- },
935
- trackPointerMove(ctx2, _evt, { send }) {
936
- return trackPointerMove(dom.getDoc(ctx2), {
937
- onPointerMove(info) {
938
- send({ type: "POINTER_MOVE", point: info.point });
939
- },
940
- onPointerUp() {
941
- send("POINTER_UP");
909
+ },
910
+ dragging: {
911
+ entry: "focusThumb",
912
+ activities: "trackPointerMove",
913
+ on: {
914
+ POINTER_UP: {
915
+ target: "focus",
916
+ actions: "invokeOnChangeEnd"
917
+ },
918
+ POINTER_MOVE: {
919
+ actions: "setPointerValue"
920
+ }
942
921
  }
943
- });
922
+ }
944
923
  }
945
924
  },
946
- actions: {
947
- checkValue(ctx2) {
948
- const value = utils.convert(ctx2, ctx2.value);
949
- Object.assign(ctx2, { value, initialValue: value });
950
- },
951
- invokeOnChangeStart(ctx2) {
952
- var _a;
953
- (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
954
- },
955
- invokeOnChangeEnd(ctx2) {
956
- var _a;
957
- (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
925
+ {
926
+ guards: {
927
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
928
+ isVertical: (ctx2) => ctx2.isVertical
958
929
  },
959
- invokeOnChange(ctx2) {
960
- var _a;
961
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
962
- },
963
- dispatchChangeEvent(ctx2) {
964
- dom.dispatchChangeEvent(ctx2);
965
- },
966
- setThumbSize(ctx2) {
967
- if (ctx2.thumbAlignment !== "contain")
968
- return;
969
- raf(() => {
970
- const el = dom.getThumbEl(ctx2);
971
- if (!el)
972
- return;
973
- ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
974
- });
975
- },
976
- setPointerValue(ctx2, evt) {
977
- const value = dom.getValueFromPoint(ctx2, evt.point);
978
- if (value == null)
979
- return;
980
- ctx2.value = utils.clamp(ctx2, value);
930
+ activities: {
931
+ trackFieldsetDisabled(ctx2) {
932
+ return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => {
933
+ if (disabled) {
934
+ ctx2.disabled = disabled;
935
+ }
936
+ });
937
+ },
938
+ trackFormReset(ctx2) {
939
+ return trackFormReset(dom.getInputEl(ctx2), () => {
940
+ if (ctx2.initialValue != null) {
941
+ ctx2.value = ctx2.initialValue;
942
+ }
943
+ });
944
+ },
945
+ trackPointerMove(ctx2, _evt, { send }) {
946
+ return trackPointerMove(dom.getDoc(ctx2), {
947
+ onPointerMove(info) {
948
+ send({ type: "POINTER_MOVE", point: info.point });
949
+ },
950
+ onPointerUp() {
951
+ send("POINTER_UP");
952
+ }
953
+ });
954
+ }
981
955
  },
982
- focusThumb(ctx2) {
983
- raf(() => {
956
+ actions: {
957
+ checkValue(ctx2) {
958
+ const value = utils.convert(ctx2, ctx2.value);
959
+ Object.assign(ctx2, { value, initialValue: value });
960
+ },
961
+ invokeOnChangeStart(ctx2) {
984
962
  var _a;
985
- return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
986
- });
987
- },
988
- decrement(ctx2, evt) {
989
- ctx2.value = utils.decrement(ctx2, evt.step);
990
- },
991
- increment(ctx2, evt) {
992
- ctx2.value = utils.increment(ctx2, evt.step);
993
- },
994
- setToMin(ctx2) {
995
- ctx2.value = ctx2.min;
996
- },
997
- setToMax(ctx2) {
998
- ctx2.value = ctx2.max;
999
- },
1000
- setValue(ctx2, evt) {
1001
- ctx2.value = utils.convert(ctx2, evt.value);
963
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
964
+ },
965
+ invokeOnChangeEnd(ctx2) {
966
+ var _a;
967
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
968
+ },
969
+ invokeOnChange(ctx2) {
970
+ var _a;
971
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
972
+ },
973
+ dispatchChangeEvent(ctx2) {
974
+ dom.dispatchChangeEvent(ctx2);
975
+ },
976
+ setThumbSize(ctx2) {
977
+ if (ctx2.thumbAlignment !== "contain")
978
+ return;
979
+ raf(() => {
980
+ const el = dom.getThumbEl(ctx2);
981
+ if (!el)
982
+ return;
983
+ ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
984
+ });
985
+ },
986
+ setPointerValue(ctx2, evt) {
987
+ const value = dom.getValueFromPoint(ctx2, evt.point);
988
+ if (value == null)
989
+ return;
990
+ ctx2.value = utils.clamp(ctx2, value);
991
+ },
992
+ focusThumb(ctx2) {
993
+ raf(() => {
994
+ var _a;
995
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
996
+ });
997
+ },
998
+ decrement(ctx2, evt) {
999
+ ctx2.value = utils.decrement(ctx2, evt.step);
1000
+ },
1001
+ increment(ctx2, evt) {
1002
+ ctx2.value = utils.increment(ctx2, evt.step);
1003
+ },
1004
+ setToMin(ctx2) {
1005
+ ctx2.value = ctx2.min;
1006
+ },
1007
+ setToMax(ctx2) {
1008
+ ctx2.value = ctx2.max;
1009
+ },
1010
+ setValue(ctx2, evt) {
1011
+ ctx2.value = utils.convert(ctx2, evt.value);
1012
+ }
1002
1013
  }
1003
1014
  }
1004
- });
1015
+ );
1005
1016
  }
1006
1017
  export {
1007
1018
  connect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -33,7 +33,8 @@
33
33
  "@zag-js/types": "0.2.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.8",
36
+ "@zag-js/dom-utils": "0.1.9",
37
+ "@zag-js/form-utils": "0.1.0",
37
38
  "@zag-js/number-utils": "0.1.3",
38
39
  "@zag-js/utils": "0.1.3"
39
40
  },