@zag-js/number-input 2.0.0-next.3 → 2.0.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.d.mts +6 -9
  2. package/dist/index.d.ts +6 -9
  3. package/dist/index.js +12 -38
  4. package/dist/index.mjs +2 -7
  5. package/dist/number-input.anatomy.d.mts +2 -6
  6. package/dist/number-input.anatomy.d.ts +2 -6
  7. package/dist/number-input.anatomy.js +8 -43
  8. package/dist/number-input.anatomy.mjs +4 -17
  9. package/dist/number-input.connect.d.mts +3 -8
  10. package/dist/number-input.connect.d.ts +3 -8
  11. package/dist/number-input.connect.js +483 -377
  12. package/dist/number-input.connect.mjs +478 -353
  13. package/dist/number-input.dom.d.mts +33 -33
  14. package/dist/number-input.dom.d.ts +33 -33
  15. package/dist/number-input.dom.js +99 -142
  16. package/dist/number-input.dom.mjs +78 -103
  17. package/dist/number-input.machine.d.mts +2 -8
  18. package/dist/number-input.machine.d.ts +2 -8
  19. package/dist/number-input.machine.js +600 -528
  20. package/dist/number-input.machine.mjs +596 -512
  21. package/dist/number-input.props.d.mts +3 -9
  22. package/dist/number-input.props.d.ts +3 -9
  23. package/dist/number-input.props.js +43 -69
  24. package/dist/number-input.props.mjs +39 -43
  25. package/dist/number-input.translations.d.mts +3 -8
  26. package/dist/number-input.translations.d.ts +3 -8
  27. package/dist/number-input.translations.js +9 -31
  28. package/dist/number-input.translations.mjs +5 -6
  29. package/dist/number-input.types.d.mts +418 -408
  30. package/dist/number-input.types.d.ts +418 -408
  31. package/dist/number-input.types.js +4 -18
  32. package/dist/number-input.types.mjs +1 -0
  33. package/dist/number-input.utils.d.mts +16 -12
  34. package/dist/number-input.utils.d.ts +16 -12
  35. package/dist/number-input.utils.js +51 -57
  36. package/dist/number-input.utils.mjs +39 -27
  37. package/package.json +8 -8
  38. package/dist/cursor.d.mts +0 -12
  39. package/dist/cursor.d.ts +0 -12
  40. package/dist/cursor.js +0 -111
  41. package/dist/cursor.mjs +0 -84
@@ -1,36 +1,36 @@
1
- import { Scope } from '@zag-js/core';
2
- import { Point } from '@zag-js/types';
3
- import { HintValue } from './number-input.types.mjs';
4
- import '@internationalized/number';
5
-
6
- declare const getRootId: (ctx: Scope) => any;
7
- declare const getInputId: (ctx: Scope) => any;
8
- declare const getIncrementTriggerId: (ctx: Scope) => any;
9
- declare const getDecrementTriggerId: (ctx: Scope) => any;
10
- declare const getScrubberId: (ctx: Scope) => any;
11
- declare const getScrubberCursorId: (ctx: Scope) => any;
12
- declare const getLabelId: (ctx: Scope) => any;
13
- declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
14
- declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
15
- declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
16
- declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
17
- declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
18
- declare const getPressedTriggerEl: (ctx: Scope, hint: HintValue | null) => HTMLButtonElement | null;
19
- declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
1
+ import { StepDirection } from "./number-input.types.mjs";
2
+ import { Scope } from "@zag-js/core";
3
+ import { Point } from "@zag-js/types";
4
+ export declare const getRootId: (ctx: Scope) => any;
5
+ export declare const getInputId: (ctx: Scope) => any;
6
+ export declare const getIncrementTriggerId: (ctx: Scope) => any;
7
+ export declare const getDecrementTriggerId: (ctx: Scope) => any;
8
+ export declare const getScrubberId: (ctx: Scope) => any;
9
+ export declare const getScrubberCursorId: (ctx: Scope) => any;
10
+ export declare const getLabelId: (ctx: Scope) => any;
11
+ export declare const getHiddenInputId: (ctx: Scope) => any;
12
+ export declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
13
+ export declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
14
+ export declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
15
+ export declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
16
+ export declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
17
+ export declare const getHiddenInputEl: (ctx: Scope) => HTMLInputElement | null;
18
+ export declare const dispatchHiddenInputValue: (ctx: Scope, value: string) => void;
19
+ export declare const getTriggerEl: (ctx: Scope, direction: StepDirection) => HTMLButtonElement | null;
20
+ export declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
20
21
  interface MousemoveOpts {
21
- point: Point | null;
22
- isRtl: boolean;
23
- event: MouseEvent;
24
- direction: "horizontal" | "vertical";
25
- teleportDistance?: number | undefined;
22
+ point: Point | null;
23
+ isRtl: boolean;
24
+ event: MouseEvent;
25
+ axis: "horizontal" | "vertical";
26
+ teleportDistance?: number | undefined;
26
27
  }
