@zag-js/number-input 0.80.0 → 0.81.0

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,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var anatomy$1 = require('@zag-js/anatomy');
4
- var domEvent = require('@zag-js/dom-event');
5
4
  var domQuery = require('@zag-js/dom-query');
6
- var numberUtils = require('@zag-js/number-utils');
5
+ var utils = require('@zag-js/utils');
7
6
  var core = require('@zag-js/core');
8
7
  var formUtils = require('@zag-js/form-utils');
9
- var utils = require('@zag-js/utils');
10
8
  var number = require('@internationalized/number');
11
9
 
12
10
  // src/number-input.anatomy.ts
@@ -71,8 +69,9 @@ var dom = domQuery.createScope({
71
69
  };
72
70
  },
73
71
  getMousemoveValue(ctx, event) {
74
- const x = numberUtils.roundToDevicePixel(event.movementX);
75
- const y = numberUtils.roundToDevicePixel(event.movementY);
72
+ const win = dom.getWin(ctx);
73
+ const x = utils.roundToDpr(event.movementX, win.devicePixelRatio);
74
+ const y = utils.roundToDpr(event.movementY, win.devicePixelRatio);
76
75
  let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
77
76
  if (ctx.isRtl && hint === "increment") hint = "decrement";
78
77
  if (ctx.isRtl && hint === "decrement") hint = "increment";
@@ -80,10 +79,9 @@ var dom = domQuery.createScope({
80
79
  x: ctx.scrubberCursorPoint.x + x,
81
80
  y: ctx.scrubberCursorPoint.y + y
82
81
  };
83
- const win = dom.getWin(ctx);
84
82
  const width = win.innerWidth;
85
- const half = numberUtils.roundToDevicePixel(7.5);
86
- point.x = numberUtils.wrap(point.x + half, width) - half;
83
+ const half = utils.roundToDpr(7.5, win.devicePixelRatio);
84
+ point.x = utils.wrap(point.x + half, width) - half;
87
85
  return { hint, point };
88
86
  },
89
87
  createVirtualCursor(ctx) {
@@ -242,7 +240,7 @@ function connect(state, send, normalize) {
242
240
  if (event.defaultPrevented) return;
243
241
  if (readOnly) return;
244
242
  if (domQuery.isComposingEvent(event)) return;
245
- const step = domEvent.getEventStep(event) * state.context.step;
243
+ const step = domQuery.getEventStep(event) * state.context.step;
246
244
  const keyMap = {
247
245
  ArrowUp() {
248
246
  send({ type: "INPUT.ARROW_UP", step });
@@ -253,12 +251,12 @@ function connect(state, send, normalize) {
253
251
  event.preventDefault();
254
252
  },
255
253
  Home() {
256
- if (domEvent.isModifierKey(event)) return;
254
+ if (domQuery.isModifierKey(event)) return;
257
255
  send("INPUT.HOME");
258
256
  event.preventDefault();
259
257
  },
260
258
  End() {
261
- if (domEvent.isModifierKey(event)) return;
259
+ if (domQuery.isModifierKey(event)) return;
262
260
  send("INPUT.END");
263
261
  event.preventDefault();
264
262
  },
@@ -283,7 +281,7 @@ function connect(state, send, normalize) {
283
281
  tabIndex: -1,
284
282
  "aria-controls": dom.getInputId(state.context),
285
283
  onPointerDown(event) {
286
- if (isDecrementDisabled || !domEvent.isLeftClick(event)) return;
284
+ if (isDecrementDisabled || !domQuery.isLeftClick(event)) return;
287
285
  send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
288
286
  if (event.pointerType === "mouse") {
289
287
  event.preventDefault();
@@ -313,7 +311,7 @@ function connect(state, send, normalize) {
313
311
  tabIndex: -1,
314
312
  "aria-controls": dom.getInputId(state.context),
315
313
  onPointerDown(event) {
316
- if (isIncrementDisabled || !domEvent.isLeftClick(event)) return;
314
+ if (isIncrementDisabled || !domQuery.isLeftClick(event)) return;
317
315
  send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
318
316
  if (event.pointerType === "mouse") {
319
317
  event.preventDefault();
@@ -339,9 +337,11 @@ function connect(state, send, normalize) {
339
337
  role: "presentation",
340
338
  onMouseDown(event) {
341
339
  if (disabled) return;
342
- const point = domEvent.getEventPoint(event);
343
- point.x = point.x - numberUtils.roundToDevicePixel(7.5);
344
- point.y = point.y - numberUtils.roundToDevicePixel(7.5);
340
+ const point = domQuery.getEventPoint(event);
341
+ const win = domQuery.getWindow(event.currentTarget);
342
+ const dpr = win.devicePixelRatio;
343
+ point.x = point.x - utils.roundToDpr(7.5, dpr);
344
+ point.y = point.y - utils.roundToDpr(7.5, dpr);
345
345
  send({ type: "SCRUBBER.PRESS_DOWN", point });
346
346
  event.preventDefault();
347
347
  },
@@ -451,9 +451,9 @@ function machine(userContext) {
451
451
  isRtl: (ctx2) => ctx2.dir === "rtl",
452
452
  valueAsNumber: (ctx2) => parseValue(ctx2, ctx2.value),
453
453
  formattedValue: (ctx2) => formatValue(ctx2, ctx2.valueAsNumber),
454
- isAtMin: (ctx2) => numberUtils.isAtMin(ctx2.valueAsNumber, ctx2),
455
- isAtMax: (ctx2) => numberUtils.isAtMax(ctx2.valueAsNumber, ctx2),
456
- isOutOfRange: (ctx2) => !numberUtils.isWithinRange(ctx2.valueAsNumber, ctx2),
454
+ isAtMin: (ctx2) => utils.isValueAtMin(ctx2.valueAsNumber, ctx2.min),
455
+ isAtMax: (ctx2) => utils.isValueAtMax(ctx2.valueAsNumber, ctx2.max),
456
+ isOutOfRange: (ctx2) => !utils.isValueWithinRange(ctx2.valueAsNumber, ctx2.min, ctx2.max),
457
457
  isValueEmpty: (ctx2) => ctx2.value === "",
458
458
  isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled,
459
459
  canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
@@ -663,11 +663,11 @@ function machine(userContext) {
663
663
  send("VALUE.DECREMENT");
664
664
  }
665
665
  }
666
- return domEvent.addDomEvent(inputEl, "wheel", onWheel, { passive: false });
666
+ return domQuery.addDomEvent(inputEl, "wheel", onWheel, { passive: false });
667
667
  },
668
668
  activatePointerLock(ctx2) {
669
669
  if (domQuery.isSafari()) return;
670
- return domEvent.requestPointerLock(dom.getDoc(ctx2));
670
+ return domQuery.requestPointerLock(dom.getDoc(ctx2));
671
671
  },
672
672
  trackMousemove(ctx2, _evt, { send }) {
673
673
  const doc = dom.getDoc(ctx2);
@@ -685,8 +685,8 @@ function machine(userContext) {
685
685
  send("SCRUBBER.POINTER_UP");
686
686
  }
687
687
  return utils.callAll(
688
- domEvent.addDomEvent(doc, "mousemove", onMousemove, false),
689
- domEvent.addDomEvent(doc, "mouseup", onMouseup, false)
688
+ domQuery.addDomEvent(doc, "mousemove", onMousemove, false),
689
+ domQuery.addDomEvent(doc, "mouseup", onMouseup, false)
690
690
  );
691
691
  }
692
692
  },
@@ -698,22 +698,22 @@ function machine(userContext) {
698
698
  domQuery.raf(() => inputEl?.focus({ preventScroll: true }));
699
699
  },
700
700
  increment(ctx2, evt) {
701
- const nextValue = numberUtils.increment(ctx2.valueAsNumber, evt.step ?? ctx2.step);
702
- const value = formatValue(ctx2, numberUtils.clamp(nextValue, ctx2));
701
+ const nextValue = utils.incrementValue(ctx2.valueAsNumber, evt.step ?? ctx2.step);
702
+ const value = formatValue(ctx2, utils.clampValue(nextValue, ctx2.min, ctx2.max));
703
703
  set.value(ctx2, value);
704
704
  },
705
705
  decrement(ctx2, evt) {
706
- const nextValue = numberUtils.decrement(ctx2.valueAsNumber, evt.step ?? ctx2.step);
707
- const value = formatValue(ctx2, numberUtils.clamp(nextValue, ctx2));
706
+ const nextValue = utils.decrementValue(ctx2.valueAsNumber, evt.step ?? ctx2.step);
707
+ const value = formatValue(ctx2, utils.clampValue(nextValue, ctx2.min, ctx2.max));
708
708
  set.value(ctx2, value);
709
709
  },
710
710
  setClampedValue(ctx2) {
711
- const nextValue = numberUtils.clamp(ctx2.valueAsNumber, ctx2);
711
+ const nextValue = utils.clampValue(ctx2.valueAsNumber, ctx2.min, ctx2.max);
712
712
  set.value(ctx2, formatValue(ctx2, nextValue));
713
713
  },
714
714
  setRawValue(ctx2, evt) {
715
715
  const parsedValue = parseValue(ctx2, evt.value);
716
- const value = formatValue(ctx2, numberUtils.clamp(parsedValue, ctx2));
716
+ const value = formatValue(ctx2, utils.clampValue(parsedValue, ctx2.min, ctx2.max));
717
717
  set.value(ctx2, value);
718
718
  },
719
719
  setValue(ctx2, evt) {
package/dist/index.mjs CHANGED
@@ -1,10 +1,8 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
- import { getEventStep, isLeftClick, getEventPoint, addDomEvent, requestPointerLock, isModifierKey } from '@zag-js/dom-event';
3
- import { createScope, isSafari, MAX_Z_INDEX, dataAttr, ariaAttr, isComposingEvent, observeAttributes, raf } from '@zag-js/dom-query';
4
- import { roundToDevicePixel, wrap, isAtMin, isAtMax, isWithinRange, increment, clamp, decrement } from '@zag-js/number-utils';
2
+ import { createScope, isSafari, MAX_Z_INDEX, dataAttr, ariaAttr, isComposingEvent, getEventStep, isLeftClick, getEventPoint, getWindow, observeAttributes, addDomEvent, requestPointerLock, raf, isModifierKey } from '@zag-js/dom-query';
3
+ import { roundToDpr, wrap, compact, isValueAtMin, isValueAtMax, isValueWithinRange, callAll, incrementValue, clampValue, decrementValue, isEqual } from '@zag-js/utils';
5
4
  import { createMachine, choose, ref, guards } from '@zag-js/core';
6
5
  import { trackFormControl, setElementValue } from '@zag-js/form-utils';
7
- import { compact, callAll, isEqual } from '@zag-js/utils';
8
6
  import { NumberParser } from '@internationalized/number';
9
7
 
10
8
  // src/number-input.anatomy.ts
@@ -69,8 +67,9 @@ var dom = createScope({
69
67
  };
70
68
  },
71
69
  getMousemoveValue(ctx, event) {
72
- const x = roundToDevicePixel(event.movementX);
73
- const y = roundToDevicePixel(event.movementY);
70
+ const win = dom.getWin(ctx);
71
+ const x = roundToDpr(event.movementX, win.devicePixelRatio);
72
+ const y = roundToDpr(event.movementY, win.devicePixelRatio);
74
73
  let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
75
74
  if (ctx.isRtl && hint === "increment") hint = "decrement";
76
75
  if (ctx.isRtl && hint === "decrement") hint = "increment";
@@ -78,9 +77,8 @@ var dom = createScope({
78
77
  x: ctx.scrubberCursorPoint.x + x,
79
78
  y: ctx.scrubberCursorPoint.y + y
80
79
  };
81
- const win = dom.getWin(ctx);
82
80
  const width = win.innerWidth;
83
- const half = roundToDevicePixel(7.5);
81
+ const half = roundToDpr(7.5, win.devicePixelRatio);
84
82
  point.x = wrap(point.x + half, width) - half;
85
83
  return { hint, point };
86
84
  },
@@ -338,8 +336,10 @@ function connect(state, send, normalize) {
338
336
  onMouseDown(event) {
339
337
  if (disabled) return;
340
338
  const point = getEventPoint(event);
341
- point.x = point.x - roundToDevicePixel(7.5);
342
- point.y = point.y - roundToDevicePixel(7.5);
339
+ const win = getWindow(event.currentTarget);
340
+ const dpr = win.devicePixelRatio;
341
+ point.x = point.x - roundToDpr(7.5, dpr);
342
+ point.y = point.y - roundToDpr(7.5, dpr);
343
343
  send({ type: "SCRUBBER.PRESS_DOWN", point });
344
344
  event.preventDefault();
345
345
  },
@@ -449,9 +449,9 @@ function machine(userContext) {
449
449
  isRtl: (ctx2) => ctx2.dir === "rtl",
450
450
  valueAsNumber: (ctx2) => parseValue(ctx2, ctx2.value),
451
451
  formattedValue: (ctx2) => formatValue(ctx2, ctx2.valueAsNumber),
452
- isAtMin: (ctx2) => isAtMin(ctx2.valueAsNumber, ctx2),
453
- isAtMax: (ctx2) => isAtMax(ctx2.valueAsNumber, ctx2),
454
- isOutOfRange: (ctx2) => !isWithinRange(ctx2.valueAsNumber, ctx2),
452
+ isAtMin: (ctx2) => isValueAtMin(ctx2.valueAsNumber, ctx2.min),
453
+ isAtMax: (ctx2) => isValueAtMax(ctx2.valueAsNumber, ctx2.max),
454
+ isOutOfRange: (ctx2) => !isValueWithinRange(ctx2.valueAsNumber, ctx2.min, ctx2.max),
455
455
  isValueEmpty: (ctx2) => ctx2.value === "",
456
456
  isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled,
457
457
  canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
@@ -696,22 +696,22 @@ function machine(userContext) {
696
696
  raf(() => inputEl?.focus({ preventScroll: true }));
697
697
  },
698
698
  increment(ctx2, evt) {
699
- const nextValue = increment(ctx2.valueAsNumber, evt.step ?? ctx2.step);
700
- const value = formatValue(ctx2, clamp(nextValue, ctx2));
699
+ const nextValue = incrementValue(ctx2.valueAsNumber, evt.step ?? ctx2.step);
700
+ const value = formatValue(ctx2, clampValue(nextValue, ctx2.min, ctx2.max));
701
701
  set.value(ctx2, value);
702
702
  },
703
703
  decrement(ctx2, evt) {
704
- const nextValue = decrement(ctx2.valueAsNumber, evt.step ?? ctx2.step);
705
- const value = formatValue(ctx2, clamp(nextValue, ctx2));
704
+ const nextValue = decrementValue(ctx2.valueAsNumber, evt.step ?? ctx2.step);
705
+ const value = formatValue(ctx2, clampValue(nextValue, ctx2.min, ctx2.max));
706
706
  set.value(ctx2, value);
707
707
  },
708
708
  setClampedValue(ctx2) {
709
- const nextValue = clamp(ctx2.valueAsNumber, ctx2);
709
+ const nextValue = clampValue(ctx2.valueAsNumber, ctx2.min, ctx2.max);
710
710
  set.value(ctx2, formatValue(ctx2, nextValue));
711
711
  },
712
712
  setRawValue(ctx2, evt) {
713
713
  const parsedValue = parseValue(ctx2, evt.value);
714
- const value = formatValue(ctx2, clamp(parsedValue, ctx2));
714
+ const value = formatValue(ctx2, clampValue(parsedValue, ctx2.min, ctx2.max));
715
715
  set.value(ctx2, value);
716
716
  },
717
717
  setValue(ctx2, evt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "0.80.0",
3
+ "version": "0.81.0",
4
4
  "description": "Core logic for the number-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,14 +27,12 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@internationalized/number": "3.6.0",
30
- "@zag-js/anatomy": "0.80.0",
31
- "@zag-js/core": "0.80.0",
32
- "@zag-js/dom-event": "0.80.0",
33
- "@zag-js/dom-query": "0.80.0",
34
- "@zag-js/form-utils": "0.80.0",
35
- "@zag-js/number-utils": "0.80.0",
36
- "@zag-js/types": "0.80.0",
37
- "@zag-js/utils": "0.80.0"
30
+ "@zag-js/anatomy": "0.81.0",
31
+ "@zag-js/core": "0.81.0",
32
+ "@zag-js/dom-query": "0.81.0",
33
+ "@zag-js/form-utils": "0.81.0",
34
+ "@zag-js/types": "0.81.0",
35
+ "@zag-js/utils": "0.81.0"
38
36
  },
39
37
  "devDependencies": {
40
38
  "clean-package": "2.2.0"