@zag-js/slider 1.47.0 → 1.49.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.d.mts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/slider.anatomy.d.mts +2 -6
- package/dist/slider.anatomy.d.ts +2 -6
- package/dist/slider.anatomy.js +8 -44
- package/dist/slider.anatomy.mjs +4 -18
- package/dist/slider.connect.d.mts +3 -7
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +371 -351
- package/dist/slider.connect.mjs +365 -329
- package/dist/slider.dom.d.mts +27 -30
- package/dist/slider.dom.d.ts +27 -30
- package/dist/slider.dom.js +93 -137
- package/dist/slider.dom.mjs +70 -93
- package/dist/slider.machine.d.mts +2 -7
- package/dist/slider.machine.d.ts +2 -7
- package/dist/slider.machine.js +322 -367
- package/dist/slider.machine.mjs +317 -350
- package/dist/slider.props.d.mts +7 -12
- package/dist/slider.props.d.ts +7 -12
- package/dist/slider.props.js +45 -73
- package/dist/slider.props.mjs +35 -42
- package/dist/slider.style.d.mts +15 -17
- package/dist/slider.style.d.ts +15 -17
- package/dist/slider.style.js +126 -156
- package/dist/slider.style.mjs +114 -123
- package/dist/slider.types.d.mts +307 -309
- package/dist/slider.types.d.ts +307 -309
- package/dist/slider.types.js +4 -18
- package/dist/slider.types.mjs +1 -0
- package/dist/slider.utils.d.mts +18 -21
- package/dist/slider.utils.d.ts +18 -21
- package/dist/slider.utils.js +144 -168
- package/dist/slider.utils.mjs +132 -135
- package/package.json +8 -8
package/dist/slider.dom.d.mts
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Point } from
|
|
3
|
-
import { SliderSchema } from
|
|
4
|
-
|
|
5
|
-
declare const
|
|
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
|
|
20
|
-
declare const
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
|
|
1
|
+
import { Params, Scope } from "@zag-js/core";
|
|
2
|
+
import { Point } from "@zag-js/types";
|
|
3
|
+
import { SliderSchema } from "./slider.types.mjs";
|
|
4
|
+
export declare const getRootId: (ctx: Scope) => any;
|
|
5
|
+
export declare const getThumbId: (ctx: Scope, index: number) => any;
|
|
6
|
+
export declare const getHiddenInputId: (ctx: Scope, index: number) => any;
|
|
7
|
+
export declare const getControlId: (ctx: Scope) => any;
|
|
8
|
+
export declare const getTrackId: (ctx: Scope) => any;
|
|
9
|
+
export declare const getRangeId: (ctx: Scope) => any;
|
|
10
|
+
export declare const getLabelId: (ctx: Scope) => any;
|
|
11
|
+
export declare const getValueTextId: (ctx: Scope) => any;
|
|
12
|
+
export declare const getMarkerId: (ctx: Scope, value: number) => any;
|
|
13
|
+
export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
export declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
|
|
15
|
+
export declare const getThumbEls: (ctx: Scope) => HTMLElement[];
|
|
16
|
+
export declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
|
|
17
|
+
export declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
|
|
18
|
+
export declare const getControlEl: (ctx: Scope) => HTMLElement | null;
|
|
19
|
+
export declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
|
|
20
|
+
export declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
|
|
21
|
+
export declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
|
|
22
|
+
export declare const getOffsetRect: (el: HTMLElement | undefined) => {
|
|
23
|
+
left: number;
|
|
24
|
+
top: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
package/dist/slider.dom.d.ts
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Point } from
|
|
3
|
-
import { SliderSchema } from
|
|
4
|
-
|
|
5
|
-
declare const
|
|
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
|
|
20
|
-
declare const
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
|
|
1
|
+
import { Params, Scope } from "@zag-js/core";
|
|
2
|
+
import { Point } from "@zag-js/types";
|
|
3
|
+
import { SliderSchema } from "./slider.types.js";
|
|
4
|
+
export declare const getRootId: (ctx: Scope) => any;
|
|
5
|
+
export declare const getThumbId: (ctx: Scope, index: number) => any;
|
|
6
|
+
export declare const getHiddenInputId: (ctx: Scope, index: number) => any;
|
|
7
|
+
export declare const getControlId: (ctx: Scope) => any;
|
|
8
|
+
export declare const getTrackId: (ctx: Scope) => any;
|
|
9
|
+
export declare const getRangeId: (ctx: Scope) => any;
|
|
10
|
+
export declare const getLabelId: (ctx: Scope) => any;
|
|
11
|
+
export declare const getValueTextId: (ctx: Scope) => any;
|
|
12
|
+
export declare const getMarkerId: (ctx: Scope, value: number) => any;
|
|
13
|
+
export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
export declare const getThumbEl: (ctx: Scope, index: number) => HTMLElement | null;
|
|
15
|
+
export declare const getThumbEls: (ctx: Scope) => HTMLElement[];
|
|
16
|
+
export declare const getFirstThumbEl: (ctx: Scope) => HTMLElement;
|
|
17
|
+
export declare const getHiddenInputEl: (ctx: Scope, index: number) => HTMLInputElement | null;
|
|
18
|
+
export declare const getControlEl: (ctx: Scope) => HTMLElement | null;
|
|
19
|
+
export declare const getRangeEl: (ctx: Scope) => HTMLElement | null;
|
|
20
|
+
export declare const getPointValue: (params: Params<SliderSchema>, point: Point) => number | undefined;
|
|
21
|
+
export declare const dispatchChangeEvent: (ctx: Scope, value: number[]) => void;
|
|
22
|
+
export declare const getOffsetRect: (el: HTMLElement | undefined) => {
|
|
23
|
+
left: number;
|
|
24
|
+
top: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
package/dist/slider.dom.js
CHANGED
|
@@ -1,144 +1,100 @@
|
|
|
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/slider.dom.ts
|
|
21
|
-
var slider_dom_exports = {};
|
|
22
|
-
__export(slider_dom_exports, {
|
|
23
|
-
dispatchChangeEvent: () => dispatchChangeEvent,
|
|
24
|
-
getControlEl: () => getControlEl,
|
|
25
|
-
getControlId: () => getControlId,
|
|
26
|
-
getFirstThumbEl: () => getFirstThumbEl,
|
|
27
|
-
getHiddenInputEl: () => getHiddenInputEl,
|
|
28
|
-
getHiddenInputId: () => getHiddenInputId,
|
|
29
|
-
getLabelId: () => getLabelId,
|
|
30
|
-
getMarkerId: () => getMarkerId,
|
|
31
|
-
getOffsetRect: () => getOffsetRect,
|
|
32
|
-
getPointValue: () => getPointValue,
|
|
33
|
-
getRangeEl: () => getRangeEl,
|
|
34
|
-
getRangeId: () => getRangeId,
|
|
35
|
-
getRootEl: () => getRootEl,
|
|
36
|
-
getRootId: () => getRootId,
|
|
37
|
-
getThumbEl: () => getThumbEl,
|
|
38
|
-
getThumbEls: () => getThumbEls,
|
|
39
|
-
getThumbId: () => getThumbId,
|
|
40
|
-
getTrackId: () => getTrackId,
|
|
41
|
-
getValueTextId: () => getValueTextId
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
42
4
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const isVertical = orientation === "vertical";
|
|
65
|
-
return isContain ? (isVertical ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
|
|
5
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
6
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
7
|
+
// src/slider.dom.ts
|
|
8
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
|
|
9
|
+
const getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
|
|
10
|
+
const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
|
|
11
|
+
const getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
|
|
12
|
+
const getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
|
|
13
|
+
const getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
|
|
14
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
|
|
15
|
+
const getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
|
|
16
|
+
const getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
|
|
17
|
+
const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
18
|
+
const getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
|
|
19
|
+
const getThumbEls = (ctx) => (0, _zag_js_dom_query.queryAll)(getControlEl(ctx), "[role=slider]");
|
|
20
|
+
const getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
|
|
21
|
+
const getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
|
|
22
|
+
const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
23
|
+
const getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
|
|
24
|
+
const getThumbInset = (thumbSize, thumbAlignment, orientation) => {
|
|
25
|
+
return thumbAlignment === "contain" ? (orientation === "vertical" ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
|
|
66
26
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
inverted: { y: true }
|
|
82
|
-
});
|
|
83
|
-
return (0, import_utils.getPercentValue)(percent, prop("min"), prop("max"), prop("step"));
|
|
27
|
+
const getPointValue = (params, point) => {
|
|
28
|
+
const { context, prop, scope, refs } = params;
|
|
29
|
+
const controlEl = getControlEl(scope);
|
|
30
|
+
if (!controlEl) return;
|
|
31
|
+
const offset = refs.get("thumbDragOffset");
|
|
32
|
+
const percent = getRelativePointWithInset({
|
|
33
|
+
x: point.x - (offset?.x ?? 0),
|
|
34
|
+
y: point.y - (offset?.y ?? 0)
|
|
35
|
+
}, controlEl, getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"))).getPercentValue({
|
|
36
|
+
orientation: prop("orientation"),
|
|
37
|
+
dir: prop("dir"),
|
|
38
|
+
inverted: { y: true }
|
|
39
|
+
});
|
|
40
|
+
return (0, _zag_js_utils.getPercentValue)(percent, prop("min"), prop("max"), prop("step"));
|
|
84
41
|
};
|
|
85
42
|
function getRelativePointWithInset(point, element, inset) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
43
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
44
|
+
const effectiveWidth = width - inset * 2;
|
|
45
|
+
const effectiveHeight = height - inset * 2;
|
|
46
|
+
const effectiveLeft = left + inset;
|
|
47
|
+
const effectiveTop = top + inset;
|
|
48
|
+
const offset = {
|
|
49
|
+
x: point.x - effectiveLeft,
|
|
50
|
+
y: point.y - effectiveTop
|
|
51
|
+
};
|
|
52
|
+
const percent = {
|
|
53
|
+
x: effectiveWidth > 0 ? (0, _zag_js_utils.clampPercent)(offset.x / effectiveWidth) : 0,
|
|
54
|
+
y: effectiveHeight > 0 ? (0, _zag_js_utils.clampPercent)(offset.y / effectiveHeight) : 0
|
|
55
|
+
};
|
|
56
|
+
function getPercentValue(options = {}) {
|
|
57
|
+
const { dir = "ltr", orientation = "horizontal", inverted } = options;
|
|
58
|
+
const invertX = typeof inverted === "object" ? inverted.x : inverted;
|
|
59
|
+
const invertY = typeof inverted === "object" ? inverted.y : inverted;
|
|
60
|
+
if (orientation === "horizontal") return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
|
|
61
|
+
return invertY ? 1 - percent.y : percent.y;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
offset,
|
|
65
|
+
percent,
|
|
66
|
+
getPercentValue
|
|
67
|
+
};
|
|
109
68
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
69
|
+
const dispatchChangeEvent = (ctx, value) => {
|
|
70
|
+
value.forEach((value, index) => {
|
|
71
|
+
const inputEl = getHiddenInputEl(ctx, index);
|
|
72
|
+
if (!inputEl) return;
|
|
73
|
+
(0, _zag_js_dom_query.dispatchInputValueEvent)(inputEl, { value });
|
|
74
|
+
});
|
|
116
75
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
123
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
-
0 && (module.exports = {
|
|
125
|
-
dispatchChangeEvent,
|
|
126
|
-
getControlEl,
|
|
127
|
-
getControlId,
|
|
128
|
-
getFirstThumbEl,
|
|
129
|
-
getHiddenInputEl,
|
|
130
|
-
getHiddenInputId,
|
|
131
|
-
getLabelId,
|
|
132
|
-
getMarkerId,
|
|
133
|
-
getOffsetRect,
|
|
134
|
-
getPointValue,
|
|
135
|
-
getRangeEl,
|
|
136
|
-
getRangeId,
|
|
137
|
-
getRootEl,
|
|
138
|
-
getRootId,
|
|
139
|
-
getThumbEl,
|
|
140
|
-
getThumbEls,
|
|
141
|
-
getThumbId,
|
|
142
|
-
getTrackId,
|
|
143
|
-
getValueTextId
|
|
76
|
+
const getOffsetRect = (el) => ({
|
|
77
|
+
left: el?.offsetLeft ?? 0,
|
|
78
|
+
top: el?.offsetTop ?? 0,
|
|
79
|
+
width: el?.offsetWidth ?? 0,
|
|
80
|
+
height: el?.offsetHeight ?? 0
|
|
144
81
|
});
|
|
82
|
+
exports.dispatchChangeEvent = dispatchChangeEvent;
|
|
83
|
+
exports.getControlEl = getControlEl;
|
|
84
|
+
exports.getControlId = getControlId;
|
|
85
|
+
exports.getFirstThumbEl = getFirstThumbEl;
|
|
86
|
+
exports.getHiddenInputEl = getHiddenInputEl;
|
|
87
|
+
exports.getHiddenInputId = getHiddenInputId;
|
|
88
|
+
exports.getLabelId = getLabelId;
|
|
89
|
+
exports.getMarkerId = getMarkerId;
|
|
90
|
+
exports.getOffsetRect = getOffsetRect;
|
|
91
|
+
exports.getPointValue = getPointValue;
|
|
92
|
+
exports.getRangeEl = getRangeEl;
|
|
93
|
+
exports.getRangeId = getRangeId;
|
|
94
|
+
exports.getRootEl = getRootEl;
|
|
95
|
+
exports.getRootId = getRootId;
|
|
96
|
+
exports.getThumbEl = getThumbEl;
|
|
97
|
+
exports.getThumbEls = getThumbEls;
|
|
98
|
+
exports.getThumbId = getThumbId;
|
|
99
|
+
exports.getTrackId = getTrackId;
|
|
100
|
+
exports.getValueTextId = getValueTextId;
|
package/dist/slider.dom.mjs
CHANGED
|
@@ -1,101 +1,78 @@
|
|
|
1
|
-
// src/slider.dom.ts
|
|
2
1
|
import { dispatchInputValueEvent, queryAll } from "@zag-js/dom-query";
|
|
3
2
|
import { clampPercent, getPercentValue } from "@zag-js/utils";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return isContain ? (isVertical ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
|
|
3
|
+
// src/slider.dom.ts
|
|
4
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
|
|
5
|
+
const getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
|
|
6
|
+
const getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
|
|
7
|
+
const getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
|
|
8
|
+
const getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
|
|
9
|
+
const getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
|
|
10
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
|
|
11
|
+
const getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
|
|
12
|
+
const getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
|
|
13
|
+
const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
14
|
+
const getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
|
|
15
|
+
const getThumbEls = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
|
|
16
|
+
const getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
|
|
17
|
+
const getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
|
|
18
|
+
const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
19
|
+
const getRangeEl = (ctx) => ctx.getById(getRangeId(ctx));
|
|
20
|
+
const getThumbInset = (thumbSize, thumbAlignment, orientation) => {
|
|
21
|
+
return thumbAlignment === "contain" ? (orientation === "vertical" ? thumbSize?.height ?? 0 : thumbSize?.width ?? 0) / 2 : 0;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
inverted: { y: true }
|
|
40
|
-
});
|
|
41
|
-
return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
|
|
23
|
+
const getPointValue = (params, point) => {
|
|
24
|
+
const { context, prop, scope, refs } = params;
|
|
25
|
+
const controlEl = getControlEl(scope);
|
|
26
|
+
if (!controlEl) return;
|
|
27
|
+
const offset = refs.get("thumbDragOffset");
|
|
28
|
+
const percent = getRelativePointWithInset({
|
|
29
|
+
x: point.x - (offset?.x ?? 0),
|
|
30
|
+
y: point.y - (offset?.y ?? 0)
|
|
31
|
+
}, controlEl, getThumbInset(context.get("thumbSize"), prop("thumbAlignment"), prop("orientation"))).getPercentValue({
|
|
32
|
+
orientation: prop("orientation"),
|
|
33
|
+
dir: prop("dir"),
|
|
34
|
+
inverted: { y: true }
|
|
35
|
+
});
|
|
36
|
+
return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
|
|
42
37
|
};
|
|
43
38
|
function getRelativePointWithInset(point, element, inset) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
39
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
40
|
+
const effectiveWidth = width - inset * 2;
|
|
41
|
+
const effectiveHeight = height - inset * 2;
|
|
42
|
+
const effectiveLeft = left + inset;
|
|
43
|
+
const effectiveTop = top + inset;
|
|
44
|
+
const offset = {
|
|
45
|
+
x: point.x - effectiveLeft,
|
|
46
|
+
y: point.y - effectiveTop
|
|
47
|
+
};
|
|
48
|
+
const percent = {
|
|
49
|
+
x: effectiveWidth > 0 ? clampPercent(offset.x / effectiveWidth) : 0,
|
|
50
|
+
y: effectiveHeight > 0 ? clampPercent(offset.y / effectiveHeight) : 0
|
|
51
|
+
};
|
|
52
|
+
function getPercentValue(options = {}) {
|
|
53
|
+
const { dir = "ltr", orientation = "horizontal", inverted } = options;
|
|
54
|
+
const invertX = typeof inverted === "object" ? inverted.x : inverted;
|
|
55
|
+
const invertY = typeof inverted === "object" ? inverted.y : inverted;
|
|
56
|
+
if (orientation === "horizontal") return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
|
|
57
|
+
return invertY ? 1 - percent.y : percent.y;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
offset,
|
|
61
|
+
percent,
|
|
62
|
+
getPercentValue
|
|
63
|
+
};
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
const dispatchChangeEvent = (ctx, value) => {
|
|
66
|
+
value.forEach((value, index) => {
|
|
67
|
+
const inputEl = getHiddenInputEl(ctx, index);
|
|
68
|
+
if (!inputEl) return;
|
|
69
|
+
dispatchInputValueEvent(inputEl, { value });
|
|
70
|
+
});
|
|
74
71
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
const getOffsetRect = (el) => ({
|
|
73
|
+
left: el?.offsetLeft ?? 0,
|
|
74
|
+
top: el?.offsetTop ?? 0,
|
|
75
|
+
width: el?.offsetWidth ?? 0,
|
|
76
|
+
height: el?.offsetHeight ?? 0
|
|
80
77
|
});
|
|
81
|
-
export {
|
|
82
|
-
dispatchChangeEvent,
|
|
83
|
-
getControlEl,
|
|
84
|
-
getControlId,
|
|
85
|
-
getFirstThumbEl,
|
|
86
|
-
getHiddenInputEl,
|
|
87
|
-
getHiddenInputId,
|
|
88
|
-
getLabelId,
|
|
89
|
-
getMarkerId,
|
|
90
|
-
getOffsetRect,
|
|
91
|
-
getPointValue,
|
|
92
|
-
getRangeEl,
|
|
93
|
-
getRangeId,
|
|
94
|
-
getRootEl,
|
|
95
|
-
getRootId,
|
|
96
|
-
getThumbEl,
|
|
97
|
-
getThumbEls,
|
|
98
|
-
getThumbId,
|
|
99
|
-
getTrackId,
|
|
100
|
-
getValueTextId
|
|
101
|
-
};
|
|
78
|
+
export { dispatchChangeEvent, getControlEl, getControlId, getFirstThumbEl, getHiddenInputEl, getHiddenInputId, getLabelId, getMarkerId, getOffsetRect, getPointValue, getRangeEl, getRangeId, getRootEl, getRootId, getThumbEl, getThumbEls, getThumbId, getTrackId, getValueTextId };
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const machine: _zag_js_core.Machine<SliderSchema>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { SliderSchema } from "./slider.types.mjs";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<SliderSchema>;
|
package/dist/slider.machine.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const machine: _zag_js_core.Machine<SliderSchema>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { SliderSchema } from "./slider.types.js";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<SliderSchema>;
|