27
- declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
28
- hint: string | null;
29
- point: {
30
- x: number;
31
- y: number;
32
- };
33
- delta: number;
28
+ export declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
29
+ direction: StepDirection | null;
30
+ point: {
31
+ x: number;
32
+ y: number;
33
+ };
34
+ delta: number;
34
35
  };
35
-
36
- export { getDecrementTriggerEl, getDecrementTriggerId, getIncrementTriggerEl, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getMousemoveValue, getPressedTriggerEl, getRootId, getScrubberCursorEl, getScrubberCursorId, getScrubberEl, getScrubberId, preventTextSelection };
36
+ export {};
@@ -1,36 +1,36 @@
1
- import { Scope } from '@zag-js/core';
2
- import { Point } from '@zag-js/types';
3
- import { HintValue } from './number-input.types.js';
4
- import '@internationalized/number';
5
-
6
- declare const getRootId: (ctx: Scope) => any;
7
- declare const getInputId: (ctx: Scope) => any;
8
- declare const getIncrementTriggerId: (ctx: Scope) => any;
9
- declare const getDecrementTriggerId: (ctx: Scope) => any;
10
- declare const getScrubberId: (ctx: Scope) => any;
11
- declare const getScrubberCursorId: (ctx: Scope) => any;
12
- declare const getLabelId: (ctx: Scope) => any;
13
- declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
14
- declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
15
- declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
16
- declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
17
- declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
18
- declare const getPressedTriggerEl: (ctx: Scope, hint: HintValue | null) => HTMLButtonElement | null;
19
- declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
1
+ import { StepDirection } from "./number-input.types.js";
2
+ import { Point } from "@zag-js/types";
3
+ import { Scope } from "@zag-js/core";
4
+ export declare const getRootId: (ctx: Scope) => any;
5
+ export declare const getInputId: (ctx: Scope) => any;
6
+ export declare const getIncrementTriggerId: (ctx: Scope) => any;
7
+ export declare const getDecrementTriggerId: (ctx: Scope) => any;
8
+ export declare const getScrubberId: (ctx: Scope) => any;
9
+ export declare const getScrubberCursorId: (ctx: Scope) => any;
10
+ export declare const getLabelId: (ctx: Scope) => any;
11
+ export declare const getHiddenInputId: (ctx: Scope) => any;
12
+ export declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
13
+ export declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
14
+ export declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
15
+ export declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
16
+ export declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
17
+ export declare const getHiddenInputEl: (ctx: Scope) => HTMLInputElement | null;
18
+ export declare const dispatchHiddenInputValue: (ctx: Scope, value: string) => void;
19
+ export declare const getTriggerEl: (ctx: Scope, direction: StepDirection) => HTMLButtonElement | null;
20
+ export declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
20
21
  interface MousemoveOpts {
21
- point: Point | null;
22
- isRtl: boolean;
23
- event: MouseEvent;
24
- direction: "horizontal" | "vertical";
25
- teleportDistance?: number | undefined;
22
+ point: Point | null;
23
+ isRtl: boolean;
24
+ event: MouseEvent;
25
+ axis: "horizontal" | "vertical";
26
+ teleportDistance?: number | undefined;
26
27
  }
