@zag-js/number-input 0.1.12 → 0.1.15

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,25 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
6
  var __export = (target, all) => {
24
7
  for (var name in all)
25
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -43,22 +26,6 @@ __export(src_exports, {
43
26
  module.exports = __toCommonJS(src_exports);
44
27
 
45
28
  // ../../utilities/dom/dist/index.mjs
46
- var __defProp2 = Object.defineProperty;
47
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
48
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
49
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
50
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
51
- var __spreadValues2 = (a, b) => {
52
- for (var prop in b || (b = {}))
53
- if (__hasOwnProp2.call(b, prop))
54
- __defNormalProp2(a, prop, b[prop]);
55
- if (__getOwnPropSymbols2)
56
- for (var prop of __getOwnPropSymbols2(b)) {
57
- if (__propIsEnum2.call(b, prop))
58
- __defNormalProp2(a, prop, b[prop]);
59
- }
60
- return a;
61
- };
62
29
  var dataAttr = (guard) => {
63
30
  return guard ? "" : void 0;
64
31
  };
@@ -68,7 +35,7 @@ var ariaAttr = (guard) => {
68
35
  var MAX_Z_INDEX = 2147483647;
69
36
  var runIfFn = (v, ...a) => {
70
37
  const res = typeof v === "function" ? v(...a) : v;
71
- return res != null ? res : void 0;
38
+ return res ?? void 0;
72
39
  };
73
40
  var callAll = (...fns) => (...a) => {
74
41
  fns.forEach(function(fn) {
@@ -80,17 +47,13 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
80
47
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
81
48
  var isDom = () => typeof window !== "undefined";
82
49
  function getPlatform() {
83
- var _a;
84
50
  const agent = navigator.userAgentData;
85
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
51
+ return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
86
52
  }
87
53
  var pt = (v) => isDom() && v.test(getPlatform());
88
54
  var vn = (v) => isDom() && v.test(navigator.vendor);
89
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
90
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
91
55
  var isSafari = () => isApple() && vn(/apple/i);
92
56
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
93
- var isIos = () => isApple() && !isMac();
94
57
  function isDocument(el) {
95
58
  return el.nodeType === Node.DOCUMENT_NODE;
96
59
  }
@@ -98,52 +61,35 @@ function isWindow(value) {
98
61
  return (value == null ? void 0 : value.toString()) === "[object Window]";
99
62
  }
100
63
  function getDocument(el) {
101
- var _a;
102
64
  if (isWindow(el))
103
65
  return el.document;
104
66
  if (isDocument(el))
105
67
  return el;
106
- return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
68
+ return (el == null ? void 0 : el.ownerDocument) ?? document;
107
69
  }
108
70
  function defineDomHelpers(helpers) {
109
71
  const dom2 = {
110
72
  getRootNode: (ctx) => {
111
- var _a, _b;
112
- return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
113
- },
114
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
115
- getWin: (ctx) => {
116
73
  var _a;
117
- return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
74
+ return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
118
75
  },
76
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
77
+ getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
119
78
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
120
79
  getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
121
80
  };
122
- return __spreadValues2(__spreadValues2({}, dom2), helpers);
81
+ return {
82
+ ...dom2,
83
+ ...helpers
84
+ };
123
85
  }
124
86
  function getNativeEvent(e) {
125
- var _a;
126
- return (_a = e.nativeEvent) != null ? _a : e;
87
+ return e.nativeEvent ?? e;
127
88
  }
128
89
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
129
90
  var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
130
91
  var isLeftClick = (v) => v.button === 0;
131
92
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
132
- function observeAttributes(node, attributes, fn) {
133
- if (!node)
134
- return;
135
- const attrs = Array.isArray(attributes) ? attributes : [attributes];
136
- const win = node.ownerDocument.defaultView || window;
137
- const obs = new win.MutationObserver((changes) => {
138
- for (const change of changes) {
139
- if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
140
- fn(change);
141
- }
142
- }
143
- });
144
- obs.observe(node, { attributes: true, attributeFilter: attrs });
145
- return () => obs.disconnect();
146
- }
147
93
  var fallback = {
148
94
  pageX: 0,
149
95
  pageY: 0,
@@ -151,8 +97,7 @@ var fallback = {
151
97
  clientY: 0
152
98
  };
153
99
  function getEventPoint(event, type = "page") {
154
- var _a, _b;
155
- const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
100
+ const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
156
101
  return { x: point[`${type}X`], y: point[`${type}Y`] };
157
102
  }
158
103
  var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
@@ -174,6 +119,21 @@ function addDomEvent(target, eventName, handler, options) {
174
119
  node == null ? void 0 : node.removeEventListener(eventName, handler, options);
175
120
  };
176
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
+ }
177
137
  function raf(fn) {
178
138
  const id = globalThis.requestAnimationFrame(fn);
179
139
  return function cleanup() {
@@ -212,7 +172,10 @@ function requestPointerLock(doc, handlers = {}) {
212
172
  if (!supported)
213
173
  return;
214
174
  body.requestPointerLock();
215
- const cleanup = callAll(addPointerlockChangeListener(doc, onPointerChange), addPointerlockErrorListener(doc, onPointerError));
175
+ const cleanup = callAll(
176
+ addPointerlockChangeListener(doc, onPointerChange),
177
+ addPointerlockErrorListener(doc, onPointerError)
178
+ );
216
179
  return function dispose() {
217
180
  if (!supported)
218
181
  return;
@@ -222,7 +185,6 @@ function requestPointerLock(doc, handlers = {}) {
222
185
  }
223
186
 
224
187
  // ../../utilities/number/dist/index.mjs
225
- var __pow = Math.pow;
226
188
  function wrap(num, max) {
227
189
  return (num % max + max) % max;
228
190
  }
@@ -276,7 +238,7 @@ function isWithinRange(v, o) {
276
238
  function decimalOperation(a, op, b) {
277
239
  let result = op === "+" ? a + b : a - b;
278
240
  if (a % 1 !== 0 || b % 1 !== 0) {
279
- const multiplier = __pow(10, Math.max(countDecimals(a), countDecimals(b)));
241
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
280
242
  a = Math.round(a * multiplier);
281
243
  b = Math.round(b * multiplier);
282
244
  result = op === "+" ? a + b : a - b;
@@ -289,35 +251,73 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
289
251
  // src/number-input.dom.ts
290
252
  var dom = defineDomHelpers({
291
253
  getRootId: (ctx) => {
292
- var _a, _b;
293
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
254
+ var _a;
255
+ return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `number-input:${ctx.id}`;
294
256
  },
295
257
  getInputId: (ctx) => {
296
- var _a, _b;
297
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
258
+ var _a;
259
+ return ((_a = ctx.ids) == null ? void 0 : _a.input) ?? `number-input:${ctx.id}:input`;
298
260
  },
299
261
  getIncButtonId: (ctx) => {
300
- var _a, _b;
301
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
262
+ var _a;
263
+ return ((_a = ctx.ids) == null ? void 0 : _a.incBtn) ?? `number-input:${ctx.id}:inc-btn`;
302
264
  },
303
265
  getDecButtonId: (ctx) => {
304
- var _a, _b;
305
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
266
+ var _a;
267
+ return ((_a = ctx.ids) == null ? void 0 : _a.decBtn) ?? `number-input:${ctx.id}:dec-btn`;
306
268
  },
307
269
  getScrubberId: (ctx) => {
308
- var _a, _b;
309
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
270
+ var _a;
271
+ return ((_a = ctx.ids) == null ? void 0 : _a.scrubber) ?? `number-input:${ctx.id}:scrubber`;
310
272
  },
311
273
  getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
312
274
  getLabelId: (ctx) => {
313
- var _a, _b;
314
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
275
+ var _a;
276
+ return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `number-input:${ctx.id}:label`;
315
277
  },
316
278
  getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
317
279
  getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
318
280
  getDecButtonEl: (ctx) => dom.getById(ctx, dom.getDecButtonId(ctx)),
319
281
  getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
320
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
+ },
321
321
  getMousementValue(ctx, event) {
322
322
  const x = roundToDevicePixel(event.movementX);
323
323
  const y = roundToDevicePixel(event.movementY);
@@ -366,39 +366,38 @@ var dom = defineDomHelpers({
366
366
  // src/number-input.utils.ts
367
367
  var utils = {
368
368
  isValidNumericEvent: (ctx, event) => {
369
- var _a, _b;
369
+ var _a;
370
370
  if (event.key == null)
371
371
  return true;
372
372
  const isModifier = isModifiedEvent(event);
373
373
  const isSingleKey = event.key.length === 1;
374
374
  if (isModifier || !isSingleKey)
375
375
  return true;
376
- return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
376
+ return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) ?? utils.isFloatingPoint(event.key);
377
377
  },
378
378
  isFloatingPoint: (v) => /^[Ee0-9+\-.]$/.test(v),
379
379
  sanitize: (ctx, value) => {
380
- var _a;
381
- return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
380
+ return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
382
381
  },
383
382
  increment: (ctx, step) => {
384
- const value = increment(ctx.value, step != null ? step : ctx.step);
383
+ const value = increment(ctx.value, step ?? ctx.step);
385
384
  return formatDecimal(clamp(value, ctx), ctx);
386
385
  },
387
386
  decrement: (ctx, step) => {
388
- const value = decrement(ctx.value, step != null ? step : ctx.step);
387
+ const value = decrement(ctx.value, step ?? ctx.step);
389
388
  return formatDecimal(clamp(value, ctx), ctx);
390
389
  },
391
390
  clamp: (ctx) => {
392
391
  return formatDecimal(clamp(ctx.value, ctx), ctx);
393
392
  },
394
393
  parse: (ctx, value) => {
395
- var _a, _b;
396
- return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
394
+ var _a;
395
+ return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) ?? value;
397
396
  },
398
397
  format: (ctx, value) => {
399
- var _a, _b;
398
+ var _a;
400
399
  const _val = value.toString();
401
- return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
400
+ return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) ?? _val;
402
401
  },
403
402
  round: (ctx) => {
404
403
  return formatDecimal(ctx.value, ctx);
@@ -442,6 +441,10 @@ function connect(state, send, normalize) {
442
441
  var _a;
443
442
  (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
444
443
  },
444
+ blur() {
445
+ var _a;
446
+ (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
447
+ },
445
448
  rootProps: normalize.element({
446
449
  id: dom.getRootId(state.context),
447
450
  "data-part": "root",
@@ -467,7 +470,7 @@ function connect(state, send, normalize) {
467
470
  name: state.context.name,
468
471
  id: dom.getInputId(state.context),
469
472
  role: "spinbutton",
470
- value: state.context.formattedValue,
473
+ defaultValue: state.context.formattedValue,
471
474
  pattern: state.context.pattern,
472
475
  inputMode: state.context.inputMode,
473
476
  "aria-invalid": isInvalid || void 0,
@@ -479,7 +482,7 @@ function connect(state, send, normalize) {
479
482
  autoCorrect: "off",
480
483
  spellCheck: "false",
481
484
  type: "text",
482
- "aria-roledescription": !isIos() ? "number field" : void 0,
485
+ "aria-roledescription": "numberfield",
483
486
  "aria-valuemin": state.context.min,
484
487
  "aria-valuemax": state.context.max,
485
488
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -605,384 +608,419 @@ var callAll2 = (...fns) => (...a) => {
605
608
  });
606
609
  };
607
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
+
608
633
  // src/number-input.machine.ts
609
634
  var { not, and } = import_core.guards;
610
635
  function machine(ctx) {
611
- return (0, import_core.createMachine)({
612
- id: "number-input",
613
- initial: "unknown",
614
- context: __spreadProps(__spreadValues({
615
- dir: "ltr",
616
- focusInputOnChange: true,
617
- clampValueOnBlur: true,
618
- allowOverflow: false,
619
- inputMode: "decimal",
620
- pattern: "[0-9]*(.[0-9]+)?",
621
- hint: null,
622
- value: "",
623
- step: 1,
624
- min: Number.MIN_SAFE_INTEGER,
625
- max: Number.MAX_SAFE_INTEGER,
626
- scrubberCursorPoint: null,
627
- invalid: false
628
- }, ctx), {
629
- messages: __spreadValues({
630
- incrementLabel: "increment value",
631
- decrementLabel: "decrease value"
632
- }, ctx.messages)
633
- }),
634
- computed: {
635
- isRtl: (ctx2) => ctx2.dir === "rtl",
636
- valueAsNumber: (ctx2) => valueOf(ctx2.value),
637
- isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
638
- isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
639
- isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
640
- isValueEmpty: (ctx2) => ctx2.value === "",
641
- canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
642
- canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
643
- valueText: (ctx2) => {
644
- var _a, _b;
645
- return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
646
- },
647
- formattedValue: (ctx2) => {
648
- var _a, _b;
649
- return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
650
- }
651
- },
652
- watch: {
653
- value: ["invokeOnChange"],
654
- isOutOfRange: ["invokeOnInvalid"]
655
- },
656
- on: {
657
- SET_VALUE: {
658
- actions: ["setValue", "setHintToSet"]
659
- },
660
- CLEAR_VALUE: {
661
- actions: ["clearValue"]
662
- },
663
- INCREMENT: {
664
- 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
+ }
665
661
  },
666
- DECREMENT: {
667
- actions: ["decrement"]
668
- }
669
- },
670
- states: {
671
- unknown: {
672
- on: {
673
- SETUP: {
674
- target: "idle",
675
- actions: "syncInputValue"
676
- }
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;
677
678
  }
678
679
  },
679
- idle: {
680
- on: {
681
- PRESS_DOWN: {
682
- target: "before:spin",
683
- actions: ["focusInput", "setHint"]
684
- },
685
- PRESS_DOWN_SCRUBBER: {
686
- target: "scrubbing",
687
- 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"]
688
690
  },
689
- 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"]
690
703
  }
691
704
  },
692
- focused: {
693
- tags: ["focus"],
694
- entry: "focusInput",
695
- activities: "attachWheelListener",
696
- on: {
697
- PRESS_DOWN: {
698
- target: "before:spin",
699
- actions: ["focusInput", "setHint"]
700
- },
701
- PRESS_DOWN_SCRUBBER: {
702
- target: "scrubbing",
703
- actions: ["focusInput", "setHint", "setCursorPoint"]
704
- },
705
- ARROW_UP: {
706
- actions: "increment"
707
- },
708
- ARROW_DOWN: {
709
- actions: "decrement"
710
- },
711
- HOME: {
712
- actions: "setToMin"
713
- },
714
- END: {
715
- actions: "setToMax"
716
- },
717
- CHANGE: {
718
- actions: ["setValue", "setHint"]
719
- },
720
- BLUR: [
721
- {
722
- guard: "isInvalidExponential",
705
+ states: {
706
+ unknown: {
707
+ on: {
708
+ SETUP: {
723
709
  target: "idle",
724
- 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"]
725
720
  },
726
- {
727
- guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
728
- target: "idle",
729
- actions: ["clampValue", "clearHint"]
721
+ PRESS_DOWN_SCRUBBER: {
722
+ target: "scrubbing",
723
+ actions: ["focusInput", "setHint", "setCursorPoint"]
730
724
  },
731
- {
732
- target: "idle",
733
- actions: "roundValue"
734
- }
735
- ]
736
- }
737
- },
738
- "before:spin": {
739
- tags: ["focus"],
740
- activities: "trackButtonDisabled",
741
- entry: (0, import_core.choose)([
742
- { guard: "isIncrementHint", actions: "increment" },
743
- { guard: "isDecrementHint", actions: "decrement" }
744
- ]),
745
- after: {
746
- CHANGE_DELAY: {
747
- target: "spinning",
748
- guard: "isInRange"
725
+ FOCUS: "focused"
749
726
  }
750
727
  },
751
- on: {
752
- PRESS_UP: {
753
- target: "focused",
754
- 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
+ ]
755
772
  }
756
- }
757
- },
758
- spinning: {
759
- tags: ["focus"],
760
- activities: "trackButtonDisabled",
761
- every: [
762
- {
763
- delay: "CHANGE_INTERVAL",
764
- guard: and(not("isAtMin"), "isIncrementHint"),
765
- 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
+ }
766
786
  },
767
- {
768
- delay: "CHANGE_INTERVAL",
769
- guard: and(not("isAtMax"), "isDecrementHint"),
770
- actions: "decrement"
771
- }
772
- ],
773
- on: {
774
- PRESS_UP: {
775
- target: "focused",
776
- actions: "clearHint"
787
+ on: {
788
+ PRESS_UP: {
789
+ target: "focused",
790
+ actions: "clearHint"
791
+ }
777
792
  }
778
- }
779
- },
780
- scrubbing: {
781
- tags: ["focus"],
782
- entry: ["addCustomCursor", "disableTextSelection"],
783
- exit: ["removeCustomCursor", "restoreTextSelection"],
784
- activities: ["activatePointerLock", "trackMousemove"],
785
- on: {
786
- POINTER_UP_SCRUBBER: {
787
- target: "focused",
788
- actions: "clearCursorPoint"
789
- },
790
- POINTER_MOVE_SCRUBBER: [
793
+ },
794
+ spinning: {
795
+ tags: "focus",
796
+ activities: "trackButtonDisabled",
797
+ every: [
791
798
  {
792
- guard: "isIncrementHint",
793
- actions: ["increment", "setCursorPoint", "updateCursor"]
799
+ delay: "CHANGE_INTERVAL",
800
+ guard: and(not("isAtMin"), "isIncrementHint"),
801
+ actions: "increment"
794
802
  },
795
803
  {
796
- guard: "isDecrementHint",
797
- 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"
798
813
  }
799
- ]
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
+ }
800
833
  }
801
834
  }
802
- }
803
- }, {
804
- delays: {
805
- CHANGE_INTERVAL: 50,
806
- CHANGE_DELAY: 300
807
835
  },
808
- guards: {
809
- clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
810
- isAtMin: (ctx2) => ctx2.isAtMin,
811
- isAtMax: (ctx2) => ctx2.isAtMax,
812
- isInRange: (ctx2) => !ctx2.isOutOfRange,
813
- isDecrementHint: (ctx2, evt) => {
814
- var _a;
815
- return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
836
+ {
837
+ delays: {
838
+ CHANGE_INTERVAL: 50,
839
+ CHANGE_DELAY: 300
816
840
  },
817
- isEmptyValue: (ctx2) => ctx2.isValueEmpty,
818
- isIncrementHint: (ctx2, evt) => {
819
- var _a;
820
- return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
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")
821
851
  },
822
- isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
823
- },
824
- activities: {
825
- trackButtonDisabled(ctx2, _evt, { send }) {
826
- let btnEl = null;
827
- if (ctx2.hint === "increment") {
828
- btnEl = dom.getIncButtonEl(ctx2);
829
- }
830
- if (ctx2.hint === "decrement") {
831
- btnEl = dom.getDecButtonEl(ctx2);
832
- }
833
- return observeAttributes(btnEl, "disabled", function onDisable() {
834
- send("PRESS_UP");
835
- });
836
- },
837
- attachWheelListener(ctx2, _evt, { send }) {
838
- const input = dom.getInputEl(ctx2);
839
- if (!input)
840
- return;
841
- function onWheel(event) {
842
- const isInputFocused = dom.getDoc(ctx2).activeElement === input;
843
- if (!ctx2.allowMouseWheel || !isInputFocused)
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)
844
866
  return;
845
- event.preventDefault();
846
- const dir = Math.sign(event.deltaY) * -1;
847
- if (dir === 1) {
848
- send("INCREMENT");
849
- } else if (dir === -1) {
850
- 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
+ }
851
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");
902
+ }
903
+ return callAll2(
904
+ addDomEvent(doc, "mousemove", onMousemove, false),
905
+ addDomEvent(doc, "mouseup", onMouseup, false)
906
+ );
852
907
  }
853
- return addDomEvent(input, "wheel", onWheel, { passive: false });
854
- },
855
- activatePointerLock(ctx2) {
856
- if (isSafari() || !supportsPointerEvent())
857
- return;
858
- return requestPointerLock(dom.getDoc(ctx2));
859
908
  },
860
- trackMousemove(ctx2, _evt, { send }) {
861
- const doc = dom.getDoc(ctx2);
862
- function onMousemove(event) {
863
- if (!ctx2.scrubberCursorPoint)
909
+ actions: {
910
+ focusInput(ctx2) {
911
+ if (!ctx2.focusInputOnChange)
864
912
  return;
865
- const value = dom.getMousementValue(ctx2, event);
866
- 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)
867
986
  return;
868
- send({
869
- type: "POINTER_MOVE_SCRUBBER",
870
- hint: value.hint,
871
- 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
872
992
  });
873
- }
874
- function onMouseup() {
875
- send("POINTER_UP_SCRUBBER");
876
- }
877
- return callAll2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
878
- }
879
- },
880
- actions: {
881
- focusInput(ctx2) {
882
- if (!ctx2.focusInputOnChange)
883
- return;
884
- const input = dom.getInputEl(ctx2);
885
- raf(() => input == null ? void 0 : input.focus());
886
- },
887
- increment(ctx2, evt) {
888
- ctx2.value = utils.increment(ctx2, evt.step);
889
- },
890
- decrement(ctx2, evt) {
891
- ctx2.value = utils.decrement(ctx2, evt.step);
892
- },
893
- clampValue(ctx2) {
894
- ctx2.value = utils.clamp(ctx2);
895
- },
896
- roundValue(ctx2) {
897
- if (ctx2.value !== "") {
898
- ctx2.value = utils.round(ctx2);
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);
899
1016
  }
900
1017
  },
901
- setValue(ctx2, evt) {
902
- var _a, _b;
903
- const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
904
- ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
905
- },
906
- clearValue(ctx2) {
907
- ctx2.value = "";
908
- },
909
- setToMax(ctx2) {
910
- ctx2.value = ctx2.max.toString();
911
- },
912
- setToMin(ctx2) {
913
- ctx2.value = ctx2.min.toString();
914
- },
915
- setHint(ctx2, evt) {
916
- ctx2.hint = evt.hint;
917
- },
918
- clearHint(ctx2) {
919
- ctx2.hint = null;
920
- },
921
- setHintToSet(ctx2) {
922
- ctx2.hint = "set";
923
- },
924
- invokeOnChange(ctx2) {
925
- var _a;
926
- (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, {
927
- value: ctx2.value,
928
- valueAsNumber: ctx2.valueAsNumber
929
- });
930
- },
931
- invokeOnInvalid(ctx2) {
932
- var _a;
933
- if (!ctx2.isOutOfRange)
934
- return;
935
- const reason = ctx2.valueAsNumber > ctx2.max ? "rangeOverflow" : "rangeUnderflow";
936
- (_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, {
937
- reason,
938
- value: ctx2.formattedValue,
939
- valueAsNumber: ctx2.valueAsNumber
940
- });
941
- },
942
- syncInputValue(ctx2) {
943
- const input = dom.getInputEl(ctx2);
944
- if (!input || input.value == ctx2.value)
945
- return;
946
- const value = utils.parse(ctx2, input.value);
947
- ctx2.value = utils.sanitize(ctx2, value);
948
- },
949
- setCursorPoint(ctx2, evt) {
950
- ctx2.scrubberCursorPoint = evt.point;
951
- },
952
- clearCursorPoint(ctx2) {
953
- ctx2.scrubberCursorPoint = null;
954
- },
955
- updateCursor(ctx2) {
956
- const cursor = dom.getCursorEl(ctx2);
957
- if (!cursor || !ctx2.scrubberCursorPoint)
958
- return;
959
- const { x, y } = ctx2.scrubberCursorPoint;
960
- cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
961
- },
962
- addCustomCursor(ctx2) {
963
- if (isSafari() || !supportsPointerEvent())
964
- return;
965
- dom.createVirtualCursor(ctx2);
966
- },
967
- removeCustomCursor(ctx2) {
968
- var _a;
969
- if (isSafari() || !supportsPointerEvent())
970
- return;
971
- (_a = dom.getCursorEl(ctx2)) == null ? void 0 : _a.remove();
972
- },
973
- disableTextSelection(ctx2) {
974
- const doc = dom.getDoc(ctx2);
975
- doc.body.style.pointerEvents = "none";
976
- doc.documentElement.style.userSelect = "none";
977
- doc.documentElement.style.cursor = "ew-resize";
978
- },
979
- restoreTextSelection(ctx2) {
980
- const doc = dom.getDoc(ctx2);
981
- doc.body.style.pointerEvents = "";
982
- doc.documentElement.style.userSelect = "";
983
- doc.documentElement.style.cursor = "";
984
- }
985
- },
986
- hookSync: true
987
- });
1018
+ hookSync: true
1019
+ }
1020
+ );
988
1021
  }
1022
+ // Annotate the CommonJS export names for ESM import in node:
1023
+ 0 && (module.exports = {
1024
+ connect,
1025
+ machine
1026
+ });