@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.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;
@@ -253,6 +253,44 @@ var dom = defineDomHelpers({
253
253
  getDecButtonEl: (ctx) => dom.getById(ctx, dom.getDecButtonId(ctx)),
254
254
  getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
255
255
  getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
256
+ getActiveButton: (ctx, hint = ctx.hint) => {
257
+ let btnEl = null;
258
+ if (hint === "increment") {
259
+ btnEl = dom.getIncButtonEl(ctx);
260
+ }
261
+ if (hint === "decrement") {
262
+ btnEl = dom.getDecButtonEl(ctx);
263
+ }
264
+ return btnEl;
265
+ },
266
+ setupVirtualCursor(ctx) {
267
+ if (isSafari() || !supportsPointerEvent())
268
+ return;
269
+ dom.createVirtualCursor(ctx);
270
+ return () => {
271
+ var _a;
272
+ (_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
273
+ };
274
+ },
275
+ preventTextSelection(ctx) {
276
+ const doc = dom.getDoc(ctx);
277
+ const html = doc.documentElement;
278
+ const body = doc.body;
279
+ body.style.pointerEvents = "none";
280
+ html.style.userSelect = "none";
281
+ html.style.cursor = "ew-resize";
282
+ return () => {
283
+ body.style.pointerEvents = "";
284
+ html.style.userSelect = "";
285
+ html.style.cursor = "";
286
+ if (!html.style.length) {
287
+ html.removeAttribute("style");
288
+ }
289
+ if (!body.style.length) {
290
+ body.removeAttribute("style");
291
+ }
292
+ };
293
+ },
256
294
  getMousementValue(ctx, event) {
257
295
  const x = roundToDevicePixel(event.movementX);
258
296
  const y = roundToDevicePixel(event.movementY);
@@ -376,6 +414,10 @@ function connect(state, send, normalize) {
376
414
  var _a;
377
415
  (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
378
416
  },
417
+ blur() {
418
+ var _a;
419
+ (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
420
+ },
379
421
  rootProps: normalize.element({
380
422
  id: dom.getRootId(state.context),
381
423
  "data-part": "root",
@@ -401,7 +443,7 @@ function connect(state, send, normalize) {
401
443
  name: state.context.name,
402
444
  id: dom.getInputId(state.context),
403
445
  role: "spinbutton",
404
- value: state.context.formattedValue,
446
+ defaultValue: state.context.formattedValue,
405
447
  pattern: state.context.pattern,
406
448
  inputMode: state.context.inputMode,
407
449
  "aria-invalid": isInvalid || void 0,
@@ -413,7 +455,7 @@ function connect(state, send, normalize) {
413
455
  autoCorrect: "off",
414
456
  spellCheck: "false",
415
457
  type: "text",
416
- "aria-roledescription": !isIos() ? "number field" : void 0,
458
+ "aria-roledescription": "numberfield",
417
459
  "aria-valuemin": state.context.min,
418
460
  "aria-valuemax": state.context.max,
419
461
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -539,381 +581,416 @@ var callAll2 = (...fns) => (...a) => {
539
581
  });
540
582
  };
541
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
+
542
606
  // src/number-input.machine.ts
543
607
  var { not, and } = guards;
544
608
  function machine(ctx) {
545
- return createMachine({
546
- id: "number-input",
547
- initial: "unknown",
548
- context: {
549
- dir: "ltr",
550
- focusInputOnChange: true,
551
- clampValueOnBlur: true,
552
- allowOverflow: false,
553
- inputMode: "decimal",
554
- pattern: "[0-9]*(.[0-9]+)?",
555
- hint: null,
556
- value: "",
557
- step: 1,
558
- min: Number.MIN_SAFE_INTEGER,
559
- max: Number.MAX_SAFE_INTEGER,
560
- scrubberCursorPoint: null,
561
- invalid: false,
562
- ...ctx,
563
- messages: {
564
- incrementLabel: "increment value",
565
- decrementLabel: "decrease value",
566
- ...ctx.messages
567
- }
568
- },
569
- computed: {
570
- isRtl: (ctx2) => ctx2.dir === "rtl",
571
- valueAsNumber: (ctx2) => valueOf(ctx2.value),
572
- isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
573
- isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
574
- isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
575
- isValueEmpty: (ctx2) => ctx2.value === "",
576
- canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
577
- canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
578
- valueText: (ctx2) => {
579
- var _a, _b;
580
- return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
581
- },
582
- formattedValue: (ctx2) => {
583
- var _a;
584
- return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
585
- }
586
- },
587
- watch: {
588
- value: ["invokeOnChange"],
589
- isOutOfRange: ["invokeOnInvalid"]
590
- },
591
- on: {
592
- SET_VALUE: {
593
- actions: ["setValue", "setHintToSet"]
594
- },
595
- CLEAR_VALUE: {
596
- actions: ["clearValue"]
597
- },
598
- INCREMENT: {
599
- 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
+ }
600
634
  },
601
- DECREMENT: {
602
- actions: ["decrement"]
603
- }
604
- },
605
- states: {
606
- unknown: {
607
- on: {
608
- SETUP: {
609
- target: "idle",
610
- actions: "syncInputValue"
611
- }
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;
612
651
  }
613
652
  },
614
- idle: {
615
- on: {
616
- PRESS_DOWN: {
617
- target: "before:spin",
618
- actions: ["focusInput", "setHint"]
619
- },
620
- PRESS_DOWN_SCRUBBER: {
621
- target: "scrubbing",
622
- 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"]
623
663
  },
624
- 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"]
625
676
  }
626
677
  },
627
- focused: {
628
- tags: ["focus"],
629
- entry: "focusInput",
630
- activities: "attachWheelListener",
631
- on: {
632
- PRESS_DOWN: {
633
- target: "before:spin",
634
- actions: ["focusInput", "setHint"]
635
- },
636
- PRESS_DOWN_SCRUBBER: {
637
- target: "scrubbing",
638
- actions: ["focusInput", "setHint", "setCursorPoint"]
639
- },
640
- ARROW_UP: {
641
- actions: "increment"
642
- },
643
- ARROW_DOWN: {
644
- actions: "decrement"
645
- },
646
- HOME: {
647
- actions: "setToMin"
648
- },
649
- END: {
650
- actions: "setToMax"
651
- },
652
- CHANGE: {
653
- actions: ["setValue", "setHint"]
654
- },
655
- BLUR: [
656
- {
657
- guard: "isInvalidExponential",
678
+ states: {
679
+ unknown: {
680
+ on: {
681
+ SETUP: {
658
682
  target: "idle",
659
- actions: ["clearValue", "clearHint"]
683
+ actions: "syncInputValue"
684
+ }
685
+ }
686
+ },
687
+ idle: {
688
+ exit: "invokeOnFocus",
689
+ on: {
690
+ PRESS_DOWN: {
691
+ target: "before:spin",
692
+ actions: ["focusInput", "setHint"]
660
693
  },
661
- {
662
- guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
663
- target: "idle",
664
- actions: ["clampValue", "clearHint"]
694
+ PRESS_DOWN_SCRUBBER: {
695
+ target: "scrubbing",
696
+ actions: ["focusInput", "setHint", "setCursorPoint"]
665
697
  },
666
- {
667
- target: "idle",
668
- actions: "roundValue"
669
- }
670
- ]
671
- }
672
- },
673
- "before:spin": {
674
- tags: ["focus"],
675
- activities: "trackButtonDisabled",
676
- entry: choose([
677
- { guard: "isIncrementHint", actions: "increment" },
678
- { guard: "isDecrementHint", actions: "decrement" }
679
- ]),
680
- after: {
681
- CHANGE_DELAY: {
682
- target: "spinning",
683
- guard: "isInRange"
698
+ FOCUS: "focused"
684
699
  }
685
700
  },
686
- on: {
687
- PRESS_UP: {
688
- target: "focused",
689
- 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
+ ]
690
745
  }
691
- }
692
- },
693
- spinning: {
694
- tags: ["focus"],
695
- activities: "trackButtonDisabled",
696
- every: [
697
- {
698
- delay: "CHANGE_INTERVAL",
699
- guard: and(not("isAtMin"), "isIncrementHint"),
700
- 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
+ }
701
759
  },
702
- {
703
- delay: "CHANGE_INTERVAL",
704
- guard: and(not("isAtMax"), "isDecrementHint"),
705
- actions: "decrement"
706
- }
707
- ],
708
- on: {
709
- PRESS_UP: {
710
- target: "focused",
711
- actions: "clearHint"
760
+ on: {
761
+ PRESS_UP: {
762
+ target: "focused",
763
+ actions: "clearHint"
764
+ }
712
765
  }
713
- }
714
- },
715
- scrubbing: {
716
- tags: ["focus"],
717
- entry: ["addCustomCursor", "disableTextSelection"],
718
- exit: ["removeCustomCursor", "restoreTextSelection"],
719
- activities: ["activatePointerLock", "trackMousemove"],
720
- on: {
721
- POINTER_UP_SCRUBBER: {
722
- target: "focused",
723
- actions: "clearCursorPoint"
724
- },
725
- POINTER_MOVE_SCRUBBER: [
766
+ },
767
+ spinning: {
768
+ tags: "focus",
769
+ activities: "trackButtonDisabled",
770
+ every: [
726
771
  {
727
- guard: "isIncrementHint",
728
- actions: ["increment", "setCursorPoint", "updateCursor"]
772
+ delay: "CHANGE_INTERVAL",
773
+ guard: and(not("isAtMin"), "isIncrementHint"),
774
+ actions: "increment"
729
775
  },
730
776
  {
731
- guard: "isDecrementHint",
732
- actions: ["decrement", "setCursorPoint", "updateCursor"]
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"
733
786
  }
734
- ]
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
+ }
735
806
  }
736
807
  }
737
- }
738
- }, {
739
- delays: {
740
- CHANGE_INTERVAL: 50,
741
- CHANGE_DELAY: 300
742
808
  },
743
- guards: {
744
- clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
745
- isAtMin: (ctx2) => ctx2.isAtMin,
746
- isAtMax: (ctx2) => ctx2.isAtMax,
747
- isInRange: (ctx2) => !ctx2.isOutOfRange,
748
- isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
749
- isEmptyValue: (ctx2) => ctx2.isValueEmpty,
750
- isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
751
- isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
752
- },
753
- activities: {
754
- trackButtonDisabled(ctx2, _evt, { send }) {
755
- let btnEl = null;
756
- if (ctx2.hint === "increment") {
757
- btnEl = dom.getIncButtonEl(ctx2);
758
- }
759
- if (ctx2.hint === "decrement") {
760
- btnEl = dom.getDecButtonEl(ctx2);
761
- }
762
- return observeAttributes(btnEl, "disabled", function onDisable() {
763
- send("PRESS_UP");
764
- });
765
- },
766
- attachWheelListener(ctx2, _evt, { send }) {
767
- const input = dom.getInputEl(ctx2);
768
- if (!input)
769
- return;
770
- function onWheel(event) {
771
- const isInputFocused = dom.getDoc(ctx2).activeElement === input;
772
- 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)
773
839
  return;
774
- event.preventDefault();
775
- const dir = Math.sign(event.deltaY) * -1;
776
- if (dir === 1) {
777
- send("INCREMENT");
778
- } else if (dir === -1) {
779
- 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
+ }
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");
780
875
  }
876
+ return callAll2(
877
+ addDomEvent(doc, "mousemove", onMousemove, false),
878
+ addDomEvent(doc, "mouseup", onMouseup, false)
879
+ );
781
880
  }
782
- return addDomEvent(input, "wheel", onWheel, { passive: false });
783
881
  },
784
- activatePointerLock(ctx2) {
785
- if (isSafari() || !supportsPointerEvent())
786
- return;
787
- return requestPointerLock(dom.getDoc(ctx2));
788
- },
789
- trackMousemove(ctx2, _evt, { send }) {
790
- const doc = dom.getDoc(ctx2);
791
- function onMousemove(event) {
792
- if (!ctx2.scrubberCursorPoint)
882
+ actions: {
883
+ focusInput(ctx2) {
884
+ if (!ctx2.focusInputOnChange)
793
885
  return;
794
- const value = dom.getMousementValue(ctx2, event);
795
- 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)
796
959
  return;
797
- send({
798
- type: "POINTER_MOVE_SCRUBBER",
799
- hint: value.hint,
800
- 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
801
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);
802
989
  }
803
- function onMouseup() {
804
- send("POINTER_UP_SCRUBBER");
805
- }
806
- return callAll2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
807
- }
808
- },
809
- actions: {
810
- focusInput(ctx2) {
811
- if (!ctx2.focusInputOnChange)
812
- return;
813
- const input = dom.getInputEl(ctx2);
814
- raf(() => input == null ? void 0 : input.focus());
815
- },
816
- increment(ctx2, evt) {
817
- ctx2.value = utils.increment(ctx2, evt.step);
818
- },
819
- decrement(ctx2, evt) {
820
- ctx2.value = utils.decrement(ctx2, evt.step);
821
- },
822
- clampValue(ctx2) {
823
- ctx2.value = utils.clamp(ctx2);
824
- },
825
- roundValue(ctx2) {
826
- if (ctx2.value !== "") {
827
- ctx2.value = utils.round(ctx2);
828
- }
829
- },
830
- setValue(ctx2, evt) {
831
- var _a;
832
- const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
833
- ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
834
990
  },
835
- clearValue(ctx2) {
836
- ctx2.value = "";
837
- },
838
- setToMax(ctx2) {
839
- ctx2.value = ctx2.max.toString();
840
- },
841
- setToMin(ctx2) {
842
- ctx2.value = ctx2.min.toString();
843
- },
844
- setHint(ctx2, evt) {
845
- ctx2.hint = evt.hint;
846
- },
847
- clearHint(ctx2) {
848
- ctx2.hint = null;
849
- },
850
- setHintToSet(ctx2) {
851
- ctx2.hint = "set";
852
- },
853
- invokeOnChange(ctx2) {
854
- var _a;
855
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
856
- value: ctx2.value,
857
- valueAsNumber: ctx2.valueAsNumber
858
- });
859
- },
860
- invokeOnInvalid(ctx2) {
861
- var _a;
862
- if (!ctx2.isOutOfRange)
863
- return;
864
- const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
865
- (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
866
- reason,
867
- value: ctx2.formattedValue,
868
- valueAsNumber: ctx2.valueAsNumber
869
- });
870
- },
871
- syncInputValue(ctx2) {
872
- const input = dom.getInputEl(ctx2);
873
- if (!input || input.value == ctx2.value)
874
- return;
875
- const value = utils.parse(ctx2, input.value);
876
- ctx2.value = utils.sanitize(ctx2, value);
877
- },
878
- setCursorPoint(ctx2, evt) {
879
- ctx2.scrubberCursorPoint = evt.point;
880
- },
881
- clearCursorPoint(ctx2) {
882
- ctx2.scrubberCursorPoint = null;
883
- },
884
- updateCursor(ctx2) {
885
- const cursor = dom.getCursorEl(ctx2);
886
- if (!cursor || !ctx2.scrubberCursorPoint)
887
- return;
888
- const { x, y } = ctx2.scrubberCursorPoint;
889
- cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
890
- },
891
- addCustomCursor(ctx2) {
892
- if (isSafari() || !supportsPointerEvent())
893
- return;
894
- dom.createVirtualCursor(ctx2);
895
- },
896
- removeCustomCursor(ctx2) {
897
- var _a;
898
- if (isSafari() || !supportsPointerEvent())
899
- return;
900
- (_a = dom.getCursorEl(ctx2)) == null ? void 0 : _a.remove();
901
- },
902
- disableTextSelection(ctx2) {
903
- const doc = dom.getDoc(ctx2);
904
- doc.body.style.pointerEvents = "none";
905
- doc.documentElement.style.userSelect = "none";
906
- doc.documentElement.style.cursor = "ew-resize";
907
- },
908
- restoreTextSelection(ctx2) {
909
- const doc = dom.getDoc(ctx2);
910
- doc.body.style.pointerEvents = "";
911
- doc.documentElement.style.userSelect = "";
912
- doc.documentElement.style.cursor = "";
913
- }
914
- },
915
- hookSync: true
916
- });
991
+ hookSync: true
992
+ }
993
+ );
917
994
  }
918
995
  export {
919
996
  connect,