27
- declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
28
- hint: string | null;
29
- point: {
30
- x: number;
31
- y: number;
32
- };
33
- delta: number;
28
+ export declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
29
+ direction: StepDirection | null;
30
+ point: {
31
+ x: number;
32
+ y: number;
33
+ };
34
+ delta: number;
34
35
  };
35
-
36
- export { getDecrementTriggerEl, getDecrementTriggerId, getIncrementTriggerEl, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getMousemoveValue, getPressedTriggerEl, getRootId, getScrubberCursorEl, getScrubberCursorId, getScrubberEl, getScrubberId, preventTextSelection };
36
+ export {};
@@ -1,146 +1,103 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/number-input.dom.ts
21
- var number_input_dom_exports = {};
22
- __export(number_input_dom_exports, {
23
- getDecrementTriggerEl: () => getDecrementTriggerEl,
24
- getDecrementTriggerId: () => getDecrementTriggerId,
25
- getIncrementTriggerEl: () => getIncrementTriggerEl,
26
- getIncrementTriggerId: () => getIncrementTriggerId,
27
- getInputEl: () => getInputEl,
28
- getInputId: () => getInputId,
29
- getLabelId: () => getLabelId,
30
- getMousemoveValue: () => getMousemoveValue,
31
- getPressedTriggerEl: () => getPressedTriggerEl,
32
- getRootId: () => getRootId,
33
- getScrubberCursorEl: () => getScrubberCursorEl,
34
- getScrubberCursorId: () => getScrubberCursorId,
35
- getScrubberEl: () => getScrubberEl,
36
- getScrubberId: () => getScrubberId,
37
- preventTextSelection: () => preventTextSelection
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
38
4
  });
