@zag-js/number-input 0.1.13 → 0.1.16

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.
package/dist/index.js CHANGED
@@ -52,11 +52,8 @@ function getPlatform() {
52
52
  }
53
53
  var pt = (v) => isDom() && v.test(getPlatform());
54
54
  var vn = (v) => isDom() && v.test(navigator.vendor);
55
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
56
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
57
55
  var isSafari = () => isApple() && vn(/apple/i);
58
56
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
59
- var isIos = () => isApple() && !isMac();
60
57
  function isDocument(el) {
61
58
  return el.nodeType === Node.DOCUMENT_NODE;
62
59
  }
@@ -93,21 +90,6 @@ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
93
90
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
94
91
  var isLeftClick = (v) => v.button === 0;
95
92
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
96
- function observeAttributes(node, attributes, fn) {
97
- if (!node)
98
- return;
99
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
100
- const win = node.ownerDocument.defaultView || window;
101
- const obs = new win.MutationObserver((changes) => {
102
- for (const change of changes) {
103
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
104
- fn(change);
105
- }
106
- }
107
- });
108
- obs.observe(node, { attributes: true, attributeFilter: attrs });
109
- return () => obs.disconnect();
110
- }
111
93
  var fallback = {
112
94
  pageX: 0,
113
95
  pageY: 0,
@@ -137,6 +119,21 @@ function addDomEvent(target, eventName, handler, options) {
137
119
  node == null ? void 0 : node.removeEventListener(eventName, handler, options);
138
120
  };
139
121
  }
