@zag-js/number-input 0.0.0-dev-20220415160434 → 0.0.0-dev-20220417135151

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
@@ -1,7 +1,24 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
5
22
  var __export = (target, all) => {
6
23
  for (var name in all)
7
24
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -187,25 +204,25 @@ function requestPointerLock(doc, handlers = {}) {
187
204
 
188
205
  // ../../utilities/number/dist/index.mjs
189
206
  var __defProp2 = Object.defineProperty;
190
- var __defProps = Object.defineProperties;
191
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
192
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
207
+ var __defProps2 = Object.defineProperties;
208
+ var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
209
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
193
210
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
194
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
211
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
195
212
  var __pow = Math.pow;
196
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
197
- var __spreadValues = (a, b) => {
213
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
214
+ var __spreadValues2 = (a, b) => {
198
215
  for (var prop in b || (b = {}))
199
216
  if (__hasOwnProp2.call(b, prop))
200
- __defNormalProp(a, prop, b[prop]);
201
- if (__getOwnPropSymbols)
202
- for (var prop of __getOwnPropSymbols(b)) {
203
- if (__propIsEnum.call(b, prop))
204
- __defNormalProp(a, prop, b[prop]);
217
+ __defNormalProp2(a, prop, b[prop]);
218
+ if (__getOwnPropSymbols2)
219
+ for (var prop of __getOwnPropSymbols2(b)) {
220
+ if (__propIsEnum2.call(b, prop))
221
+ __defNormalProp2(a, prop, b[prop]);
205
222
  }
206
223
  return a;
207
224
  };
208
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
225
+ var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
209
226
  var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
210
227
  function formatter(n) {
211
228
  return parseFloat(nf.format(n));
@@ -249,7 +266,7 @@ function getMaxPrecision(o) {
249
266
  return Math.max(valuePrecision, (_a = o.precision) != null ? _a : 0);
250
267
  }
251
268
  function roundToPrecision(v, o) {
252
- return round(v, getMaxPrecision(__spreadProps(__spreadValues({}, o), { value: v })));
269
+ return round(v, getMaxPrecision(__spreadProps2(__spreadValues2({}, o), { value: v })));
253
270
  }
254
271
  function isAtMax(v, o) {
255
272
  const val = valueOf(v);
@@ -290,30 +307,30 @@ var dom = {
290
307
  var _a;
291
308
  return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
292
309
  },
310
+ getRootId: (ctx) => {
311
+ var _a, _b;
312
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.uid}`;
313
+ },
293
314
  getInputId: (ctx) => {
294
315
  var _a, _b;
295
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input-${ctx.uid}-input`;
316
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.uid}:input`;
296
317
  },
297
318
  getIncButtonId: (ctx) => {
298
319
  var _a, _b;
299
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input-${ctx.uid}-inc-btn`;
320
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.uid}:inc-btn`;
300
321
  },
301
322
  getDecButtonId: (ctx) => {
302
323
  var _a, _b;
303
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input-${ctx.uid}-dec-btn`;
324
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.uid}:dec-btn`;
304
325
  },
305
326
  getScrubberId: (ctx) => {
306
327
  var _a, _b;
307
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input-${ctx.uid}-scrubber`;
328
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.uid}:scrubber`;
308
329
  },
309
- getCursorId: (ctx) => `number-input-${ctx.uid}-cursor`,
330
+ getCursorId: (ctx) => `number-input:${ctx.uid}:cursor`,
310
331
  getLabelId: (ctx) => {
311
332
  var _a, _b;
312
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input-${ctx.uid}-label`;
313
- },
314
- getRootId: (ctx) => {
315
- var _a, _b;
316
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input-${ctx.uid}-root`;
333
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.uid}:label`;
317
334
  },
318
335
  getInputEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getInputId(ctx)),
319
336
  getIncButtonEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getIncButtonId(ctx)),
@@ -602,380 +619,383 @@ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
602
619
 
603
620
  // src/number-input.machine.ts