39
- module.exports = __toCommonJS(number_input_dom_exports);
40
- var import_utils = require("@zag-js/utils");
41
- var import_number_input = require("./number-input.anatomy.js");
42
- var getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
43
- var getInputId = (ctx) => ctx.ids?.input ?? `${ctx.id}:input`;
44
- var getIncrementTriggerId = (ctx) => ctx.ids?.incrementTrigger ?? `${ctx.id}:inc`;
45
- var getDecrementTriggerId = (ctx) => ctx.ids?.decrementTrigger ?? `${ctx.id}:dec`;
46
- var getScrubberId = (ctx) => ctx.ids?.scrubber ?? `${ctx.id}:scrubber`;
47
- var getScrubberCursorId = (ctx) => ctx.ids?.scrubberCursor ?? `${ctx.id}:scrubber-cursor`;
48
- var getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
49
- var getInputEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.input));
50
- var getIncrementTriggerEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.incrementTrigger));
51
- var getDecrementTriggerEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.decrementTrigger));
52
- var getScrubberEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.scrubber));
53
- var getScrubberCursorEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.scrubberCursor));
54
- var getPressedTriggerEl = (ctx, hint) => {
55
- let btnEl = null;
56
- if (hint === "increment") {
57
- btnEl = getIncrementTriggerEl(ctx);
58
- }
59
- if (hint === "decrement") {
60
- btnEl = getDecrementTriggerEl(ctx);
61
- }
62
- return btnEl;
5
+ const require_number_input_anatomy = require("./number-input.anatomy.js");
6
+ let _zag_js_dom_query = require("@zag-js/dom-query");
7
+ let _zag_js_utils = require("@zag-js/utils");
8
+ // src/number-input.dom.ts
9
+ const getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
10
+ const getInputId = (ctx) => ctx.ids?.input ?? `${ctx.id}:input`;
11
+ const getIncrementTriggerId = (ctx) => ctx.ids?.incrementTrigger ?? `${ctx.id}:inc`;
12
+ const getDecrementTriggerId = (ctx) => ctx.ids?.decrementTrigger ?? `${ctx.id}:dec`;
13
+ const getScrubberId = (ctx) => ctx.ids?.scrubber ?? `${ctx.id}:scrubber`;
14
+ const getScrubberCursorId = (ctx) => ctx.ids?.scrubberCursor ?? `${ctx.id}:scrubber-cursor`;
15
+ const getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
16
+ const getHiddenInputId = (ctx) => ctx.ids?.hiddenInput ?? `${ctx.id}:hidden-input`;
17
+ const getInputEl = (ctx) => ctx.query(ctx.selector(require_number_input_anatomy.parts.input));
18
+ const getIncrementTriggerEl = (ctx) => ctx.query(ctx.selector(require_number_input_anatomy.parts.incrementTrigger));
19
+ const getDecrementTriggerEl = (ctx) => ctx.query(ctx.selector(require_number_input_anatomy.parts.decrementTrigger));
20
+ const getScrubberEl = (ctx) => ctx.query(ctx.selector(require_number_input_anatomy.parts.scrubber));
21
+ const getScrubberCursorEl = (ctx) => ctx.query(ctx.selector(require_number_input_anatomy.parts.scrubberCursor));
22
+ const getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
23
+ const dispatchHiddenInputValue = (ctx, value) => {
24
+ const inputEl = getHiddenInputEl(ctx);
25
+ if (!inputEl) return;
26
+ (0, _zag_js_dom_query.dispatchInputValueEvent)(inputEl, { value });
63
27
  };
64
- var preventTextSelection = (ctx, direction) => {
65
- const doc = ctx.getDoc();
66
- const html = doc.documentElement;
67
- const body = doc.body;
68
- body.style.pointerEvents = "none";
69
- html.style.userSelect = "none";
70
- html.style.cursor = direction === "vertical" ? "ns-resize" : "ew-resize";
71
- return () => {
72
- body.style.pointerEvents = "";
73
- html.style.userSelect = "";
74
- html.style.cursor = "";
75
- if (!html.style.length) {
76
- html.removeAttribute("style");
77
- }
78
- if (!body.style.length) {
79
- body.removeAttribute("style");
80
- }
81
- };
28
+ const getTriggerEl = (ctx, direction) => direction > 0 ? getIncrementTriggerEl(ctx) : getDecrementTriggerEl(ctx);
29
+ const preventTextSelection = (ctx, direction) => {
30
+ const doc = ctx.getDoc();
31
+ const html = doc.documentElement;
32
+ const body = doc.body;
33
+ body.style.pointerEvents = "none";
34
+ html.style.userSelect = "none";
35
+ html.style.cursor = direction === "vertical" ? "ns-resize" : "ew-resize";
36
+ return () => {
37
+ body.style.pointerEvents = "";
38
+ html.style.userSelect = "";
39
+ html.style.cursor = "";
40
+ if (!html.style.length) html.removeAttribute("style");
41
+ if (!body.style.length) body.removeAttribute("style");
42
+ };
82
43
  };
83
- var getMousemoveValue = (ctx, opts) => {
84
- const { point, isRtl, event, direction, teleportDistance } = opts;
85
- const win = ctx.getWin();
86
- const x = (0, import_utils.roundToDpr)(event.movementX, win.devicePixelRatio);
87
- const y = (0, import_utils.roundToDpr)(event.movementY, win.devicePixelRatio);
88
- const isVertical = direction === "vertical";
89
- const delta = isVertical ? y : x;
90
- let hint;
91
- if (isVertical) {
92
- hint = delta < 0 ? "increment" : delta > 0 ? "decrement" : null;
93
- } else {
94
- hint = delta > 0 ? "increment" : delta < 0 ? "decrement" : null;
95
- }
96
- if (!isVertical && isRtl) {
97
- if (hint === "increment") hint = "decrement";
98
- else if (hint === "decrement") hint = "increment";
99
- }
100
- const newPoint = { x: point.x + x, y: point.y + y };
101
- const half = (0, import_utils.roundToDpr)(7.5, win.devicePixelRatio);
102
- if (teleportDistance != null) {
103
- const scrubberEl = getScrubberEl(ctx);
104
- if (scrubberEl) {
105
- const rect = scrubberEl.getBoundingClientRect();
106
- if (isVertical) {
107
- const center = rect.top + rect.height / 2;
108
- const min = center - teleportDistance / 2;
109
- const max = center + teleportDistance / 2;
110
- newPoint.y = (0, import_utils.wrap)(newPoint.y + half - min, max - min) + min - half;
111
- } else {
112
- const center = rect.left + rect.width / 2;
113
- const min = center - teleportDistance / 2;
114
- const max = center + teleportDistance / 2;
115
- newPoint.x = (0, import_utils.wrap)(newPoint.x + half - min, max - min) + min - half;
116
- }
117
- }
118
- } else {
119
- if (isVertical) {
120
- const height = win.innerHeight;
121
- newPoint.y = (0, import_utils.wrap)(newPoint.y + half, height) - half;
122
- } else {
123
- const width = win.innerWidth;
124
- newPoint.x = (0, import_utils.wrap)(newPoint.x + half, width) - half;
125
- }
126
- }
127
- return { hint, point: newPoint, delta };
44
+ const getMousemoveValue = (ctx, opts) => {
45
+ const { point, isRtl, event, axis, teleportDistance } = opts;
46
+ const win = ctx.getWin();
47
+ const x = (0, _zag_js_utils.roundToDpr)(event.movementX, win.devicePixelRatio);
48
+ const y = (0, _zag_js_utils.roundToDpr)(event.movementY, win.devicePixelRatio);
49
+ const isVertical = axis === "vertical";
50
+ const delta = isVertical ? y : x;
51
+ const direction = Math.sign(delta) * (isVertical ? -1 : isRtl ? -1 : 1) || null;
52
+ const newPoint = {
53
+ x: point.x + x,
54
+ y: point.y + y
55
+ };
56
+ const half = (0, _zag_js_utils.roundToDpr)(7.5, win.devicePixelRatio);
57
+ if (teleportDistance != null) {
58
+ const scrubberEl = getScrubberEl(ctx);
59
+ if (scrubberEl) {
60
+ const rect = scrubberEl.getBoundingClientRect();
61
+ if (isVertical) {
62
+ const center = rect.top + rect.height / 2;
63
+ const min = center - teleportDistance / 2;
64
+ const max = center + teleportDistance / 2;
65
+ newPoint.y = (0, _zag_js_utils.wrap)(newPoint.y + half - min, max - min) + min - half;
66
+ } else {
67
+ const center = rect.left + rect.width / 2;
68
+ const min = center - teleportDistance / 2;
69
+ const max = center + teleportDistance / 2;
70
+ newPoint.x = (0, _zag_js_utils.wrap)(newPoint.x + half - min, max - min) + min - half;
71
+ }
72
+ }
73
+ } else if (isVertical) {
74
+ const height = win.innerHeight;
75
+ newPoint.y = (0, _zag_js_utils.wrap)(newPoint.y + half, height) - half;
76
+ } else {
77
+ const width = win.innerWidth;
78
+ newPoint.x = (0, _zag_js_utils.wrap)(newPoint.x + half, width) - half;
79
+ }
80
+ return {
81
+ direction,
82
+ point: newPoint,
83
+ delta
84
+ };
128
85
  };
129
- // Annotate the CommonJS export names for ESM import in node:
130
- 0 && (module.exports = {
131
- getDecrementTriggerEl,
132
- getDecrementTriggerId,
133
- getIncrementTriggerEl,
134
- getIncrementTriggerId,
135
- getInputEl,
136
- getInputId,
137
- getLabelId,
138
- getMousemoveValue,
139
- getPressedTriggerEl,
140
- getRootId,
141
- getScrubberCursorEl,
142
- getScrubberCursorId,
143
- getScrubberEl,
144
- getScrubberId,
145
- preventTextSelection
146
- });
86
+ exports.dispatchHiddenInputValue = dispatchHiddenInputValue;
87
+ exports.getDecrementTriggerEl = getDecrementTriggerEl;
88
+ exports.getDecrementTriggerId = getDecrementTriggerId;
89
+ exports.getHiddenInputEl = getHiddenInputEl;
90
+ exports.getHiddenInputId = getHiddenInputId;
91
+ exports.getIncrementTriggerEl = getIncrementTriggerEl;
92
+ exports.getIncrementTriggerId = getIncrementTriggerId;
93
+ exports.getInputEl = getInputEl;
94
+ exports.getInputId = getInputId;
95
+ exports.getLabelId = getLabelId;
96
+ exports.getMousemoveValue = getMousemoveValue;
97
+ exports.getRootId = getRootId;
98
+ exports.getScrubberCursorEl = getScrubberCursorEl;
99
+ exports.getScrubberCursorId = getScrubberCursorId;
100
+ exports.getScrubberEl = getScrubberEl;
101
+ exports.getScrubberId = getScrubberId;
102
+ exports.getTriggerEl = getTriggerEl;
103
+ exports.preventTextSelection = preventTextSelection;
@@ -1,107 +1,82 @@
1
- // src/number-input.dom.ts
2
- import { roundToDpr, wrap } from "@zag-js/utils";
3
1
  import { parts } from "./number-input.anatomy.mjs";
4
- var getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
5
- var getInputId = (ctx) => ctx.ids?.input ?? `${ctx.id}:input`;
6
- var getIncrementTriggerId = (ctx) => ctx.ids?.incrementTrigger ?? `${ctx.id}:inc`;
7
- var getDecrementTriggerId = (ctx) => ctx.ids?.decrementTrigger ?? `${ctx.id}:dec`;
8
- var getScrubberId = (ctx) => ctx.ids?.scrubber ?? `${ctx.id}:scrubber`;
9
- var getScrubberCursorId = (ctx) => ctx.ids?.scrubberCursor ?? `${ctx.id}:scrubber-cursor`;
10
- var getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
11
- var getInputEl = (ctx) => ctx.query(ctx.selector(parts.input));
12
- var getIncrementTriggerEl = (ctx) => ctx.query(ctx.selector(parts.incrementTrigger));
13
- var getDecrementTriggerEl = (ctx) => ctx.query(ctx.selector(parts.decrementTrigger));
14
- var getScrubberEl = (ctx) => ctx.query(ctx.selector(parts.scrubber));
15
- var getScrubberCursorEl = (ctx) => ctx.query(ctx.selector(parts.scrubberCursor));
16
- var getPressedTriggerEl = (ctx, hint) => {
17
- let btnEl = null;
18
- if (hint === "increment") {
19
- btnEl = getIncrementTriggerEl(ctx);
20
- }
21
- if (hint === "decrement") {
22
- btnEl = getDecrementTriggerEl(ctx);
23
- }
24
- return btnEl;
25
- };
26
- var preventTextSelection = (ctx, direction) => {
27
- const doc = ctx.getDoc();
28
- const html = doc.documentElement;
29
- const body = doc.body;
30
- body.style.pointerEvents = "none";
31
- html.style.userSelect = "none";
32
- html.style.cursor = direction === "vertical" ? "ns-resize" : "ew-resize";
33
- return () => {
34
- body.style.pointerEvents = "";
35
- html.style.userSelect = "";
36
- html.style.cursor = "";
37
- if (!html.style.length) {
38
- html.removeAttribute("style");
39
- }
40
- if (!body.style.length) {
41
- body.removeAttribute("style");
42
- }
43
- };
2
+ import { dispatchInputValueEvent } from "@zag-js/dom-query";
3
+ import { roundToDpr, wrap } from "@zag-js/utils";
4
+ // src/number-input.dom.ts
5
+ const getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
6
+ const getInputId = (ctx) => ctx.ids?.input ?? `${ctx.id}:input`;
7
+ const getIncrementTriggerId = (ctx) => ctx.ids?.incrementTrigger ?? `${ctx.id}:inc`;
8
+ const getDecrementTriggerId = (ctx) => ctx.ids?.decrementTrigger ?? `${ctx.id}:dec`;
9
+ const getScrubberId = (ctx) => ctx.ids?.scrubber ?? `${ctx.id}:scrubber`;
10
+ const getScrubberCursorId = (ctx) => ctx.ids?.scrubberCursor ?? `${ctx.id}:scrubber-cursor`;
11
+ const getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
12
+ const getHiddenInputId = (ctx) => ctx.ids?.hiddenInput ?? `${ctx.id}:hidden-input`;
13
+ const getInputEl = (ctx) => ctx.query(ctx.selector(parts.input));
14
+ const getIncrementTriggerEl = (ctx) => ctx.query(ctx.selector(parts.incrementTrigger));
15
+ const getDecrementTriggerEl = (ctx) => ctx.query(ctx.selector(parts.decrementTrigger));
16
+ const getScrubberEl = (ctx) => ctx.query(ctx.selector(parts.scrubber));
17
+ const getScrubberCursorEl = (ctx) => ctx.query(ctx.selector(parts.scrubberCursor));
18
+ const getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
19
+ const dispatchHiddenInputValue = (ctx, value) => {
20
+ const inputEl = getHiddenInputEl(ctx);
21
+ if (!inputEl) return;
22
+ dispatchInputValueEvent(inputEl, { value });
44
23
  };
45
- var getMousemoveValue = (ctx, opts) => {
46
- const { point, isRtl, event, direction, teleportDistance } = opts;
47
- const win = ctx.getWin();
48
- const x = roundToDpr(event.movementX, win.devicePixelRatio);
49
- const y = roundToDpr(event.movementY, win.devicePixelRatio);
50
- const isVertical = direction === "vertical";
51
- const delta = isVertical ? y : x;
52
- let hint;
53
- if (isVertical) {
54
- hint = delta < 0 ? "increment" : delta > 0 ? "decrement" : null;
55
- } else {
56
- hint = delta > 0 ? "increment" : delta < 0 ? "decrement" : null;
57
- }
58
- if (!isVertical && isRtl) {
59
- if (hint === "increment") hint = "decrement";
60
- else if (hint === "decrement") hint = "increment";
61
- }
62
- const newPoint = { x: point.x + x, y: point.y + y };
63
- const half = roundToDpr(7.5, win.devicePixelRatio);
64
- if (teleportDistance != null) {
65
- const scrubberEl = getScrubberEl(ctx);
66
- if (scrubberEl) {
67
- const rect = scrubberEl.getBoundingClientRect();
68
- if (isVertical) {
69
- const center = rect.top + rect.height / 2;
70
- const min = center - teleportDistance / 2;
71
- const max = center + teleportDistance / 2;
72
- newPoint.y = wrap(newPoint.y + half - min, max - min) + min - half;
73
- } else {
74
- const center = rect.left + rect.width / 2;
75
- const min = center - teleportDistance / 2;
76
- const max = center + teleportDistance / 2;
77
- newPoint.x = wrap(newPoint.x + half - min, max - min) + min - half;
78
- }
79
- }
80
- } else {
81
- if (isVertical) {
82
- const height = win.innerHeight;
83
- newPoint.y = wrap(newPoint.y + half, height) - half;
84
- } else {
85
- const width = win.innerWidth;
86
- newPoint.x = wrap(newPoint.x + half, width) - half;
87
- }
88
- }
89
- return { hint, point: newPoint, delta };
24
+ const getTriggerEl = (ctx, direction) => direction > 0 ? getIncrementTriggerEl(ctx) : getDecrementTriggerEl(ctx);
25
+ const preventTextSelection = (ctx, direction) => {
26
+ const doc = ctx.getDoc();
27
+ const html = doc.documentElement;
28
+ const body = doc.body;
29
+ body.style.pointerEvents = "none";
30
+ html.style.userSelect = "none";
31
+ html.style.cursor = direction === "vertical" ? "ns-resize" : "ew-resize";
32
+ return () => {
33
+ body.style.pointerEvents = "";
34
+ html.style.userSelect = "";
35
+ html.style.cursor = "";
36
+ if (!html.style.length) html.removeAttribute("style");
37
+ if (!body.style.length) body.removeAttribute("style");
38
+ };
90
39
  };
91
- export {
92
- getDecrementTriggerEl,
93
- getDecrementTriggerId,
94
- getIncrementTriggerEl,
95
- getIncrementTriggerId,
96
- getInputEl,
97
- getInputId,
98
- getLabelId,
99
- getMousemoveValue,
100
- getPressedTriggerEl,
101
- getRootId,
102
- getScrubberCursorEl,
103
- getScrubberCursorId,
104
- getScrubberEl,
105
- getScrubberId,
106
- preventTextSelection
40
+ const getMousemoveValue = (ctx, opts) => {
41
+ const { point, isRtl, event, axis, teleportDistance } = opts;
42
+ const win = ctx.getWin();
43
+ const x = roundToDpr(event.movementX, win.devicePixelRatio);
44
+ const y = roundToDpr(event.movementY, win.devicePixelRatio);
45
+ const isVertical = axis === "vertical";
46
+ const delta = isVertical ? y : x;
47
+ const direction = Math.sign(delta) * (isVertical ? -1 : isRtl ? -1 : 1) || null;
48
+ const newPoint = {
49
+ x: point.x + x,
50
+ y: point.y + y
51
+ };
52
+ const half = roundToDpr(7.5, win.devicePixelRatio);
53
+ if (teleportDistance != null) {
54
+ const scrubberEl = getScrubberEl(ctx);
55
+ if (scrubberEl) {
56
+ const rect = scrubberEl.getBoundingClientRect();
57
+ if (isVertical) {
58
+ const center = rect.top + rect.height / 2;
59
+ const min = center - teleportDistance / 2;
60
+ const max = center + teleportDistance / 2;
61
+ newPoint.y = wrap(newPoint.y + half - min, max - min) + min - half;
62
+ } else {
63
+ const center = rect.left + rect.width / 2;
64
+ const min = center - teleportDistance / 2;
65
+ const max = center + teleportDistance / 2;
66
+ newPoint.x = wrap(newPoint.x + half - min, max - min) + min - half;
67
+ }
68
+ }
69
+ } else if (isVertical) {
70
+ const height = win.innerHeight;
71
+ newPoint.y = wrap(newPoint.y + half, height) - half;
72
+ } else {
73
+ const width = win.innerWidth;
74
+ newPoint.x = wrap(newPoint.x + half, width) - half;
75
+ }
76
+ return {
77
+ direction,
78
+ point: newPoint,
79
+ delta
80
+ };
107
81
  };
82
+ export { dispatchHiddenInputValue, getDecrementTriggerEl, getDecrementTriggerId, getHiddenInputEl, getHiddenInputId, getIncrementTriggerEl, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getMousemoveValue, getRootId, getScrubberCursorEl, getScrubberCursorId, getScrubberEl, getScrubberId, getTriggerEl, preventTextSelection };
@@ -1,8 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { NumberInputSchema } from './number-input.types.mjs';
3
- import '@internationalized/number';
4
- import '@zag-js/types';
5
-
6
- declare const machine: _zag_js_core.Machine<NumberInputSchema>;
7
-
8
- export { machine };
1
+ import { NumberInputSchema } from "./number-input.types.mjs";
2
+ export declare const machine: import("@zag-js/core").Machine<NumberInputSchema>;
@@ -1,8 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { NumberInputSchema } from './number-input.types.js';
3
- import '@internationalized/number';
4
- import '@zag-js/types';
5
-
6
- declare const machine: _zag_js_core.Machine<NumberInputSchema>;
7
-
8
- export { machine };
1
+ import { NumberInputSchema } from "./number-input.types.js";
2
+ export declare const machine: import("@zag-js/core").Machine<NumberInputSchema>;