122
+ function observeAttributes(node, attributes, fn) {
123
+ if (!node)
124
+ return;
125
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
126
+ const win = node.ownerDocument.defaultView || window;
127
+ const obs = new win.MutationObserver((changes) => {
128
+ for (const change of changes) {
129
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
130
+ fn(change);
131
+ }
132
+ }
133
+ });
134
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
135
+ return () => obs.disconnect();
136
+ }
140
137
  function raf(fn) {
141
138
  const id = globalThis.requestAnimationFrame(fn);
142
139
  return function cleanup() {
@@ -175,7 +172,10 @@ function requestPointerLock(doc, handlers = {}) {
175
172
  if (!supported)
176
173
  return;
177
174
  body.requestPointerLock();
178
- const cleanup = callAll(addPointerlockChangeListener(doc, onPointerChange), addPointerlockErrorListener(doc, onPointerError));
175
+ const cleanup = callAll(
176
+ addPointerlockChangeListener(doc, onPointerChange),
177
+ addPointerlockErrorListener(doc, onPointerError)
178
+ );
179
179
  return function dispose() {
180
180
  if (!supported)
181
181
  return;
@@ -280,6 +280,44 @@ var dom = defineDomHelpers({
280
280
  getDecButtonEl: (ctx) => dom.getById(ctx, dom.getDecButtonId(ctx)),
281
281
  getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
282
282
  getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
283
+ getActiveButton: (ctx, hint = ctx.hint) => {
284
+ let btnEl = null;
285
+ if (hint === "increment") {
286
+ btnEl = dom.getIncButtonEl(ctx);
287
+ }
288
+ if (hint === "decrement") {
289
+ btnEl = dom.getDecButtonEl(ctx);
290
+ }
291
+ return btnEl;
292
+ },
293
+ setupVirtualCursor(ctx) {
294
+ if (isSafari() || !supportsPointerEvent())
295
+ return;
296
+ dom.createVirtualCursor(ctx);
297
+ return () => {
298
+ var _a;
299
+ (_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
300
+ };
301
+ },
302
+ preventTextSelection(ctx) {
303
+ const doc = dom.getDoc(ctx);
304
+ const html = doc.documentElement;
305
+ const body = doc.body;
306
+ body.style.pointerEvents = "none";
307
+ html.style.userSelect = "none";
308
+ html.style.cursor = "ew-resize";
309
+ return () => {
310
+ body.style.pointerEvents = "";
311
+ html.style.userSelect = "";
312
+ html.style.cursor = "";
313
+ if (!html.style.length) {
314
+ html.removeAttribute("style");
315
+ }
316
+ if (!body.style.length) {
317
+ body.removeAttribute("style");
318
+ }
319
+ };
320
+ },
283
321
  getMousementValue(ctx, event) {
284
322
  const x = roundToDevicePixel(event.movementX);
285
323
  const y = roundToDevicePixel(event.movementY);
@@ -403,6 +441,10 @@ function connect(state, send, normalize) {
403
441
  var _a;
404
442
  (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
405
443
  },
444
+ blur() {
445
+ var _a;
446
+ (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
447
+ },
406
448
  rootProps: normalize.element({
407
449
  id: dom.getRootId(state.context),
408
450
  "data-part": "root",
@@ -428,7 +470,7 @@ function connect(state, send, normalize) {
428
470
  name: state.context.name,
429
471
  id: dom.getInputId(state.context),
430
472
  role: "spinbutton",
431
- value: state.context.formattedValue,
473
+ defaultValue: state.context.formattedValue,
432
474
  pattern: state.context.pattern,
433
475
  inputMode: state.context.inputMode,
434
476
  "aria-invalid": isInvalid || void 0,
@@ -440,7 +482,7 @@ function connect(state, send, normalize) {
440
482
  autoCorrect: "off",
441
483
  spellCheck: "false",
442
484
  type: "text",
443
- "aria-roledescription": !isIos() ? "number field" : void 0,
485
+ "aria-roledescription": "numberfield",
444
486
  "aria-valuemin": state.context.min,
445
487
  "aria-valuemax": state.context.max,
446
488
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -566,381 +608,416 @@ var callAll2 = (...fns) => (...a) => {
566
608
  });
567
609
  };
568
610
 
611
+ // ../../utilities/form-utils/dist/index.mjs
612
+ function getWindow(el) {
613
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
614
+ }
615
+ function getDescriptor(el, options) {
616
+ const { type, property } = options;
617
+ const proto = getWindow(el)[type].prototype;
618
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
619
+ }
620
+ function dispatchInputValueEvent(el, value) {
621
+ var _a;
622
+ if (!el)
623
+ return;
624
+ const win = getWindow(el);
625
+ if (!(el instanceof win.HTMLInputElement))
626
+ return;
627
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
628
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
629
+ const event = new win.Event("input", { bubbles: true });
630
+ el.dispatchEvent(event);
631
+ }
632
+
569
633
  // src/number-input.machine.ts
570
634
  var { not, and } = import_core.guards;
571
635
  function machine(ctx) {
572
- return (0, import_core.createMachine)({
573
- id: "number-input",
574
- initial: "unknown",
575
- context: {
576
- dir: "ltr",
577
- focusInputOnChange: true,
578
- clampValueOnBlur: true,
579
- allowOverflow: false,
580
- inputMode: "decimal",
581
- pattern: "[0-9]*(.[0-9]+)?",
582
- hint: null,
583
- value: "",
584
- step: 1,
585
- min: Number.MIN_SAFE_INTEGER,
586
- max: Number.MAX_SAFE_INTEGER,
587
- scrubberCursorPoint: null,
588
- invalid: false,
589
- ...ctx,
590
- messages: {
591
- incrementLabel: "increment value",
592
- decrementLabel: "decrease value",
593
- ...ctx.messages
594
- }
595
- },
596
- computed: {
597
- isRtl: (ctx2) => ctx2.dir === "rtl",
598
- valueAsNumber: (ctx2) => valueOf(ctx2.value),
599
- isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
600
- isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
601
- isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
602
- isValueEmpty: (ctx2) => ctx2.value === "",
603
- canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
604
- canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
605
- valueText: (ctx2) => {
606
- var _a, _b;
607
- return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
608
- },
609
- formattedValue: (ctx2) => {
610
- var _a;
611
- return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
612
- }
613
- },
614
- watch: {
615
- value: ["invokeOnChange"],
616
- isOutOfRange: ["invokeOnInvalid"]
617
- },
618
- on: {
619
- SET_VALUE: {
620
- actions: ["setValue", "setHintToSet"]
621
- },
622
- CLEAR_VALUE: {
623
- actions: ["clearValue"]
624
- },
625
- INCREMENT: {
626
- actions: ["increment"]
636
+ return (0, import_core.createMachine)(
637
+ {
638
+ id: "number-input",
639
+ initial: "unknown",
640
+ context: {
641
+ dir: "ltr",
642
+ focusInputOnChange: true,
643
+ clampValueOnBlur: true,
644
+ allowOverflow: false,
645
+ inputMode: "decimal",
646
+ pattern: "[0-9]*(.[0-9]+)?",
647
+ hint: null,
648
+ value: "",
649
+ step: 1,
650
+ min: Number.MIN_SAFE_INTEGER,
651
+ max: Number.MAX_SAFE_INTEGER,
652
+ scrubberCursorPoint: null,
653
+ invalid: false,
654
+ spinOnPress: true,
655
+ ...ctx,
656
+ messages: {
657
+ incrementLabel: "increment value",
658
+ decrementLabel: "decrease value",
659
+ ...ctx.messages
660
+ }
627
661
  },
628
- DECREMENT: {
629
- actions: ["decrement"]
630
- }
631
- },
632
- states: {
633
- unknown: {
634
- on: {
635
- SETUP: {
636
- target: "idle",
637
- actions: "syncInputValue"
638
- }
662
+ computed: {
663
+ isRtl: (ctx2) => ctx2.dir === "rtl",
664
+ valueAsNumber: (ctx2) => valueOf(ctx2.value),
665
+ isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
666
+ isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
667
+ isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
668
+ isValueEmpty: (ctx2) => ctx2.value === "",
669
+ canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
670
+ canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
671
+ valueText: (ctx2) => {
672
+ var _a, _b;
673
+ return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
674
+ },
675
+ formattedValue: (ctx2) => {
676
+ var _a;
677
+ return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
639
678
  }
640
679
  },
641
- idle: {
642
- on: {
643
- PRESS_DOWN: {
644
- target: "before:spin",
645
- actions: ["focusInput", "setHint"]
646
- },
647
- PRESS_DOWN_SCRUBBER: {
648
- target: "scrubbing",
649
- actions: ["focusInput", "setHint", "setCursorPoint"]
680
+ watch: {
681
+ value: ["invokeOnChange", "dispatchChangeEvent"],
682
+ isOutOfRange: ["invokeOnInvalid"],
683
+ scrubberCursorPoint: ["setVirtualCursorPosition"]
684
+ },
685
+ on: {
686
+ SET_VALUE: [
687
+ {
688
+ guard: "clampOnBlur",
689
+ actions: ["setValue", "clampValue", "setHintToSet"]
650
690
  },
651
- FOCUS: "focused"
691
+ {
692
+ actions: ["setValue", "setHintToSet"]
693
+ }
694
+ ],
695
+ CLEAR_VALUE: {
696
+ actions: ["clearValue"]
697
+ },
698
+ INCREMENT: {
699
+ actions: ["increment"]
700
+ },
701
+ DECREMENT: {
702
+ actions: ["decrement"]
652
703
  }
653
704
  },
654
- focused: {
655
- tags: ["focus"],
656
- entry: "focusInput",
657
- activities: "attachWheelListener",
658
- on: {
659
- PRESS_DOWN: {
660
- target: "before:spin",
661
- actions: ["focusInput", "setHint"]
662
- },
663
- PRESS_DOWN_SCRUBBER: {
664
- target: "scrubbing",
665
- actions: ["focusInput", "setHint", "setCursorPoint"]
666
- },
667
- ARROW_UP: {
668
- actions: "increment"
669
- },
670
- ARROW_DOWN: {
671
- actions: "decrement"
672
- },
673
- HOME: {
674
- actions: "setToMin"
675
- },
676
- END: {
677
- actions: "setToMax"
678
- },
679
- CHANGE: {
680
- actions: ["setValue", "setHint"]
681
- },
682
- BLUR: [
683
- {
684
- guard: "isInvalidExponential",
705
+ states: {
706
+ unknown: {
707
+ on: {
708
+ SETUP: {
685
709
  target: "idle",
686
- actions: ["clearValue", "clearHint"]
710
+ actions: "syncInputValue"
711
+ }
712
+ }
713
+ },
714
+ idle: {
715
+ exit: "invokeOnFocus",
716
+ on: {
717
+ PRESS_DOWN: {
718
+ target: "before:spin",
719
+ actions: ["focusInput", "setHint"]
687
720
  },
688
- {
689
- guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
690
- target: "idle",
691
- actions: ["clampValue", "clearHint"]
721
+ PRESS_DOWN_SCRUBBER: {
722
+ target: "scrubbing",
723
+ actions: ["focusInput", "setHint", "setCursorPoint"]
692
724
  },
693
- {
694
- target: "idle",
695
- actions: "roundValue"
696
- }
697
- ]
698
- }
699
- },
700
- "before:spin": {
701
- tags: ["focus"],
702
- activities: "trackButtonDisabled",
703
- entry: (0, import_core.choose)([
704
- { guard: "isIncrementHint", actions: "increment" },
705
- { guard: "isDecrementHint", actions: "decrement" }
706
- ]),
707
- after: {
708
- CHANGE_DELAY: {
709
- target: "spinning",
710
- guard: "isInRange"
725
+ FOCUS: "focused"
711
726
  }
712
727
  },
713
- on: {
714
- PRESS_UP: {
715
- target: "focused",
716
- actions: "clearHint"
728
+ focused: {
729
+ tags: "focus",
730
+ entry: "focusInput",
731
+ activities: "attachWheelListener",
732
+ on: {
733
+ PRESS_DOWN: {
734
+ target: "before:spin",
735
+ actions: ["focusInput", "setHint"]
736
+ },
737
+ PRESS_DOWN_SCRUBBER: {
738
+ target: "scrubbing",
739
+ actions: ["focusInput", "setHint", "setCursorPoint"]
740
+ },
741
+ ARROW_UP: {
742
+ actions: "increment"
743
+ },
744
+ ARROW_DOWN: {
745
+ actions: "decrement"
746
+ },
747
+ HOME: {
748
+ actions: "setToMin"
749
+ },
750
+ END: {
751
+ actions: "setToMax"
752
+ },
753
+ CHANGE: {
754
+ actions: ["setValue", "setHint"]
755
+ },
756
+ BLUR: [
757
+ {
758
+ guard: "isInvalidExponential",
759
+ target: "idle",
760
+ actions: ["clearValue", "clearHint", "invokeOnBlur"]
761
+ },
762
+ {
763
+ guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
764
+ target: "idle",
765
+ actions: ["clampValue", "clearHint", "invokeOnBlur"]
766
+ },
767
+ {
768
+ target: "idle",
769
+ actions: ["roundValue", "invokeOnBlur"]
770
+ }
771
+ ]
717
772
  }
718
- }
719
- },
720
- spinning: {
721
- tags: ["focus"],
722
- activities: "trackButtonDisabled",
723
- every: [
724
- {
725
- delay: "CHANGE_INTERVAL",
726
- guard: and(not("isAtMin"), "isIncrementHint"),
727
- actions: "increment"
773
+ },
774
+ "before:spin": {
775
+ tags: "focus",
776
+ activities: "trackButtonDisabled",
777
+ entry: (0, import_core.choose)([
778
+ { guard: "isIncrementHint", actions: "increment" },
779
+ { guard: "isDecrementHint", actions: "decrement" }
780
+ ]),
781
+ after: {
782
+ CHANGE_DELAY: {
783
+ target: "spinning",
784
+ guard: and("isInRange", "spinOnPress")
785
+ }
728
786
  },
729
- {
730
- delay: "CHANGE_INTERVAL",
731
- guard: and(not("isAtMax"), "isDecrementHint"),
732
- actions: "decrement"
733
- }
734
- ],
735
- on: {
736
- PRESS_UP: {
737
- target: "focused",
738
- actions: "clearHint"
787
+ on: {
788
+ PRESS_UP: {
789
+ target: "focused",
790
+ actions: "clearHint"
791
+ }
739
792
  }
740
- }
741
- },
742
- scrubbing: {
743
- tags: ["focus"],
744
- entry: ["addCustomCursor", "disableTextSelection"],
745
- exit: ["removeCustomCursor", "restoreTextSelection"],
746
- activities: ["activatePointerLock", "trackMousemove"],
747
- on: {
748
- POINTER_UP_SCRUBBER: {
749
- target: "focused",
750
- actions: "clearCursorPoint"
751
- },
752
- POINTER_MOVE_SCRUBBER: [
793
+ },
794
+ spinning: {
795
+ tags: "focus",
796
+ activities: "trackButtonDisabled",
797
+ every: [
753
798
  {
754
- guard: "isIncrementHint",
755
- actions: ["increment", "setCursorPoint", "updateCursor"]
799
+ delay: "CHANGE_INTERVAL",
800
+ guard: and(not("isAtMin"), "isIncrementHint"),
801
+ actions: "increment"
756
802
  },
757
803
  {
758
- guard: "isDecrementHint",
759
- actions: ["decrement", "setCursorPoint", "updateCursor"]
804
+ delay: "CHANGE_INTERVAL",
805
+ guard: and(not("isAtMax"), "isDecrementHint"),
806
+ actions: "decrement"
807
+ }
808
+ ],
809
+ on: {
810
+ PRESS_UP: {
811
+ target: "focused",
812
+ actions: "clearHint"
760
813
  }
761
- ]
814
+ }
815
+ },
816
+ scrubbing: {
817
+ tags: "focus",
818
+ exit: "clearCursorPoint",
819
+ activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
820
+ on: {
821
+ POINTER_UP_SCRUBBER: "focused",
822
+ POINTER_MOVE_SCRUBBER: [
823
+ {
824
+ guard: "isIncrementHint",
825
+ actions: ["increment", "setCursorPoint"]
826
+ },
827
+ {
828
+ guard: "isDecrementHint",
829
+ actions: ["decrement", "setCursorPoint"]
830
+ }
831
+ ]
832
+ }
762
833
  }
763
834
  }
764
- }
765
- }, {
766
- delays: {
767
- CHANGE_INTERVAL: 50,
768
- CHANGE_DELAY: 300
769
835
  },
770
- guards: {
771
- clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
772
- isAtMin: (ctx2) => ctx2.isAtMin,
773
- isAtMax: (ctx2) => ctx2.isAtMax,
774
- isInRange: (ctx2) => !ctx2.isOutOfRange,
775
- isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
776
- isEmptyValue: (ctx2) => ctx2.isValueEmpty,
777
- isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
778
- isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
779
- },
780
- activities: {
781
- trackButtonDisabled(ctx2, _evt, { send }) {
782
- let btnEl = null;
783
- if (ctx2.hint === "increment") {
784
- btnEl = dom.getIncButtonEl(ctx2);
785
- }
786
- if (ctx2.hint === "decrement") {
787
- btnEl = dom.getDecButtonEl(ctx2);
788
- }
789
- return observeAttributes(btnEl, "disabled", function onDisable() {
790
- send("PRESS_UP");
791
- });
836
+ {
837
+ delays: {
838
+ CHANGE_INTERVAL: 50,
839
+ CHANGE_DELAY: 300
792
840
  },
793
- attachWheelListener(ctx2, _evt, { send }) {
794
- const input = dom.getInputEl(ctx2);
795
- if (!input)
796
- return;
797
- function onWheel(event) {
798
- const isInputFocused = dom.getDoc(ctx2).activeElement === input;
799
- if (!ctx2.allowMouseWheel || !isInputFocused)
841
+ guards: {
842
+ clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
843
+ isAtMin: (ctx2) => ctx2.isAtMin,
844
+ spinOnPress: (ctx2) => !!ctx2.spinOnPress,
845
+ isAtMax: (ctx2) => ctx2.isAtMax,
846
+ isInRange: (ctx2) => !ctx2.isOutOfRange,
847
+ isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
848
+ isEmptyValue: (ctx2) => ctx2.isValueEmpty,
849
+ isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
850
+ isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
851
+ },
852
+ activities: {
853
+ setupVirtualCursor(ctx2) {
854
+ return dom.setupVirtualCursor(ctx2);
855
+ },
856
+ preventTextSelection(ctx2) {
857
+ return dom.preventTextSelection(ctx2);
858
+ },
859
+ trackButtonDisabled(ctx2, _evt, { send }) {
860
+ const btn = dom.getActiveButton(ctx2, ctx2.hint);
861
+ return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
862
+ },
863
+ attachWheelListener(ctx2, _evt, { send }) {
864
+ const input = dom.getInputEl(ctx2);
865
+ if (!input)
800
866
  return;
801
- event.preventDefault();
802
- const dir = Math.sign(event.deltaY) * -1;
803
- if (dir === 1) {
804
- send("INCREMENT");
805
- } else if (dir === -1) {
806
- send("DECREMENT");
867
+ function onWheel(event) {
868
+ const isInputFocused = dom.getDoc(ctx2).activeElement === input;
869
+ if (!ctx2.allowMouseWheel || !isInputFocused)
870
+ return;
871
+ event.preventDefault();
872
+ const dir = Math.sign(event.deltaY) * -1;
873
+ if (dir === 1) {
874
+ send("INCREMENT");
875
+ } else if (dir === -1) {
876
+ send("DECREMENT");
877
+ }
878
+ }
879
+ return addDomEvent(input, "wheel", onWheel, { passive: false });
880
+ },
881
+ activatePointerLock(ctx2) {
882
+ if (isSafari() || !supportsPointerEvent())
883
+ return;
884
+ return requestPointerLock(dom.getDoc(ctx2));
885
+ },
886
+ trackMousemove(ctx2, _evt, { send }) {
887
+ const doc = dom.getDoc(ctx2);
888
+ function onMousemove(event) {
889
+ if (!ctx2.scrubberCursorPoint)
890
+ return;
891
+ const value = dom.getMousementValue(ctx2, event);
892
+ if (!value.hint)
893
+ return;
894
+ send({
895
+ type: "POINTER_MOVE_SCRUBBER",
896
+ hint: value.hint,
897
+ point: value.point
898
+ });
899
+ }
900
+ function onMouseup() {
901
+ send("POINTER_UP_SCRUBBER");
807
902
  }
903
+ return callAll2(
904
+ addDomEvent(doc, "mousemove", onMousemove, false),
905
+ addDomEvent(doc, "mouseup", onMouseup, false)
906
+ );
808
907
  }
809
- return addDomEvent(input, "wheel", onWheel, { passive: false });
810
908
  },
811
- activatePointerLock(ctx2) {
812
- if (isSafari() || !supportsPointerEvent())
813
- return;
814
- return requestPointerLock(dom.getDoc(ctx2));
815
- },
816
- trackMousemove(ctx2, _evt, { send }) {
817
- const doc = dom.getDoc(ctx2);
818
- function onMousemove(event) {
819
- if (!ctx2.scrubberCursorPoint)
909
+ actions: {
910
+ focusInput(ctx2) {
911
+ if (!ctx2.focusInputOnChange)
820
912
  return;
821
- const value = dom.getMousementValue(ctx2, event);
822
- if (!value.hint)
913
+ const input = dom.getInputEl(ctx2);
914
+ raf(() => input == null ? void 0 : input.focus());
915
+ },
916
+ increment(ctx2, evt) {
917
+ ctx2.value = utils.increment(ctx2, evt.step);
918
+ },
919
+ decrement(ctx2, evt) {
920
+ ctx2.value = utils.decrement(ctx2, evt.step);
921
+ },
922
+ clampValue(ctx2) {
923
+ ctx2.value = utils.clamp(ctx2);
924
+ },
925
+ roundValue(ctx2) {
926
+ if (ctx2.value !== "") {
927
+ ctx2.value = utils.round(ctx2);
928
+ }
929
+ },
930
+ setValue(ctx2, evt) {
931
+ var _a;
932
+ const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
933
+ ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
934
+ },
935
+ clearValue(ctx2) {
936
+ ctx2.value = "";
937
+ },
938
+ setToMax(ctx2) {
939
+ ctx2.value = ctx2.max.toString();
940
+ },
941
+ setToMin(ctx2) {
942
+ ctx2.value = ctx2.min.toString();
943
+ },
944
+ setHint(ctx2, evt) {
945
+ ctx2.hint = evt.hint;
946
+ },
947
+ clearHint(ctx2) {
948
+ ctx2.hint = null;
949
+ },
950
+ setHintToSet(ctx2) {
951
+ ctx2.hint = "set";
952
+ },
953
+ invokeOnChange(ctx2) {
954
+ var _a;
955
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
956
+ value: ctx2.value,
957
+ valueAsNumber: ctx2.valueAsNumber
958
+ });
959
+ },
960
+ invokeOnFocus(ctx2, evt) {
961
+ var _a;
962
+ let srcElement = null;
963
+ if (evt.type === "PRESS_DOWN") {
964
+ srcElement = dom.getActiveButton(ctx2, evt.hint);
965
+ } else if (evt.type === "FOCUS") {
966
+ srcElement = dom.getInputEl(ctx2);
967
+ } else if (evt.type === "PRESS_DOWN_SCRUBBER") {
968
+ srcElement = dom.getScrubberEl(ctx2);
969
+ }
970
+ (_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
971
+ value: ctx2.value,
972
+ valueAsNumber: ctx2.valueAsNumber,
973
+ srcElement
974
+ });
975
+ },
976
+ invokeOnBlur(ctx2) {
977
+ var _a;
978
+ (_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
979
+ value: ctx2.value,
980
+ valueAsNumber: ctx2.valueAsNumber
981
+ });
982
+ },
983
+ invokeOnInvalid(ctx2) {
984
+ var _a;
985
+ if (!ctx2.isOutOfRange)
823
986
  return;
824
- send({
825
- type: "POINTER_MOVE_SCRUBBER",
826
- hint: value.hint,
827
- point: value.point
987
+ const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
988
+ (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
989
+ reason,
990
+ value: ctx2.formattedValue,
991
+ valueAsNumber: ctx2.valueAsNumber
828
992
  });
993
+ },
994
+ syncInputValue(ctx2) {
995
+ const input = dom.getInputEl(ctx2);
996
+ if (!input || input.value == ctx2.value)
997
+ return;
998
+ const value = utils.parse(ctx2, input.value);
999
+ ctx2.value = utils.sanitize(ctx2, value);
1000
+ },
1001
+ setCursorPoint(ctx2, evt) {
1002
+ ctx2.scrubberCursorPoint = evt.point;
1003
+ },
1004
+ clearCursorPoint(ctx2) {
1005
+ ctx2.scrubberCursorPoint = null;
1006
+ },
1007
+ setVirtualCursorPosition(ctx2) {
1008
+ const cursor = dom.getCursorEl(ctx2);
1009
+ if (!cursor || !ctx2.scrubberCursorPoint)
1010
+ return;
1011
+ const { x, y } = ctx2.scrubberCursorPoint;
1012
+ cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
1013
+ },
1014
+ dispatchChangeEvent(ctx2) {
1015
+ dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
829
1016
  }
830
- function onMouseup() {
831
- send("POINTER_UP_SCRUBBER");
832
- }
833
- return callAll2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
834
- }
835
- },
836
- actions: {
837
- focusInput(ctx2) {
838
- if (!ctx2.focusInputOnChange)
839
- return;
840
- const input = dom.getInputEl(ctx2);
841
- raf(() => input == null ? void 0 : input.focus());
842
- },
843
- increment(ctx2, evt) {
844
- ctx2.value = utils.increment(ctx2, evt.step);
845
- },
846
- decrement(ctx2, evt) {
847
- ctx2.value = utils.decrement(ctx2, evt.step);
848
- },
849
- clampValue(ctx2) {
850
- ctx2.value = utils.clamp(ctx2);
851
- },
852
- roundValue(ctx2) {
853
- if (ctx2.value !== "") {
854
- ctx2.value = utils.round(ctx2);
855
- }
856
- },
857
- setValue(ctx2, evt) {
858
- var _a;
859
- const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
860
- ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
861
1017
  },
862
- clearValue(ctx2) {
863
- ctx2.value = "";
864
- },
865
- setToMax(ctx2) {
866
- ctx2.value = ctx2.max.toString();
867
- },
868
- setToMin(ctx2) {
869
- ctx2.value = ctx2.min.toString();
870
- },
871
- setHint(ctx2, evt) {
872
- ctx2.hint = evt.hint;
873
- },
874
- clearHint(ctx2) {
875
- ctx2.hint = null;
876
- },
877
- setHintToSet(ctx2) {
878
- ctx2.hint = "set";
879
- },
880
- invokeOnChange(ctx2) {
881
- var _a;
882
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
883
- value: ctx2.value,
884
- valueAsNumber: ctx2.valueAsNumber
885
- });
886
- },
887
- invokeOnInvalid(ctx2) {
888
- var _a;
889
- if (!ctx2.isOutOfRange)
890
- return;
891
- const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
892
- (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
893
- reason,
894
- value: ctx2.formattedValue,
895
- valueAsNumber: ctx2.valueAsNumber
896
- });
897
- },
898
- syncInputValue(ctx2) {
899
- const input = dom.getInputEl(ctx2);
900
- if (!input || input.value == ctx2.value)
901
- return;
902
- const value = utils.parse(ctx2, input.value);
903
- ctx2.value = utils.sanitize(ctx2, value);
904
- },
905
- setCursorPoint(ctx2, evt) {
906
- ctx2.scrubberCursorPoint = evt.point;
907
- },
908
- clearCursorPoint(ctx2) {
909
- ctx2.scrubberCursorPoint = null;
910
- },
911
- updateCursor(ctx2) {
912
- const cursor = dom.getCursorEl(ctx2);
913
- if (!cursor || !ctx2.scrubberCursorPoint)
914
- return;
915
- const { x, y } = ctx2.scrubberCursorPoint;
916
- cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
917
- },
918
- addCustomCursor(ctx2) {
919
- if (isSafari() || !supportsPointerEvent())
920
- return;
921
- dom.createVirtualCursor(ctx2);
922
- },
923
- removeCustomCursor(ctx2) {
924
- var _a;
925
- if (isSafari() || !supportsPointerEvent())
926
- return;
927
- (_a = dom.getCursorEl(ctx2)) == null ? void 0 : _a.remove();
928
- },
929
- disableTextSelection(ctx2) {
930
- const doc = dom.getDoc(ctx2);
931
- doc.body.style.pointerEvents = "none";
932
- doc.documentElement.style.userSelect = "none";
933
- doc.documentElement.style.cursor = "ew-resize";
934
- },
935
- restoreTextSelection(ctx2) {
936
- const doc = dom.getDoc(ctx2);
937
- doc.body.style.pointerEvents = "";
938
- doc.documentElement.style.userSelect = "";
939
- doc.documentElement.style.cursor = "";
940
- }
941
- },
942
- hookSync: true
943
- });
1018
+ hookSync: true
1019
+ }
1020
+ );
944
1021
  }
945
1022
  // Annotate the CommonJS export names for ESM import in node:
946
1023
  0 && (module.exports = {