604
621
  var { not, and } = import_core.guards;
605
- var machine = (0, import_core.createMachine)({
606
- id: "number-input",
607
- initial: "unknown",
608
- context: {
609
- uid: "",
610
- dir: "ltr",
611
- focusInputOnChange: true,
612
- clampValueOnBlur: true,
613
- allowOverflow: false,
614
- inputMode: "decimal",
615
- pattern: "[0-9]*(.[0-9]+)?",
616
- hint: null,
617
- value: "",
618
- step: 1,
619
- min: Number.MIN_SAFE_INTEGER,
620
- max: Number.MAX_SAFE_INTEGER,
621
- precision: 0,
622
- inputSelection: null,
623
- scrubberCursorPoint: null,
624
- invalid: false,
625
- messages: {
626
- incrementLabel: "increment value",
627
- decrementLabel: "decrease value"
628
- }
629
- },
630
- computed: {
631
- isRtl: (ctx) => ctx.dir === "rtl",
632
- valueAsNumber: (ctx) => valueOf(ctx.value),
633
- isAtMin: (ctx) => isAtMin(ctx.value, ctx),
634
- isAtMax: (ctx) => isAtMax(ctx.value, ctx),
635
- isOutOfRange: (ctx) => !isWithinRange(ctx.value, ctx),
636
- canIncrement: (ctx) => ctx.allowOverflow || !ctx.isAtMax,
637
- canDecrement: (ctx) => ctx.allowOverflow || !ctx.isAtMin,
638
- valueText: (ctx) => {
639
- var _a, _b;
640
- return (_b = (_a = ctx.messages).valueText) == null ? void 0 : _b.call(_a, ctx.value);
641
- },
642
- formattedValue: (ctx) => {
643
- var _a, _b;
644
- return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, ctx.value).toString()) != null ? _b : ctx.value;
645
- }
646
- },
647
- watch: {
648
- value: ["invokeOnChange"],
649
- isOutOfRange: ["invokeOnInvalid"]
650
- },
651
- entry: ["syncInputValue"],
652
- on: {
653
- SET_VALUE: {
654
- actions: ["setValue", "setHintToSet"]
655
- },
656
- INCREMENT: { actions: ["increment"] },
657
- DECREMENT: { actions: ["decrement"] }
658
- },
659
- states: {
660
- unknown: {
661
- on: {
662
- SETUP: {
663
- target: "idle",
664
- actions: "setupDocument"
665
- }
622
+ function machine(ctx = {}) {
623
+ return (0, import_core.createMachine)({
624
+ id: "number-input",
625
+ initial: "unknown",
626
+ context: __spreadProps(__spreadValues({
627
+ uid: "",
628
+ dir: "ltr",
629
+ focusInputOnChange: true,
630
+ clampValueOnBlur: true,
631
+ allowOverflow: false,
632
+ inputMode: "decimal",
633
+ pattern: "[0-9]*(.[0-9]+)?",
634
+ hint: null,
635
+ value: "",
636
+ step: 1,
637
+ min: Number.MIN_SAFE_INTEGER,
638
+ max: Number.MAX_SAFE_INTEGER,
639
+ precision: 0,
640
+ inputSelection: null,
641
+ scrubberCursorPoint: null,
642
+ invalid: false
643
+ }, ctx), {
644
+ messages: __spreadValues({
645
+ incrementLabel: "increment value",
646
+ decrementLabel: "decrease value"
647
+ }, ctx.messages)
648
+ }),
649
+ computed: {
650
+ isRtl: (ctx2) => ctx2.dir === "rtl",
651
+ valueAsNumber: (ctx2) => valueOf(ctx2.value),
652
+ isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
653
+ isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
654
+ isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
655
+ canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
656
+ canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
657
+ valueText: (ctx2) => {
658
+ var _a, _b;
659
+ return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
660
+ },
661
+ formattedValue: (ctx2) => {
662
+ var _a, _b;
663
+ return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
666
664
  }
667
665
  },
668
- idle: {
669
- on: {
670
- PRESS_DOWN: {
671
- target: "before:spin",
672
- actions: ["focusInput", "setHint"]
673
- },
674
- PRESS_DOWN_SCRUBBER: {
675
- target: "scrubbing",
676
- actions: ["focusInput", "setHint", "setCursorPoint"]
677
- },
678
- FOCUS: "focused"
679
- }
666
+ watch: {
667
+ value: ["invokeOnChange"],
668
+ isOutOfRange: ["invokeOnInvalid"]
680
669
  },
681
- focused: {
682
- tags: ["focus"],
683
- activities: "attachWheelListener",
684
- on: {
685
- PRESS_DOWN: {
686
- target: "before:spin",
687
- actions: ["focusInput", "setHint"]
688
- },
689
- PRESS_DOWN_SCRUBBER: {
690
- target: "scrubbing",
691
- actions: ["focusInput", "setHint", "setCursorPoint"]
692
- },
693
- ARROW_UP: {
694
- actions: "increment"
695
- },
696
- ARROW_DOWN: {
697
- actions: "decrement"
698
- },
699
- HOME: {
700
- actions: "setToMin"
701
- },
702
- END: {
703
- actions: "setToMax"
704
- },
705
- CHANGE: {
706
- actions: ["setValue", "setSelectionRange", "setHint"]
707
- },
708
- BLUR: [
709
- {
710
- guard: "isInvalidExponential",
670
+ entry: ["syncInputValue"],
671
+ on: {
672
+ SET_VALUE: {
673
+ actions: ["setValue", "setHintToSet"]
674
+ },
675
+ INCREMENT: { actions: ["increment"] },
676
+ DECREMENT: { actions: ["decrement"] }
677
+ },
678
+ states: {
679
+ unknown: {
680
+ on: {
681
+ SETUP: {
711
682
  target: "idle",
712
- actions: ["clearValue", "clearHint"]
683
+ actions: "setupDocument"
684
+ }
685
+ }
686
+ },
687
+ idle: {
688
+ on: {
689
+ PRESS_DOWN: {
690
+ target: "before:spin",
691
+ actions: ["focusInput", "setHint"]
713
692
  },
714
- {
715
- guard: and("clampOnBlur", not("isInRange")),
716
- target: "idle",
717
- actions: ["clampValue", "clearHint"]
693
+ PRESS_DOWN_SCRUBBER: {
694
+ target: "scrubbing",
695
+ actions: ["focusInput", "setHint", "setCursorPoint"]
718
696
  },
719
- {
720
- actions: ["roundValue"]
721
- }
722
- ]
723
- }
724
- },
725
- "before:spin": {
726
- tags: ["focus"],
727
- entry: (0, import_core.choose)([
728
- { guard: "isIncrementHint", actions: "increment" },
729
- { guard: "isDecrementHint", actions: "decrement" }
730
- ]),
731
- after: {
732
- CHANGE_DELAY: {
733
- target: "spinning",
734
- guard: "isInRange"
697
+ FOCUS: "focused"
735
698
  }
736
699
  },
737
- on: {
738
- PRESS_UP: {
739
- target: "focused",
740
- actions: ["clearHint", "restoreSelection"]
700
+ focused: {
701
+ tags: ["focus"],
702
+ activities: "attachWheelListener",
703
+ on: {
704
+ PRESS_DOWN: {
705
+ target: "before:spin",
706
+ actions: ["focusInput", "setHint"]
707
+ },
708
+ PRESS_DOWN_SCRUBBER: {
709
+ target: "scrubbing",
710
+ actions: ["focusInput", "setHint", "setCursorPoint"]
711
+ },
712
+ ARROW_UP: {
713
+ actions: "increment"
714
+ },
715
+ ARROW_DOWN: {
716
+ actions: "decrement"
717
+ },
718
+ HOME: {
719
+ actions: "setToMin"
720
+ },
721
+ END: {
722
+ actions: "setToMax"
723
+ },
724
+ CHANGE: {
725
+ actions: ["setValue", "setSelectionRange", "setHint"]
726
+ },
727
+ BLUR: [
728
+ {
729
+ guard: "isInvalidExponential",
730
+ target: "idle",
731
+ actions: ["clearValue", "clearHint"]
732
+ },
733
+ {
734
+ guard: and("clampOnBlur", not("isInRange")),
735
+ target: "idle",
736
+ actions: ["clampValue", "clearHint"]
737
+ },
738
+ {
739
+ actions: ["roundValue"]
740
+ }
741
+ ]
741
742
  }
742
- }
743
- },
744
- spinning: {
745
- tags: ["focus"],
746
- activities: "trackButtonDisabled",
747
- every: [
748
- {
749
- delay: "CHANGE_INTERVAL",
750
- guard: and(not("isAtMin"), "isIncrementHint"),
751
- actions: "increment"
743
+ },
744
+ "before:spin": {
745
+ tags: ["focus"],
746
+ entry: (0, import_core.choose)([
747
+ { guard: "isIncrementHint", actions: "increment" },
748
+ { guard: "isDecrementHint", actions: "decrement" }
749
+ ]),
750
+ after: {
751
+ CHANGE_DELAY: {
752
+ target: "spinning",
753
+ guard: "isInRange"
754
+ }
752
755
  },
753
- {
754
- delay: "CHANGE_INTERVAL",
755
- guard: and(not("isAtMax"), "isDecrementHint"),
756
- actions: "decrement"
757
- }
758
- ],
759
- on: {
760
- PRESS_UP: {
761
- target: "focused",
762
- actions: ["clearHint", "restoreSelection"]
756
+ on: {
757
+ PRESS_UP: {
758
+ target: "focused",
759
+ actions: ["clearHint", "restoreSelection"]
760
+ }
763
761
  }
764
- }
765
- },
766
- scrubbing: {
767
- tags: ["focus"],
768
- entry: ["addCustomCursor", "disableTextSelection"],
769
- exit: ["removeCustomCursor", "restoreTextSelection"],
770
- activities: ["activatePointerLock", "trackMousemove"],
771
- on: {
772
- POINTER_UP_SCRUBBER: {
773
- target: "focused",
774
- actions: ["clearCursorPoint"]
775
- },
776
- POINTER_MOVE_SCRUBBER: [
762
+ },
763
+ spinning: {
764
+ tags: ["focus"],
765
+ activities: "trackButtonDisabled",
766
+ every: [
777
767
  {
778
- guard: "isIncrementHint",
779
- actions: ["increment", "setCursorPoint", "updateCursor"]
768
+ delay: "CHANGE_INTERVAL",
769
+ guard: and(not("isAtMin"), "isIncrementHint"),
770
+ actions: "increment"
780
771
  },
781
772
  {
782
- guard: "isDecrementHint",
783
- actions: ["decrement", "setCursorPoint", "updateCursor"]
773
+ delay: "CHANGE_INTERVAL",
774
+ guard: and(not("isAtMax"), "isDecrementHint"),
775
+ actions: "decrement"
784
776
  }
785
- ]
777
+ ],
778
+ on: {
779
+ PRESS_UP: {
780
+ target: "focused",
781
+ actions: ["clearHint", "restoreSelection"]
782
+ }
783
+ }
784
+ },
785
+ scrubbing: {
786
+ tags: ["focus"],
787
+ entry: ["addCustomCursor", "disableTextSelection"],
788
+ exit: ["removeCustomCursor", "restoreTextSelection"],
789
+ activities: ["activatePointerLock", "trackMousemove"],
790
+ on: {
791
+ POINTER_UP_SCRUBBER: {
792
+ target: "focused",
793
+ actions: ["clearCursorPoint"]
794
+ },
795
+ POINTER_MOVE_SCRUBBER: [
796
+ {
797
+ guard: "isIncrementHint",
798
+ actions: ["increment", "setCursorPoint", "updateCursor"]
799
+ },
800
+ {
801
+ guard: "isDecrementHint",
802
+ actions: ["decrement", "setCursorPoint", "updateCursor"]
803
+ }
804
+ ]
805
+ }
786
806
  }
787
807
  }
788
- }
789
- }, {
790
- delays: {
791
- CHANGE_INTERVAL: 50,
792
- CHANGE_DELAY: 300
793
- },
794
- guards: {
795
- clampOnBlur: (ctx) => !!ctx.clampValueOnBlur,
796
- isAtMin: (ctx) => ctx.isAtMin,
797
- isAtMax: (ctx) => ctx.isAtMax,
798
- isInRange: (ctx) => !ctx.isOutOfRange,
799
- isDecrementHint: (ctx, evt) => {
800
- var _a;
801
- return ((_a = evt.hint) != null ? _a : ctx.hint) === "decrement";
802
- },
803
- isIncrementHint: (ctx, evt) => {
804
- var _a;
805
- return ((_a = evt.hint) != null ? _a : ctx.hint) === "increment";
806
- },
807
- isInvalidExponential: (ctx) => ctx.value.toString().startsWith("e")
808
- },
809
- activities: {
810
- trackButtonDisabled(ctx, _evt, { send }) {
811
- let btnEl = null;
812
- if (ctx.hint === "increment") {
813
- btnEl = dom.getIncButtonEl(ctx);
814
- }
815
- if (ctx.hint === "decrement") {
816
- btnEl = dom.getDecButtonEl(ctx);
817
- }
818
- return observeAttributes(btnEl, "disabled", function onDisable() {
819
- send("PRESS_UP");
820
- });
808
+ }, {
809
+ delays: {
810
+ CHANGE_INTERVAL: 50,
811
+ CHANGE_DELAY: 300
812
+ },
813
+ guards: {
814
+ clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
815
+ isAtMin: (ctx2) => ctx2.isAtMin,
816
+ isAtMax: (ctx2) => ctx2.isAtMax,
817
+ isInRange: (ctx2) => !ctx2.isOutOfRange,
818
+ isDecrementHint: (ctx2, evt) => {
819
+ var _a;
820
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
821
+ },
822
+ isIncrementHint: (ctx2, evt) => {
823
+ var _a;
824
+ return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
825
+ },
826
+ isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
821
827
  },
822
- attachWheelListener(ctx) {
823
- const cleanups = [];
824
- cleanups.push(nextTick(() => {
825
- const input = dom.getInputEl(ctx);
826
- if (!input)
828
+ activities: {
829
+ trackButtonDisabled(ctx2, _evt, { send }) {
830
+ let btnEl = null;
831
+ if (ctx2.hint === "increment") {
832
+ btnEl = dom.getIncButtonEl(ctx2);
833
+ }
834
+ if (ctx2.hint === "decrement") {
835
+ btnEl = dom.getDecButtonEl(ctx2);
836
+ }
837
+ return observeAttributes(btnEl, "disabled", function onDisable() {
838
+ send("PRESS_UP");
839
+ });
840
+ },
841
+ attachWheelListener(ctx2) {
842
+ const cleanups = [];
843
+ cleanups.push(nextTick(() => {
844
+ const input = dom.getInputEl(ctx2);
845
+ if (!input)
846
+ return;
847
+ function onWheel(event) {
848
+ const isInputFocused = dom.getDoc(ctx2).activeElement === input;
849
+ if (!ctx2.allowMouseWheel || !isInputFocused)
850
+ return;
851
+ event.preventDefault();
852
+ const dir = Math.sign(event.deltaY) * -1;
853
+ if (dir === 1)
854
+ ctx2.value = utils.increment(ctx2);
855
+ else if (dir === -1)
856
+ ctx2.value = utils.decrement(ctx2);
857
+ }
858
+ cleanups.push(addDomEvent(input, "wheel", onWheel, { passive: false }));
859
+ }));
860
+ return () => cleanups.forEach((c) => c());
861
+ },
862
+ activatePointerLock(ctx2) {
863
+ if (isSafari() || !supportsPointerEvent())
827
864
  return;
828
- function onWheel(event) {
829
- const isInputFocused = dom.getDoc(ctx).activeElement === input;
830
- if (!ctx.allowMouseWheel || !isInputFocused)
865
+ return requestPointerLock(dom.getDoc(ctx2));
866
+ },
867
+ trackMousemove(ctx2, _evt, { send }) {
868
+ const doc = dom.getDoc(ctx2);
869
+ function onMousemove(event) {
870
+ if (!ctx2.scrubberCursorPoint)
831
871
  return;
832
- event.preventDefault();
833
- const dir = Math.sign(event.deltaY) * -1;
834
- if (dir === 1)
835
- ctx.value = utils.increment(ctx);
836
- else if (dir === -1)
837
- ctx.value = utils.decrement(ctx);
872
+ const value = dom.getMousementValue(ctx2, event);
873
+ if (!value.hint)
874
+ return;
875
+ send({ type: "POINTER_MOVE_SCRUBBER", hint: value.hint, point: value.point });
838
876
  }
839
- cleanups.push(addDomEvent(input, "wheel", onWheel, { passive: false }));
840
- }));
841
- return () => cleanups.forEach((c) => c());
842
- },
843
- activatePointerLock(ctx) {
844
- if (isSafari() || !supportsPointerEvent())
845
- return;
846
- return requestPointerLock(dom.getDoc(ctx));
877
+ function onMouseup() {
878
+ send("POINTER_UP_SCRUBBER");
879
+ }
880
+ return pipe2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
881
+ }
847
882
  },
848
- trackMousemove(ctx, _evt, { send }) {
849
- const doc = dom.getDoc(ctx);
850
- function onMousemove(event) {
851
- if (!ctx.scrubberCursorPoint)
883
+ actions: {
884
+ setupDocument: (ctx2, evt) => {
885
+ if (evt.doc)
886
+ ctx2.doc = (0, import_core.ref)(evt.doc);
887
+ ctx2.uid = evt.id;
888
+ },
889
+ focusInput(ctx2) {
890
+ if (!ctx2.focusInputOnChange)
852
891
  return;
853
- const value = dom.getMousementValue(ctx, event);
854
- if (!value.hint)
892
+ const input = dom.getInputEl(ctx2);
893
+ nextTick(() => input == null ? void 0 : input.focus());
894
+ },
895
+ increment(ctx2, evt) {
896
+ ctx2.value = utils.increment(ctx2, evt.step);
897
+ },
898
+ decrement(ctx2, evt) {
899
+ ctx2.value = utils.decrement(ctx2, evt.step);
900
+ },
901
+ clampValue(ctx2) {
902
+ ctx2.value = utils.clamp(ctx2);
903
+ },
904
+ roundValue(ctx2) {
905
+ ctx2.value = utils.round(ctx2);
906
+ },
907
+ setValue(ctx2, evt) {
908
+ var _a, _b;
909
+ const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
910
+ ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value));
911
+ },
912
+ clearValue(ctx2) {
913
+ ctx2.value = "";
914
+ },
915
+ setToMax(ctx2) {
916
+ ctx2.value = ctx2.max.toString();
917
+ },
918
+ setToMin(ctx2) {
919
+ ctx2.value = ctx2.min.toString();
920
+ },
921
+ setHint(ctx2, evt) {
922
+ ctx2.hint = evt.hint;
923
+ },
924
+ clearHint(ctx2) {
925
+ ctx2.hint = null;
926
+ },
927
+ setHintToSet(ctx2) {
928
+ ctx2.hint = "set";
929
+ },
930
+ setSelectionRange(ctx2, evt) {
931
+ ctx2.inputSelection = {
932
+ start: evt.target.selectionStart,
933
+ end: evt.target.selectionEnd
934
+ };
935
+ },
936
+ restoreSelection(ctx2) {
937
+ var _a, _b, _c;
938
+ const input = dom.getInputEl(ctx2);
939
+ if (!input || !ctx2.inputSelection)
855
940
  return;
856
- send({ type: "POINTER_MOVE_SCRUBBER", hint: value.hint, point: value.point });
857
- }
858
- function onMouseup() {
859
- send("POINTER_UP_SCRUBBER");
941
+ input.selectionStart = (_b = ctx2.inputSelection.start) != null ? _b : (_a = input.value) == null ? void 0 : _a.length;
942
+ input.selectionEnd = (_c = ctx2.inputSelection.end) != null ? _c : input.selectionStart;
943
+ },
944
+ invokeOnChange(ctx2) {
945
+ var _a;
946
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value, valueAsNumber: ctx2.valueAsNumber });
947
+ },
948
+ invokeOnInvalid(ctx2) {
949
+ var _a;
950
+ if (!ctx2.isOutOfRange)
951
+ return;
952
+ const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
953
+ (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, { reason, value: ctx2.formattedValue, valueAsNumber: ctx2.valueAsNumber });
954
+ },
955
+ syncInputValue(ctx2) {
956
+ const input = dom.getInputEl(ctx2);
957
+ if (!input || input.value == ctx2.value)
958
+ return;
959
+ const value = utils.parse(ctx2, input.value);
960
+ ctx2.value = utils.sanitize(ctx2, value);
961
+ },
962
+ setCursorPoint(ctx2, evt) {
963
+ ctx2.scrubberCursorPoint = evt.point;
964
+ },
965
+ clearCursorPoint(ctx2) {
966
+ ctx2.scrubberCursorPoint = null;
967
+ },
968
+ updateCursor(ctx2) {
969
+ const cursor = dom.getCursorEl(ctx2);
970
+ if (!cursor || !ctx2.scrubberCursorPoint)
971
+ return;
972
+ cursor.style.transform = `translate3d(${ctx2.scrubberCursorPoint.x}px, ${ctx2.scrubberCursorPoint.y}px, 0px)`;
973
+ },
974
+ addCustomCursor(ctx2) {
975
+ if (isSafari() || !supportsPointerEvent())
976
+ return;
977
+ dom.createVirtualCursor(ctx2);
978
+ },
979
+ removeCustomCursor(ctx2) {
980
+ if (isSafari() || !supportsPointerEvent())
981
+ return;
982
+ const doc = dom.getDoc(ctx2);
983
+ const el = doc.getElementById(dom.getCursorId(ctx2));
984
+ el == null ? void 0 : el.remove();
985
+ },
986
+ disableTextSelection(ctx2) {
987
+ const doc = dom.getDoc(ctx2);
988
+ doc.body.style.pointerEvents = "none";
989
+ doc.documentElement.style.userSelect = "none";
990
+ doc.documentElement.style.cursor = "ew-resize";
991
+ },
992
+ restoreTextSelection(ctx2) {
993
+ const doc = dom.getDoc(ctx2);
994
+ doc.body.style.pointerEvents = "";
995
+ doc.documentElement.style.userSelect = "";
996
+ doc.documentElement.style.cursor = "";
860
997
  }
861
- return pipe2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
862
998
  }
863
- },
864
- actions: {
865
- setupDocument: (ctx, evt) => {
866
- if (evt.doc)
867
- ctx.doc = (0, import_core.ref)(evt.doc);
868
- ctx.uid = evt.id;
869
- },
870
- focusInput(ctx) {
871
- if (!ctx.focusInputOnChange)
872
- return;
873
- const input = dom.getInputEl(ctx);
874
- nextTick(() => input == null ? void 0 : input.focus());
875
- },
876
- increment(ctx, evt) {
877
- ctx.value = utils.increment(ctx, evt.step);
878
- },
879
- decrement(ctx, evt) {
880
- ctx.value = utils.decrement(ctx, evt.step);
881
- },
882
- clampValue(ctx) {
883
- ctx.value = utils.clamp(ctx);
884
- },
885
- roundValue(ctx) {
886
- ctx.value = utils.round(ctx);
887
- },
888
- setValue(ctx, evt) {
889
- var _a, _b;
890
- const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
891
- ctx.value = utils.sanitize(ctx, utils.parse(ctx, value));
892
- },
893
- clearValue(ctx) {
894
- ctx.value = "";
895
- },
896
- setToMax(ctx) {
897
- ctx.value = ctx.max.toString();
898
- },
899
- setToMin(ctx) {
900
- ctx.value = ctx.min.toString();
901
- },
902
- setHint(ctx, evt) {
903
- ctx.hint = evt.hint;
904
- },
905
- clearHint(ctx) {
906
- ctx.hint = null;
907
- },
908
- setHintToSet(ctx) {
909
- ctx.hint = "set";
910
- },
911
- setSelectionRange(ctx, evt) {
912
- ctx.inputSelection = {
913
- start: evt.target.selectionStart,
914
- end: evt.target.selectionEnd
915
- };
916
- },
917
- restoreSelection(ctx) {
918
- var _a, _b, _c;
919
- const input = dom.getInputEl(ctx);
920
- if (!input || !ctx.inputSelection)
921
- return;
922
- input.selectionStart = (_b = ctx.inputSelection.start) != null ? _b : (_a = input.value) == null ? void 0 : _a.length;
923
- input.selectionEnd = (_c = ctx.inputSelection.end) != null ? _c : input.selectionStart;
924
- },
925
- invokeOnChange(ctx) {
926
- var _a;
927
- (_a = ctx.onChange) == null ? void 0 : _a.call(ctx, { value: ctx.value, valueAsNumber: ctx.valueAsNumber });
928
- },
929
- invokeOnInvalid(ctx) {
930
- var _a;
931
- if (!ctx.isOutOfRange)
932
- return;
933
- const reason = ctx.valueAsNumber > ctx.max ? "rangeOverflow" : "rangeUnderflow";
934
- (_a = ctx.onInvalid) == null ? void 0 : _a.call(ctx, { reason, value: ctx.formattedValue, valueAsNumber: ctx.valueAsNumber });
935
- },
936
- syncInputValue(ctx) {
937
- const input = dom.getInputEl(ctx);
938
- if (!input || input.value == ctx.value)
939
- return;
940
- const value = utils.parse(ctx, input.value);
941
- ctx.value = utils.sanitize(ctx, value);
942
- },
943
- setCursorPoint(ctx, evt) {
944
- ctx.scrubberCursorPoint = evt.point;
945
- },
946
- clearCursorPoint(ctx) {
947
- ctx.scrubberCursorPoint = null;
948
- },
949
- updateCursor(ctx) {
950
- const cursor = dom.getCursorEl(ctx);
951
- if (!cursor || !ctx.scrubberCursorPoint)
952
- return;
953
- cursor.style.transform = `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)`;
954
- },
955
- addCustomCursor(ctx) {
956
- if (isSafari() || !supportsPointerEvent())
957
- return;
958
- dom.createVirtualCursor(ctx);
959
- },
960
- removeCustomCursor(ctx) {
961
- if (isSafari() || !supportsPointerEvent())
962
- return;
963
- const doc = dom.getDoc(ctx);
964
- const el = doc.getElementById(dom.getCursorId(ctx));
965
- el == null ? void 0 : el.remove();
966
- },
967
- disableTextSelection(ctx) {
968
- const doc = dom.getDoc(ctx);
969
- doc.body.style.pointerEvents = "none";
970
- doc.documentElement.style.userSelect = "none";
971
- doc.documentElement.style.cursor = "ew-resize";
972
- },
973
- restoreTextSelection(ctx) {
974
- const doc = dom.getDoc(ctx);
975
- doc.body.style.pointerEvents = "";
976
- doc.documentElement.style.userSelect = "";
977
- doc.documentElement.style.cursor = "";
978
- }
979
- }
980
- });
999
+ });
1000
+ }
981
1001
  //# sourceMappingURL=index.js.map