@zag-js/number-input 2.0.0-next.2 → 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.
- package/dist/index.d.mts +6 -9
- package/dist/index.d.ts +6 -9
- package/dist/index.js +12 -38
- package/dist/index.mjs +2 -7
- package/dist/number-input.anatomy.d.mts +2 -6
- package/dist/number-input.anatomy.d.ts +2 -6
- package/dist/number-input.anatomy.js +8 -43
- package/dist/number-input.anatomy.mjs +4 -17
- package/dist/number-input.connect.d.mts +3 -8
- package/dist/number-input.connect.d.ts +3 -8
- package/dist/number-input.connect.js +483 -377
- package/dist/number-input.connect.mjs +478 -353
- package/dist/number-input.dom.d.mts +33 -33
- package/dist/number-input.dom.d.ts +33 -33
- package/dist/number-input.dom.js +99 -142
- package/dist/number-input.dom.mjs +78 -103
- package/dist/number-input.machine.d.mts +2 -8
- package/dist/number-input.machine.d.ts +2 -8
- package/dist/number-input.machine.js +600 -528
- package/dist/number-input.machine.mjs +596 -512
- package/dist/number-input.props.d.mts +3 -9
- package/dist/number-input.props.d.ts +3 -9
- package/dist/number-input.props.js +43 -69
- package/dist/number-input.props.mjs +39 -43
- package/dist/number-input.translations.d.mts +3 -8
- package/dist/number-input.translations.d.ts +3 -8
- package/dist/number-input.translations.js +9 -31
- package/dist/number-input.translations.mjs +5 -6
- package/dist/number-input.types.d.mts +418 -408
- package/dist/number-input.types.d.ts +418 -408
- package/dist/number-input.types.js +4 -18
- package/dist/number-input.types.mjs +1 -0
- package/dist/number-input.utils.d.mts +16 -12
- package/dist/number-input.utils.d.ts +16 -12
- package/dist/number-input.utils.js +51 -57
- package/dist/number-input.utils.mjs +39 -27
- package/package.json +8 -8
- package/dist/cursor.d.mts +0 -12
- package/dist/cursor.d.ts +0 -12
- package/dist/cursor.js +0 -111
- package/dist/cursor.mjs +0 -84
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
declare const
|
|
17
|
-
declare const
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 {
|
|
2
|
-
import { Point } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
declare const
|
|
17
|
-
declare const
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 {};
|
package/dist/number-input.dom.js
CHANGED
|
@@ -1,146 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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>;
|