@zag-js/number-input 0.0.0-dev-20220730064719 → 0.0.0-dev-20220823143115

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 +396 -359
  2. package/dist/index.mjs +398 -361
  3. package/package.json +5 -4
package/dist/index.mjs CHANGED
@@ -25,11 +25,8 @@ function getPlatform() {
25
25
  }
26
26
  var pt = (v) => isDom() && v.test(getPlatform());
27
27
  var vn = (v) => isDom() && v.test(navigator.vendor);
28
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
29
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
30
28
  var isSafari = () => isApple() && vn(/apple/i);
31
29
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
32
- var isIos = () => isApple() && !isMac();
33
30
  function isDocument(el) {
34
31
  return el.nodeType === Node.DOCUMENT_NODE;
35
32
  }
@@ -66,21 +63,6 @@ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
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
66
  var fallback = {
85
67
  pageX: 0,
86
68
  pageY: 0,
@@ -110,6 +92,21 @@ function addDomEvent(target, eventName, handler, options) {
110
92
  node == null ? void 0 : node.removeEventListener(eventName, handler, options);
111
93
  };
112
94
  }
95
+ function observeAttributes(node, attributes, fn) {
96
+ if (!node)
97
+ return;
98
+ const attrs = Array.isArray(attributes) ? attributes : [attributes];
99
+ const win = node.ownerDocument.defaultView || window;
100
+ const obs = new win.MutationObserver((changes) => {
101
+ for (const change of changes) {
102
+ if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
103
+ fn(change);
104
+ }
105
+ }
106
+ });
107
+ obs.observe(node, { attributes: true, attributeFilter: attrs });
108
+ return () => obs.disconnect();
109
+ }
113
110
  function raf(fn) {
114
111
  const id = globalThis.requestAnimationFrame(fn);
115
112
  return function cleanup() {
@@ -148,7 +145,10 @@ function requestPointerLock(doc, handlers = {}) {
148
145
  if (!supported)
149
146
  return;
150
147
  body.requestPointerLock();
151
- const cleanup = callAll(addPointerlockChangeListener(doc, onPointerChange), addPointerlockErrorListener(doc, onPointerError));
148
+ const cleanup = callAll(
149
+ addPointerlockChangeListener(doc, onPointerChange),
150
+ addPointerlockErrorListener(doc, onPointerError)
151
+ );
152
152
  return function dispose() {
153
153
  if (!supported)
154
154
  return;
@@ -443,7 +443,7 @@ function connect(state, send, normalize) {
443
443
  name: state.context.name,
444
444
  id: dom.getInputId(state.context),
445
445
  role: "spinbutton",
446
- value: state.context.formattedValue,
446
+ defaultValue: state.context.formattedValue,
447
447
  pattern: state.context.pattern,
448
448
  inputMode: state.context.inputMode,
449
449
  "aria-invalid": isInvalid || void 0,
@@ -455,7 +455,7 @@ function connect(state, send, normalize) {
455
455
  autoCorrect: "off",
456
456
  spellCheck: "false",
457
457
  type: "text",
458
- "aria-roledescription": !isIos() ? "number field" : void 0,
458
+ "aria-roledescription": "numberfield",
459
459
  "aria-valuemin": state.context.min,
460
460
  "aria-valuemax": state.context.max,
461
461
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -581,379 +581,416 @@ var callAll2 = (...fns) => (...a) => {
581
581
  });
582
582
  };
583
583
 
584
+ // ../../utilities/form-utils/dist/index.mjs
585
+ function getWindow(el) {
586
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
587
+ }
588
+ function getDescriptor(el, options) {
589
+ const { type, property } = options;
590
+ const proto = getWindow(el)[type].prototype;
591
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
592
+ }
593
+ function dispatchInputValueEvent(el, value) {
594
+ var _a;
595
+ if (!el)
596
+ return;
597
+ const win = getWindow(el);
598
+ if (!(el instanceof win.HTMLInputElement))
599
+ return;
600
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
601
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
602
+ const event = new win.Event("input", { bubbles: true });
603
+ el.dispatchEvent(event);
604
+ }
605
+
584
606
  // src/number-input.machine.ts
585
607
  var { not, and } = guards;
586
608
  function machine(ctx) {
587
- return createMachine({
588
- id: "number-input",
589
- initial: "unknown",
590
- context: {
591
- dir: "ltr",
592
- focusInputOnChange: true,
593
- clampValueOnBlur: true,
594
- allowOverflow: false,
595
- inputMode: "decimal",
596
- pattern: "[0-9]*(.[0-9]+)?",
597
- hint: null,
598
- value: "",
599
- step: 1,
600
- min: Number.MIN_SAFE_INTEGER,
601
- max: Number.MAX_SAFE_INTEGER,
602
- scrubberCursorPoint: null,
603
- invalid: false,
604
- spinOnPress: true,
605
- ...ctx,
606
- messages: {
607
- incrementLabel: "increment value",
608
- decrementLabel: "decrease value",
609
- ...ctx.messages
610
- }
611
- },
612
- computed: {
613
- isRtl: (ctx2) => ctx2.dir === "rtl",
614
- valueAsNumber: (ctx2) => valueOf(ctx2.value),
615
- isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
616
- isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
617
- isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
618
- isValueEmpty: (ctx2) => ctx2.value === "",
619
- canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
620
- canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
621
- valueText: (ctx2) => {
622
- var _a, _b;
623
- return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
624
- },
625
- formattedValue: (ctx2) => {
626
- var _a;
627
- return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
628
- }
629
- },
630
- watch: {
631
- value: ["invokeOnChange"],
632
- isOutOfRange: ["invokeOnInvalid"],
633
- scrubberCursorPoint: ["setVirtualCursorPosition"]
634
- },
635
- on: {
636
- SET_VALUE: {
637
- actions: ["setValue", "setHintToSet"]
638
- },
639
- CLEAR_VALUE: {
640
- actions: ["clearValue"]
641
- },
642
- INCREMENT: {
643
- actions: ["increment"]
609
+ return createMachine(
610
+ {
611
+ id: "number-input",
612
+ initial: "unknown",
613
+ context: {
614
+ dir: "ltr",
615
+ focusInputOnChange: true,
616
+ clampValueOnBlur: true,
617
+ allowOverflow: false,
618
+ inputMode: "decimal",
619
+ pattern: "[0-9]*(.[0-9]+)?",
620
+ hint: null,
621
+ value: "",
622
+ step: 1,
623
+ min: Number.MIN_SAFE_INTEGER,
624
+ max: Number.MAX_SAFE_INTEGER,
625
+ scrubberCursorPoint: null,
626
+ invalid: false,
627
+ spinOnPress: true,
628
+ ...ctx,
629
+ messages: {
630
+ incrementLabel: "increment value",
631
+ decrementLabel: "decrease value",
632
+ ...ctx.messages
633
+ }
644
634
  },
645
- DECREMENT: {
646
- actions: ["decrement"]
647
- }
648
- },
649
- states: {
650
- unknown: {
651
- on: {
652
- SETUP: {
653
- target: "idle",
654
- actions: "syncInputValue"
655
- }
635
+ computed: {
636
+ isRtl: (ctx2) => ctx2.dir === "rtl",
637
+ valueAsNumber: (ctx2) => valueOf(ctx2.value),
638
+ isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
639
+ isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
640
+ isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
641
+ isValueEmpty: (ctx2) => ctx2.value === "",
642
+ canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
643
+ canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
644
+ valueText: (ctx2) => {
645
+ var _a, _b;
646
+ return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
647
+ },
648
+ formattedValue: (ctx2) => {
649
+ var _a;
650
+ return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
656
651
  }
657
652
  },
658
- idle: {
659
- exit: "invokeOnFocus",
660
- on: {
661
- PRESS_DOWN: {
662
- target: "before:spin",
663
- actions: ["focusInput", "setHint"]
664
- },
665
- PRESS_DOWN_SCRUBBER: {
666
- target: "scrubbing",
667
- actions: ["focusInput", "setHint", "setCursorPoint"]
653
+ watch: {
654
+ value: ["invokeOnChange", "dispatchChangeEvent"],
655
+ isOutOfRange: ["invokeOnInvalid"],
656
+ scrubberCursorPoint: ["setVirtualCursorPosition"]
657
+ },
658
+ on: {
659
+ SET_VALUE: [
660
+ {
661
+ guard: "clampOnBlur",
662
+ actions: ["setValue", "clampValue", "setHintToSet"]
668
663
  },
669
- FOCUS: "focused"
664
+ {
665
+ actions: ["setValue", "setHintToSet"]
666
+ }
667
+ ],
668
+ CLEAR_VALUE: {
669
+ actions: ["clearValue"]
670
+ },
671
+ INCREMENT: {
672
+ actions: ["increment"]
673
+ },
674
+ DECREMENT: {
675
+ actions: ["decrement"]
670
676
  }
671
677
  },
672
- focused: {
673
- tags: "focus",
674
- entry: "focusInput",
675
- activities: "attachWheelListener",
676
- on: {
677
- PRESS_DOWN: {
678
- target: "before:spin",
679
- actions: ["focusInput", "setHint"]
680
- },
681
- PRESS_DOWN_SCRUBBER: {
682
- target: "scrubbing",
683
- actions: ["focusInput", "setHint", "setCursorPoint"]
684
- },
685
- ARROW_UP: {
686
- actions: "increment"
687
- },
688
- ARROW_DOWN: {
689
- actions: "decrement"
690
- },
691
- HOME: {
692
- actions: "setToMin"
693
- },
694
- END: {
695
- actions: "setToMax"
696
- },
697
- CHANGE: {
698
- actions: ["setValue", "setHint"]
699
- },
700
- BLUR: [
701
- {
702
- guard: "isInvalidExponential",
678
+ states: {
679
+ unknown: {
680
+ on: {
681
+ SETUP: {
703
682
  target: "idle",
704
- actions: ["clearValue", "clearHint", "invokeOnBlur"]
683
+ actions: "syncInputValue"
684
+ }
685
+ }
686
+ },
687
+ idle: {
688
+ exit: "invokeOnFocus",
689
+ on: {
690
+ PRESS_DOWN: {
691
+ target: "before:spin",
692
+ actions: ["focusInput", "setHint"]
705
693
  },
706
- {
707
- guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
708
- target: "idle",
709
- actions: ["clampValue", "clearHint", "invokeOnBlur"]
694
+ PRESS_DOWN_SCRUBBER: {
695
+ target: "scrubbing",
696
+ actions: ["focusInput", "setHint", "setCursorPoint"]
710
697
  },
711
- {
712
- target: "idle",
713
- actions: ["roundValue", "invokeOnBlur"]
714
- }
715
- ]
716
- }
717
- },
718
- "before:spin": {
719
- tags: "focus",
720
- activities: "trackButtonDisabled",
721
- entry: choose([
722
- { guard: "isIncrementHint", actions: "increment" },
723
- { guard: "isDecrementHint", actions: "decrement" }
724
- ]),
725
- after: {
726
- CHANGE_DELAY: {
727
- target: "spinning",
728
- guard: and("isInRange", "spinOnPress")
698
+ FOCUS: "focused"
729
699
  }
730
700
  },
731
- on: {
732
- PRESS_UP: {
733
- target: "focused",
734
- actions: "clearHint"
701
+ focused: {
702
+ tags: "focus",
703
+ entry: "focusInput",
704
+ activities: "attachWheelListener",
705
+ on: {
706
+ PRESS_DOWN: {
707
+ target: "before:spin",
708
+ actions: ["focusInput", "setHint"]
709
+ },
710
+ PRESS_DOWN_SCRUBBER: {
711
+ target: "scrubbing",
712
+ actions: ["focusInput", "setHint", "setCursorPoint"]
713
+ },
714
+ ARROW_UP: {
715
+ actions: "increment"
716
+ },
717
+ ARROW_DOWN: {
718
+ actions: "decrement"
719
+ },
720
+ HOME: {
721
+ actions: "setToMin"
722
+ },
723
+ END: {
724
+ actions: "setToMax"
725
+ },
726
+ CHANGE: {
727
+ actions: ["setValue", "setHint"]
728
+ },
729
+ BLUR: [
730
+ {
731
+ guard: "isInvalidExponential",
732
+ target: "idle",
733
+ actions: ["clearValue", "clearHint", "invokeOnBlur"]
734
+ },
735
+ {
736
+ guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
737
+ target: "idle",
738
+ actions: ["clampValue", "clearHint", "invokeOnBlur"]
739
+ },
740
+ {
741
+ target: "idle",
742
+ actions: ["roundValue", "invokeOnBlur"]
743
+ }
744
+ ]
735
745
  }
736
- }
737
- },
738
- spinning: {
739
- tags: "focus",
740
- activities: "trackButtonDisabled",
741
- every: [
742
- {
743
- delay: "CHANGE_INTERVAL",
744
- guard: and(not("isAtMin"), "isIncrementHint"),
745
- actions: "increment"
746
+ },
747
+ "before:spin": {
748
+ tags: "focus",
749
+ activities: "trackButtonDisabled",
750
+ entry: choose([
751
+ { guard: "isIncrementHint", actions: "increment" },
752
+ { guard: "isDecrementHint", actions: "decrement" }
753
+ ]),
754
+ after: {
755
+ CHANGE_DELAY: {
756
+ target: "spinning",
757
+ guard: and("isInRange", "spinOnPress")
758
+ }
746
759
  },
747
- {
748
- delay: "CHANGE_INTERVAL",
749
- guard: and(not("isAtMax"), "isDecrementHint"),
750
- actions: "decrement"
751
- }
752
- ],
753
- on: {
754
- PRESS_UP: {
755
- target: "focused",
756
- actions: "clearHint"
760
+ on: {
761
+ PRESS_UP: {
762
+ target: "focused",
763
+ actions: "clearHint"
764
+ }
757
765
  }
758
- }
759
- },
760
- scrubbing: {
761
- tags: "focus",
762
- exit: "clearCursorPoint",
763
- activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
764
- on: {
765
- POINTER_UP_SCRUBBER: "focused",
766
- POINTER_MOVE_SCRUBBER: [
766
+ },
767
+ spinning: {
768
+ tags: "focus",
769
+ activities: "trackButtonDisabled",
770
+ every: [
767
771
  {
768
- guard: "isIncrementHint",
769
- actions: ["increment", "setCursorPoint"]
772
+ delay: "CHANGE_INTERVAL",
773
+ guard: and(not("isAtMin"), "isIncrementHint"),
774
+ actions: "increment"
770
775
  },
771
776
  {
772
- guard: "isDecrementHint",
773
- actions: ["decrement", "setCursorPoint"]
777
+ delay: "CHANGE_INTERVAL",
778
+ guard: and(not("isAtMax"), "isDecrementHint"),
779
+ actions: "decrement"
780
+ }
781
+ ],
782
+ on: {
783
+ PRESS_UP: {
784
+ target: "focused",
785
+ actions: "clearHint"
774
786
  }
775
- ]
787
+ }
788
+ },
789
+ scrubbing: {
790
+ tags: "focus",
791
+ exit: "clearCursorPoint",
792
+ activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
793
+ on: {
794
+ POINTER_UP_SCRUBBER: "focused",
795
+ POINTER_MOVE_SCRUBBER: [
796
+ {
797
+ guard: "isIncrementHint",
798
+ actions: ["increment", "setCursorPoint"]
799
+ },
800
+ {
801
+ guard: "isDecrementHint",
802
+ actions: ["decrement", "setCursorPoint"]
803
+ }
804
+ ]
805
+ }
776
806
  }
777
807
  }
778
- }
779
- }, {
780
- delays: {
781
- CHANGE_INTERVAL: 50,
782
- CHANGE_DELAY: 300
783
- },
784
- guards: {
785
- clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
786
- isAtMin: (ctx2) => ctx2.isAtMin,
787
- spinOnPress: (ctx2) => !!ctx2.spinOnPress,
788
- isAtMax: (ctx2) => ctx2.isAtMax,
789
- isInRange: (ctx2) => !ctx2.isOutOfRange,
790
- isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
791
- isEmptyValue: (ctx2) => ctx2.isValueEmpty,
792
- isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
793
- isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
794
808
  },
795
- activities: {
796
- setupVirtualCursor(ctx2) {
797
- return dom.setupVirtualCursor(ctx2);
798
- },
799
- preventTextSelection(ctx2) {
800
- return dom.preventTextSelection(ctx2);
801
- },
802
- trackButtonDisabled(ctx2, _evt, { send }) {
803
- const btn = dom.getActiveButton(ctx2, ctx2.hint);
804
- return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
805
- },
806
- attachWheelListener(ctx2, _evt, { send }) {
807
- const input = dom.getInputEl(ctx2);
808
- if (!input)
809
- return;
810
- function onWheel(event) {
811
- const isInputFocused = dom.getDoc(ctx2).activeElement === input;
812
- if (!ctx2.allowMouseWheel || !isInputFocused)
809
+ {
810
+ delays: {
811
+ CHANGE_INTERVAL: 50,
812
+ CHANGE_DELAY: 300
813
+ },
814
+ guards: {
815
+ clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
816
+ isAtMin: (ctx2) => ctx2.isAtMin,
817
+ spinOnPress: (ctx2) => !!ctx2.spinOnPress,
818
+ isAtMax: (ctx2) => ctx2.isAtMax,
819
+ isInRange: (ctx2) => !ctx2.isOutOfRange,
820
+ isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
821
+ isEmptyValue: (ctx2) => ctx2.isValueEmpty,
822
+ isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
823
+ isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
824
+ },
825
+ activities: {
826
+ setupVirtualCursor(ctx2) {
827
+ return dom.setupVirtualCursor(ctx2);
828
+ },
829
+ preventTextSelection(ctx2) {
830
+ return dom.preventTextSelection(ctx2);
831
+ },
832
+ trackButtonDisabled(ctx2, _evt, { send }) {
833
+ const btn = dom.getActiveButton(ctx2, ctx2.hint);
834
+ return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
835
+ },
836
+ attachWheelListener(ctx2, _evt, { send }) {
837
+ const input = dom.getInputEl(ctx2);
838
+ if (!input)
813
839
  return;
814
- event.preventDefault();
815
- const dir = Math.sign(event.deltaY) * -1;
816
- if (dir === 1) {
817
- send("INCREMENT");
818
- } else if (dir === -1) {
819
- send("DECREMENT");
840
+ function onWheel(event) {
841
+ const isInputFocused = dom.getDoc(ctx2).activeElement === input;
842
+ if (!ctx2.allowMouseWheel || !isInputFocused)
843
+ return;
844
+ event.preventDefault();
845
+ const dir = Math.sign(event.deltaY) * -1;
846
+ if (dir === 1) {
847
+ send("INCREMENT");
848
+ } else if (dir === -1) {
849
+ send("DECREMENT");
850
+ }
820
851
  }
852
+ return addDomEvent(input, "wheel", onWheel, { passive: false });
853
+ },
854
+ activatePointerLock(ctx2) {
855
+ if (isSafari() || !supportsPointerEvent())
856
+ return;
857
+ return requestPointerLock(dom.getDoc(ctx2));
858
+ },
859
+ trackMousemove(ctx2, _evt, { send }) {
860
+ const doc = dom.getDoc(ctx2);
861
+ function onMousemove(event) {
862
+ if (!ctx2.scrubberCursorPoint)
863
+ return;
864
+ const value = dom.getMousementValue(ctx2, event);
865
+ if (!value.hint)
866
+ return;
867
+ send({
868
+ type: "POINTER_MOVE_SCRUBBER",
869
+ hint: value.hint,
870
+ point: value.point
871
+ });
872
+ }
873
+ function onMouseup() {
874
+ send("POINTER_UP_SCRUBBER");
875
+ }
876
+ return callAll2(
877
+ addDomEvent(doc, "mousemove", onMousemove, false),
878
+ addDomEvent(doc, "mouseup", onMouseup, false)
879
+ );
821
880
  }
822
- return addDomEvent(input, "wheel", onWheel, { passive: false });
823
881
  },
824
- activatePointerLock(ctx2) {
825
- if (isSafari() || !supportsPointerEvent())
826
- return;
827
- return requestPointerLock(dom.getDoc(ctx2));
828
- },
829
- trackMousemove(ctx2, _evt, { send }) {
830
- const doc = dom.getDoc(ctx2);
831
- function onMousemove(event) {
832
- if (!ctx2.scrubberCursorPoint)
882
+ actions: {
883
+ focusInput(ctx2) {
884
+ if (!ctx2.focusInputOnChange)
833
885
  return;
834
- const value = dom.getMousementValue(ctx2, event);
835
- if (!value.hint)
886
+ const input = dom.getInputEl(ctx2);
887
+ raf(() => input == null ? void 0 : input.focus());
888
+ },
889
+ increment(ctx2, evt) {
890
+ ctx2.value = utils.increment(ctx2, evt.step);
891
+ },
892
+ decrement(ctx2, evt) {
893
+ ctx2.value = utils.decrement(ctx2, evt.step);
894
+ },
895
+ clampValue(ctx2) {
896
+ ctx2.value = utils.clamp(ctx2);
897
+ },
898
+ roundValue(ctx2) {
899
+ if (ctx2.value !== "") {
900
+ ctx2.value = utils.round(ctx2);
901
+ }
902
+ },
903
+ setValue(ctx2, evt) {
904
+ var _a;
905
+ const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
906
+ ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
907
+ },
908
+ clearValue(ctx2) {
909
+ ctx2.value = "";
910
+ },
911
+ setToMax(ctx2) {
912
+ ctx2.value = ctx2.max.toString();
913
+ },
914
+ setToMin(ctx2) {
915
+ ctx2.value = ctx2.min.toString();
916
+ },
917
+ setHint(ctx2, evt) {
918
+ ctx2.hint = evt.hint;
919
+ },
920
+ clearHint(ctx2) {
921
+ ctx2.hint = null;
922
+ },
923
+ setHintToSet(ctx2) {
924
+ ctx2.hint = "set";
925
+ },
926
+ invokeOnChange(ctx2) {
927
+ var _a;
928
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
929
+ value: ctx2.value,
930
+ valueAsNumber: ctx2.valueAsNumber
931
+ });
932
+ },
933
+ invokeOnFocus(ctx2, evt) {
934
+ var _a;
935
+ let srcElement = null;
936
+ if (evt.type === "PRESS_DOWN") {
937
+ srcElement = dom.getActiveButton(ctx2, evt.hint);
938
+ } else if (evt.type === "FOCUS") {
939
+ srcElement = dom.getInputEl(ctx2);
940
+ } else if (evt.type === "PRESS_DOWN_SCRUBBER") {
941
+ srcElement = dom.getScrubberEl(ctx2);
942
+ }
943
+ (_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
944
+ value: ctx2.value,
945
+ valueAsNumber: ctx2.valueAsNumber,
946
+ srcElement
947
+ });
948
+ },
949
+ invokeOnBlur(ctx2) {
950
+ var _a;
951
+ (_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
952
+ value: ctx2.value,
953
+ valueAsNumber: ctx2.valueAsNumber
954
+ });
955
+ },
956
+ invokeOnInvalid(ctx2) {
957
+ var _a;
958
+ if (!ctx2.isOutOfRange)
836
959
  return;
837
- send({
838
- type: "POINTER_MOVE_SCRUBBER",
839
- hint: value.hint,
840
- point: value.point
960
+ const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
961
+ (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
962
+ reason,
963
+ value: ctx2.formattedValue,
964
+ valueAsNumber: ctx2.valueAsNumber
841
965
  });
966
+ },
967
+ syncInputValue(ctx2) {
968
+ const input = dom.getInputEl(ctx2);
969
+ if (!input || input.value == ctx2.value)
970
+ return;
971
+ const value = utils.parse(ctx2, input.value);
972
+ ctx2.value = utils.sanitize(ctx2, value);
973
+ },
974
+ setCursorPoint(ctx2, evt) {
975
+ ctx2.scrubberCursorPoint = evt.point;
976
+ },
977
+ clearCursorPoint(ctx2) {
978
+ ctx2.scrubberCursorPoint = null;
979
+ },
980
+ setVirtualCursorPosition(ctx2) {
981
+ const cursor = dom.getCursorEl(ctx2);
982
+ if (!cursor || !ctx2.scrubberCursorPoint)
983
+ return;
984
+ const { x, y } = ctx2.scrubberCursorPoint;
985
+ cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
986
+ },
987
+ dispatchChangeEvent(ctx2) {
988
+ dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
842
989
  }
843
- function onMouseup() {
844
- send("POINTER_UP_SCRUBBER");
845
- }
846
- return callAll2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
847
- }
848
- },
849
- actions: {
850
- focusInput(ctx2) {
851
- if (!ctx2.focusInputOnChange)
852
- return;
853
- const input = dom.getInputEl(ctx2);
854
- raf(() => input == null ? void 0 : input.focus());
855
- },
856
- increment(ctx2, evt) {
857
- ctx2.value = utils.increment(ctx2, evt.step);
858
- },
859
- decrement(ctx2, evt) {
860
- ctx2.value = utils.decrement(ctx2, evt.step);
861
- },
862
- clampValue(ctx2) {
863
- ctx2.value = utils.clamp(ctx2);
864
- },
865
- roundValue(ctx2) {
866
- if (ctx2.value !== "") {
867
- ctx2.value = utils.round(ctx2);
868
- }
869
- },
870
- setValue(ctx2, evt) {
871
- var _a;
872
- const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
873
- ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
874
- },
875
- clearValue(ctx2) {
876
- ctx2.value = "";
877
- },
878
- setToMax(ctx2) {
879
- ctx2.value = ctx2.max.toString();
880
- },
881
- setToMin(ctx2) {
882
- ctx2.value = ctx2.min.toString();
883
- },
884
- setHint(ctx2, evt) {
885
- ctx2.hint = evt.hint;
886
- },
887
- clearHint(ctx2) {
888
- ctx2.hint = null;
889
- },
890
- setHintToSet(ctx2) {
891
- ctx2.hint = "set";
892
- },
893
- invokeOnChange(ctx2) {
894
- var _a;
895
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
896
- value: ctx2.value,
897
- valueAsNumber: ctx2.valueAsNumber
898
- });
899
- },
900
- invokeOnFocus(ctx2, evt) {
901
- var _a;
902
- let srcElement = null;
903
- if (evt.type === "PRESS_DOWN") {
904
- srcElement = dom.getActiveButton(ctx2, evt.hint);
905
- } else if (evt.type === "FOCUS") {
906
- srcElement = dom.getInputEl(ctx2);
907
- } else if (evt.type === "PRESS_DOWN_SCRUBBER") {
908
- srcElement = dom.getScrubberEl(ctx2);
909
- }
910
- (_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
911
- value: ctx2.value,
912
- valueAsNumber: ctx2.valueAsNumber,
913
- srcElement
914
- });
915
990
  },
916
- invokeOnBlur(ctx2) {
917
- var _a;
918
- (_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
919
- value: ctx2.value,
920
- valueAsNumber: ctx2.valueAsNumber
921
- });
922
- },
923
- invokeOnInvalid(ctx2) {
924
- var _a;
925
- if (!ctx2.isOutOfRange)
926
- return;
927
- const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
928
- (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
929
- reason,
930
- value: ctx2.formattedValue,
931
- valueAsNumber: ctx2.valueAsNumber
932
- });
933
- },
934
- syncInputValue(ctx2) {
935
- const input = dom.getInputEl(ctx2);
936
- if (!input || input.value == ctx2.value)
937
- return;
938
- const value = utils.parse(ctx2, input.value);
939
- ctx2.value = utils.sanitize(ctx2, value);
940
- },
941
- setCursorPoint(ctx2, evt) {
942
- ctx2.scrubberCursorPoint = evt.point;
943
- },
944
- clearCursorPoint(ctx2) {
945
- ctx2.scrubberCursorPoint = null;
946
- },
947
- setVirtualCursorPosition(ctx2) {
948
- const cursor = dom.getCursorEl(ctx2);
949
- if (!cursor || !ctx2.scrubberCursorPoint)
950
- return;
951
- const { x, y } = ctx2.scrubberCursorPoint;
952
- cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
953
- }
954
- },
955
- hookSync: true
956
- });
991
+ hookSync: true
992
+ }
993
+ );
957
994
  }
958
995
  export {
959
996
  connect,